/* This header SHOULD NOT be included by other headers in this directory. */
-#include <ServiceBase.h>
+#include <IService.h>
+#include <IServiceRunner.h>
+#include <IMethodCallHandler.h>
namespace ctx {
- class EXPORT_API SensorRecorderService : public ServiceBase {
+ class EXPORT_API SensorRecorderService : public IService {
public:
- SensorRecorderService(GDBusConnection* conn);
+ SensorRecorderService();
~SensorRecorderService();
+ void setServiceRunner(IServiceRunner* runner);
+
bool isUserService();
- protected:
+ const char* getServiceName();
+ const char* getMethodSpecs();
+
bool prepare();
void cleanup();
- ClientBase* createClient(const std::string& busName);
+ void onUserActivated();
+ void onUserDeactivated();
+
+ IMethodCallHandler* createMethodCallHandler();
+
+ GDBusConnection* getConnection();
+
+ private:
+ IServiceRunner* __serviceRunner;
};
}
Name: context-sensor-recorder
Summary: Sensor recorder service server and client libraries
-Version: 1.0.0
+Version: 1.0.1
Release: 1
Group: Service Framework/Context
License: Apache-2.0
* limitations under the License.
*/
+#include <stdexcept>
#include <SensorRecorderTypesPrivate.h>
#include <SensorRecorderService.h>
using namespace ctx;
-SensorRecorderService::SensorRecorderService(GDBusConnection* conn) :
- ServiceBase(conn, CTX_SENSOR_RECORDER, CTX_SENSOR_RECORDER_SPEC)
+SensorRecorderService::SensorRecorderService() :
+ __serviceRunner(NULL)
{
throw std::runtime_error("Sensor Recorder is not supported");
}
{
}
+void SensorRecorderService::setServiceRunner(IServiceRunner* runner)
+{
+}
+
bool SensorRecorderService::isUserService()
{
return true;
}
+const char* SensorRecorderService::getServiceName()
+{
+ return NULL;
+}
+
+const char* SensorRecorderService::getMethodSpecs()
+{
+ return NULL;
+}
+
bool SensorRecorderService::prepare()
{
return false;
{
}
-ClientBase* SensorRecorderService::createClient(const std::string& busName)
+void SensorRecorderService::onUserActivated()
+{
+}
+
+void SensorRecorderService::onUserDeactivated()
+{
+}
+
+IMethodCallHandler* SensorRecorderService::createMethodCallHandler()
{
return NULL;
}
* limitations under the License.
*/
-#include <ServiceBase.h>
-#include <MethodCall.h>
+#include <ServerUtil.h>
#include <Tuple.h>
-#include "SensorRecorderClient.h"
+#include "MethodCallHandler.h"
#include "legacy/SensorProvider.h"
#define IDX_SUBJECT 0
using namespace ctx;
-SensorRecorderClient::SensorRecorderClient(ServiceBase* hostService, const std::string& busName) :
- ClientBase(hostService, busName)
+MethodCallHandler::MethodCallHandler() :
+ __caller(NULL)
{
}
-SensorRecorderClient::~SensorRecorderClient()
+MethodCallHandler::~MethodCallHandler()
{
}
-void SensorRecorderClient::onMethodCalled(MethodCall* methodCall)
+void MethodCallHandler::setCaller(IClient* client)
+{
+ __caller = client;
+}
+
+void MethodCallHandler::onMethodCalled(IMethodCall* methodCall)
{
try {
__verifyUid(methodCall->getUid());
delete methodCall;
}
-void SensorRecorderClient::onDisconnected()
+void MethodCallHandler::onDisconnected()
{
}
-void SensorRecorderClient::__verifyUid(uid_t uid)
+void MethodCallHandler::__verifyUid(uid_t uid)
{
- if (!isSystemUid(uid) && uid != ServiceBase::getActiveUser()) {
- _E("Invalid Uid: %u != %u (ActiveUser)", uid, ServiceBase::getActiveUser());
+ if (!util::isSystemUid(uid) && uid != util::getActiveUid()) {
+ _E("Invalid Uid: %u != %u (ActiveUser)", uid, util::getActiveUid());
throw static_cast<int>(E_ACCESS);
}
}
-std::string SensorRecorderClient::__extractParameter(GVariant* param, unsigned int idx)
+std::string MethodCallHandler::__extractParameter(GVariant* param, unsigned int idx)
{
const char* val = NULL;
g_variant_get_child(param, idx, "&s", &val);
return val;
}
-void SensorRecorderClient::__startRecording(SensorProvider& provider, MethodCall& methodCall)
+void MethodCallHandler::__startRecording(SensorProvider& provider, IMethodCall& methodCall)
{
- if (!hasPrivilege(provider.getPrivilege()))
+ if (!methodCall.hasPrivilege(provider.getPrivilege()))
throw static_cast<int>(E_ACCESS);
// TODO: use the 'real' package id, instead of the smack label
- std::string pkgId = getClientId();
+ std::string pkgId = methodCall.getCallerId();
std::string option = __extractParameter(methodCall.getParam(), IDX_OPTION);
_D("Option: %s", option.c_str());
methodCall.reply(error);
}
-void SensorRecorderClient::__stopRecording(SensorProvider& provider, MethodCall& methodCall)
+void MethodCallHandler::__stopRecording(SensorProvider& provider, IMethodCall& methodCall)
{
// TODO: use the 'real' package id, instead of the smack label
- std::string pkgId = getClientId();
+ std::string pkgId = methodCall.getCallerId();
int error = provider.stopRecording(pkgId);
methodCall.reply(error);
}
-void SensorRecorderClient::__readRecords(SensorProvider& provider, MethodCall& methodCall)
+void MethodCallHandler::__readRecords(SensorProvider& provider, IMethodCall& methodCall)
{
- if (!hasPrivilege(provider.getPrivilege()))
+ if (!methodCall.hasPrivilege(provider.getPrivilege()))
throw static_cast<int>(E_ACCESS);
// TODO: use the 'real' package id, instead of the smack label
- std::string pkgId = getClientId();
+ std::string pkgId = methodCall.getCallerId();
std::string option = __extractParameter(methodCall.getParam(), IDX_OPTION);
_D("Option: %s", option.c_str());
* limitations under the License.
*/
-#ifndef __SENSOR_RECORDER_CLIENT_H__
-#define __SENSOR_RECORDER_CLIENT_H__
+#ifndef __SENSOR_RECORDER_METHOD_CALL_HANDLER_H__
+#define __SENSOR_RECORDER_METHOD_CALL_HANDLER_H__
-#include <ClientBase.h>
+#include <IMethodCallHandler.h>
+#include <IMethodCall.h>
+#include <IClient.h>
namespace ctx {
class SensorProvider;
- class SensorRecorderClient : public ClientBase {
+ class MethodCallHandler : public IMethodCallHandler {
public:
- SensorRecorderClient(ServiceBase* hostService, const std::string& busName);
- ~SensorRecorderClient();
+ MethodCallHandler();
+ ~MethodCallHandler();
- void onMethodCalled(MethodCall* methodCall);
+ void setCaller(IClient* client);
+ void onMethodCalled(IMethodCall* methodCall);
void onDisconnected();
private:
void __verifyUid(uid_t uid);
std::string __extractParameter(GVariant* param, unsigned int idx);
- void __startRecording(SensorProvider& provider, MethodCall& methodCall);
- void __stopRecording(SensorProvider& provider, MethodCall& methodCall);
- void __readRecords(SensorProvider& provider, MethodCall& methodCall);
+ void __startRecording(SensorProvider& provider, IMethodCall& methodCall);
+ void __stopRecording(SensorProvider& provider, IMethodCall& methodCall);
+ void __readRecords(SensorProvider& provider, IMethodCall& methodCall);
+
+ IClient* __caller;
};
}
-#endif /* __SENSOR_RECORDER_CLIENT_H__ */
+#endif /* __SENSOR_RECORDER_METHOD_CALL_HANDLER_H__ */
* limitations under the License.
*/
+#include <ServerUtil.h>
#include <SensorRecorderTypesPrivate.h>
#include <SensorRecorderService.h>
-#include "SensorRecorderClient.h"
+#include "MethodCallHandler.h"
#include "SensorDatabase.h"
#include "SensorTimer.h"
#include "legacy/SensorProvider.h"
using namespace ctx;
-SensorRecorderService::SensorRecorderService(GDBusConnection* conn) :
- ServiceBase(conn, CTX_SENSOR_RECORDER, CTX_SENSOR_RECORDER_SPEC)
+SensorRecorderService::SensorRecorderService() :
+ __serviceRunner(NULL)
{
}
{
}
+void SensorRecorderService::setServiceRunner(IServiceRunner* runner)
+{
+ __serviceRunner = runner;
+}
+
bool SensorRecorderService::isUserService()
{
return true;
}
+const char* SensorRecorderService::getServiceName()
+{
+ return CTX_SENSOR_RECORDER;
+}
+
+const char* SensorRecorderService::getMethodSpecs()
+{
+ return CTX_SENSOR_RECORDER_SPEC;
+}
+
bool SensorRecorderService::prepare()
{
RecorderClientInfo::setHostService(this);
- if (!SensorDatabase::open(getActiveUser()))
+ if (!SensorDatabase::open(util::getActiveUid()))
return false;
- SensorTimer::init(this);
+ SensorTimer::init(__serviceRunner->getMainContext());
SensorProvider::init();
return true;
SensorDatabase::close();
}
-ClientBase* SensorRecorderService::createClient(const std::string& busName)
+void SensorRecorderService::onUserActivated()
+{
+}
+
+void SensorRecorderService::onUserDeactivated()
+{
+}
+
+IMethodCallHandler* SensorRecorderService::createMethodCallHandler()
+{
+ return new MethodCallHandler();
+}
+
+GDBusConnection* SensorRecorderService::getConnection()
{
- return new SensorRecorderClient(this, busName);
+ return __serviceRunner->getConnection();
}
#include <Timer.h>
#include <ITimerListener.h>
-#include <ServiceBase.h>
#include <SensorRecorderTypesPrivate.h>
#include "SensorTimer.h"
{
}
-void SensorTimer::init(ServiceBase* hostService)
+void SensorTimer::init(GMainContext* mainContext)
{
- __timer = new Timer(hostService);
+ __timer = new Timer(mainContext);
}
void SensorTimer::release()
#ifndef __SENSOR_RECORDER_TIMER_H__
#define __SENSOR_RECORDER_TIMER_H__
+#include <ContextTypes.h>
+
namespace ctx {
- class ServiceBase;
class Timer;
class ITimerListener;
class SensorTimer {
public:
- static void init(ServiceBase* hostService);
+ static void init(GMainContext* mainContext);
static void release();
static unsigned int addIdle(GSourceFunc callback, gpointer userData);