using namespace ctx;
ServiceRunner::ServiceRunner(GDBusConnection* conn, IService* service) :
- serviceInstance(service),
- started(false),
+ __serviceInstance(service),
+ __started(false),
__uid(0),
__connection(conn),
__objPath(CTX_DBUS_PATH "/"),
__nodeInfo(NULL),
__registrationId(0)
{
- __objPath += serviceInstance->getServiceName();
- __interface += serviceInstance->getServiceName();
+ __objPath += __serviceInstance->getServiceName();
+ __interface += __serviceInstance->getServiceName();
}
ServiceRunner::~ServiceRunner()
{
+ delete __serviceInstance;
}
GMainContext* ServiceRunner::getMainContext()
IService* ServiceRunner::getService()
{
- return serviceInstance;
+ return __serviceInstance;
}
bool ServiceRunner::start(uid_t uid)
{
- IF_FAIL_RETURN(!started, true);
+ IF_FAIL_RETURN(!__started, true);
- _I(CYAN("Starting '%s'"), serviceInstance->getServiceName());
+ _I(CYAN("Starting '%s'"), __serviceInstance->getServiceName());
if (!__init(uid)) {
_E("Starting failed");
return false;
}
- started = true;
+ __started = true;
__uid = uid;
return true;
}
void ServiceRunner::stop()
{
- IF_FAIL_VOID(started);
- started = false;
+ IF_FAIL_VOID(__started);
+ __started = false;
- _I(PURPLE("Stopping '%s'"), serviceInstance->getServiceName());
+ _I(PURPLE("Stopping '%s'"), __serviceInstance->getServiceName());
__release(__uid);
}
vtable.set_property = NULL;
std::string introspection("<node><interface name='");
- introspection += __interface + "'>" + serviceInstance->getMethodSpecs() + "</interface></node>";
+ introspection += __interface + "'>" + __serviceInstance->getMethodSpecs() + "</interface></node>";
__nodeInfo = g_dbus_node_info_new_for_xml(introspection.c_str(), NULL);
IF_FAIL_RETURN_TAG(__nodeInfo, false, _E, "NodeInfo creation failed");
ServiceClient* client = __createClient(busName);
IF_FAIL_RETURN(client, NULL);
- IMethodCallHandler* callHandler = serviceInstance->createMethodCallHandler(client);
+ IMethodCallHandler* callHandler = __serviceInstance->createMethodCallHandler(client);
if (!callHandler) {
- _E("%s's method call handler cannot be NULL.", serviceInstance->getServiceName());
+ _E("%s's method call handler cannot be NULL.", __serviceInstance->getServiceName());
delete client;
return NULL;
}
void ServiceRunner::__removeClient(const std::string& busName)
{
- _I("'%s' lost '%s'", serviceInstance->getServiceName(), busName.c_str());
+ _I("'%s' lost '%s'", __serviceInstance->getServiceName(), busName.c_str());
auto iter = __clients.find(busName);
IF_FAIL_VOID(iter != __clients.end());
void SystemServiceRunner::notifyUserNew(uid_t uid)
{
- if (started)
- static_cast<ISystemService*>(serviceInstance)->onUserActivated(uid);
+ if (__started)
+ static_cast<ISystemService*>(__serviceInstance)->onUserActivated(uid);
}
void SystemServiceRunner::notifyUserRemoved(uid_t uid)
{
- if (started)
- static_cast<ISystemService*>(serviceInstance)->onUserDeactivated(uid);
+ if (__started)
+ static_cast<ISystemService*>(__serviceInstance)->onUserDeactivated(uid);
}
bool SystemServiceRunner::__prepare(uid_t uid)
{
- return static_cast<ISystemService*>(serviceInstance)->prepare();
+ return static_cast<ISystemService*>(__serviceInstance)->prepare();
}
void SystemServiceRunner::__cleanup(uid_t uid)
{
- static_cast<ISystemService*>(serviceInstance)->cleanup();
+ static_cast<ISystemService*>(__serviceInstance)->cleanup();
}
ServiceClient* SystemServiceRunner::__createClient(const std::string& busName)
bool UserServiceRunner::__prepare(uid_t uid)
{
- return static_cast<IUserService*>(serviceInstance)->prepare(uid);
+ return static_cast<IUserService*>(__serviceInstance)->prepare(uid);
}
void UserServiceRunner::__cleanup(uid_t uid)
{
- static_cast<IUserService*>(serviceInstance)->cleanup(uid);
+ static_cast<IUserService*>(__serviceInstance)->cleanup(uid);
}
ServiceClient* UserServiceRunner::__createClient(const std::string& busName)
}
if (!util::is_normal_user(client->getUid())) {
- _W("%s does not support container users.", serviceInstance->getServiceName());
+ _W("%s does not support container users.", __serviceInstance->getServiceName());
delete client;
return NULL;
}