Fix RequestBroker
[platform/core/appfw/tizen-theme-manager.git] / src / theme / dbus / request_broker.h
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef THEME_DBUS_REQUEST_BROKER_H_
18 #define THEME_DBUS_REQUEST_BROKER_H_
19
20 #include <gio/gio.h>
21
22 #include <map>
23 #include <memory>
24 #include <string>
25
26 #include "theme/dbus/request_filter.h"
27
28 namespace ttm {
29 namespace dbus {
30
31 class RequestBroker {
32  public:
33   static RequestBroker& GetInst();
34   GDBusConnection* GetConnection();
35
36   int RegisterRequestFilter(RequestFilter filter);
37   bool EmitSignal(std::string signal_name,
38       Command cmd, tizen_base::Bundle data);
39   bool Listen();
40   bool Subscribe();
41   tizen_base::Bundle SendData(Command cmd, tizen_base::Bundle&);
42   void SendDataAsync(Command cmd, tizen_base::Bundle&);
43
44  private:
45   void OnReceiveDbusMethod(GDBusConnection* connection,
46       const gchar* sender, const gchar* object_path,
47       const gchar* interface_name, const gchar* method_name,
48       GVariant* parameters, GDBusMethodInvocation* invocation,
49       gpointer user_data);
50
51   RequestBroker() : registration_id_(0), subscribe_id_(0),
52       connection_(nullptr) {}
53   ~RequestBroker() = default;
54   bool Init();
55
56   int registration_id_;
57   int subscribe_id_;
58   GDBusConnection* connection_;
59   std::map<Command, RequestFilter> filters_;
60 };
61
62 }  // namespace dbus
63 }  // namespace ttm
64
65 #endif  // THEME_DBUS_REQUEST_BROKER_H_