2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __CONTEXT_SERVICE_BASE_H__
18 #define __CONTEXT_SERVICE_BASE_H__
22 #include <ContextTypes.h>
26 /* Forward declarations */
30 class EXPORT_API ServiceBase {
32 virtual ~ServiceBase();
34 // These functions should not be called from individual services
38 void notifyUserRemoved();
39 static void setActiveUser(uid_t uid);
40 static void setSingleThreading();
43 // If the GVariant 'param' is floating, it is consumed.
44 void publish(const std::string& busName, const std::string& signalName, GVariant* param);
46 GDBusConnection* getConnection();
48 static uid_t getActiveUser();
50 virtual bool isUserService() = 0;
53 ServiceBase(GDBusConnection* conn, const char* serviceName, const char* methodSpecs);
55 virtual bool prepare() = 0;
57 virtual void cleanup() = 0;
59 virtual ClientBase* createClient(const std::string& busName) = 0;
61 virtual void onUserActivated();
63 virtual void onUserDeactivated();
66 static gpointer __threadFunc(gpointer data);
68 static void __onMethodCalled(GDBusConnection* conn, const gchar* sender,
69 const gchar* path, const gchar* iface, const gchar* name,
70 GVariant* param, GDBusMethodInvocation* invocation, gpointer userData);
72 static void __onNameOwnerChanged(GDBusConnection* conn, const gchar* sender,
73 const gchar* path, const gchar* iface, const gchar* name,
74 GVariant* param, gpointer userData);
76 static gboolean __onUserActivated(gpointer data);
78 static gboolean __onUserDeactivated(gpointer data);
80 static gboolean __stopMainLoop(gpointer data);
82 void __onMethodCalled(const std::string& sender,
83 const std::string& name, GVariant* param, GDBusMethodInvocation* invocation);
89 ClientBase* __getClient(const std::string& busName);
90 void __removeClient(const std::string& busName);
91 unsigned int __watch(const std::string& busName, ClientBase* client);
92 void __unwatch(unsigned int watchId);
95 const char* __serviceName;
97 GMainContext* __mainContext;
98 GMainLoop* __mainLoop;
101 GDBusConnection* __connection;
102 const char* __methodSpecs;
103 std::string __objPath;
104 std::string __interface;
106 GDBusNodeInfo* __nodeInfo;
107 guint __registrationId;
111 unsigned int watchId;
114 std::map<std::string, ClientInfo> __clients;
116 static bool __singleThreading;
121 #endif /* __CONTEXT_SERVICE_BASE_H__ */