Kea 1.5.0
d2_controller.cc
Go to the documentation of this file.
1// Copyright (C) 2013-2017 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#include <config.h>
8
9#include <d2/d2_controller.h>
10#include <d2/d2_process.h>
11#include <d2/parser_context.h>
12
13#include <stdlib.h>
14
15using namespace isc::process;
16
17namespace isc {
18namespace d2 {
19
22const char* D2Controller::d2_app_name_ = "DhcpDdns";
23
25const char* D2Controller::d2_bin_name_ = "kea-dhcp-ddns";
26
29 // If the instance hasn't been created yet, create it. Note this method
30 // must use the base class singleton instance methods.
31 if (!getController()) {
32 DControllerBasePtr controller_ptr(new D2Controller());
33 setController(controller_ptr);
34 }
35
36 return (getController());
37}
38
39DProcessBase* D2Controller::createProcess() {
40 // Instantiate and return an instance of the D2 application process. Note
41 // that the process is passed the controller's io_service.
42 return (new D2Process(getAppName().c_str(), getIOService()));
43}
44
45D2Controller::D2Controller()
46 : DControllerBase(d2_app_name_, d2_bin_name_) {
47}
48
50D2Controller::parseFile(const std::string& file_name) {
52
53 // Read contents of the file and parse it as JSON
54 D2ParserContext parser;
55 elements = parser.parseFile(file_name, D2ParserContext::PARSER_DHCPDDNS);
56 if (!elements) {
57 isc_throw(isc::BadValue, "no configuration found in file");
58 }
59
60 return (elements);
61}
62
64}
65
66std::string
68 std::stringstream stream;
69 // Currently the only dependency D2 adds to base is cryptolink
70 stream << isc::cryptolink::CryptoLink::getVersion() << std::endl;
71 return (stream.str());
72
73}
74
75}; // end namespace isc::d2
76}; // end namespace isc
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
Process Controller for D2 Process This class is the DHCP-DDNS specific derivation of DControllerBase.
Definition: d2_controller.h:25
static process::DControllerBasePtr & instance()
Static singleton instance method.
static const char * d2_app_name_
Defines the application name, this is passed into base class and appears in log statements.
Definition: d2_controller.h:39
static const char * d2_bin_name_
Defines the executable name.
Definition: d2_controller.h:43
virtual std::string getVersionAddendum()
Returns version info specific to D2.
virtual ~D2Controller()
Destructor.
Evaluation context, an interface to the expression evaluation.
@ PARSER_DHCPDDNS
Used for parsing content of DhcpDdns.
isc::data::ElementPtr parseFile(const std::string &filename, ParserType parser_type)
Run the parser on the file specified.
DHCP-DDNS Application Process.
Definition: d2_process.h:24
Application Controller.
Definition: d_controller.h:104
asiolink::IOServicePtr & getIOService()
Getter for fetching the controller's IOService.
Definition: d_controller.h:412
static DControllerBasePtr & getController()
Static getter which returns the singleton instance.
Definition: d_controller.h:420
static void setController(const DControllerBasePtr &controller)
Static setter which sets the singleton instance.
Definition: d_controller.cc:39
std::string getAppName() const
Fetches the name of the application under control.
Definition: d_controller.h:224
Application Process Interface.
Definition: d_process.h:67
#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< DControllerBase > DControllerBasePtr
Definition: d_controller.h:79
Defines the logger used by the top-level component of kea-dhcp-ddns.