Change std::map to ctx::CtxJson for managing method options 26/136526/1
authorkibak.yoon <kibak.yoon@samsung.com>
Tue, 23 May 2017 12:55:05 +0000 (21:55 +0900)
committerkibak.yoon <kibak.yoon@samsung.com>
Fri, 30 Jun 2017 05:54:26 +0000 (14:54 +0900)
* CtxJson will be changed to Jsoncpp

Change-Id: Ie97f308cbb30f986dcbdf3f4aefb01d3de929339
Signed-off-by: kibak.yoon <kibak.yoon@samsung.com>
src/client/sensor_recorder.cpp

index 86c64c9..618cfcf 100644 (file)
  * limitations under the License.
  */
 
-#include <map>
 #include <sensor_recorder_internal.h>
 #include <SensorRecorderTypesPrivate.h>
 #include <ServiceProxy.h>
+#include <CtxJson.h>
 #include "QueryResultListener.h"
 
 #define STR_BUFFER_SIZE 128
 
 using namespace ctx;
 
-typedef std::map<std::string, int64_t> ctx_sensor_rec_option_t;
-typedef std::map<std::string, int64_t> ctx_sensor_rec_query_t;
-
 static ServiceProxy* __getServiceProxy()
 {
        static ServiceProxy proxy(CTX_SENSOR_RECORDER);
        return &proxy;
 }
 
