Kea 1.5.0
d_process.h
Go to the documentation of this file.
1// Copyright (C) 2013-2018 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
18namespace isc {
19namespace process {
20
23public:
24 DProcessBaseError(const char* file, size_t line, const char* what) :
25 isc::Exception(file, line, what) { };
26};
27
29static const std::string VERSION_GET_COMMAND("version-get");
30
32static const std::string BUILD_REPORT_COMMAND("build-report");
33
35static const std::string CONFIG_GET_COMMAND("config-get");
36
38static const std::string CONFIG_WRITE_COMMAND("config-write");
39
41static const std::string CONFIG_TEST_COMMAND("config-test");
42
44static const std::string SHUT_DOWN_COMMAND("shutdown");
45
47static const int COMMAND_SUCCESS = 0;
48
50static const int COMMAND_ERROR = 1;
51
53static const int COMMAND_INVALID = 2;
54
68public:
79 DProcessBase(const char* app_name, asiolink::IOServicePtr io_service,
80 DCfgMgrBasePtr cfg_mgr)
81 : app_name_(app_name), io_service_(io_service), shut_down_flag_(false),
82 cfg_mgr_(cfg_mgr) {
83 if (!io_service_) {
84 isc_throw (DProcessBaseError, "IO Service cannot be null");
85 }
86
87 if (!cfg_mgr_) {
88 isc_throw (DProcessBaseError, "CfgMgr cannot be null");
89 }
90 };
91
97 virtual void init() = 0;
98
104 virtual void run() = 0;
105
121
137 bool check_only = false) = 0;
138
140 virtual ~DProcessBase(){};
141
145 bool shouldShutdown() const {
146 return (shut_down_flag_);
147 }
148
152 void setShutdownFlag(bool value) {
153 shut_down_flag_ = value;
154 }
155
159 const std::string getAppName() const {
160 return (app_name_);
161 }
162
167 return (io_service_);
168 }
169
175 io_service_->stop();
176 }
177
182 return (cfg_mgr_);
183 }
184
185private:
188 std::string app_name_;
189
191 asiolink::IOServicePtr io_service_;
192
194 bool shut_down_flag_;
195
197 DCfgMgrBasePtr cfg_mgr_;
198};
199
201typedef boost::shared_ptr<DProcessBase> DProcessBasePtr;
202
203}; // namespace isc::process
204}; // namespace isc
205
206#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:22
DProcessBaseError(const char *file, size_t line, const char *what)
Definition: d_process.h:24
Application Process Interface.
Definition: d_process.h:67
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:152
DProcessBase(const char *app_name, asiolink::IOServicePtr io_service, DCfgMgrBasePtr cfg_mgr)
Constructor.
Definition: d_process.h:79
void stopIOService()
Convenience method for stopping IOservice processing.
Definition: d_process.h:174
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:166
const std::string getAppName() const
Fetches the application name.
Definition: d_process.h:159
virtual ~DProcessBase()
Destructor.
Definition: d_process.h:140
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:145
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:181
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:23
boost::shared_ptr< DCfgMgrBase > DCfgMgrBasePtr
Defines a shared pointer to DCfgMgrBase.
Definition: d_cfg_mgr.h:219
boost::shared_ptr< DProcessBase > DProcessBasePtr
Defines a shared pointer to DProcessBase.
Definition: d_process.h:201
Defines the logger used by the top-level component of kea-dhcp-ddns.