Store the dbus connection while launching the service
[platform/core/context/context-service.git] / src / agent / legacy / DBusServer.h
1 /*
2  * Copyright (c) 2015 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 _CONTEXT_DBUS_SERVER_H_
18 #define _CONTEXT_DBUS_SERVER_H_
19
20 #include <glib.h>
21 #include <gio/gio.h>
22 #include <string>
23
24 namespace ctx {
25
26         class DBusServer {
27         public:
28                 ~DBusServer();
29
30                 static void publish(std::string dest, int reqId, std::string subject, int error, std::string data);
31                 static void call(std::string dest, std::string obj, std::string iface, std::string method, GVariant *param);
32
33         private:
34                 DBusServer();
35
36                 static void __onMethodCalled(GDBusConnection *conn, const gchar *sender,
37                                 const gchar *path, const gchar *iface, const gchar *name,
38                                 GVariant *param, GDBusMethodInvocation *invocation, gpointer user_data);
39                 static void __onBusAcquired(GDBusConnection *conn, const gchar *name, gpointer userData);
40                 static void __onNameAcquired(GDBusConnection *conn, const gchar *name, gpointer userData);
41                 static void __onNameLost(GDBusConnection *conn, const gchar *name, gpointer userData);
42                 static void __onCallDone(GObject *source, GAsyncResult *res, gpointer userData);
43
44                 bool __init();
45                 void __release();
46                 void __publish(const char *dest, int reqId, const char *subject, int error, const char *data);
47                 void __call(const char *dest, const char *obj, const char *iface, const char *method, GVariant *param);
48
49                 void __processRequest(const char *sender, GVariant *param, GDBusMethodInvocation *invocation);
50                 void __reply(GDBusMethodInvocation *invocation, int error);
51
52                 static DBusServer *__theInstance;
53
54                 guint __owner;
55                 GDBusConnection *__connection;
56                 GDBusNodeInfo *__nodeInfo;
57
58                 friend class Server;
59
60         };      /* class ctx::DBusServer */
61
62 }       /* namespace ctx */
63
64 #endif  /* End of _CONTEXT_DBUS_SERVER_H_ */