Repository navigation
Expand file tree
/
Copy pathmain.cpp
More file actions
95 lines (64 loc) · 2.65 KB
/
Copy pathmain.cpp
File metadata and controls
95 lines (64 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <cpprest/http_listener.h>
using namespace web;
using namespace web::http;
using namespace web::http::experimental::listener;
#include <iostream>
#include <utility>
#include <string>
#include "cpprestsdk/cpprestsdkController.hpp"
#include "data/student.hpp"
#include <map>
#include "service/studentregistryservice.hpp"
#include "pistacheLib/pistacheController.h"
#include "pistache/endpoint.h"
#include "crow/crowController.h"
#include "oatpp/web/server/HttpConnectionHandler.hpp"
#include "oatpp/oatppController.h"
#include "oatpp/network/Server.hpp"
#include "oatpp/network/tcp/server/ConnectionProvider.hpp"
void startCppRestSdk(Studentregistryservice srs){
cpprestsdkController controller(srs);
controller.createServer();
controller.openListeners();
controller.openServer().then([&controller](){std::cout << "started";}).wait();
while(true);
}
void startPistache(Studentregistryservice srs){
pistacheController app({"192.168.0.28", 10011},srs);
app.init(Pistache::Http::Endpoint::options().threads(std::thread::hardware_concurrency()));
app.serve();
}
void startCrow(Studentregistryservice srs){
crowController controller(srs);
controller.setupServer();
}
void startOatpp(Studentregistryservice srs){
oatpp::base::Environment::init();
/* Create Router for HTTP requests routing */
auto router = oatpp::web::server::HttpRouter::createShared();
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::data::mapping::ObjectMapper>, apiObjectMapper)([] {
auto objectMapper = oatpp::parser::json::mapping::ObjectMapper::createShared();
objectMapper->getDeserializer()->getConfig()->allowUnknownFields = false;
return objectMapper;
}());
router->addController(std::make_shared<oatppController>());
/* Create HTTP connection handler with router */
auto connectionHandler = oatpp::web::server::HttpConnectionHandler::createShared(router);
/* Create TCP connection provider */
auto connectionProvider = oatpp::network::tcp::server::ConnectionProvider::createShared({"192.168.0.28", 8010, oatpp::network::Address::IP_4});
/* Create server which takes provided TCP connections and passes them to HTTP connection handler */
oatpp::network::Server server(connectionProvider, connectionHandler);
/* Print info about server port */
OATPP_LOGI("MyApp", "Server running on port %s", connectionProvider->getProperty("port").getData());
/* Run server */
server.run();
oatpp::base::Environment::destroy();
}
int main(int argc, char** argv)
{
Studentregistryservice srs;
//startCrow(srs);
startPistache(srs);
//startCppRestSdk(srs);
//startOatpp(srs);
}