-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
101 lines (69 loc) · 3.11 KB
/
main.cpp
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
93
94
95
96
97
98
99
100
101
#include <iostream>
#include "oatpp-swagger/Controller.hpp"
#include "rest_api/AppComponent.h"
#include <rest_api/ImageController.h>
#include <rest_api/MediaController.h>
#include "oatpp/network/Server.hpp"
#include <iostream>
#include <core/DependencyInjector.h>
#include <rest_api/VideoController.h>
void init_imagerepo(shared_ptr<DependencyInjector> di){
string fileName = "test.db";
di->install_data_base(fileName);
di->install_multimedia_repo(di);
di->install_image_repo(di);
di->install_video_repo(di);
di->install_vlc_wrapper();
auto db = di->get_data_base(di);
db->init_db();
auto multimedia_repo = di->get_multimedia_repo(di);
Multimedia::install_repo(multimedia_repo);
auto image_repo = di->get_image_repo(di);
Image::install_repo(image_repo);
auto video_repo = di->get_video_repo(di);
Video::install_repo(video_repo);
}
void run(shared_ptr<DependencyInjector> di) {
AppComponent components; // Create scope Environment components
/* create ApiControllers and add endpoints to router */
shared_ptr<oatpp::web::server::HttpRouter> router = components.httpRouter.getObject();
oatpp::web::server::api::Endpoints endpoints;
auto imageController = VideoController::createShared();
router->addController(imageController);
endpoints.append(imageController->getEndpoints());
auto videoController = ImageController::createShared();
router->addController(videoController);
endpoints.append(videoController->getEndpoints());
auto mediaController = MediaController::createShared();
router->addController(mediaController);
mediaController->setVlc(di->get_vlc_wrapper(di));
mediaController->setDi(di);
endpoints.append(mediaController->getEndpoints());
auto swaggerController = oatpp::swagger::Controller::createShared(endpoints);
router->addController(swaggerController);
/* Get connection handler component */
OATPP_COMPONENT(std::shared_ptr<oatpp::network::ConnectionHandler>, connectionHandler);
/* Get connection provider component */
OATPP_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>, connectionProvider);
/* create server */
oatpp::network::Server server(connectionProvider,
connectionHandler);
OATPP_LOGD("Server", "Running on port %s...", connectionProvider->getProperty("port").toString()->c_str());
server.run();
}
/**
* main
*/
int main(int argc, const char * argv[]) {
shared_ptr<DependencyInjector> di = make_shared<DependencyInjector> ();
init_imagerepo(di);
oatpp::base::Environment::init();
run(di);
/* Print how much objects were created during app running, and what have left-probably leaked */
/* Disable object counting for release builds using '-D OATPP_DISABLE_ENV_OBJECT_COUNTERS' flag for better performance */
std::cout << "\nEnvironment:\n";
std::cout << "objectsCount = " << oatpp::base::Environment::getObjectsCount() << "\n";
std::cout << "objectsCreated = " << oatpp::base::Environment::getObjectsCreated() << "\n\n";
oatpp::base::Environment::destroy();
return 0;
}