PageRenderTime 9ms CodeModel.GetById 2ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

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