Added function to check whether a history item is supported 96/125196/4
authorSomin Kim <somin926.kim@samsung.com>
Fri, 14 Apr 2017 05:59:17 +0000 (14:59 +0900)
committerSomin Kim <somin926.kim@samsung.com>
Wed, 19 Apr 2017 07:47:40 +0000 (16:47 +0900)
Change-Id: Ieb4801a00bb33a9267212bf60646be46e90a861f
Signed-off-by: Somin Kim <somin926.kim@samsung.com>
include/app_history_internal.h
src/client-dummy/app_history.cpp
src/client/app_history.cpp
src/server/AppHistoryClient.cpp
src/server/StatsProvider.cpp
src/server/StatsProvider.h
src/shared/AppHistoryTypesPrivate.h

index 68d443d..6c49de1 100644 (file)
@@ -32,6 +32,8 @@ int ctx_history_query(const char* uri, int64_t start_time, int64_t end_time, uns
 
 int _ctx_history_query(const char* uri, const char* filter, ctx_history_cursor_h* cursor);
 
+int ctx_history_is_supported(const char* uri, bool* supported);
+
 /* Cursor */
 int ctx_history_cursor_destroy(ctx_history_cursor_h cursor);
 
index 68f15f1..7d38180 100644 (file)
@@ -31,6 +31,11 @@ EXPORT_API int _ctx_history_query(const char* uri, const char* filter, ctx_histo
        return E_SUPPORT;
 }
 
+EXPORT_API int ctx_history_is_supported(const char* uri, bool* supported)
+{
+       return E_SUPPORT;
+}
+
 EXPORT_API int ctx_history_cursor_destroy(ctx_history_cursor_h cursor)
 {
        return E_SUPPORT;
index 8e18fd3..7e28dfd 100644 (file)
 
 using namespace ctx;
 
+static ServiceProxy* __getServiceProxy()
+{
+       static ServiceProxy proxy(CTX_APP_HISTORY);
+       return &proxy;
+}
+
 EXPORT_API int ctx_history_query(const char* uri, int64_t start_time, int64_t end_time, unsigned int result_size, ctx_history_cursor_h* cursor)
 {
        Json filter;
@@ -39,10 +45,8 @@ EXPORT_API int _ctx_history_query(const char* uri, const char* filter, ctx_histo
 {
        IF_FAIL_RETURN(uri && cursor, E_PARAM);
 
-       ServiceProxy proxy(CTX_APP_HISTORY);
-
        GVariant* output = NULL;
-       int err = proxy.call("readJson", g_variant_new("(ss)", uri, filter), &output);
+       int err = __getServiceProxy()->call("readJson", g_variant_new("(ss)", uri, filter), &output);
        IF_FAIL_RETURN_TAG(err == E_NONE, err, _E, "%s", CTX_ERROR_STR(err));
 
        char* columnNames = NULL;
@@ -68,6 +72,22 @@ EXPORT_API int _ctx_history_query(const char* uri, const char* filter, ctx_histo
        return err;
 }
 
+EXPORT_API int ctx_history_is_supported(const char* uri, bool* supported)
+{
+       IF_FAIL_RETURN(uri, E_PARAM);
+
+       *supported = false;
+
+       int err = __getServiceProxy()->call("isSupported", g_variant_new("(s)", uri));
+       if (err == E_NONE)
+               *supported =  true;
+
+       if (err == E_SUPPORT)
+               return E_NONE;
+
+       return err;
+}
+
 EXPORT_API int ctx_history_cursor_destroy(ctx_history_cursor_h cursor)
 {
        IF_FAIL_RETURN(cursor, E_NONE);
@@ -163,7 +183,6 @@ EXPORT_API int ctx_history_cursor_get_int64(ctx_history_cursor_h cursor, const c
        int64_t val;
        IF_FAIL_RETURN_TAG(cursor->tuples[cursor->index]->getAt(idx, &val), E_PARAM, _E, "Invalid data");
 
-       //TODO: Type checking & locale-invariant?
        *value = val;
 
        return E_NONE;
@@ -179,7 +198,6 @@ EXPORT_API int ctx_history_cursor_get_double(ctx_history_cursor_h cursor, const
        double val;
        IF_FAIL_RETURN_TAG(cursor->tuples[cursor->index]->getAt(idx, &val), E_PARAM, _E, "Invalid data");
 
-       //TODO: Type checking & locale-invariant?
        *value = val;
 
        return E_NONE;
index c69b841..c353e88 100644 (file)
@@ -58,8 +58,19 @@ void AppHistoryClient::onMethodCalled(MethodCall* methodCall)
                        throw static_cast<int>(E_PARAM);
                }
 
+               /* Check history data supported */
+               StatsProvider* provider = StatsManager::getProvider(subject);
+               if (!provider) {
+                       throw static_cast<int>(E_SUPPORT);
+               } else if (!provider->isSupported()) {
+                       throw static_cast<int>(E_SUPPORT);
+               }
+
+               /* Process method call */
                if (methodCall->getMethodName() == "readJson") {
-                       __readJson(StatsManager::getProvider(subject), methodCall);
+                       __readJson(provider, methodCall);
+               } else if (methodCall->getMethodName() == "isSupported") {
+                       methodCall->reply(E_NONE);
                }
        } catch (int error) {
                methodCall->reply(error);
@@ -74,9 +85,6 @@ void AppHistoryClient::onDisconnected()
 
 void AppHistoryClient::__readJson(StatsProvider* provider, MethodCall* methodCall)
 {
-       if (!provider)
-               throw static_cast<int>(E_SUPPORT);
-
        if (!provider->isAllowed(*this))
                throw static_cast<int>(E_ACCESS);
 
index 3c3c0e9..b48d7b2 100644 (file)
@@ -34,9 +34,9 @@ std::string &StatsProvider::getSubject(void)
        return __subject;
 }
 
-int StatsProvider::isSupported(void)
+bool StatsProvider::isSupported(void)
 {
-       return E_NONE;
+       return true;
 }
 
 bool StatsProvider::isAllowed(AppHistoryClient& client)
index 7a8487c..64503a2 100644 (file)
@@ -36,7 +36,7 @@ namespace ctx {
 
                std::string& getSubject(void);
 
-               virtual int isSupported(void);
+               virtual bool isSupported(void);
                virtual bool isAllowed(AppHistoryClient& clieint);
 
                virtual std::string getQuery(Json& filter);
index b9f0ddf..af90c05 100644 (file)
@@ -28,6 +28,9 @@
        "       <arg type='s' name='columnNames' direction='out'/>" \
        "       <arg type='v' name='result' direction='out'/>" \
        "</method>" \
+       "<method name='isSupported'>" \
+       "       <arg type='s' name='uri' direction='in'/>" \
+       "</method>" \
        "<method name='getLastFullyChargedTime'>" \
        "       <arg type='i' name='result' direction='out'/>" \
        "</method>"