Kea 2.2.0
d_process.h
Go to the documentation of this file.
1// Copyright (C) 2013-2020 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_WRITE_COMMAND("config-write");
41
43static const std::string CONFIG_TEST_COMMAND("config-test");
44
46static const std::string CONFIG_RELOAD_COMMAND("config-reload");
47
49static const std::string CONFIG_SET_COMMAND("config-set");
50
52static const std::string SERVER_TAG_GET_COMMAND("server-tag-get");
53
55static const std::string SHUT_DOWN_COMMAND("shutdown");
56
58static const std::string STATUS_GET_COMMAND("status-get");
59
61static const int COMMAND_SUCCESS = 0;
62
64static const int COMMAND_ERROR = 1;
65
67static const int COMMAND_INVALID = 2;
68
82public:
93 DProcessBase(const char* app_name, asiolink::IOServicePtr io_service,
94 DCfgMgrBasePtr cfg_mgr)
95 : app_name_(app_name), io_service_(io_service), shut_down_flag_(false),
96 cfg_mgr_(cfg_mgr) {
97 if (!io_service_) {
98 isc_throw (DProcessBaseError, "IO Service cannot be null");
99 }
100
101 if (!cfg_mgr_) {
102 isc_throw (DProcessBaseError, "CfgMgr cannot be null");
103 }
104 };
105
111 virtual void init() = 0;
112
118 virtual void run() = 0;
119
135
151 bool check_only = false) = 0;
152
154 virtual ~DProcessBase(){};
155
159 bool shouldShutdown() const {
160 return (shut_down_flag_);
161 }
162
166 void setShutdownFlag(bool value) {
167 shut_down_flag_ = value;
168 }
169
173 const std::string getAppName() const {
174 return (app_name_);
175 }
176
181 return (io_service_);
182 }
183
189 io_service_->stop();
190 }
191
196 return (cfg_mgr_);
197 }
198
199private:
202 std::string app_name_;
203
205 asiolink::IOServicePtr io_service_;
206
208 std::atomic<bool> shut_down_flag_;
209
211 DCfgMgrBasePtr cfg_mgr_;
212};
213
215typedef boost::shared_ptr<DProcessBase> DProcessBasePtr;
216
217}; // namespace isc::process
218}; // namespace isc
219
220#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:81
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:166
DProcessBase(const char *app_name, asiolink::IOServicePtr io_service, DCfgMgrBasePtr cfg_mgr)
Constructor.
Definition: d_process.h:93
void stopIOService()
Convenience method for stopping IOservice processing.
Definition: d_process.h:188
virtual isc::data::ConstElementPtr shutdown(isc::data::ConstElementPtr args)=0
Initiates the process's shutdown process.
asiolink::IOServicePtr & getIoService()
Fetches the controller's IOService.
Definition: d_process.h:180
const std::string getAppName() const
Fetches the application name.
Definition: d_process.h:173
virtual ~DProcessBase()
Destructor.
Definition: d_process.h:154
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:159
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:195
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:27
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:215
Defines the logger used by the top-level component of kea-lfc.