Skip to content
Snippets Groups Projects
Commit a66cfe89 authored by kongr45gpen's avatar kongr45gpen
Browse files

Create a ServicePool that contains all Service instances

parent d8c60bdd
No related branches found
No related tags found
No related merge requests found
...@@ -18,6 +18,7 @@ add_library(common OBJECT ...@@ -18,6 +18,7 @@ add_library(common OBJECT
src/ErrorHandler.cpp src/ErrorHandler.cpp
src/Message.cpp src/Message.cpp
src/MessageParser.cpp src/MessageParser.cpp
src/ServicePool.cpp
src/Helpers/CRCHelper.cpp src/Helpers/CRCHelper.cpp
src/Helpers/TimeHelper.cpp src/Helpers/TimeHelper.cpp
src/Services/EventReportService.cpp src/Services/EventReportService.cpp
......
#ifndef ECSS_SERVICES_SERVICEPOOL_HPP
#define ECSS_SERVICES_SERVICEPOOL_HPP
#include "Services/RequestVerificationService.hpp"
#include "Services/TimeManagementService.hpp"
#include "Services/EventReportService.hpp"
#include "Services/EventActionService.hpp"
#include "Services/ParameterService.hpp"
#include "Services/TestService.hpp"
#include "Services/MemoryManagementService.hpp"
/**
* Defines a class that contains instances of all Services.
*
* All Services should be stored here and should not be instantiated in a different way.
*
* @todo Find a way to disable services which are not used
*/
class ServicePool {
public:
RequestVerificationService requestVerification;
EventReportService eventReport;
MemoryManagementService memoryManagement;
TimeManagementService timeManagement;
EventActionService eventAction;
TestService testService;
ParameterService parameterManagement;
/**
* The default ServicePool constructor
*/
ServicePool() = default;
/**
* Reset all the services and their contents/properties to the original values
*
* @note This performs the reset in-place, i.e. no new memory is allocated. As such, all
* Services already stored as values will point to the "new" Services after a reset.
*/
void reset();
};
/**
* A global variable that defines the basic pool where services can be fetched from
*/
extern ServicePool Services;
#endif //ECSS_SERVICES_SERVICEPOOL_HPP
#include "ServicePool.hpp"
ServicePool Services = ServicePool();
void ServicePool::reset() {
// Call the destructor
this->~ServicePool();
// Call the constructor
// Note the usage of "placement new" that replaces the contents of the Services variable.
// This is not dangerous usage, since all the memory that will be used for this has been
// statically allocated from before.
new (this) ServicePool();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment