1 /******************************************************************************
3 * Copyright (C) 2012-2016 Icinga Development Team (https://www.icinga.org/) *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software Foundation *
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ******************************************************************************/
20 #ifndef CONSOLECOMMAND_H
21 #define CONSOLECOMMAND_H
23 #include "cli/clicommand.hpp"
24 #include "base/exception.hpp"
25 #include "base/scriptframe.hpp"
31 * The "console" CLI command.
35 class ConsoleCommand : public CLICommand
38 DECLARE_PTR_TYPEDEFS(ConsoleCommand);
40 static void StaticInitialize(void);
42 virtual String GetDescription(void) const override;
43 virtual String GetShortDescription(void) const override;
44 virtual ImpersonationLevel GetImpersonationLevel(void) const override;
45 virtual void InitParameters(boost::program_options::options_description& visibleDesc,
46 boost::program_options::options_description& hiddenDesc) const override;
47 virtual int Run(const boost::program_options::variables_map& vm, const std::vector<std::string>& ap) const override;
49 static int RunScriptConsole(ScriptFrame& scriptFrame, const String& addr = String(),
50 const String& session = String(), const String& commandOnce = String());
53 mutable boost::mutex m_Mutex;
54 mutable boost::condition_variable m_CV;
55 mutable bool m_CommandReady;
57 static void ExecuteScriptCompletionHandler(boost::mutex& mutex, boost::condition_variable& cv,
58 bool& ready, boost::exception_ptr eptr, const Value& result, Value& resultOut,
59 boost::exception_ptr& eptrOut);
60 static void AutocompleteScriptCompletionHandler(boost::mutex& mutex, boost::condition_variable& cv,
61 bool& ready, boost::exception_ptr eptr, const Array::Ptr& result, Array::Ptr& resultOut);
64 static char *ConsoleCompleteHelper(const char *word, int state);
65 #endif /* HAVE_EDITLINE */
67 static void BreakpointHandler(ScriptFrame& frame, ScriptError *ex, const DebugInfo& di);
73 #endif /* CONSOLECOMMAND_H */