hooked_command_mgr.h 3.71 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// Copyright (C) 2017 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef HOOKED_COMMAND_MGR_H
#define HOOKED_COMMAND_MGR_H

#include <cc/data.h>
#include <config/base_command_mgr.h>

namespace isc {
namespace config {

/// @brief Command Manager which can delegate commands to a hook library.
///
/// This class extends @ref BaseCommandMgr with the logic to delegate the
/// commands to a hook library if the hook library is installed and provides
20 21 22
/// command handlers for the control API.
///
/// The command handlers are registered by a hook library by calling
23
/// @ref isc::hooks::LibraryHandle::registerCommandCallout. This call
24
/// creates a hook point for this command (if one doesn't exist) and then
Josh Soref's avatar
Josh Soref committed
25
/// registers the specified handler(s). When the @ref HookedCommandMgr
26 27 28 29 30 31 32 33 34
/// receives a command for processing it calls the
/// @ref isc::hooks::HooksManager::commandHandlersPresent to check if there
/// are handlers present for this command. If so, the @ref HookedCommandMgr
/// calls @ref isc::hooks::HooksManager::callCommandHandlers to process
/// the command in the hooks libraries. If command handlers are not installed
/// for this command, the @ref HookedCommandMgr will try to process the
/// command on its own.
///
/// The @ref isc::hooks::CalloutHandle::CalloutNextStep flag setting by the
35
/// command handlers does NOT have any influence on the operation of the
36 37 38
/// @ref HookedCommandMgr, i.e. it will always skip processing command on
/// its own if the command handlers are present for the given command, even
/// if the handlers return an error code.
39 40 41 42 43 44 45 46 47 48
class HookedCommandMgr : public BaseCommandMgr {
public:

    /// @brief Constructor.
    ///
    /// Initializes callout handle used by the Command Manager.
    HookedCommandMgr();

protected:

49
    /// @brief Handles the command within the hooks libraries.
50
    ///
51
    /// This method checks if the hooks libraries are installed which implement
52 53 54
    /// command handlers for the specified command to be processed. If the
    /// command handlers are present, this method calls them to create a response
    /// and then passes the response back within the @c answer argument.
55 56 57
    ///
    /// Values of all arguments can be modified by the hook library.
    ///
58 59 60
    /// @param cmd_name Command name.
    /// @param params Command arguments.
    /// @param original_cmd Original command received.
61 62 63 64
    /// @param [out] answer Command processing result returned by the hook.
    ///
    /// @return Boolean value indicating if any callouts have been executed.
    bool
65 66 67
    delegateCommandToHookLibrary(const std::string& cmd_name,
                                 const isc::data::ConstElementPtr& params,
                                 const isc::data::ConstElementPtr& original_cmd,
68 69 70 71 72 73
                                 isc::data::ElementPtr& answer);

    /// @brief Handles the command having a given name and arguments.
    ///
    /// This method calls @ref HookedCommandMgr::delegateCommandToHookLibrary to
    /// try to process the command with the hook libraries, if they are installed.
74 75 76
    ///
    /// @param cmd_name Command name.
    /// @param params Command arguments.
77
    /// @param original_cmd Original command received.
78 79 80 81 82
    ///
    /// @return Pointer to the const data element representing response
    /// to a command.
    virtual isc::data::ConstElementPtr
    handleCommand(const std::string& cmd_name,
83 84
                  const isc::data::ConstElementPtr& params,
                  const isc::data::ConstElementPtr& original_cmd);
85 86 87 88 89 90 91

};

} // end of namespace isc::config
} // end of namespace isc

#endif