| Kea 3.0.2-git

d_process.h
Go to the documentation of this file.
1// Copyright (C) 2013-2025 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef D_PROCESS_H
8#define D_PROCESS_H
9
10#include <asiolink/io_service.h>
11#include <cc/data.h>
12#include <process/d_cfg_mgr.h>
13
14#include <boost/shared_ptr.hpp>
15
16#include <exceptions/exceptions.h>
17
18#include <atomic>
19
20 namespace isc {
21 namespace process {
22
24 class DProcessBaseError : public isc::Exception {
25 public:
26 DProcessBaseError(const char* file, size_t line, const char* what) :
27 isc::Exception(file, line, what) { }
28};
29
31 static const std::string VERSION_GET_COMMAND("version-get");
32
34 static const std::string BUILD_REPORT_COMMAND("build-report");
35
37 static const std::string CONFIG_GET_COMMAND("config-get");
38
40 static const std::string CONFIG_HASH_GET_COMMAND("config-hash-get");
41
43 static const std::string CONFIG_WRITE_COMMAND("config-write");
44
46 static const std::string CONFIG_TEST_COMMAND("config-test");
47
49 static const std::string CONFIG_RELOAD_COMMAND("config-reload");
50
52 static const std::string CONFIG_SET_COMMAND("config-set");
53
55 static const std::string SERVER_TAG_GET_COMMAND("server-tag-get");
56
58 static const std::string SHUT_DOWN_COMMAND("shutdown");
59
61 static const std::string STATUS_GET_COMMAND("status-get");
62
75 class DProcessBase {
76 public:
87 DProcessBase(const char* app_name, asiolink::IOServicePtr io_service,
88 DCfgMgrBasePtr cfg_mgr)
89 : app_name_(app_name), io_service_(io_service), shut_down_flag_(false),
90 cfg_mgr_(cfg_mgr) {
91 if (!io_service_) {
92 isc_throw (DProcessBaseError, "IO Service cannot be null");
93 }
94
95 if (!cfg_mgr_) {
96 isc_throw (DProcessBaseError, "CfgMgr cannot be null");
97 }
98 }
99
105 virtual void init() = 0;
106
112 virtual void run() = 0;
113
127 virtual isc::data::ConstElementPtr
128 shutdown(isc::data::ConstElementPtr args) = 0;
129
143 virtual isc::data::ConstElementPtr
144 configure(isc::data::ConstElementPtr config_set,
145 bool check_only = false) = 0;
146
148 virtual ~DProcessBase() {
149 io_service_->stopAndPoll();
150 }
151
155 bool shouldShutdown() const {
156 return (shut_down_flag_);
157 }
158
162 void setShutdownFlag(bool value) {
163 shut_down_flag_ = value;
164 }
165
169 const std::string getAppName() const {
170 return (app_name_);
171 }
172
176 asiolink::IOServicePtr& getIOService() {
177 return (io_service_);
178 }
179
184 void stopIOService() {
185 io_service_->stop();
186 }
187
191 DCfgMgrBasePtr& getCfgMgr() {
192 return (cfg_mgr_);
193 }
194
195 private:
198 std::string app_name_;
199
201 asiolink::IOServicePtr io_service_;
202
204 std::atomic<bool> shut_down_flag_;
205
207 DCfgMgrBasePtr cfg_mgr_;
208};
209
211 typedef boost::shared_ptr<DProcessBase> DProcessBasePtr;
212
213} // namespace process
214} // namespace isc
215
216#endif
isc::Exception
This is a base class for exceptions thrown from the DNS library module.
Definition exceptions/exceptions.h:23
isc::Exception::Exception
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
Definition exceptions/exceptions.cc:17
isc::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition exceptions/exceptions.cc:32
isc::process::DProcessBaseError
Exception thrown if the process encountered an operational error.
Definition d_process.h:24
isc::process::DProcessBaseError::DProcessBaseError
DProcessBaseError(const char *file, size_t line, const char *what)
Definition d_process.h:26
isc::process::DProcessBase::init
virtual void init()=0
May be used after instantiation to perform initialization unique to application.
isc::process::DProcessBase::setShutdownFlag
void setShutdownFlag(bool value)
Sets the process shut down flag to the given value.
Definition d_process.h:162
isc::process::DProcessBase::DProcessBase
DProcessBase(const char *app_name, asiolink::IOServicePtr io_service, DCfgMgrBasePtr cfg_mgr)
Constructor.
Definition d_process.h:87
isc::process::DProcessBase::stopIOService
void stopIOService()
Convenience method for stopping IOservice processing.
Definition d_process.h:184
isc::process::DProcessBase::shutdown
virtual isc::data::ConstElementPtr shutdown(isc::data::ConstElementPtr args)=0
Initiates the process's shutdown process.
isc::process::DProcessBase::getAppName
const std::string getAppName() const
Fetches the application name.
Definition d_process.h:169
isc::process::DProcessBase::~DProcessBase
virtual ~DProcessBase()
Destructor.
Definition d_process.h:148
isc::process::DProcessBase::run
virtual void run()=0
Implements the process's event loop.
isc::process::DProcessBase::shouldShutdown
bool shouldShutdown() const
Checks if the process has been instructed to shut down.
Definition d_process.h:155
isc::process::DProcessBase::getIOService
asiolink::IOServicePtr & getIOService()
Fetches the controller's IOService.
Definition d_process.h:176
isc::process::DProcessBase::configure
virtual isc::data::ConstElementPtr configure(isc::data::ConstElementPtr config_set, bool check_only=false)=0
Processes the given configuration.
isc::process::DProcessBase::getCfgMgr
DCfgMgrBasePtr & getCfgMgr()
Fetches the process's configuration manager.
Definition d_process.h:191
d_cfg_mgr.h
data.h
exceptions.h
isc_throw
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition exceptions/exceptions.h:210
io_service.h
isc::asiolink::IOServicePtr
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
Definition io_service.h:28
isc::data::ConstElementPtr
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
isc::process
Definition cb_ctl_base.h:22
isc::process::DCfgMgrBasePtr
boost::shared_ptr< DCfgMgrBase > DCfgMgrBasePtr
Defines a shared pointer to DCfgMgrBase.
Definition d_cfg_mgr.h:247
isc::process::DProcessBasePtr
boost::shared_ptr< DProcessBase > DProcessBasePtr
Defines a shared pointer to DProcessBase.
Definition d_process.h:211
isc
Defines the logger used by the top-level component of kea-lfc.
Definition agent_parser.cc:148