Dependency cleanup: apply the modified service & client interfaces 67/133267/2
authorMu-Woong Lee <muwoong.lee@samsung.com>
Fri, 9 Jun 2017 11:09:20 +0000 (20:09 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Fri, 9 Jun 2017 11:18:28 +0000 (20:18 +0900)
Change-Id: Ideb34e24b35c9e92e233785fe985461aefacde24
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
include/private/AppHistoryService.h
packaging/context-app-history.spec
src/server-dummy/AppHistoryService.cpp
src/server/AppHistoryService.cpp
src/server/MethodCallHandler.cpp [moved from src/server/AppHistoryClient.cpp with 82% similarity]
src/server/MethodCallHandler.h [moved from src/server/AppHistoryClient.h with 54% similarity]
src/server/StatsProvider.cpp
src/server/StatsProvider.h

index 470fde9..68319de 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>
 #include <AppHistoryTypes.h>
 
 namespace ctx {
 
-       class EXPORT_API AppHistoryService : public ServiceBase {
+       class EXPORT_API AppHistoryService : public IService {
        public:
-               AppHistoryService(GDBusConnection* conn);
+               AppHistoryService();
                ~AppHistoryService();
 
+               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();
+
+       private:
+               IServiceRunner* __serviceRunner;
        };
 
 }
index 40041db..2528567 100644 (file)
@@ -1,6 +1,6 @@
 Name:       context-app-history
 Summary:    Application history service server and client libraries
-Version:    0.10.1
+Version:    0.10.2
 Release:    1
 Group:      Service Framework/Context
 License:    Apache-2.0
index 637b5b8..71e27bf 100644 (file)
  * limitations under the License.
  */
 
+#include <stdexcept>
 #include <AppHistoryTypesPrivate.h>
 #include <AppHistoryService.h>
 
 using namespace ctx;
 
-AppHistoryService::AppHistoryService(GDBusConnection* conn) :
-       ServiceBase(conn, CTX_APP_HISTORY, CTX_APP_HISTORY_SPEC)
+
+AppHistoryService::AppHistoryService() :
+       __serviceRunner(NULL)
 {
        throw std::runtime_error("App-History is not supported");
 }
@@ -29,11 +31,25 @@ AppHistoryService::~AppHistoryService()
 {
 }
 
+void AppHistoryService::setServiceRunner(IServiceRunner* runner)
+{
+}
+
 bool AppHistoryService::isUserService()
 {
        return true;
 }
 
+const char* AppHistoryService::getServiceName()
+{
+       return NULL;
+}
+
+const char* AppHistoryService::getMethodSpecs()
+{
+       return NULL;
+}
+
 bool AppHistoryService::prepare()
 {
        return false;
@@ -43,7 +59,15 @@ void AppHistoryService::cleanup()
 {
 }
 
-ClientBase* AppHistoryService::createClient(const std::string& busName)
+void AppHistoryService::onUserActivated()
+{
+}
+
+void AppHistoryService::onUserDeactivated()
+{
+}
+
+IMethodCallHandler* AppHistoryService::createMethodCallHandler()
 {
        return NULL;
 }
index 85dd541..bdfd3b4 100644 (file)
  * limitations under the License.
  */
 
+#include <ServerUtil.h>
 #include <AppHistoryTypesPrivate.h>
 #include <AppHistoryService.h>
 #include <Timer.h>
-#include "AppHistoryClient.h"
+#include "MethodCallHandler.h"
 #include "battery-stats/BatteryStatsManager.h"
 #include "usage-stats/UsageStatsManager.h"
 #include "DatabaseManager.h"
@@ -28,8 +29,8 @@ static Timer* __timer = NULL;
 static StatsManager* __batteryMgr = NULL;
 static StatsManager* __usageMgr = NULL;
 
-AppHistoryService::AppHistoryService(GDBusConnection* conn) :
-       ServiceBase(conn, CTX_APP_HISTORY, CTX_APP_HISTORY_SPEC)
+AppHistoryService::AppHistoryService() :
+       __serviceRunner(NULL)
 {
 }
 
@@ -37,25 +38,40 @@ AppHistoryService::~AppHistoryService()
 {
 }
 
+void AppHistoryService::setServiceRunner(IServiceRunner* runner)
+{
+       __serviceRunner = runner;
+}
+
 bool AppHistoryService::isUserService()
 {
        return true;
 }
 
+const char* AppHistoryService::getServiceName()
+{
+       return CTX_APP_HISTORY;
+}
+
+const char* AppHistoryService::getMethodSpecs()
+{
+       return CTX_APP_HISTORY_SPEC;
+}
+
 bool AppHistoryService::prepare()
 {
        /* Opoen database */
-       bool ret = DatabaseManager::initialize(getActiveUser());
+       bool ret = DatabaseManager::initialize(util::getActiveUid());
        IF_FAIL_RETURN_TAG(ret, false, _E, "%s", "Failed to initialize DatabaseManager");
 
        /* Create timer */
-       __timer = new Timer(getMainContext());
+       __timer = new Timer(__serviceRunner->getMainContext());
 
        /* Create battery stats manager */
        __batteryMgr = new BatteryStatsManager(__timer);
 
        /* Create usage stats manager */
-       __usageMgr = new UsageStatsManager(getConnection(), __timer);
+       __usageMgr = new UsageStatsManager(__serviceRunner->getConnection(), __timer);
 
        return true;
 }
@@ -84,7 +100,15 @@ void AppHistoryService::cleanup()
        DatabaseManager::destroy();
 }
 
-ClientBase* AppHistoryService::createClient(const std::string& busName)
+void AppHistoryService::onUserActivated()
+{
+}
+
+void AppHistoryService::onUserDeactivated()
+{
+}
+
+IMethodCallHandler* AppHistoryService::createMethodCallHandler()
 {
-       return new AppHistoryClient(this, busName);
+       return new MethodCallHandler();
 }
similarity index 82%
rename from src/server/AppHistoryClient.cpp
rename to src/server/MethodCallHandler.cpp
index 2040252..f4b19fb 100644 (file)
  */
 
 #include <CtxJson.h>
-#include <ServiceBase.h>
-#include <MethodCall.h>
+#include <ServerUtil.h>
 #include "StatsManager.h"
-#include "AppHistoryClient.h"
+#include "MethodCallHandler.h"
 #include "battery-stats/BatteryMonitor.h"
 
 using namespace ctx;
@@ -37,20 +36,25 @@ static std::string columnNamesToTuple(std::vector<std::string>& columnNames)
        return result;
 }
 
-AppHistoryClient::AppHistoryClient(ServiceBase* hostService, const std::string& busName) :
-       ClientBase(hostService, busName)
+MethodCallHandler::MethodCallHandler() :
+       __caller(NULL)
 {
 }
 
-AppHistoryClient::~AppHistoryClient()
+MethodCallHandler::~MethodCallHandler()
 {
 }
 
-void AppHistoryClient::onMethodCalled(MethodCall* methodCall)
+void MethodCallHandler::setCaller(IClient* client)
+{
+       __caller = client;
+}
+
+void MethodCallHandler::onMethodCalled(IMethodCall* methodCall)
 {
        try{
                char* param = g_variant_print(methodCall->getParam(), FALSE);
-               _I("Caller: %s, Method: %s", methodCall->getSender().getBusName().c_str(), methodCall->getMethodName().c_str());
+               _I("Caller: %s, Method: %s", methodCall->getCaller().getBusName().c_str(), methodCall->getMethodName().c_str());
                _I("Parameters: %s", param);
                g_free(param);
 
@@ -69,11 +73,11 @@ void AppHistoryClient::onMethodCalled(MethodCall* methodCall)
        delete methodCall;
 }
 
-void AppHistoryClient::onDisconnected()
+void MethodCallHandler::onDisconnected()
 {
 }
 
-void AppHistoryClient::__query(MethodCall* methodCall)
+void MethodCallHandler::__query(IMethodCall* methodCall)
 {
        const char* subject = NULL;
        const char* filter = NULL;
@@ -89,7 +93,7 @@ void AppHistoryClient::__query(MethodCall* methodCall)
                throw static_cast<int>(E_SUPPORT);
        } else if (!provider->isSupported()) {
                throw static_cast<int>(E_SUPPORT);
-       } else if (!provider->isAllowed(*this)) {
+       } else if (!provider->isAllowed(methodCall->getCaller())) {
                throw static_cast<int>(E_ACCESS);
        }
 
@@ -106,7 +110,7 @@ void AppHistoryClient::__query(MethodCall* methodCall)
        methodCall->reply(g_variant_new("(sv)", columnNamesToTuple(columnNames).c_str(), Tuple::toGVariant(result)));
 }
 
-void AppHistoryClient::__isSupported(MethodCall* methodCall)
+void MethodCallHandler::__isSupported(IMethodCall* methodCall)
 {
        const char* subject = NULL;
 
@@ -126,7 +130,7 @@ void AppHistoryClient::__isSupported(MethodCall* methodCall)
        methodCall->reply(E_NONE);
 }
 
-void AppHistoryClient::__getLastFullyChargedTime(MethodCall* methodCall)
+void MethodCallHandler::__getLastFullyChargedTime(IMethodCall* methodCall)
 {
        BatteryMonitor* monitor = BatteryMonitor::getInstance();
        IF_FAIL_VOID_TAG(monitor, _E, "Failted to get battery monitor instance");
similarity index 54%
rename from src/server/AppHistoryClient.h
rename to src/server/MethodCallHandler.h
index 0b02efd..4582f74 100644 (file)
  * limitations under the License.
  */
 
-#ifndef __CONTEXT_APP_HISTORY_CLIENT_H__
-#define __CONTEXT_APP_HISTORY_CLIENT_H__
+#ifndef __CONTEXT_APP_HISTORY_METHOD_CALL_HANDLER_H__
+#define __CONTEXT_APP_HISTORY_METHOD_CALL_HANDLER_H__
 
-#include <ClientBase.h>
+#include <IMethodCallHandler.h>
+#include <IMethodCall.h>
+#include <IClient.h>
 
 namespace ctx {
 
        class StatsProvider;
 
-       class AppHistoryClient : public ClientBase {
+       class MethodCallHandler : public IMethodCallHandler {
        public:
-               AppHistoryClient(ServiceBase* hostService, const std::string& busName);
-               ~AppHistoryClient();
+               MethodCallHandler();
+               ~MethodCallHandler();
 
-               void onMethodCalled(MethodCall* methodCall);
+               void setCaller(IClient* client);
+               void onMethodCalled(IMethodCall* methodCall);
                void onDisconnected();
 
        private:
-               void __query(MethodCall* methodCall);
-               void __isSupported(MethodCall* methodCall);
-               void __getLastFullyChargedTime(MethodCall* methodCall);
+               void __query(IMethodCall* methodCall);
+               void __isSupported(IMethodCall* methodCall);
+               void __getLastFullyChargedTime(IMethodCall* methodCall);
 
+               IClient* __caller;
        };
 
 }
 
-#endif /* __CONTEXT_APP_HISTORY_CLIENT_H__ */
+#endif /* __CONTEXT_APP_HISTORY_METHOD_CALL_HANDLER_H__ */
index 29015c4..c49f69c 100644 (file)
@@ -14,7 +14,6 @@
  * limitations under the License.
  */
 
-#include "AppHistoryClient.h"
 #include "StatsProvider.h"
 
 using namespace ctx;
@@ -39,9 +38,9 @@ bool StatsProvider::isSupported(void)
        return true;
 }
 
-bool StatsProvider::isAllowed(AppHistoryClient& client)
+bool StatsProvider::isAllowed(IClient& caller)
 {
-       if (!client.hasPrivileges(__privileges))
+       if (!caller.hasPrivileges(__privileges))
                return false;
 
        return true;
index cf81234..b54ac13 100644 (file)
 #include <vector>
 #include <CtxJson.h>
 #include <Tuple.h>
+#include <IClient.h>
 #include <AppHistoryTypes.h>
 #include <AppHistoryTypesPrivate.h>
 #include "DatabaseManager.h"
 
 namespace ctx {
 
-       class AppHistoryClient;
 
        class StatsProvider {
        public:
@@ -37,7 +37,7 @@ namespace ctx {
                std::string& getSubject(void);
 
                virtual bool isSupported(void);
-               virtual bool isAllowed(AppHistoryClient& clieint);
+               virtual bool isAllowed(IClient& caller);
 
                virtual std::string getQuery(CtxJson& filter);
                virtual int read(CtxJson& filter, std::vector<std::string>& columnNames, std::vector<std::shared_ptr<Tuple>>& records);