Dependency cleanup: apply the modified service & client interfaces 56/133256/2
authorMu-Woong Lee <muwoong.lee@samsung.com>
Fri, 9 Jun 2017 10:45:42 +0000 (19:45 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Fri, 9 Jun 2017 11:19:52 +0000 (20:19 +0900)
Change-Id: I9eda5fa56e03338e5acd8768976714f5bf007d5f
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
include/private/SensorRecorderService.h
packaging/context-sensor-recorder.spec
src/server-dummy/SensorRecorderService.cpp
src/server/MethodCallHandler.cpp [moved from src/server/SensorRecorderClient.cpp with 70% similarity]
src/server/MethodCallHandler.h [moved from src/server/SensorRecorderClient.h with 55% similarity]
src/server/SensorRecorderService.cpp
src/server/SensorTimer.cpp
src/server/SensorTimer.h

index 50f9a8b..90520f4 100644 (file)
 
 /* 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;
        };
 
 }
index a09e3a2..83efa7b 100644 (file)
@@ -1,6 +1,6 @@
 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
index 2501a40..06cf899 100644 (file)
  * 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");
 }
@@ -29,11 +30,25 @@ SensorRecorderService::~SensorRecorderService()
 {
 }
 
+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;
@@ -43,7 +58,15 @@ void SensorRecorderService::cleanup()
 {
 }
 
-ClientBase* SensorRecorderService::createClient(const std::string& busName)
+void SensorRecorderService::onUserActivated()
+{
+}
+
+void SensorRecorderService::onUserDeactivated()
+{
+}
+
+IMethodCallHandler* SensorRecorderService::createMethodCallHandler()
 {
        return NULL;
 }
similarity index 70%
rename from src/server/SensorRecorderClient.cpp
rename to src/server/MethodCallHandler.cpp
index 87eed76..8a20944 100644 (file)
  * 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());
@@ -64,19 +68,19 @@ void SensorRecorderClient::onMethodCalled(MethodCall* methodCall)
        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);
@@ -87,13 +91,13 @@ std::string SensorRecorderClient::__extractParameter(GVariant* param, unsigned i
        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());
 
@@ -101,22 +105,22 @@ void SensorRecorderClient::__startRecording(SensorProvider& provider, MethodCall
        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());
 
similarity index 55%
rename from src/server/SensorRecorderClient.h
rename to src/server/MethodCallHandler.h
index 45cc9fe..cde2a2b 100644 (file)
  * 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__ */
index b9ddf11..bb1ae60 100644 (file)
  * 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"
@@ -24,8 +25,8 @@
 
 using namespace ctx;
 
-SensorRecorderService::SensorRecorderService(GDBusConnection* conn) :
-       ServiceBase(conn, CTX_SENSOR_RECORDER, CTX_SENSOR_RECORDER_SPEC)
+SensorRecorderService::SensorRecorderService() :
+       __serviceRunner(NULL)
 {
 }
 
@@ -33,19 +34,34 @@ SensorRecorderService::~SensorRecorderService()
 {
 }
 
+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;
@@ -58,7 +74,20 @@ void SensorRecorderService::cleanup()
        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();
 }
index 62f7da9..2e83968 100644 (file)
@@ -16,7 +16,6 @@
 
 #include <Timer.h>
 #include <ITimerListener.h>
-#include <ServiceBase.h>
 #include <SensorRecorderTypesPrivate.h>
 #include "SensorTimer.h"
 
@@ -28,9 +27,9 @@ SensorTimer::SensorTimer()
 {
 }
 
-void SensorTimer::init(ServiceBase* hostService)
+void SensorTimer::init(GMainContext* mainContext)
 {
-       __timer = new Timer(hostService);
+       __timer = new Timer(mainContext);
 }
 
 void SensorTimer::release()
index ba79daa..3f258a3 100644 (file)
 #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);