Kea  2.5.3
d_process.h
Go to the documentation of this file.
1 // Copyright (C) 2013-2023 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_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 
129 
145  bool check_only = false) = 0;
146 
148  virtual ~DProcessBase(){};
149 
153  bool shouldShutdown() const {
154  return (shut_down_flag_);
155  }
156 
160  void setShutdownFlag(bool value) {
161  shut_down_flag_ = value;
162  }
163 
167  const std::string getAppName() const {
168  return (app_name_);
169  }
170 
175  return (io_service_);
176  }
177 
182  void stopIOService() {
183  io_service_->stop();
184  }
185 
190  return (cfg_mgr_);
191  }
192 
193 private:
196  std::string app_name_;
197 
199  asiolink::IOServicePtr io_service_;
200 
202  std::atomic<bool> shut_down_flag_;
203 
205  DCfgMgrBasePtr cfg_mgr_;
206 };
207 
209 typedef boost::shared_ptr<DProcessBase> DProcessBasePtr;
210 
211 } // namespace process
212 } // namespace isc
213 
214 #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:160
asiolink::IOServicePtr & getIoService()
Fetches the controller's IOService.
Definition: d_process.h:174
DProcessBase(const char *app_name, asiolink::IOServicePtr io_service, DCfgMgrBasePtr cfg_mgr)
Constructor.
Definition: d_process.h:87
DCfgMgrBasePtr & getCfgMgr()
Fetches the process's configuration manager.
Definition: d_process.h:189
void stopIOService()
Convenience method for stopping IOservice processing.
Definition: d_process.h:182
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:167
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:153
virtual isc::data::ConstElementPtr configure(isc::data::ConstElementPtr config_set, bool check_only=false)=0
Processes the given configuration.
#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:209
Defines the logger used by the top-level component of kea-lfc.