lintel 0.2.0
Loading...
Searching...
No Matches
AbstractService.h
Go to the documentation of this file.
1#ifndef LOGGING_ABSTRACTSERVICE_H
2#define LOGGING_ABSTRACTSERVICE_H
3
5#include <memory>
6#include <ostream>
7#include <string>
8#include <utility>
9#include <vector>
10
12namespace lintel {
13class PropertyBase;
14
15class PropertyService;
16
19{
20public:
22 virtual void onInitialize() = 0;
23
25 virtual void onShutdown() = 0;
26
30
33 virtual std::string_view getClassName() const = 0;
34
37 virtual const std::string &getProcessName() const = 0;
38
41 virtual const std::string &getInstanceName() const = 0;
42
43 virtual ~AbstractServiceInterface() = default;
44
45private:
46 virtual std::vector<std::shared_ptr<PropertyBase>> getProperties() = 0;
47
48 friend class PropertyService;
49};
50
57template<class T> class AbstractService : public AbstractServiceInterface
58{
59private:
60 const std::string m_processName;
61 const std::string m_instanceName;
62
63 std::vector<std::shared_ptr<PropertyBase>> getProperties() override { return m_properties; }
64
65protected:
66 std::vector<std::shared_ptr<PropertyBase>> m_properties;
67
68public:
69 AbstractService() = delete;
70
74 AbstractService(std::string processName, std::string instanceName)
75 : m_processName(std::move(processName)), m_instanceName(std::move(instanceName))
76 {}
77
80 explicit AbstractService(std::string processName) : m_processName(std::move(processName)), m_instanceName("__DEFAULT")
81 {}
82
84 void onInitialize() override {}
85
87 void onShutdown() override {}
88
92
95 [[nodiscard]] const std::string &getProcessName() const override { return m_processName; }
96
99 [[nodiscard]] const std::string &getInstanceName() const override { return m_instanceName; }
100
103 [[nodiscard]] std::string_view getClassName() const override { return type_name<T>(); }
104
105 friend std::ostream &operator<<(std::ostream &os, const AbstractService &service)
106 {
107 os << "processName: " << service.m_processName << " instanceName: " << service.m_instanceName
108 << " className: " << service.getClassName();
109 return os;
110 }
111};
112
113}// namespace lintel
114#endif// LOGGING_ABSTRACTSERVICE_H
Definition AbstractService.h:19
virtual ShutdownPriority shutdownPriorityOf() const =0
virtual const std::string & getInstanceName() const =0
virtual std::string_view getClassName() const =0
virtual const std::string & getProcessName() const =0
virtual ~AbstractServiceInterface()=default
Definition AbstractService.h:58
void onShutdown() override
Definition AbstractService.h:87
friend std::ostream & operator<<(std::ostream &os, const AbstractService &service)
Definition AbstractService.h:105
std::vector< std::shared_ptr< PropertyBase > > m_properties
Definition AbstractService.h:66
ShutdownPriority shutdownPriorityOf() const override
Definition AbstractService.h:91
const std::string & getProcessName() const override
Definition AbstractService.h:95
const std::string & getInstanceName() const override
Definition AbstractService.h:99
AbstractService(std::string processName, std::string instanceName)
Definition AbstractService.h:74
std::string_view getClassName() const override
Definition AbstractService.h:103
AbstractService(std::string processName)
Definition AbstractService.h:80
void onInitialize() override
Definition AbstractService.h:84
Definition PropertyService.h:31
Definition BaseFeature.h:6
ShutdownPriority
Definition ShutdownPriority.h:8
@ DEFAULT
Definition ShutdownPriority.h:9
constexpr std::string_view type_name()
Definition TypeName.h:9