/src/applicationHooks.cpp

https://github.com/deltaforge/nebu-app-framework-cpp · C++ · 70 lines · 59 code · 9 blank · 2 comment · 3 complexity · 77ca2efb7e9c2a3b42d79ac79745ca54 MD5 · raw file

  1. #include "nebu-app-framework/applicationHooks.h"
  2. #include "nebu-app-framework/configuration.h"
  3. #include "nebu-app-framework/daemonCollection.h"
  4. #include "nebu-app-framework/topologyManager.h"
  5. #include "nebu-app-framework/vmManager.h"
  6. #include "nebu/appPhysRequest.h"
  7. #include "nebu/appVirtRequest.h"
  8. #include "nebu/nebuClient.h"
  9. #include "nebu/restClientAdapter.h"
  10. #include "log4cxx/basicconfigurator.h"
  11. // Using declarations - nebu-common
  12. using nebu::common::AppPhysRequest;
  13. using nebu::common::AppVirtRequest;
  14. using nebu::common::NebuClient;
  15. using nebu::common::RestClientAdapter;
  16. // Using declarations - standard library
  17. using std::make_shared;
  18. using std::shared_ptr;
  19. namespace nebu
  20. {
  21. namespace app
  22. {
  23. namespace framework
  24. {
  25. void ApplicationHooks::prepareLogging()
  26. {
  27. log4cxx::BasicConfigurator::configure();
  28. log4cxx::Logger::getRootLogger()->setLevel(log4cxx::Level::getWarn());
  29. }
  30. shared_ptr<DaemonCollection> ApplicationHooks::getDaemonCollection()
  31. {
  32. if (!this->daemonCollection) {
  33. this->daemonCollection = make_shared<DaemonCollection>();
  34. }
  35. return this->daemonCollection;
  36. }
  37. shared_ptr<TopologyManager> ApplicationHooks::getTopologyManager()
  38. {
  39. if (!this->topologyManager) {
  40. shared_ptr<NebuClient> nebuClient = make_shared<NebuClient>(RestClientAdapter::getInstance(),
  41. CONFIG_GET(CONFIG_NEBU_URL));
  42. shared_ptr<AppPhysRequest> appPhysRequest = make_shared<AppPhysRequest>(nebuClient,
  43. CONFIG_GET(CONFIG_APP_UUID));
  44. this->topologyManager = make_shared<TopologyManager>(appPhysRequest);
  45. }
  46. return this->topologyManager;
  47. }
  48. shared_ptr<VMManager> ApplicationHooks::getVMManager()
  49. {
  50. if (!this->vmManager) {
  51. shared_ptr<NebuClient> nebuClient = make_shared<NebuClient>(RestClientAdapter::getInstance(),
  52. CONFIG_GET(CONFIG_NEBU_URL));
  53. shared_ptr<AppVirtRequest> appVirtRequest = make_shared<AppVirtRequest>(nebuClient,
  54. CONFIG_GET(CONFIG_APP_UUID));
  55. this->vmManager = make_shared<VMManager>(appVirtRequest);
  56. }
  57. return this->vmManager;
  58. }
  59. }
  60. }
  61. }