|
| 1 | +// |
| 2 | +// main.cpp |
| 3 | +// web-starter-project |
| 4 | +// |
| 5 | +// Created by Leonid on 2/12/18. |
| 6 | +// Copyright © 2018 oatpp. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +//#define OATPP_USE_TARGET |
| 10 | +//#define OATPP_TARGET_TEST |
| 11 | + |
| 12 | +////////////////////////////////// |
| 13 | +// App |
| 14 | + |
| 15 | +#include "./controller/MyController.hpp" |
| 16 | +#include "./AppComponent.hpp" |
| 17 | +#include "./Logger.hpp" |
| 18 | + |
| 19 | +////////////////////////////////// |
| 20 | +// Test |
| 21 | + |
| 22 | +#ifdef OATPP_TARGET_TEST |
| 23 | +#endif |
| 24 | + |
| 25 | +////////////////////////////////// |
| 26 | +// oatpp |
| 27 | + |
| 28 | +#include "oatpp/network/server/Server.hpp" |
| 29 | + |
| 30 | +////////////////////////////////// |
| 31 | +// std |
| 32 | + |
| 33 | +#include <iostream> |
| 34 | + |
| 35 | +/** |
| 36 | + * run() method. |
| 37 | + * 1) set Environment components. |
| 38 | + * 2) add ApiController's endpoints to router |
| 39 | + * 3) run server |
| 40 | + */ |
| 41 | +void run() { |
| 42 | + |
| 43 | + AppComponent components; // Create scope Environment components |
| 44 | + |
| 45 | + /* create ApiControllers and add endpoints to router */ |
| 46 | + |
| 47 | + auto router = components.httpRouter.getObject(); |
| 48 | + |
| 49 | + auto MyController = MyController::createShared(); |
| 50 | + MyController->addEndpointsToRouter(router); |
| 51 | + |
| 52 | + /* create server */ |
| 53 | + |
| 54 | + oatpp::network::server::Server server(components.serverConnectionProvider.getObject(), |
| 55 | + components.serverConnectionHandler.getObject()); |
| 56 | + |
| 57 | + OATPP_LOGD("Server", "Running on port %s...", components.serverConnectionProvider.getObject()->getProperty("port").toString()->c_str()); |
| 58 | + |
| 59 | + server.run(); |
| 60 | + |
| 61 | +} |
| 62 | + |
| 63 | +/** |
| 64 | + * main |
| 65 | + */ |
| 66 | +int main(int argc, const char * argv[]) { |
| 67 | + |
| 68 | + oatpp::base::Environment::setLogger(new Logger()); |
| 69 | + oatpp::base::Environment::init(); |
| 70 | + |
| 71 | +#if !defined(OATPP_USE_TARGET) | defined(OATPP_TARGET_APP) |
| 72 | + run(); |
| 73 | +#endif |
| 74 | + |
| 75 | +#ifdef OATPP_TARGET_TEST |
| 76 | +#endif |
| 77 | + |
| 78 | + oatpp::base::Environment::setLogger(nullptr); ///< free Logger |
| 79 | + |
| 80 | + /* Print how much objects were created during app running, and what have left-probably leaked */ |
| 81 | + /* Disable object counting for release builds using '-D OATPP_DISABLE_ENV_OBJECT_COUNTERS' flag for better performance */ |
| 82 | + std::cout << "\nEnvironment:\n"; |
| 83 | + std::cout << "objectsCount = " << oatpp::base::Environment::getObjectsCount() << "\n"; |
| 84 | + std::cout << "objectsCreated = " << oatpp::base::Environment::getObjectsCreated() << "\n\n"; |
| 85 | + |
| 86 | + oatpp::base::Environment::destroy(); |
| 87 | + |
| 88 | + return 0; |
| 89 | +} |
0 commit comments