* 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);
{
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);
{
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;
{
IF_FAIL_RETURN(option, E_PARAM);
- delete static_cast<ctx_sensor_rec_option_t*>(option);
+ delete static_cast<ctx::CtxJson*>(option);
return E_NONE;
}
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;
}
{
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;
{
IF_FAIL_RETURN(query, E_PARAM);
- delete static_cast<ctx_sensor_rec_query_t*>(query);
+ delete static_cast<ctx::CtxJson*>(query);
return E_NONE;
}
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;
}
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;
}
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);
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;