]> granicus.if.org Git - icinga2/blob - lib/cli/consolecommand.hpp
Merge branch 'support/2.5'
[icinga2] / lib / cli / consolecommand.hpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2016 Icinga Development Team (https://www.icinga.org/)  *
4  *                                                                            *
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.                     *
9  *                                                                            *
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.                               *
14  *                                                                            *
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  ******************************************************************************/
19
20 #ifndef CONSOLECOMMAND_H
21 #define CONSOLECOMMAND_H
22
23 #include "cli/clicommand.hpp"
24 #include "base/exception.hpp"
25 #include "base/scriptframe.hpp"
26
27 namespace icinga
28 {
29
30 /**
31  * The "console" CLI command.
32  *
33  * @ingroup cli
34  */
35 class ConsoleCommand : public CLICommand
36 {
37 public:
38         DECLARE_PTR_TYPEDEFS(ConsoleCommand);
39
40         static void StaticInitialize(void);
41
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;
48
49         static int RunScriptConsole(ScriptFrame& scriptFrame, const String& addr = String(),
50             const String& session = String(), const String& commandOnce = String());
51
52 private:
53         mutable boost::mutex m_Mutex;
54         mutable boost::condition_variable m_CV;
55
56         static void ExecuteScriptCompletionHandler(boost::mutex& mutex, boost::condition_variable& cv,
57             bool& ready, boost::exception_ptr eptr, const Value& result, Value& resultOut,
58             boost::exception_ptr& eptrOut);
59         static void AutocompleteScriptCompletionHandler(boost::mutex& mutex, boost::condition_variable& cv,
60             bool& ready, boost::exception_ptr eptr, const Array::Ptr& result, Array::Ptr& resultOut);
61
62 #ifdef HAVE_EDITLINE
63         static char *ConsoleCompleteHelper(const char *word, int state);
64 #endif /* HAVE_EDITLINE */
65
66         static void BreakpointHandler(ScriptFrame& frame, ScriptError *ex, const DebugInfo& di);
67
68 };
69
70 }
71
72 #endif /* CONSOLECOMMAND_H */