PageRenderTime 26ms CodeModel.GetById 20ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/include/nebu-app-framework/vmManager.h

https://github.com/deltaforge/nebu-app-framework-cpp
C Header | 81 lines | 44 code | 15 blank | 22 comment | 0 complexity | ea8f2bf178e78a6dafc22be4e18befcf MD5 | raw file
 1
 2#ifndef NEBUAPPFRAMEWORK_VMMANAGER_H_
 3#define NEBUAPPFRAMEWORK_VMMANAGER_H_
 4
 5#include "nebu-app-framework/vmEventHandler.h"
 6
 7#include "nebu/appVirtRequest.h"
 8#include "nebu/virtualMachine.h"
 9
10#include <list>
11#include <memory>
12#include <string>
13#include <unordered_map>
14#include <vector>
15
16namespace nebu
17{
18	namespace app
19	{
20		namespace framework
21		{
22
23			/** Manages the list and states of VirtualMachines in the application. */
24			class VMManager
25			{
26			public:
27				/** Creates a VMManager using the given connection to the Nebu middleware.
28				 *  @param[in] appVirtRequest a connection to the Nebu middleware for the AppVirtRequest.
29				 */
30				VMManager(std::shared_ptr<nebu::common::AppVirtRequest> appVirtRequest) :
31					vmEventHandlers(), appVirtRequest(appVirtRequest), vmList() { }
32				/** Empty destructor provided for inheritance. */
33				virtual ~VMManager() { }
34
35				/** Refreshes the list of VMs and detects any changes in that list.
36				 *  @return true iff no exceptions occured in contacting the middleware.
37				 */
38				virtual bool refreshVMList();
39
40				/** Retrieves a list of all VirtualMachines known to the VMManager.
41				 *  @return a vector of VirtualMachines.
42				 */
43				virtual std::vector<std::shared_ptr<nebu::common::VirtualMachine>> getVMs() const;
44				/** Retrieves a single VirtualMachine by its unique identifier.
45				 *  @param[in] uuid the unique ID of the VM.
46				 *  @return the VirtualMachine.
47				 */
48				virtual std::shared_ptr<nebu::common::VirtualMachine> getVM(const std::string &uuid) const;
49				/** Checks if a VirtualMachine with the given identifier exists.
50				 *	@return true iff the VirtualMachine exists.
51				 */
52				virtual bool hasVM(const std::string &uuid) const;
53
54				/** Registers a VMEventHandler, allowing it to receive notifications of events detected
55				 *  in refreshVMList().
56				 *  @param[in] eventHandler the VMEventhandler to register.
57				 */
58				virtual void registerVMEventHandler(std::shared_ptr<VMEventHandler> eventHandler);
59
60			protected:
61				void addVM(std::shared_ptr<nebu::common::VirtualMachine> vm);
62				void updateVM(std::shared_ptr<nebu::common::VirtualMachine> vm,
63						const nebu::common::VirtualMachine &updated);
64				void removeVM(std::shared_ptr<nebu::common::VirtualMachine> vm);
65
66				bool addNewVMs(std::vector<std::string> &retrievedVMIds);
67				bool updateVMs(std::vector<std::string> &filteredVMIds);
68				void removeVMs(std::vector<std::string> &retrievedVMIds);
69
70			private:
71				std::list<std::shared_ptr<VMEventHandler>> vmEventHandlers;
72				std::shared_ptr<nebu::common::AppVirtRequest> appVirtRequest;
73				std::unordered_map<std::string, std::shared_ptr<nebu::common::VirtualMachine>> vmList;
74			};
75
76		}
77	}
78}
79
80#endif
81