* limitations under the License.
*/
-#ifndef __CONTEXT_CLIENT_PROXY_H__
-#define __CONTEXT_CLIENT_PROXY_H__
+#ifndef __CONTEXT_CLIENT_BASE_H__
+#define __CONTEXT_CLIENT_BASE_H__
#include <string>
#include <ContextTypes.h>
namespace ctx {
/* Forward declarations */
- class DBusService;
+ class ServiceBase;
class MethodCall;
class Credential;
- class EXPORT_API ClientProxy {
+ class EXPORT_API ClientBase {
public:
- virtual ~ClientProxy();
+ virtual ~ClientBase();
virtual void onMethodCalled(MethodCall* methodCall) = 0;
Credential* getCredential();
- DBusService* getHostService();
+ ServiceBase* getHostService();
// If the GVariant 'param' is floating, it is consumed.
void publish(const std::string& signalName, GVariant* param);
protected:
- ClientProxy(DBusService* hostService, const std::string& busName);
+ ClientBase(ServiceBase* hostService, const std::string& busName);
private:
- DBusService* __hostService;
+ ServiceBase* __hostService;
std::string __busName;
Credential* __credential;
};
}
-#endif /* __CONTEXT_CLIENT_PROXY_H__ */
+#endif /* __CONTEXT_CLIENT_BASE_H__ */
* limitations under the License.
*/
-#ifndef __CONTEXT_I_CLIENT_RESULT_LISTENER_H__
-#define __CONTEXT_I_CLIENT_RESULT_LISTENER_H__
+#ifndef __CONTEXT_I_SERVICE_RESULT_LISTENER_H__
+#define __CONTEXT_I_SERVICE_RESULT_LISTENER_H__
#include <string>
#include <ContextTypes.h>
namespace ctx {
- class IClientResultListener {
+ class IServiceResultListener {
public:
- virtual ~IClientResultListener() {}
+ virtual ~IServiceResultListener() {}
// The GVariant 'param' is released automatically.
// To keep accessing it, its reference count needs to be increased.
}
-#endif /* _CONTEXT_I_CLIENT_RESULT_LISTENER_H_ */
+#endif /* _CONTEXT_I_SERVICE_RESULT_LISTENER_H_ */
* limitations under the License.
*/
-#ifndef __CONTEXT_I_CLIENT_SIGNAL_LISTENER_H__
-#define __CONTEXT_I_CLIENT_SIGNAL_LISTENER_H__
+#ifndef __CONTEXT_I_SERVICE_SIGNAL_LISTENER_H__
+#define __CONTEXT_I_SERVICE_SIGNAL_LISTENER_H__
#include <string>
#include <ContextTypes.h>
namespace ctx {
- class IClientSignalListener {
+ class IServiceSignalListener {
public:
- virtual ~IClientSignalListener() {}
+ virtual ~IServiceSignalListener() {}
// The GVariant 'param' is released automatically.
virtual void onSignal(const std::string& signalName, GVariant* param) = 0;
}
-#endif /* _CONTEXT_I_CLIENT_SIGNAL_LISTENER_H_ */
+#endif /* _CONTEXT_I_SERVICE_SIGNAL_LISTENER_H_ */
namespace ctx {
/* Forward declaration */
- class ClientProxy;
+ class ClientBase;
class EXPORT_API MethodCall {
public:
- MethodCall(ClientProxy* proxy, const std::string& methodName, GVariant* param, GDBusMethodInvocation* invocation);
+ MethodCall(ClientBase* client, const std::string& methodName, GVariant* param, GDBusMethodInvocation* invocation);
~MethodCall();
- ClientProxy* getSender();
+ ClientBase* getSender();
const std::string& getMethodName() const;
// The returned GVariant object should be not freed.
bool reply(int error);
private:
- ClientProxy* __clientProxy;
+ ClientBase* __client;
std::string __methodName;
GVariant* __param;
GDBusMethodInvocation* __invocation;
* limitations under the License.
*/
-#ifndef __CONTEXT_DBUS_SERVICE_H__
-#define __CONTEXT_DBUS_SERVICE_H__
+#ifndef __CONTEXT_SERVICE_BASE_H__
+#define __CONTEXT_SERVICE_BASE_H__
#include <string>
#include <map>
namespace ctx {
/* Forward declarations */
- class ClientProxy;
+ class ClientBase;
class MethodCall;
- class EXPORT_API DBusService {
+ class EXPORT_API ServiceBase {
public:
- virtual ~DBusService();
+ virtual ~ServiceBase();
GDBusConnection* getConnection();
uid_t getActiveUser();
protected:
- DBusService(GDBusConnection* conn, const char* serviceName, const char* methodSpecs);
+ ServiceBase(GDBusConnection* conn, const char* serviceName, const char* methodSpecs);
virtual bool prepare() = 0;
virtual void onUserActivated(uid_t uid) = 0;
- virtual ClientProxy* createProxy(const std::string& busName) = 0;
+ virtual ClientBase* createClient(const std::string& busName) = 0;
private:
static gpointer __threadFunc(gpointer data);
bool __init();
void __release();
- ClientProxy* __getClientProxy(const std::string& busName);
- void __removeClientProxy(const std::string& busName);
- unsigned int __watch(const std::string& busName, ClientProxy* proxy);
+ ClientBase* __getClient(const std::string& busName);
+ void __removeClient(const std::string& busName);
+ unsigned int __watch(const std::string& busName, ClientBase* client);
void __unwatch(unsigned int watchId);
const char* __serviceName;
guint __userNewSignalId;
uid_t __activeUid;
- struct ProxyInfo {
- ClientProxy* proxy;
+ struct ClientInfo {
+ ClientBase* client;
unsigned int watchId;
};
- std::map<std::string, ProxyInfo> __proxies;
+ std::map<std::string, ClientInfo> __clients;
};
}
-#endif /* __CONTEXT_DBUS_SERVICE_H__ */
+#endif /* __CONTEXT_SERVICE_BASE_H__ */
* limitations under the License.
*/
-#ifndef __CONTEXT_DBUS_CLIENT_H__
-#define __CONTEXT_DBUS_CLIENT_H__
+#ifndef __CONTEXT_SERVICE_PROXY_H__
+#define __CONTEXT_SERVICE_PROXY_H__
#include <string>
#include <ContextTypes.h>
namespace ctx {
- class IClientResultListener;
- class IClientSignalListener;
+ class IServiceResultListener;
+ class IServiceSignalListener;
- class EXPORT_API DBusClient {
+ class EXPORT_API ServiceProxy {
public:
- DBusClient(const char* serviceName);
- ~DBusClient();
+ ServiceProxy(const char* serviceName);
+ ~ServiceProxy();
// The GVariant 'inParam' is consumed, if it is floating.
// If succeeded, the GVariant 'outParam' contains return values. Free with g_variant_unref().
int call(const std::string& methodName, GVariant* inParam, GVariant** outParam);
- int call(const std::string& methodName, GVariant* inParam, IClientResultListener* listener);
+ int call(const std::string& methodName, GVariant* inParam, IServiceResultListener* listener);
- unsigned int subscribe(const std::string& signalName, IClientSignalListener* listener);
+ unsigned int subscribe(const std::string& signalName, IServiceSignalListener* listener);
void unsubscribe(unsigned int subscriptionId);
private:
static void __signalCb(GDBusConnection* conn, const gchar* sender, const gchar* path,
const gchar* iface, const gchar* name, GVariant* param, gpointer userData);
- void __onSuccess(const std::string& methodName, GVariant* param, IClientResultListener* listener);
- void __onError(const std::string& methodName, GError* gerr, IClientResultListener* listener);
+ void __onSuccess(const std::string& methodName, GVariant* param, IServiceResultListener* listener);
+ void __onError(const std::string& methodName, GError* gerr, IServiceResultListener* listener);
const char* __serviceName;
std::string __objPath;
} /* namespace ctx */
-#endif /* __CONTEXT_DBUS_CLIENT_H__ */
+#endif /* __CONTEXT_SERVICE_PROXY_H__ */
* limitations under the License.
*/
-#include <IClientResultListener.h>
-#include <IClientSignalListener.h>
-#include <DBusClient.h>
+#include <IServiceResultListener.h>
+#include <IServiceSignalListener.h>
+#include <ServiceProxy.h>
using namespace ctx;
struct ResultCbData {
- DBusClient* client;
+ ServiceProxy* proxy;
std::string name;
- IClientResultListener* resultListener;
+ IServiceResultListener* resultListener;
};
-DBusClient::DBusClient(const char* serviceName) :
+ServiceProxy::ServiceProxy(const char* serviceName) :
__serviceName(serviceName),
__objPath(CTX_DBUS_PATH),
__interface(CTX_DBUS_IFACE),
_I("Connection established (%s)", g_dbus_connection_get_unique_name(__connection));
}
-DBusClient::~DBusClient()
+ServiceProxy::~ServiceProxy()
{
if (!__connection)
return;
_I("Connection released");
}
-int DBusClient::call(const std::string& methodName, GVariant* inParam, GVariant** outParam)
+int ServiceProxy::call(const std::string& methodName, GVariant* inParam, GVariant** outParam)
{
IF_FAIL_RETURN_TAG(__connection, E_FAILED, _E, "Not connected");
_D("Call '%s' (sync)", methodName.c_str());
return ret;
}
-int DBusClient::call(const std::string& methodName, GVariant* inParam, IClientResultListener* listener)
+int ServiceProxy::call(const std::string& methodName, GVariant* inParam, IServiceResultListener* listener)
{
IF_FAIL_RETURN_TAG(__connection, E_FAILED, _E, "Not connected");
_D("Call '%s' (async)", methodName.c_str());
ResultCbData* cbData = new(std::nothrow) ResultCbData;
IF_FAIL_RETURN_TAG(cbData, E_NO_MEM, _E, "Memory allocation failed");
- cbData->client = this;
+ cbData->proxy = this;
cbData->name = methodName;
cbData->resultListener = listener;
return E_NONE;
}
-unsigned int DBusClient::subscribe(const std::string& signalName, IClientSignalListener* listener)
+unsigned int ServiceProxy::subscribe(const std::string& signalName, IServiceSignalListener* listener)
{
IF_FAIL_RETURN_TAG(__connection, 0, _E, "Not connected");
return sid;
}
-void DBusClient::unsubscribe(unsigned int subscriptionId)
+void ServiceProxy::unsubscribe(unsigned int subscriptionId)
{
g_dbus_connection_signal_unsubscribe(__connection, subscriptionId);
}
-void DBusClient::__asyncReadyCb(GObject* srcObj, GAsyncResult* res, gpointer userData)
+void ServiceProxy::__asyncReadyCb(GObject* srcObj, GAsyncResult* res, gpointer userData)
{
ResultCbData* cbData = static_cast<ResultCbData*>(userData);
GError *gerr = NULL;
- GVariant* param = g_dbus_connection_call_finish(cbData->client->__connection, res, &gerr);
+ GVariant* param = g_dbus_connection_call_finish(cbData->proxy->__connection, res, &gerr);
if (param)
- cbData->client->__onSuccess(cbData->name, param, cbData->resultListener);
+ cbData->proxy->__onSuccess(cbData->name, param, cbData->resultListener);
else
- cbData->client->__onError(cbData->name, gerr, cbData->resultListener);
+ cbData->proxy->__onError(cbData->name, gerr, cbData->resultListener);
delete cbData;
}
-void DBusClient::__signalCb(GDBusConnection* conn, const gchar* sender, const gchar* path, const gchar* iface, const gchar* name, GVariant* param, gpointer userData)
+void ServiceProxy::__signalCb(GDBusConnection* conn, const gchar* sender, const gchar* path, const gchar* iface, const gchar* name, GVariant* param, gpointer userData)
{
- IClientSignalListener* listener = static_cast<IClientSignalListener*>(userData);
+ IServiceSignalListener* listener = static_cast<IServiceSignalListener*>(userData);
listener->onSignal(name, param);
}
-void DBusClient::__onSuccess(const std::string& methodName, GVariant* param, IClientResultListener* listener)
+void ServiceProxy::__onSuccess(const std::string& methodName, GVariant* param, IServiceResultListener* listener)
{
_D("Reply to %s.%s", __serviceName, methodName.c_str());
g_variant_unref(param);
}
-void DBusClient::__onError(const std::string& methodName, GError* gerr, IClientResultListener* listener)
+void ServiceProxy::__onError(const std::string& methodName, GError* gerr, IServiceResultListener* listener)
{
_D("Error on %s.%s", __serviceName, methodName.c_str());
* limitations under the License.
*/
-#include <DBusService.h>
+#include <ServiceBase.h>
#include <Credential.h>
#include <MethodCall.h>
-#include <ClientProxy.h>
+#include <ClientBase.h>
using namespace ctx;
-ClientProxy::ClientProxy(DBusService* hostService, const std::string& busName) :
+ClientBase::ClientBase(ServiceBase* hostService, const std::string& busName) :
__hostService(hostService),
__busName(busName),
__credential(NULL)
{
}
-ClientProxy::~ClientProxy()
+ClientBase::~ClientBase()
{
delete __credential;
}
-const std::string& ClientProxy::getBusName() const
+const std::string& ClientBase::getBusName() const
{
return __busName;
}
-Credential* ClientProxy::getCredential()
+Credential* ClientBase::getCredential()
{
if (__credential)
return __credential;
return __credential;
}
-DBusService* ClientProxy::getHostService()
+ServiceBase* ClientBase::getHostService()
{
return __hostService;
}
-void ClientProxy::publish(const std::string& signalName, GVariant* param)
+void ClientBase::publish(const std::string& signalName, GVariant* param)
{
__hostService->publish(__busName, signalName, param);
}
* limitations under the License.
*/
-#include <ClientProxy.h>
+#include <ClientBase.h>
#include <MethodCall.h>
using namespace ctx;
-MethodCall::MethodCall(ClientProxy* proxy, const std::string& methodName, GVariant* param, GDBusMethodInvocation* invocation) :
- __clientProxy(proxy),
+MethodCall::MethodCall(ClientBase* client, const std::string& methodName, GVariant* param, GDBusMethodInvocation* invocation) :
+ __client(client),
__methodName(methodName),
__param(param),
__invocation(invocation)
if (!__invocation)
return;
- _E("Method call '%s' from '%s' is not handled yet", __methodName.c_str(), __clientProxy->getBusName().c_str());
+ _E("Method call '%s' from '%s' is not handled yet", __methodName.c_str(), __client->getBusName().c_str());
g_dbus_method_invocation_return_error_literal(__invocation, CTX_ERROR_DOMAIN, E_FAILED, "");
}
-ClientProxy* MethodCall::getSender()
+ClientBase* MethodCall::getSender()
{
- return __clientProxy;
+ return __client;
}
const std::string& MethodCall::getMethodName() const
#include <systemd/sd-login.h>
#include <ScopeMutex.h>
-#include <ClientProxy.h>
+#include <ClientBase.h>
#include <MethodCall.h>
-#include <DBusService.h>
+#include <ServiceBase.h>
using namespace ctx;
-DBusService::DBusService(GDBusConnection* conn, const char* serviceName, const char* methodSpecs) :
+ServiceBase::ServiceBase(GDBusConnection* conn, const char* serviceName, const char* methodSpecs) :
__serviceName(serviceName),
__mainContext(NULL),
__mainLoop(NULL),
__interface += serviceName;
}
-DBusService::~DBusService()
+ServiceBase::~ServiceBase()
{
}
-GDBusConnection* DBusService::getConnection()
+GDBusConnection* ServiceBase::getConnection()
{
return __connection;
}
-bool DBusService::start()
+bool ServiceBase::start()
{
_I("Preparing '%s'", __serviceName);
return true;
}
-void DBusService::stop()
+void ServiceBase::stop()
{
#ifndef SINGLE_THREADING
if (__mainLoop && g_main_loop_is_running(__mainLoop)) {
#endif
}
-gboolean DBusService::__stopMainLoop(gpointer data)
+gboolean ServiceBase::__stopMainLoop(gpointer data)
{
- DBusService* svc = static_cast<DBusService*>(data);
+ ServiceBase* svc = static_cast<ServiceBase*>(data);
_I(PURPLE("Stopping '%s'"), svc->__serviceName);
g_main_loop_quit(svc->__mainLoop);
return G_SOURCE_REMOVE;
}
-void DBusService::publish(const std::string& busName, const std::string& signalName, GVariant* param)
+void ServiceBase::publish(const std::string& busName, const std::string& signalName, GVariant* param)
{
GError* gerr = NULL;
g_dbus_connection_emit_signal(__connection,
HANDLE_GERROR(gerr);
}
-uid_t DBusService::getActiveUser()
+uid_t ServiceBase::getActiveUser()
{
if (__activeUid == 0) {
uid_t* users = NULL;
return __activeUid;
}
-gpointer DBusService::__threadFunc(gpointer data)
+gpointer ServiceBase::__threadFunc(gpointer data)
{
- DBusService* service = static_cast<DBusService*>(data);
+ ServiceBase* service = static_cast<ServiceBase*>(data);
service->__run();
return NULL;
}
-void DBusService::__run()
+void ServiceBase::__run()
{
if (!__init()) {
_E("Starting failed");
__release();
}
-bool DBusService::__init()
+bool ServiceBase::__init()
{
GError* gerr = NULL;
GDBusInterfaceVTable vtable;
return prepare();
}
-void DBusService::__release()
+void ServiceBase::__release()
{
_D("Releasing '%s'", __serviceName);
- for (auto iter = __proxies.begin(); iter != __proxies.end(); ++iter) {
- iter->second.proxy->onDisconnected();
- delete iter->second.proxy;
+ for (auto iter = __clients.begin(); iter != __clients.end(); ++iter) {
+ iter->second.client->onDisconnected();
+ delete iter->second.client;
}
- __proxies.clear();
+ __clients.clear();
cleanup();
g_main_context_unref(__mainContext);
}
-void DBusService::__onUserNew(GDBusConnection* conn, const gchar* sender,
+void ServiceBase::__onUserNew(GDBusConnection* conn, const gchar* sender,
const gchar* path, const gchar* iface, const gchar* name,
GVariant* param, gpointer userData)
{
g_variant_get_child(param, 0, "u", &uid);
IF_FAIL_VOID_TAG(uid > 0, _W, "UID == 0");
- DBusService* svc = static_cast<DBusService*>(userData);
+ ServiceBase* svc = static_cast<ServiceBase*>(userData);
if (svc->__activeUid == static_cast<uid_t>(uid))
return;
svc->onUserActivated(svc->__activeUid);
}
-void DBusService::__onMethodCalled(GDBusConnection* conn, const gchar* sender,
+void ServiceBase::__onMethodCalled(GDBusConnection* conn, const gchar* sender,
const gchar* path, const gchar* iface, const gchar* name,
GVariant* param, GDBusMethodInvocation* invocation, gpointer userData)
{
- DBusService* service = static_cast<DBusService*>(userData);
+ ServiceBase* service = static_cast<ServiceBase*>(userData);
service->__onMethodCalled(sender, name, param, invocation);
}
-void DBusService::__onMethodCalled(const std::string& sender,
+void ServiceBase::__onMethodCalled(const std::string& sender,
const std::string& name, GVariant* param, GDBusMethodInvocation* invocation)
{
_I("'%s' called '%s.%s'", sender.c_str(), __serviceName, name.c_str());
- ClientProxy* proxy = __getClientProxy(sender);
- IF_FAIL_VOID(proxy);
+ ClientBase* client = __getClient(sender);
+ IF_FAIL_VOID(client);
- MethodCall* methodCall = new(std::nothrow) MethodCall(proxy, name, param, invocation);
+ MethodCall* methodCall = new(std::nothrow) MethodCall(client, name, param, invocation);
IF_FAIL_VOID_TAG(methodCall, _E, "Memory allocation failed");
- proxy->onMethodCalled(methodCall);
+ client->onMethodCalled(methodCall);
}
-ClientProxy* DBusService::__getClientProxy(const std::string& busName)
+ClientBase* ServiceBase::__getClient(const std::string& busName)
{
- auto iter = __proxies.find(busName);
+ auto iter = __clients.find(busName);
- if (iter != __proxies.end())
- return iter->second.proxy;
+ if (iter != __clients.end())
+ return iter->second.client;
- ClientProxy* proxy = createProxy(busName);
- IF_FAIL_RETURN_TAG(proxy, NULL, _E, "Memory allocation failed");
+ ClientBase* client = createClient(busName);
+ IF_FAIL_RETURN_TAG(client, NULL, _E, "Memory allocation failed");
- ProxyInfo info = {proxy, __watch(busName, proxy)};
- __proxies[busName] = info;
+ ClientInfo info = {client, __watch(busName, client)};
+ __clients[busName] = info;
- return proxy;
+ return client;
}
-void DBusService::__onNameOwnerChanged(GDBusConnection* conn, const gchar* sender,
+void ServiceBase::__onNameOwnerChanged(GDBusConnection* conn, const gchar* sender,
const gchar* path, const gchar* iface, const gchar* name,
GVariant* param, gpointer userData)
{
- ClientProxy* proxy = static_cast<ClientProxy*>(userData);
- proxy->getHostService()->__removeClientProxy(proxy->getBusName());
+ ClientBase* client = static_cast<ClientBase*>(userData);
+ client->getHostService()->__removeClient(client->getBusName());
}
-void DBusService::__removeClientProxy(const std::string& busName)
+void ServiceBase::__removeClient(const std::string& busName)
{
_I("'%s' lost '%s'", __serviceName, busName.c_str());
- auto iter = __proxies.find(busName);
- IF_FAIL_VOID(iter != __proxies.end());
+ auto iter = __clients.find(busName);
+ IF_FAIL_VOID(iter != __clients.end());
- ProxyInfo info = iter->second;
- __proxies.erase(iter);
+ ClientInfo info = iter->second;
+ __clients.erase(iter);
__unwatch(info.watchId);
- info.proxy->onDisconnected();
- delete info.proxy;
+ info.client->onDisconnected();
+ delete info.client;
}
-unsigned int DBusService::__watch(const std::string& busName, ClientProxy* proxy)
+unsigned int ServiceBase::__watch(const std::string& busName, ClientBase* client)
{
return g_dbus_connection_signal_subscribe(__connection,
"org.freedesktop.DBus", "org.freedesktop.DBus", "NameOwnerChanged", "/org/freedesktop/DBus",
- busName.c_str(), G_DBUS_SIGNAL_FLAGS_NONE, __onNameOwnerChanged, proxy, NULL);
+ busName.c_str(), G_DBUS_SIGNAL_FLAGS_NONE, __onNameOwnerChanged, client, NULL);
}
-void DBusService::__unwatch(unsigned int watchId)
+void ServiceBase::__unwatch(unsigned int watchId)
{
g_dbus_connection_signal_unsubscribe(__connection, watchId);
}