]> granicus.if.org Git - icinga2/blob - icinga-studio/api.hpp
Sync cluster config before replaying the logs
[icinga2] / icinga-studio / api.hpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2015 Icinga Development Team (http://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 API_H
21 #define API_H
22
23 #include "remote/httpclientconnection.hpp"
24 #include "base/value.hpp"
25 #include <vector>
26
27 namespace icinga
28 {
29
30 struct ApiFieldAttributes
31 {
32 public:
33         bool Config;
34         bool Internal;
35         bool Required;
36         bool State;
37 };
38
39 class ApiType;
40
41 struct ApiField
42 {
43 public:
44         String Name;
45         int ID;
46         int ArrayRank;
47         ApiFieldAttributes FieldAttributes;
48         String TypeName;
49         intrusive_ptr<ApiType> Type;
50 };
51
52 class ApiType : public Object
53 {
54 public:
55         DECLARE_PTR_TYPEDEFS(ApiType);
56
57         String Name;
58         String PluralName;
59         String BaseName;
60         ApiType::Ptr Base;
61         bool Abstract;
62         std::map<String, ApiField> Fields;
63         std::vector<String> PrototypeKeys;
64 };
65
66 struct ApiObjectReference
67 {
68 public:
69         String Name;
70         String Type;
71 };
72
73 struct ApiObject : public Object
74 {
75 public:
76         DECLARE_PTR_TYPEDEFS(ApiObject);
77
78         std::map<String, Value> Attrs;
79         std::vector<ApiObjectReference> UsedBy;
80 };
81
82 class ApiClient : public Object
83 {
84 public:
85         DECLARE_PTR_TYPEDEFS(ApiClient);
86
87         ApiClient(const String& host, const String& port,
88             const String& user, const String& password);
89
90         typedef boost::function<void(const std::vector<ApiType::Ptr>&)> TypesCompletionCallback;
91         void GetTypes(const TypesCompletionCallback& callback) const;
92
93         typedef boost::function<void(const std::vector<ApiObject::Ptr>&)> ObjectsCompletionCallback;
94         void GetObjects(const String& pluralType, const ObjectsCompletionCallback& callback,
95             const std::vector<String>& names = std::vector<String>(),
96             const std::vector<String>& attrs = std::vector<String>()) const;
97
98 private:
99         HttpClientConnection::Ptr m_Connection;
100         String m_User;
101         String m_Password;
102
103         static void TypesHttpCompletionCallback(HttpRequest& request,
104             HttpResponse& response, const TypesCompletionCallback& callback);
105         static void ObjectsHttpCompletionCallback(HttpRequest& request,
106             HttpResponse& response, const ObjectsCompletionCallback& callback);
107 };
108
109 }
110
111 #endif /* API_H */