Kea  2.1.7-git
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 
16 #include <exceptions/exceptions.h>
17 
18 #include <atomic>
19 
20 namespace isc {
21 namespace process {
22 
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_WRITE_COMMAND("config-write");
41 
43 static const std::string CONFIG_TEST_COMMAND("config-test");
44 
46 static const std::string CONFIG_RELOAD_COMMAND("config-reload");
47 
49 static const std::string CONFIG_SET_COMMAND("config-set");
50 
52 static const std::string SERVER_TAG_GET_COMMAND("server-tag-get");
53 
55 static const std::string SHUT_DOWN_COMMAND("shutdown");
56 
58 static const std::string STATUS_GET_COMMAND("status-get");
59 
61 static const int COMMAND_SUCCESS = 0;
62 
64 static const int COMMAND_ERROR = 1;
65 
67 static const int COMMAND_INVALID = 2;
68 
81 class DProcessBase {
82 public:
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 
134  shutdown(isc::data::ConstElementPtr args) = 0;
135 
150  configure(isc::data::ConstElementPtr config_set,
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 
188  void stopIOService() {
189  io_service_->stop();
190  }
191 
196  return (cfg_mgr_);
197  }
198 
199 private:
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 
215 typedef boost::shared_ptr<DProcessBase> DProcessBasePtr;
216 
217 }; // namespace isc::process
218 }; // namespace isc
219 
220 #endif
virtual ~DProcessBase()
Destructor.
Definition: d_process.h:154
void setShutdownFlag(bool value)
Sets the process shut down flag to the given value.
Definition: d_process.h:166
boost::shared_ptr< DCfgMgrBase > DCfgMgrBasePtr
Defines a shared pointer to DCfgMgrBase.
Definition: d_cfg_mgr.h:247
const std::string getAppName() const
Fetches the application name.
Definition: d_process.h:173
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
boost::shared_ptr< DProcessBase > DProcessBasePtr
Defines a shared pointer to DProcessBase.
Definition: d_process.h:215
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
DCfgMgrBasePtr & getCfgMgr()
Fetches the process&#39;s configuration manager.
Definition: d_process.h:195
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:27
DProcessBaseError(const char *file, size_t line, const char *what)
Definition: d_process.h:26
void stopIOService()
Convenience method for stopping IOservice processing.
Definition: d_process.h:188
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-lfc.
asiolink::IOServicePtr & getIoService()
Fetches the controller&#39;s IOService.
Definition: d_process.h:180
Exception thrown if the process encountered an operational error.
Definition: d_process.h:24
Application Process Interface.
Definition: d_process.h:81
DProcessBase(const char *app_name, asiolink::IOServicePtr io_service, DCfgMgrBasePtr cfg_mgr)
Constructor.
Definition: d_process.h:93
bool shouldShutdown() const
Checks if the process has been instructed to shut down.
Definition: d_process.h:159