Kea 2.6.0
d_controller.h
Go to the documentation of this file.
1// Copyright (C) 2013-2024 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_CONTROLLER_H
8#define D_CONTROLLER_H
9
10#include <asiolink/io_service.h>
12#include <cc/data.h>
14#include <log/logger_support.h>
15#include <process/daemon.h>
16#include <process/d_log.h>
17#include <process/d_process.h>
18
19#include <boost/shared_ptr.hpp>
20#include <boost/noncopyable.hpp>
21
22#include <string>
23#include <set>
24
25namespace isc {
26namespace process {
27
31public:
32 InvalidUsage(const char* file, size_t line, const char* what) :
33 isc::Exception(file, line, what) { };
34};
35
42public:
43 VersionMessage(const char* file, size_t line, const char* what) :
44 isc::Exception(file, line, what) { };
45};
46
49public:
50 LaunchError (const char* file, size_t line, const char* what) :
51 isc::Exception(file, line, what) { };
52};
53
56public:
57 ProcessInitError (const char* file, size_t line, const char* what) :
58 isc::Exception(file, line, what) { };
59};
60
64public:
65 ProcessRunError (const char* file, size_t line, const char* what) :
66 isc::Exception(file, line, what) { };
67};
68
71public:
72 DControllerBaseError (const char* file, size_t line, const char* what) :
73 isc::Exception(file, line, what) { };
74};
75
77class DControllerBase;
78typedef boost::shared_ptr<DControllerBase> DControllerBasePtr;
79
103class DControllerBase : public Daemon {
104public:
110 DControllerBase(const char* app_name, const char* bin_name);
111
113 virtual ~DControllerBase();
114
117 std::string getVersion(bool extended);
118
152 virtual int launch(int argc, char* argv[], const bool test_mode);
153
166 new_config);
167
181 new_config);
182
217
221 std::string getAppName() const {
222 return (app_name_);
223 }
224
228 std::string getBinName() const {
229 return (bin_name_);
230 }
231
241 versionGetHandler(const std::string& command,
243
253 buildReportHandler(const std::string& command,
255
265 configGetHandler(const std::string& command,
267
277 configHashGetHandler(const std::string& command,
279
294 configWriteHandler(const std::string& command,
296
306 configTestHandler(const std::string& command,
308
318 configReloadHandler(const std::string& command,
320
330 configSetHandler(const std::string& command,
332
341 shutdownHandler(const std::string& command,
343
353 serverTagGetHandler(const std::string& command,
355
366 statusGetHandler(const std::string& command,
368
369protected:
381 virtual bool customOption(int option, char *optarg);
382
392
398 virtual const std::string getUsageText() const {
399 return ("");
400 }
401
408 virtual const std::string getCustomOpts() const {
409 return ("");
410 }
411
417 void checkConfigOnly();
418
434 virtual void processSignal(int signum);
435
439 bool isVerbose() const {
440 return (verbose_);
441 }
442
446 void setVerbose(bool value) {
447 verbose_ = value;
448 }
449
453 bool isCheckOnly() const {
454 return (check_only_);
455 }
456
462 void setCheckOnly(bool value) {
463 check_only_ = value;
464 }
465
470 return (io_service_);
471 }
472
478 return (controller_);
479 }
480
487 static void setController(const DControllerBasePtr& controller);
488
503 void parseArgs(int argc, char* argv[]);
504
520 virtual isc::data::ConstElementPtr parseFile(const std::string& file_name);
521
537 virtual isc::data::ConstElementPtr parseText(const std::string& input) {
538 static_cast<void>(input); // just tu shut up the unused parameter warning
540 return (elements);
541 }
542
551 void initProcess();
552
561 // @throw throws DControllerBaseError or indirectly DProcessBaseError
562 void runProcess();
563
583
589 void initSignalHandling();
590
595 return (process_);
596 }
597
602 void usage(const std::string& text);
603
611 virtual std::string getVersionAddendum() { return (std::string()); }
612
621
622private:
626 std::string app_name_;
627
631 std::string bin_name_;
632
634 bool verbose_;
635
638 bool check_only_;
639
644 DProcessBasePtr process_;
645
647 isc::asiolink::IOServicePtr io_service_;
648
650 isc::asiolink::IOSignalSetPtr io_signal_set_;
651
653 static DControllerBasePtr controller_;
654
655 // DControllerTest is named a friend class to facilitate unit testing while
656 // leaving the intended member scopes intact.
657 friend class DControllerTest;
658
660 struct ExhaustOptions {
661 ExhaustOptions(int argc, char* argv[], std::string opts)
662 : argc_(argc), argv_(argv), opts_(opts) {
663 }
664 ~ExhaustOptions() {
665 while (getopt(argc_, argv_, opts_.c_str()) != -1) {
666 }
667 }
668
669 private:
670 int argc_;
671 char** argv_;
672 std::string opts_;
673 };
674};
675
676} // namespace process
677} // namespace isc
678
679#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 when the controller encounters an operational error.
Definition: d_controller.h:70
DControllerBaseError(const char *file, size_t line, const char *what)
Definition: d_controller.h:72
Application Controller.
Definition: d_controller.h:103
void setVerbose(bool value)
Method for enabling or disabling verbose logging.
Definition: d_controller.h:446
isc::data::ConstElementPtr configReloadHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for config-reload command
isc::data::ConstElementPtr buildReportHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for 'build-report' command
void runProcess()
Invokes the application process's event loop,(DBaseProcess::run).
void initProcess()
Instantiates the application process and then initializes it.
virtual std::string getVersionAddendum()
Fetches text containing additional version specifics.
Definition: d_controller.h:611
isc::data::ConstElementPtr statusGetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for status-get command
asiolink::IOServicePtr & getIOService()
Getter for fetching the controller's IOService.
Definition: d_controller.h:469
static DControllerBasePtr & getController()
Static getter which returns the singleton instance.
Definition: d_controller.h:477
isc::data::ConstElementPtr shutdownProcess(isc::data::ConstElementPtr args)
Initiates shutdown procedure.
virtual const std::string getCustomOpts() const
Virtual method which returns a string containing the option letters for any custom command line optio...
Definition: d_controller.h:408
virtual void processSignal(int signum)
Application-level signal processing method.
std::string getBinName() const
Fetches the name of the application executable.
Definition: d_controller.h:228
virtual ~DControllerBase()
Destructor.
isc::data::ConstElementPtr configWriteHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for config-write command
static void setController(const DControllerBasePtr &controller)
Static setter which sets the singleton instance.
Definition: d_controller.cc:51
std::string handleOtherObjects(isc::data::ConstElementPtr args)
Deals with other (i.e.
isc::data::ConstElementPtr versionGetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for version-get command
isc::data::ConstElementPtr configSetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for config-set command
void initSignalHandling()
Initializes signal handling.
virtual const std::string getUsageText() const
Virtual method which can be used to contribute derivation specific usage text.
Definition: d_controller.h:398
virtual isc::data::ConstElementPtr checkConfig(isc::data::ConstElementPtr new_config)
Instance method invoked by the configuration event handler and which processes the actual configurati...
bool isVerbose() const
Supplies whether or not verbose logging is enabled.
Definition: d_controller.h:439
virtual DProcessBase * createProcess()=0
Abstract method that is responsible for instantiating the application process object.
bool isCheckOnly() const
Supplies whether or not check only mode is enabled.
Definition: d_controller.h:453
void setCheckOnly(bool value)
Method for enabling or disabling check only mode.
Definition: d_controller.h:462
isc::data::ConstElementPtr configGetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for config-get command
virtual int launch(int argc, char *argv[], const bool test_mode)
Acts as the primary entry point into the controller execution and provides the outermost application ...
Definition: d_controller.cc:68
DProcessBasePtr getProcess()
Fetches the current process.
Definition: d_controller.h:594
void parseArgs(int argc, char *argv[])
Processes the command line arguments.
virtual isc::data::ConstElementPtr parseText(const std::string &input)
Parse text into Elements.
Definition: d_controller.h:537
virtual bool customOption(int option, char *optarg)
Virtual method that provides derivations the opportunity to support additional command line options.
isc::data::ConstElementPtr configHashGetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for config-hash-get command
isc::data::ConstElementPtr configTestHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for config-test command
isc::data::ConstElementPtr serverTagGetHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for server-tag-get command
std::string getAppName() const
Fetches the name of the application under control.
Definition: d_controller.h:221
virtual isc::data::ConstElementPtr parseFile(const std::string &file_name)
Parse a given file into Elements.
Definition: d_controller.cc:62
virtual isc::data::ConstElementPtr configFromFile()
Reconfigures the process from a configuration file.
std::string getVersion(bool extended)
returns Kea version on stdout and exit.
virtual isc::data::ConstElementPtr updateConfig(isc::data::ConstElementPtr new_config)
Instance method invoked by the configuration event handler and which processes the actual configurati...
void checkConfigOnly()
Check the configuration.
isc::data::ConstElementPtr shutdownHandler(const std::string &command, isc::data::ConstElementPtr args)
handler for 'shutdown' command
Application Process Interface.
Definition: d_process.h:75
Base class for all services.
Definition: daemon.h:48
Exception thrown when the command line is invalid.
Definition: d_controller.h:30
InvalidUsage(const char *file, size_t line, const char *what)
Definition: d_controller.h:32
Exception thrown when the controller launch fails.
Definition: d_controller.h:48
LaunchError(const char *file, size_t line, const char *what)
Definition: d_controller.h:50
Exception thrown when the application process fails.
Definition: d_controller.h:55
ProcessInitError(const char *file, size_t line, const char *what)
Definition: d_controller.h:57
Exception thrown when the application process encounters an operation in its event loop (i....
Definition: d_controller.h:63
ProcessRunError(const char *file, size_t line, const char *what)
Definition: d_controller.h:65
Exception used to convey version info upwards.
Definition: d_controller.h:41
VersionMessage(const char *file, size_t line, const char *what)
Definition: d_controller.h:43
void usage()
Print Usage.
Logging initialization functions.
boost::shared_ptr< const Element > ConstElementPtr
Definition: data.h:29
boost::shared_ptr< DProcessBase > DProcessBasePtr
Defines a shared pointer to DProcessBase.
Definition: d_process.h:211
boost::shared_ptr< DControllerBase > DControllerBasePtr
Definition: d_controller.h:78
Defines the logger used by the top-level component of kea-lfc.