-static std::string __mapToJson(const std::map<std::string, int64_t>& input)
-{
-       std::string output("{");
-       char buf[STR_BUFFER_SIZE];
-
-       for (auto& elem : input) {
-               snprintf(buf, STR_BUFFER_SIZE, "\"%s\":%lld,", elem.first.c_str(), elem.second);
-               output += buf;
-       }
-
-       if (output.back() == ',')
-               output.back() = '}';
-       else
-               output += "}";
-
-       return output;
-}
-
 EXPORT_API int ctx_sensor_rec_is_supported(const char* subject, bool *supported)
 {
        IF_FAIL_RETURN(subject && supported, E_PARAM);
@@ -68,10 +47,10 @@ EXPORT_API int ctx_sensor_rec_start(const char* subject, ctx_sensor_rec_option_h
 {
        IF_FAIL_RETURN(subject, E_PARAM);
 
-       std::string optionStr("");
-
+       std::string optionStr;
        if (option)
-               optionStr = __mapToJson(*static_cast<ctx_sensor_rec_option_t*>(option));
+               optionStr = static_cast<ctx::CtxJson *>(option)->str();
+
        GVariant* param = g_variant_new("(ss)", subject, optionStr.c_str());
 
        return __getServiceProxy()->call(METHOD_START_REC, param);
@@ -87,7 +66,7 @@ EXPORT_API int ctx_sensor_rec_create_option(ctx_sensor_rec_option_h *option)
 {
        IF_FAIL_RETURN(option, E_PARAM);
 
-       *option = new(std::nothrow) ctx_sensor_rec_option_t;
+       *option = new(std::nothrow) ctx::CtxJson;
        IF_FAIL_RETURN(*option, E_NO_MEM);
 
        return E_NONE;
@@ -97,7 +76,7 @@ EXPORT_API int ctx_sensor_rec_destroy_option(ctx_sensor_rec_option_h option)
 {
        IF_FAIL_RETURN(option, E_PARAM);
 
-       delete static_cast<ctx_sensor_rec_option_t*>(option);
+       delete static_cast<ctx::CtxJson*>(option);
 
        return E_NONE;
 }
@@ -108,7 +87,8 @@ EXPORT_API int ctx_sensor_rec_option_set_int(ctx_sensor_rec_option_h option, con
        IF_FAIL_RETURN(STR_EQ(param, CTX_SENSOR_RECORDER_KEY_INTERVAL) ||
                                   STR_EQ(param, CTX_SENSOR_RECORDER_KEY_RETENTION), E_PARAM);
 
-       (*static_cast<ctx_sensor_rec_option_t*>(option))[param] = static_cast<int64_t>(value);
+       ctx::CtxJson* optionCtxJson = static_cast<ctx::CtxJson*>(option);
+       optionCtxJson->set(NULL, param, static_cast<int64_t>(value));
 
        return E_NONE;
 }
@@ -117,7 +97,7 @@ EXPORT_API int ctx_sensor_rec_create_query(ctx_sensor_rec_query_h *query)
 {
        IF_FAIL_RETURN(query, E_PARAM);
 
-       *query = new(std::nothrow) ctx_sensor_rec_query_t;
+       *query = new(std::nothrow) ctx::CtxJson;
        IF_FAIL_RETURN(*query, E_NO_MEM);
 
        return E_NONE;
@@ -127,7 +107,7 @@ EXPORT_API int ctx_sensor_rec_destroy_query(ctx_sensor_rec_query_h query)
 {
        IF_FAIL_RETURN(query, E_PARAM);
 
-       delete static_cast<ctx_sensor_rec_query_t*>(query);
+       delete static_cast<ctx::CtxJson*>(query);
 
        return E_NONE;
 }
@@ -140,7 +120,8 @@ EXPORT_API int ctx_sensor_rec_query_set_int(ctx_sensor_rec_query_h query, const
                                   STR_EQ(param, CTX_SENSOR_RECORDER_KEY_START_TIME) ||
                                   STR_EQ(param, CTX_SENSOR_RECORDER_KEY_END_TIME), E_PARAM);
 
-       (*static_cast<ctx_sensor_rec_query_t*>(query))[param] = static_cast<int64_t>(value);
+       ctx::CtxJson* queryCtxJson = static_cast<ctx::CtxJson*>(query);
+       queryCtxJson->set(NULL, param, static_cast<int64_t>(value));
 
        return E_NONE;
 }
@@ -152,7 +133,8 @@ EXPORT_API int ctx_sensor_rec_query_set_time(ctx_sensor_rec_query_h query, const
                                   STR_EQ(param, CTX_SENSOR_RECORDER_KEY_START_TIME) ||
                                   STR_EQ(param, CTX_SENSOR_RECORDER_KEY_END_TIME), E_PARAM);
 
-       (*static_cast<ctx_sensor_rec_query_t*>(query))[param] = static_cast<int64_t>(t);
+       ctx::CtxJson* queryCtxJson = static_cast<ctx::CtxJson*>(query);
+       queryCtxJson->set(NULL, param, static_cast<int64_t>(t));
 
        return E_NONE;
 }
@@ -164,7 +146,7 @@ EXPORT_API int ctx_sensor_rec_read(const char* subject, ctx_sensor_rec_query_h q
        QueryResultListener* listener = new(std::nothrow) QueryResultListener(subject, cb, user_data);
        IF_FAIL_RETURN_TAG(listener, E_NO_MEM, _E, E_STR_ALLOC);
 
-       std::string queryStr = __mapToJson(*static_cast<ctx_sensor_rec_query_t*>(query));
+       std::string queryStr = static_cast<ctx::CtxJson*>(query)->str();
        GVariant* param = g_variant_new("(ss)", subject, queryStr.c_str());
 
        int error = __getServiceProxy()->call(METHOD_READ_REC, param, listener);
@@ -182,7 +164,7 @@ EXPORT_API int ctx_sensor_rec_read_sync(const char* subject, ctx_sensor_rec_quer
        QueryResultListener* listener = new(std::nothrow) QueryResultListener(subject, cb, user_data);
        IF_FAIL_RETURN_TAG(listener, E_NO_MEM, _E, E_STR_ALLOC);
 
-       std::string queryStr = __mapToJson(*static_cast<ctx_sensor_rec_query_t*>(query));
+       std::string queryStr = static_cast<ctx::CtxJson*>(query)->str();
        GVariant* param = g_variant_new("(ss)", subject, queryStr.c_str());
 
        GVariant* outParam = NULL;