/* 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;
};
}
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
* 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");
}
{
}
+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;
{
}
-ClientBase* AppHistoryService::createClient(const std::string& busName)
+void AppHistoryService::onUserActivated()
+{
+}
+
+void AppHistoryService::onUserDeactivated()
+{
+}
+
+IMethodCallHandler* AppHistoryService::createMethodCallHandler()
{
return NULL;
}
* 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"
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)
{
}
{
}
+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;
}
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();
}
*/
#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;
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);
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;
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);
}
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;
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");
* 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__ */
* limitations under the License.
*/
-#include "AppHistoryClient.h"
#include "StatsProvider.h"
using namespace ctx;
return true;
}
-bool StatsProvider::isAllowed(AppHistoryClient& client)
+bool StatsProvider::isAllowed(IClient& caller)
{
- if (!client.hasPrivileges(__privileges))
+ if (!caller.hasPrivileges(__privileges))
return false;
return true;
#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:
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);