2014-11-23 12:35:13 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2015-01-22 12:00:23 +01:00
|
|
|
* Copyright (C) 2012-2015 Icinga Development Team (http://www.icinga.org) *
|
2014-11-23 12:35:13 +01:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software Foundation *
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
2015-01-12 14:29:08 +01:00
|
|
|
#ifndef CONSOLECOMMAND_H
|
|
|
|
#define CONSOLECOMMAND_H
|
2014-11-23 12:35:13 +01:00
|
|
|
|
|
|
|
#include "cli/clicommand.hpp"
|
2015-11-02 16:35:21 +01:00
|
|
|
#include "base/exception.hpp"
|
2015-11-05 14:29:45 +01:00
|
|
|
#include "base/scriptframe.hpp"
|
2014-11-23 12:35:13 +01:00
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
2015-01-12 14:29:08 +01:00
|
|
|
* The "console" CLI command.
|
2014-11-23 12:35:13 +01:00
|
|
|
*
|
|
|
|
* @ingroup cli
|
|
|
|
*/
|
2015-01-12 14:29:08 +01:00
|
|
|
class ConsoleCommand : public CLICommand
|
2014-11-23 12:35:13 +01:00
|
|
|
{
|
|
|
|
public:
|
2015-01-12 14:29:08 +01:00
|
|
|
DECLARE_PTR_TYPEDEFS(ConsoleCommand);
|
2014-11-23 12:35:13 +01:00
|
|
|
|
2015-11-05 14:29:45 +01:00
|
|
|
static void StaticInitialize(void);
|
|
|
|
|
2015-08-18 09:12:49 +02:00
|
|
|
virtual String GetDescription(void) const override;
|
|
|
|
virtual String GetShortDescription(void) const override;
|
|
|
|
virtual ImpersonationLevel GetImpersonationLevel(void) const override;
|
2014-11-23 12:35:13 +01:00
|
|
|
virtual void InitParameters(boost::program_options::options_description& visibleDesc,
|
2015-08-18 09:12:49 +02:00
|
|
|
boost::program_options::options_description& hiddenDesc) const override;
|
|
|
|
virtual int Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const override;
|
2015-11-02 16:35:21 +01:00
|
|
|
|
2015-11-05 14:29:45 +01:00
|
|
|
static int RunScriptConsole(ScriptFrame& scriptFrame, const String& addr = String(),
|
|
|
|
const String& session = String(), const String& commandOnce = String());
|
|
|
|
|
2015-11-02 16:35:21 +01:00
|
|
|
private:
|
|
|
|
mutable boost::mutex m_Mutex;
|
|
|
|
mutable boost::condition_variable m_CV;
|
|
|
|
mutable bool m_CommandReady;
|
|
|
|
|
|
|
|
static void ExecuteScriptCompletionHandler(boost::mutex& mutex, boost::condition_variable& cv,
|
|
|
|
bool& ready, boost::exception_ptr eptr, const Value& result, Value& resultOut,
|
|
|
|
boost::exception_ptr& eptrOut);
|
|
|
|
static void AutocompleteScriptCompletionHandler(boost::mutex& mutex, boost::condition_variable& cv,
|
|
|
|
bool& ready, boost::exception_ptr eptr, const Array::Ptr& result, Array::Ptr& resultOut);
|
|
|
|
|
|
|
|
#ifdef HAVE_EDITLINE
|
|
|
|
static char *ConsoleCompleteHelper(const char *word, int state);
|
|
|
|
#endif /* HAVE_EDITLINE */
|
|
|
|
|
2015-11-05 14:29:45 +01:00
|
|
|
static void BreakpointHandler(ScriptFrame& frame, ScriptError *ex, const DebugInfo& di);
|
|
|
|
|
2014-11-23 12:35:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-01-12 14:29:08 +01:00
|
|
|
#endif /* CONSOLECOMMAND_H */
|