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 
16 #include <exceptions/exceptions.h>
17 
18 namespace isc {
19 namespace process {
20 
23 public:
24  DProcessBaseError(const char* file, size_t line, const char* what) :
25  isc::Exception(file, line, what) { };
26 };
27 
29 static const std::string VERSION_GET_COMMAND("version-get");
30 
32 static const std::string BUILD_REPORT_COMMAND("build-report");
33 
35 static const std::string CONFIG_GET_COMMAND("config-get");
36 
38 static const std::string CONFIG_WRITE_COMMAND("config-write");
39 
41 static const std::string CONFIG_TEST_COMMAND("config-test");
42 
44 static const std::string SHUT_DOWN_COMMAND("shutdown");
45 
47 static const int COMMAND_SUCCESS = 0;
48 
50 static const int COMMAND_ERROR = 1;
51 
53 static const int COMMAND_INVALID = 2;
54 
67 class DProcessBase {
68 public:
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 
174  void stopIOService() {
175  io_service_->stop();
176  }
177 
182  return (cfg_mgr_);
183  }
184 
185 private:
188  std::string app_name_;
189 
191  asiolink::IOServicePtr io_service_;
192 
194  bool shut_down_flag_;
195 
197  DCfgMgrBasePtr cfg_mgr_;
198 };
199 
201 typedef boost::shared_ptr<DProcessBase> DProcessBasePtr;
202 
203 }; // namespace isc::process
204 }; // namespace isc
205 
206 #endif
isc::process::DProcessBase::stopIOService
void stopIOService()
Convenience method for stopping IOservice processing.
Definition: d_process.h:174
isc::process::DProcessBase::getIoService
asiolink::IOServicePtr & getIoService()
Fetches the controller's IOService.
Definition: d_process.h:166
isc::process::DProcessBase::init
virtual void init()=0
May be used after instantiation to perform initialization unique to application.
isc::process::DProcessBase::configure
virtual isc::data::ConstElementPtr configure(isc::data::ConstElementPtr config_set, bool check_only=false)=0
Processes the given configuration.
isc::process::DProcessBase::shutdown
virtual isc::data::ConstElementPtr shutdown(isc::data::ConstElementPtr args)=0
Initiates the process's shutdown process.
io_service.h
isc::Exception
This is a base class for exceptions thrown from the DNS library module.
Definition: exceptions/exceptions.h:23
isc
Defines the logger used by the top-level component of kea-dhcp-ddns.
Definition: agent_parser.cc:144
isc::Exception::what
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Definition: exceptions/exceptions.cc:32
isc::process::DProcessBaseError
Exception thrown if the process encountered an operational error.
Definition: d_process.h:22
isc::process::DProcessBase::run
virtual void run()=0
Implements the process's event loop.
isc::process::DProcessBase::~DProcessBase
virtual ~DProcessBase()
Destructor.
Definition: d_process.h:140
isc_throw
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Definition: exceptions/exceptions.h:192
isc::process::DProcessBase::shouldShutdown
bool shouldShutdown() const
Checks if the process has been instructed to shut down.
Definition: d_process.h:145
isc::process::DProcessBase
Application Process Interface.
Definition: d_process.h:67
isc::process::DProcessBase::setShutdownFlag
void setShutdownFlag(bool value)
Sets the process shut down flag to the given value.
Definition: d_process.h:152
isc::process::DCfgMgrBasePtr
boost::shared_ptr< DCfgMgrBase > DCfgMgrBasePtr
Defines a shared pointer to DCfgMgrBase.
Definition: d_cfg_mgr.h:219
isc::process::DProcessBase::DProcessBase
DProcessBase(const char *app_name, asiolink::IOServicePtr io_service, DCfgMgrBasePtr cfg_mgr)
Constructor.
Definition: d_process.h:79
isc::process::DProcessBasePtr
boost::shared_ptr< DProcessBase > DProcessBasePtr
Defines a shared pointer to DProcessBase.
Definition: d_process.h:201
data.h
isc::process::DProcessBase::getCfgMgr
DCfgMgrBasePtr & getCfgMgr()
Fetches the process's configuration manager.
Definition: d_process.h:181
exceptions.h
d_cfg_mgr.h
isc::data::ConstElementPtr
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:23
isc::process::DProcessBase::getAppName
const std::string getAppName() const
Fetches the application name.
Definition: d_process.h:159
isc::process::DProcessBaseError::DProcessBaseError
DProcessBaseError(const char *file, size_t line, const char *what)
Definition: d_process.h:24