Kea 2.7.6
cmds_impl.h
Go to the documentation of this file.
1// Copyright (C) 2017-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#ifndef CMDS_IMPL_H
7#define CMDS_IMPL_H
8
9#include <config.h>
11#include <cc/data.h>
12#include <hooks/hooks.h>
14
15#include <string>
16
17namespace isc {
18namespace config {
19
21class CmdsImpl {
22protected:
30 try {
32 handle.getArgument("command", command);
34 } catch (const std::exception& ex) {
35 isc_throw(isc::BadValue, "JSON command text is invalid: " << ex.what());
36 }
37 }
38
43 void setSuccessResponse(hooks::CalloutHandle& handle, const std::string& text) {
45 setResponse(handle, response);
46 }
47
54 void setErrorResponse(hooks::CalloutHandle& handle, const std::string& text,
55 int status = CONTROL_RESULT_ERROR) {
56 data::ConstElementPtr response = createAnswer(status, text);
57 setResponse(handle, response);
58 }
59
65 handle.setArgument("response", response);
66 }
67
69 std::string cmd_name_;
70
73};
74
75}
76}
77
78#endif // CMDS_IMPL_H
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
Base class that command handler implementers may use for common tasks.
Definition cmds_impl.h:21
std::string cmd_name_
Stores the command name extracted by a call to extractCommand.
Definition cmds_impl.h:69
void setErrorResponse(hooks::CalloutHandle &handle, const std::string &text, int status=CONTROL_RESULT_ERROR)
Set the callout argument "response" to indicate an error.
Definition cmds_impl.h:54
data::ConstElementPtr cmd_args_
Stores the command arguments extracted by a call to extractCommand.
Definition cmds_impl.h:72
void extractCommand(hooks::CalloutHandle &handle)
Extracts the command name and arguments from a Callout handle.
Definition cmds_impl.h:29
void setSuccessResponse(hooks::CalloutHandle &handle, const std::string &text)
Set the callout argument "response" to indicate success.
Definition cmds_impl.h:43
void setResponse(hooks::CalloutHandle &handle, data::ConstElementPtr &response)
Set the callout argument "response" to the given response.
Definition cmds_impl.h:64
Per-packet callout handle.
void getArgument(const std::string &name, T &value) const
Get argument.
void setArgument(const std::string &name, T value)
Set argument.
This file contains several functions and constants that are used for handling commands and responses ...
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
const int CONTROL_RESULT_ERROR
Status code indicating a general failure.
std::string parseCommand(ConstElementPtr &arg, ConstElementPtr command)
Parses the given command into a string containing the actual command and an ElementPtr containing the...
ConstElementPtr createAnswer()
Creates a standard config/command level success answer message (i.e.
const int CONTROL_RESULT_SUCCESS
Status code indicating a successful operation.
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
Defines the logger used by the top-level component of kea-lfc.