Fix invalid licenses
[platform/framework/web/crosswalk-tizen.git] / src / common / dbus_server.h
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
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 WRT_COMMON_DBUS_SERVER_H_
18 #define WRT_COMMON_DBUS_SERVER_H_
19
20 #include <glib.h>
21 #include <gio/gio.h>
22 #include <string>
23 #include <map>
24 #include <functional>
25
26 namespace wrt {
27
28 class DBusServer {
29  public:
30   typedef std::function<bool(GCredentials* creds)> PeerCredentialsCallback;
31   typedef std::function<void(GDBusConnection* connection,
32                              const std::string& method_name,
33                              GVariant* parameters,
34                              GDBusMethodInvocation* invocation)> MethodCallback;
35   typedef std::function<GVariant*(GDBusConnection* connection,
36                                   const gchar* property)> PropertyGetter;
37   typedef std::function<bool(GDBusConnection* connection,
38                              const gchar* property,
39                              GVariant* value)> PropertySetter;
40
41   DBusServer();
42   virtual ~DBusServer();
43
44   void Start(const std::string& name);
45
46   std::string GetClientAddress() const;
47
48   void SetIntrospectionXML(const std::string& xml);
49   GDBusNodeInfo* GetIntrospectionNodeInfo() const { return node_info_; }
50
51   void SendSignal(GDBusConnection* connection,
52                   const std::string& iface, const std::string& signal_name,
53                   GVariant* parameters);
54
55   void SetPeerCredentialsCallback(PeerCredentialsCallback func);
56   void SetMethodCallback(const std::string& iface, MethodCallback func);
57   void SetPropertyGetter(const std::string& iface, PropertyGetter func);
58   void SetPropertySetter(const std::string& iface, PropertySetter func);
59   PeerCredentialsCallback GetPeerCredentialsCallback() const;
60   MethodCallback GetMethodCallback(const std::string& iface);
61   PropertySetter GetPropertySetter(const std::string& iface);
62   PropertyGetter GetPropertyGetter(const std::string& iface);
63
64  private:
65   std::string address_path_;
66   GDBusServer* server_;
67   GDBusNodeInfo* node_info_;
68
69   PeerCredentialsCallback peer_credentials_callback_;
70   std::map<std::string, MethodCallback> method_callbacks_;
71   std::map<std::string, PropertyGetter> property_getters_;
72   std::map<std::string, PropertySetter> property_setters_;
73 };
74
75 }  // namespace wrt
76
77 #endif  // WRT_COMMON_DBUS_SERVER_H_