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__
23 #include <ContextTypes.h>
27 /* Forward declarations */
31 class EXPORT_API ServiceBase {
33 virtual ~ServiceBase();
35 // These functions should not be called from individual services
39 void notifyUserRemoved();
40 static void setActiveUser(uid_t uid);
43 // If the GVariant 'param' is floating, it is consumed.
44 void publish(const std::string& busName, const std::string& signalName, GVariant* param);
46 GMainContext* getMainContext();
48 GDBusConnection* getConnection();
50 static uid_t getActiveUser();
52 virtual bool isUserService() = 0;
55 ServiceBase(GDBusConnection* conn, const char* serviceName, const char* methodSpecs);
57 virtual bool prepare() = 0;
59 virtual void cleanup() = 0;
61 virtual ClientBase* createClient(const std::string& busName) = 0;
63 virtual void onUserActivated();
65 virtual void onUserDeactivated();
68 static gpointer __threadFunc(gpointer data);
70 static void __onMethodCalled(GDBusConnection* conn, const gchar* sender,
71 const gchar* path, const gchar* iface, const gchar* name,
72 GVariant* param, GDBusMethodInvocation* invocation, gpointer userData);
74 static void __onNameOwnerChanged(GDBusConnection* conn, const gchar* sender,
75 const gchar* path, const gchar* iface, const gchar* name,
76 GVariant* param, gpointer userData);
78 static gboolean __onUserActivated(gpointer data);
80 static gboolean __onUserDeactivated(gpointer data);
82 static gboolean __stopMainLoop(gpointer data);
84 void __onMethodCalled(const std::string& sender,
85 const std::string& name, GVariant* param, GDBusMethodInvocation* invocation);
91 ClientBase* __getClient(const std::string& busName);
92 void __removeClient(const std::string& busName);
93 unsigned int __watch(const std::string& busName, ClientBase* client);
94 void __unwatch(unsigned int watchId);
97 std::atomic_bool __threadRunning;
98 const char* __serviceName;
100 GMainContext* __mainContext;
101 GMainLoop* __mainLoop;
104 GDBusConnection* __connection;
105 const char* __methodSpecs;
106 std::string __objPath;
107 std::string __interface;
109 GDBusNodeInfo* __nodeInfo;
110 guint __registrationId;
112 struct __ClientInfo {
114 unsigned int watchId;
117 std::map<std::string, __ClientInfo> __clients;
122 #endif /* __CONTEXT_SERVICE_BASE_H__ */