Kea 2.5.9
d_process.h
Go to the documentation of this file.
1// Copyright (C) 2013-2024 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
17
18#include <atomic>
19
20namespace isc {
21namespace process {
22
25public:
26 DProcessBaseError(const char* file, size_t line, const char* what) :
27 isc::Exception(file, line, what) { };
28};
29
31static const std::string VERSION_GET_COMMAND("version-get");
32
34static const std::string BUILD_REPORT_COMMAND("build-report");
35
37static const std::string CONFIG_GET_COMMAND("config-get");
38
40static const std::string CONFIG_HASH_GET_COMMAND("config-hash-get");
41
43static const std::string CONFIG_WRITE_COMMAND("config-write");
44
46static const std::string CONFIG_TEST_COMMAND("config-test");
47
49static const std::string CONFIG_RELOAD_COMMAND("config-reload");
50
52static const std::string CONFIG_SET_COMMAND("config-set");
53
55static const std::string SERVER_TAG_GET_COMMAND("server-tag-get");
56
58static const std::string SHUT_DOWN_COMMAND("shutdown");
59
61static const std::string STATUS_GET_COMMAND("status-get");
62
76public:
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
129
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
177 return (io_service_);
178 }
179
185 io_service_->stop();
186 }
187
192 return (cfg_mgr_);
193 }
194
195private:
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
211typedef boost::shared_ptr<DProcessBase> DProcessBasePtr;
212
213} // namespace process
214} // namespace isc
215
216#endif
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Exception thrown if the process encountered an operational error.
Definition: d_process.h:24
DProcessBaseError(const char *file, size_t line, const char *what)
Definition: d_process.h:26
Application Process Interface.
Definition: d_process.h:75
virtual void init()=0
May be used after instantiation to perform initialization unique to application.
void setShutdownFlag(bool value)
Sets the process shut down flag to the given value.
Definition: d_process.h:162
DProcessBase(const char *app_name, asiolink::IOServicePtr io_service, DCfgMgrBasePtr cfg_mgr)
Constructor.
Definition: d_process.h:87
void stopIOService()
Convenience method for stopping IOservice processing.
Definition: d_process.h:184
virtual isc::data::ConstElementPtr shutdown(isc::data::ConstElementPtr args)=0
Initiates the process's shutdown process.
const std::string getAppName() const
Fetches the application name.
Definition: d_process.h:169
virtual ~DProcessBase()
Destructor.
Definition: d_process.h:148
virtual void run()=0
Implements the process's event loop.
bool shouldShutdown() const
Checks if the process has been instructed to shut down.
Definition: d_process.h:155
asiolink::IOServicePtr & getIOService()
Fetches the controller's IOService.
Definition: d_process.h:176
virtual isc::data::ConstElementPtr configure(isc::data::ConstElementPtr config_set, bool check_only=false)=0
Processes the given configuration.
DCfgMgrBasePtr & getCfgMgr()
Fetches the process's configuration manager.
Definition: d_process.h:191
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:29
boost::shared_ptr< DCfgMgrBase > DCfgMgrBasePtr
Defines a shared pointer to DCfgMgrBase.
Definition: d_cfg_mgr.h:247
boost::shared_ptr< DProcessBase > DProcessBasePtr
Defines a shared pointer to DProcessBase.
Definition: d_process.h:211
Defines the logger used by the top-level component of kea-lfc.