#ifndef __TIZEN_CONTEXT_HISTORY_TYPES_INTERNAL_H__
#define __TIZEN_CONTEXT_HISTORY_TYPES_INTERNAL_H__
-#include <json.h>
-
#define CONTEXT_HISTORY_DATA "QueryResult"
#define SUBJ_RECENTLY_USED_APP "stats/app/recently"
return __request(REQ_SUPPORT, __generateReqId(), subject.c_str(), NULL, NULL, NULL);
}
-int DBusClient::subscribe(std::string subject, json option, int *reqId, json *result)
+int DBusClient::subscribe(std::string subject, Json option, int *reqId, Json *result)
{
IF_FAIL_RETURN(__init(), ERR_OPERATION_FAILED);
ASSERT_NOT_NULL(reqId);
return __request(REQ_UNSUBSCRIBE, reqId, subject.c_str(), NULL, NULL, NULL);
}
-int DBusClient::read(std::string subject, json option, int *reqId, json *result)
+int DBusClient::read(std::string subject, Json option, int *reqId, Json *result)
{
IF_FAIL_RETURN(__init(), ERR_OPERATION_FAILED);
ASSERT_NOT_NULL(reqId);
return error;
}
-int DBusClient::readSync(std::string subject, json option, int *reqId, json *outputData)
+int DBusClient::readSync(std::string subject, Json option, int *reqId, Json *outputData)
{
IF_FAIL_RETURN(__init(), ERR_OPERATION_FAILED);
ASSERT_NOT_NULL(reqId);
return error;
}
-int DBusClient::write(std::string subject, json inputData)
+int DBusClient::write(std::string subject, Json inputData)
{
IF_FAIL_RETURN(__init(), ERR_OPERATION_FAILED);
return error;
}
-int DBusClient::write(std::string subject, json inputData, json *result)
+int DBusClient::write(std::string subject, Json inputData, Json *result)
{
IF_FAIL_RETURN(__init(), ERR_OPERATION_FAILED);
int isSupported(std::string subject);
- int subscribe(std::string subject, json option, int *reqId, json *result);
+ int subscribe(std::string subject, Json option, int *reqId, Json *result);
int unsubscribe(std::string subject, int reqId);
- int read(std::string subject, json option, int *reqId, json *result);
- int readSync(std::string subject, json option, int *reqId, json *outputData);
- int write(std::string subject, json inputData);
- int write(std::string subject, json inputData, json *result);
+ int read(std::string subject, Json option, int *reqId, Json *result);
+ int readSync(std::string subject, Json option, int *reqId, Json *outputData);
+ int write(std::string subject, Json inputData);
+ int write(std::string subject, Json inputData, Json *result);
private:
static void __onMethodCalled(GDBusConnection *conn, const gchar *sender,
#define _CONTEXT_I_DBUS_CLIENT_LISTENER_H_
#include <string>
-#include <json.h>
+#include <Json.h>
namespace ctx {
class IDBusClientListener {
public:
virtual ~IDBusClientListener() {}
- virtual void onPublish(std::string subject, int reqId, int error, json event) = 0;
+ virtual void onPublish(std::string subject, int reqId, int error, Json event) = 0;
};
} /* namespace ctx */
*/
#include <map>
-#include <json.h>
+#include <Json.h>
#include <context_history.h>
#include <context_history_types_internal.h>
#include "request_handler.h"
} _cx_history_handle;
typedef struct _context_history_filter_handle_s {
- ctx::json jfilter;
+ ctx::Json jfilter;
} _cx_history_filter_handle;
typedef struct _context_history_list_handle_s {
- ctx::json jlist;
+ ctx::Json jlist;
int current;
_context_history_list_handle_s()
{
} _cx_history_list_handle;
typedef struct _context_history_record_handle_s {
- ctx::json jrecord;
+ ctx::Json jrecord;
} _cx_history_record_handle;
static std::string convert_filter_to_string(context_history_filter_e filter_type);
IF_FAIL_RETURN_TAG(check_invalid_filter(data_type, filter), CONTEXT_HISTORY_ERROR_INVALID_PARAMETER, _E, "Invalid filter key");
int req_id;
- ctx::json tmp_list;
+ ctx::Json tmp_list;
int err = ctx::request_handler::read_sync(data_type_str.c_str(), (filter)? &filter->jfilter : NULL, &req_id, &tmp_list);
IF_FAIL_RETURN_TAG(err==ERR_NONE, err, _E, "Getting list failed");
_J("Read response", tmp_list);
- IF_FAIL_RETURN_TAG(tmp_list.array_get_size(NULL, CONTEXT_HISTORY_DATA) > 0, CONTEXT_HISTORY_ERROR_NO_DATA, _D, "No data");
+ IF_FAIL_RETURN_TAG(tmp_list.getSize(NULL, CONTEXT_HISTORY_DATA) > 0, CONTEXT_HISTORY_ERROR_NO_DATA, _D, "No data");
*list = new(std::nothrow) _cx_history_list_handle();
ASSERT_ALLOC(*list);
ASSERT_NOT_NULL(count);
*count = 0;
- int result = list->jlist.array_get_size(NULL, CONTEXT_HISTORY_DATA);
+ int result = list->jlist.getSize(NULL, CONTEXT_HISTORY_DATA);
IF_FAIL_RETURN(result > 0, CONTEXT_HISTORY_ERROR_OPERATION_FAILED);
*count = result;
ASSERT_NOT_NULL(record);
*record = NULL;
- ctx::json tmp_record;
- int error = list->jlist.get_array_elem(NULL, CONTEXT_HISTORY_DATA, list->current, &tmp_record);
+ ctx::Json tmp_record;
+ int error = list->jlist.getAt(NULL, CONTEXT_HISTORY_DATA, list->current, &tmp_record);
IF_FAIL_RETURN_TAG(error, CONTEXT_HISTORY_ERROR_OPERATION_FAILED, _E, "Record load failed");
*record = new(std::nothrow) _cx_history_record_handle();
{
ASSERT_NOT_NULL(list);
- IF_FAIL_RETURN_TAG(list->current+1 < list->jlist.array_get_size(NULL, CONTEXT_HISTORY_DATA), CONTEXT_HISTORY_ERROR_NO_DATA, _D, "End of list");
+ IF_FAIL_RETURN_TAG(list->current+1 < list->jlist.getSize(NULL, CONTEXT_HISTORY_DATA), CONTEXT_HISTORY_ERROR_NO_DATA, _D, "End of list");
list->current++;
IF_FAIL_RETURN_TAG(check_record_key_data_type(TYPE_INT, key), CONTEXT_HISTORY_ERROR_INVALID_PARAMETER, _E, "Data type mismatched");
std::list<std::string> key_list;
- record->jrecord.get_keys(&key_list);
+ record->jrecord.getKeys(&key_list);
IF_FAIL_RETURN_TAG(key_list.size() > 0, CONTEXT_HISTORY_ERROR_NO_DATA, _E, "No data");
// Check invalid record key
IF_FAIL_RETURN_TAG(check_record_key_data_type(TYPE_STRING, key), CONTEXT_HISTORY_ERROR_INVALID_PARAMETER, _E, "Data type mismatched");
std::list<std::string> key_list;
- record->jrecord.get_keys(&key_list);
+ record->jrecord.getKeys(&key_list);
IF_FAIL_RETURN_TAG(key_list.size() > 0, CONTEXT_HISTORY_ERROR_NO_DATA, _E, "No data");
// Check Invalid record key
bool found = true;
std::list<std::string> keys;
- filter->jfilter.get_keys(&keys);
+ filter->jfilter.getKeys(&keys);
for (std::list<std::string>::iterator it = keys.begin(); it != keys.end(); ++it) {
std::string key = (*it);
//#include <sstream>
//#include <iomanip>
#include <types_internal.h>
-#include <json.h>
+#include <Json.h>
#include <app_control_internal.h>
#include <bundle.h>
#include <bundle_internal.h>
//static std::string double_to_string(int value);
typedef struct _context_trigger_rule_s {
- ctx::json jrule; // rule_id, description, details(event, condition[])
- ctx::json jref;
+ ctx::Json jrule; // rule_id, description, details(event, condition[])
+ ctx::Json jref;
_context_trigger_rule_s()
{
} _context_trigger_rule_h;
typedef struct _context_trigger_rule_entry_s {
- ctx::json jentry; // key, value, operator
+ ctx::Json jentry; // key, value, operator
int type;
- ctx::json jref;
+ ctx::Json jref;
_context_trigger_rule_entry_s(int t): type(t)
{
if (!ret)
return CONTEXT_TRIGGER_ERROR_INVALID_RULE;
- ctx::json jrule_id;
+ ctx::Json jrule_id;
int error = ctx::request_handler::write_with_reply(CONTEXT_TRIGGER_SUBJECT_ADD, &(rule->jrule), &jrule_id);
if (error == ERR_NONE) {
if (rule_id <= 0)
return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER;
- ctx::json jrule_id;
+ ctx::Json jrule_id;
jrule_id.set(NULL, CT_RULE_ID, rule_id);
int error = ctx::request_handler::write_with_reply(CONTEXT_TRIGGER_SUBJECT_REMOVE, &jrule_id, NULL);
if (rule_id <= 0)
return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER;
- ctx::json jrule_id;
+ ctx::Json jrule_id;
jrule_id.set(NULL, CT_RULE_ID, rule_id);
int req_id; // Useless in context_trigger
if (rule_id <= 0)
return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER;
- ctx::json jrule_id;
+ ctx::Json jrule_id;
jrule_id.set(NULL, CT_RULE_ID, rule_id);
int error = ctx::request_handler::write_with_reply(CONTEXT_TRIGGER_SUBJECT_DISABLE, &jrule_id, NULL);
ASSERT_NOT_NULL(enabled_rule_ids && enabled_rule_count && disabled_rule_ids && disabled_rule_count);
int req_id;
- ctx::json data_read;
+ ctx::Json data_read;
int error = ctx::request_handler::read_sync(CONTEXT_TRIGGER_SUBJECT_GET_RULE_IDS, NULL, &req_id, &data_read);
if (error != ERR_NONE) {
// Enabled rules
int* e_arr = NULL;
- *enabled_rule_count = data_read.array_get_size(NULL, CT_RULE_ARRAY_ENABLED);
+ *enabled_rule_count = data_read.getSize(NULL, CT_RULE_ARRAY_ENABLED);
if (*enabled_rule_count > 0) {
e_arr = static_cast<int*>(g_malloc((*enabled_rule_count) * sizeof(int)));
IF_FAIL_RETURN_TAG(e_arr, CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY, _E, "Memory allocation failed");
int id;
- for (int i = 0; data_read.get_array_elem(NULL, CT_RULE_ARRAY_ENABLED, i, &id); i++) {
+ for (int i = 0; data_read.getAt(NULL, CT_RULE_ARRAY_ENABLED, i, &id); i++) {
*(e_arr + i) = id;
}
}
// Disabled rules
int* d_arr = NULL;
- *disabled_rule_count = data_read.array_get_size(NULL, CT_RULE_ARRAY_DISABLED);
+ *disabled_rule_count = data_read.getSize(NULL, CT_RULE_ARRAY_DISABLED);
if (*disabled_rule_count > 0) {
d_arr = static_cast<int*>(g_malloc((*disabled_rule_count) * sizeof(int)));
IF_FAIL_RETURN_TAG(d_arr, CONTEXT_TRIGGER_ERROR_OUT_OF_MEMORY, _E, "Memory allocation failed");
int id;
- for (int i = 0; data_read.get_array_elem(NULL, CT_RULE_ARRAY_DISABLED, i, &id); i++) {
+ for (int i = 0; data_read.getAt(NULL, CT_RULE_ARRAY_DISABLED, i, &id); i++) {
*(d_arr + i) = id;
}
}
if (rule_id <= 0)
return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER;
- ctx::json option;
+ ctx::Json option;
option.set(NULL, CT_RULE_ID, rule_id);
int req_id;
- ctx::json data_read;
+ ctx::Json data_read;
int error = ctx::request_handler::read_sync(CONTEXT_TRIGGER_SUBJECT_GET, &option, &req_id, &data_read);
if (error == ERR_NO_DATA) {
if (entry->type == TYPE_EVENT) {
// Err: More than one event
- ctx::json elem;
+ ctx::Json elem;
if ((rule->jrule).get(CT_RULE_DETAILS, CT_RULE_EVENT, &elem)) {
return CONTEXT_TRIGGER_ERROR_INVALID_RULE;
}
ret = ctx::rule_validator::check_referential_data(ename, rule->jref);
IF_FAIL_RETURN(ret, CONTEXT_TRIGGER_ERROR_INVALID_RULE);
- ctx::json temp = (entry->jentry).str();
+ ctx::Json temp = (entry->jentry).str();
ret = (rule->jrule).set(CT_RULE_DETAILS, CT_RULE_EVENT, temp);
} else if (entry->type == TYPE_CONDITION) {
// Err: Condition without comparison data
- if ((entry->jentry).array_get_size(NULL, CT_RULE_DATA_ARR) < 1) {
+ if ((entry->jentry).getSize(NULL, CT_RULE_DATA_ARR) < 1) {
return CONTEXT_TRIGGER_ERROR_INVALID_RULE;
}
- ctx::json elem;
- for (int i = 0; (entry->jentry).get_array_elem(NULL, CT_RULE_DATA_ARR, i, &elem); i++) {
- int val_arr_size = elem.array_get_size(NULL, CT_RULE_DATA_VALUE_ARR);
- int op_arr_size = elem.array_get_size(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR);
+ ctx::Json elem;
+ for (int i = 0; (entry->jentry).getAt(NULL, CT_RULE_DATA_ARR, i, &elem); i++) {
+ int val_arr_size = elem.getSize(NULL, CT_RULE_DATA_VALUE_ARR);
+ int op_arr_size = elem.getSize(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR);
// Err: Condition without comparison data
if (val_arr_size != op_arr_size || val_arr_size < 1 || op_arr_size < 1) {
IF_FAIL_RETURN(ret, CONTEXT_TRIGGER_ERROR_INVALID_RULE);
} else {
// If not, copy referential information to rule entry
- ctx::json info;
- for (int j = 0; (entry->jref).get_array_elem(NULL, TYPE_OPTION_STR, j, &info); j++) {
- (rule->jref).array_append(NULL, TYPE_OPTION_STR, info);
+ ctx::Json info;
+ for (int j = 0; (entry->jref).getAt(NULL, TYPE_OPTION_STR, j, &info); j++) {
+ (rule->jref).append(NULL, TYPE_OPTION_STR, info);
}
- for (int j = 0; (entry->jref).get_array_elem(NULL, TYPE_ATTR_STR, j, &info); j++) {
- (rule->jref).array_append(NULL, TYPE_ATTR_STR, info);
+ for (int j = 0; (entry->jref).getAt(NULL, TYPE_ATTR_STR, j, &info); j++) {
+ (rule->jref).append(NULL, TYPE_ATTR_STR, info);
}
}
}
- ctx::json temp = (entry->jentry).str();
- ret = (rule->jrule).array_append(CT_RULE_DETAILS, CT_RULE_CONDITION, temp);
+ ctx::Json temp = (entry->jentry).str();
+ ret = (rule->jrule).append(CT_RULE_DETAILS, CT_RULE_CONDITION, temp);
} else {
// Entry is not created
return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER;
bool ret = ctx::rule_validator::check_valid_key(TYPE_ATTR_STR, name, key);
IF_FAIL_RETURN(ret, CONTEXT_TRIGGER_ERROR_INVALID_RULE);
- ctx::json elem;
- for (int i = 0; (entry->jentry).get_array_elem(NULL, CT_RULE_DATA_ARR, i, &elem); i++) {
+ ctx::Json elem;
+ for (int i = 0; (entry->jentry).getAt(NULL, CT_RULE_DATA_ARR, i, &elem); i++) {
std::string elem_item;
elem.get(NULL, CT_RULE_DATA_KEY, &elem_item);
// Err: Comparison key is already added
}
}
- ctx::json data;
+ ctx::Json data;
data.set(NULL, CT_RULE_DATA_KEY, key);
data.set(NULL, CT_RULE_DATA_KEY_OPERATOR, logical_str);
- (entry->jentry).array_append(NULL, CT_RULE_DATA_ARR, data);
+ (entry->jentry).append(NULL, CT_RULE_DATA_ARR, data);
return CONTEXT_TRIGGER_ERROR_NONE;
}
static int context_trigger_rule_entry_add_comparison_string_internal(context_trigger_rule_entry_h entry, const char* key, std::string op, std::string value)
{
- ctx::json elem;
- for (int i = 0; (entry->jentry).get_array_elem(NULL, CT_RULE_DATA_ARR, i, &elem); i++) {
+ ctx::Json elem;
+ for (int i = 0; (entry->jentry).getAt(NULL, CT_RULE_DATA_ARR, i, &elem); i++) {
std::string elem_item;
elem.get(NULL, CT_RULE_DATA_KEY, &elem_item);
if (elem_item.compare(key) == 0) {
std::string elem_val;
std::string elem_op;
- for (int j = 0; elem.get_array_elem(NULL, CT_RULE_DATA_VALUE_ARR, j, &elem_val); j++) {
- elem.get_array_elem(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR, j, &elem_op);
+ for (int j = 0; elem.getAt(NULL, CT_RULE_DATA_VALUE_ARR, j, &elem_val); j++) {
+ elem.getAt(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR, j, &elem_op);
// Err: Duplicated <operator, value>
if (elem_val.compare(value) == 0 && elem_op.compare(op) == 0) {
return CONTEXT_TRIGGER_ERROR_INVALID_RULE;
}
}
- elem.array_append(NULL, CT_RULE_DATA_VALUE_ARR, value.c_str());
- elem.array_append(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR, op);
- (entry->jentry).array_set_at(NULL, CT_RULE_DATA_ARR, i, elem);
+ elem.append(NULL, CT_RULE_DATA_VALUE_ARR, value.c_str());
+ elem.append(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR, op);
+ (entry->jentry).setAt(NULL, CT_RULE_DATA_ARR, i, elem);
return CONTEXT_TRIGGER_ERROR_NONE;
}
static int context_trigger_rule_entry_add_comparison_int_internal(context_trigger_rule_entry_h entry, const char* key, std::string op, int value)
{
- ctx::json elem;
- for (int i = 0; (entry->jentry).get_array_elem(NULL, CT_RULE_DATA_ARR, i, &elem); i++) {
+ ctx::Json elem;
+ for (int i = 0; (entry->jentry).getAt(NULL, CT_RULE_DATA_ARR, i, &elem); i++) {
std::string elem_item;
elem.get(NULL, CT_RULE_DATA_KEY, &elem_item);
if (elem_item.compare(key) == 0) {
int elem_val;
std::string elem_op;
- for (int j = 0; elem.get_array_elem(NULL, CT_RULE_DATA_VALUE_ARR, j, &elem_val); j++) {
- elem.get_array_elem(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR, j, &elem_op);
+ for (int j = 0; elem.getAt(NULL, CT_RULE_DATA_VALUE_ARR, j, &elem_val); j++) {
+ elem.getAt(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR, j, &elem_op);
// Err: Duplicated <operator, value>
if (elem_val == value && elem_op.compare(op) == 0) {
return CONTEXT_TRIGGER_ERROR_INVALID_RULE;
}
}
- elem.array_append(NULL, CT_RULE_DATA_VALUE_ARR, value);
- elem.array_append(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR, op);
- (entry->jentry).array_set_at(NULL, CT_RULE_DATA_ARR, i, elem);
+ elem.append(NULL, CT_RULE_DATA_VALUE_ARR, value);
+ elem.append(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR, op);
+ (entry->jentry).setAt(NULL, CT_RULE_DATA_ARR, i, elem);
return CONTEXT_TRIGGER_ERROR_NONE;
}
_D("BEGIN");
ASSERT_NOT_NULL(name && attr_template);
- // Err: Invalid json
- ctx::json jattr_template = attr_template;
+ // Err: Invalid Json
+ ctx::Json jattr_template = attr_template;
IF_FAIL_RETURN_TAG(jattr_template.valid(), CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER, _E, "Failed to parse template");
// Err: Invalid template
bool ret = ctx::rule_validator::is_valid_template(jattr_template);
IF_FAIL_RETURN_TAG(ret, CONTEXT_TRIGGER_ERROR_INVALID_DATA, _E, "Invalid template");
- ctx::json data;
+ ctx::Json data;
data.set(NULL, CT_CUSTOM_NAME, name);
data.set(NULL, CT_CUSTOM_ATTRIBUTES, jattr_template);
_D("BEGIN");
ASSERT_NOT_NULL(name);
- ctx::json data;
+ ctx::Json data;
data.set(NULL, CT_CUSTOM_NAME, name);
- ctx::json subj;
+ ctx::Json subj;
int error = ctx::request_handler::write_with_reply(CONTEXT_TRIGGER_SUBJECT_CUSTOM_REMOVE, &data, &subj);
IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "Failed to remove custom item: %#x", error);
_D("BEGIN");
ASSERT_NOT_NULL(name && fact);
- // Err: Invalid json
- ctx::json jfact = fact;
- IF_FAIL_RETURN_TAG(jfact.valid(), CONTEXT_TRIGGER_ERROR_INVALID_RULE, _E, "Cannot parse fact json" );
+ // Err: Invalid Json
+ ctx::Json jfact = fact;
+ IF_FAIL_RETURN_TAG(jfact.valid(), CONTEXT_TRIGGER_ERROR_INVALID_RULE, _E, "Cannot parse fact Json" );
- ctx::json data;
+ ctx::Json data;
data.set(NULL, CT_CUSTOM_NAME, name);
data.set(NULL, CT_CUSTOM_FACT, jfact);
DBusClientListenerImpl() {}
~DBusClientListenerImpl() {}
void setCb(std::string subject, request_handler::subject_response_cb cb);
- void onPublish(std::string subject, int reqId, int error, json event);
+ void onPublish(std::string subject, int reqId, int error, Json event);
private:
std::map<std::string, request_handler::subject_response_cb> __callbackMap;
};
__callbackMap[subject] = cb;
}
-void DBusClientListenerImpl::onPublish(std::string subject, int reqId, int error, json event)
+void DBusClientListenerImpl::onPublish(std::string subject, int reqId, int error, Json event)
{
auto it = __callbackMap.find(subject);
IF_FAIL_VOID_TAG(it != __callbackMap.end(), _W, "Unregistered subject");
static DBusClientListenerImpl __dbusListener;
static DBusClient __dbusClient;
-EXTAPI int ctx::request_handler::subscribe(const char* subject, ctx::json* option, int* req_id, ctx::json* request_result)
+EXTAPI int ctx::request_handler::subscribe(const char* subject, ctx::Json* option, int* req_id, ctx::Json* request_result)
{
return __dbusClient.subscribe(subject, option ? *option : NULL, req_id, request_result);
}
return __dbusClient.unsubscribe(subject, req_id);
}
-EXTAPI int ctx::request_handler::read(const char* subject, ctx::json* option, int* req_id, ctx::json* request_result)
+EXTAPI int ctx::request_handler::read(const char* subject, ctx::Json* option, int* req_id, ctx::Json* request_result)
{
return __dbusClient.read(subject, option ? *option : NULL, req_id, request_result);
}
-EXTAPI int ctx::request_handler::read_sync(const char* subject, ctx::json* option, int* req_id, ctx::json* data_read)
+EXTAPI int ctx::request_handler::read_sync(const char* subject, ctx::Json* option, int* req_id, ctx::Json* data_read)
{
return __dbusClient.readSync(subject, option ? *option : NULL, req_id, data_read);
}
-EXTAPI int ctx::request_handler::write(const char* subject, ctx::json* data)
+EXTAPI int ctx::request_handler::write(const char* subject, ctx::Json* data)
{
return __dbusClient.write(subject, *data);
}
-EXTAPI int ctx::request_handler::write_with_reply(const char* subject, ctx::json* data, ctx::json* request_result)
+EXTAPI int ctx::request_handler::write_with_reply(const char* subject, ctx::Json* data, ctx::Json* request_result)
{
return __dbusClient.write(subject, *data, request_result);
}
#ifndef __CONTEXT_LIB_REQUEST_HANDLER_H__
#define __CONTEXT_LIB_REQUEST_HANDLER_H__
-#include <json.h>
+#include <Json.h>
namespace ctx { namespace request_handler {
/*
*/
- typedef void(* subject_response_cb)(const char* subject, int req_id, int error, ctx::json response);
+ typedef void(* subject_response_cb)(const char* subject, int req_id, int error, ctx::Json response);
/*
*/
/*
*/
- int subscribe(const char* subject, ctx::json* option, int* req_id, ctx::json* request_result = NULL);
+ int subscribe(const char* subject, ctx::Json* option, int* req_id, ctx::Json* request_result = NULL);
/*
*/
/*
*/
- int read(const char* subject, ctx::json* option, int* req_id, ctx::json* request_result = NULL);
+ int read(const char* subject, ctx::Json* option, int* req_id, ctx::Json* request_result = NULL);
/*
*/
- int read_sync(const char* subject, ctx::json* option, int* req_id, ctx::json* data_read);
+ int read_sync(const char* subject, ctx::Json* option, int* req_id, ctx::Json* data_read);
/*
*/
- int write(const char* subject, ctx::json* data);
+ int write(const char* subject, ctx::Json* data);
/*
*/
- int write_with_reply(const char* subject, ctx::json* data, ctx::json* request_result = NULL);
+ int write_with_reply(const char* subject, ctx::Json* data, ctx::Json* request_result = NULL);
/*
*/
#define KEY_VALUES "values"
#define KEY_REF "ref"
-typedef std::map<std::string, ctx::json> template_map_t;
+typedef std::map<std::string, ctx::Json> template_map_t;
template_map_t template_map; // <name, template>
static int string_to_int(std::string str);
-static bool check_value_int(ctx::json& tmpl, std::string key, int value);
-static bool check_value_string(ctx::json& tmpl, std::string key, std::string value);
-static ctx::json get_template(std::string name);
+static bool check_value_int(ctx::Json& tmpl, std::string key, int value);
+static bool check_value_string(ctx::Json& tmpl, std::string key, std::string value);
+static ctx::Json get_template(std::string name);
int string_to_int(std::string str)
{
return i;
}
-ctx::json get_template(std::string name)
+ctx::Json get_template(std::string name)
{
ctx::rule_validator::request_template(name);
return template_map[name];
}
// Request template
- ctx::json request;
+ ctx::Json request;
request.set(NULL, SUBJECT_STR, name);
int req_id;
- ctx::json tmpl;
+ ctx::Json tmpl;
int error = ctx::request_handler::read_sync(CONTEXT_TRIGGER_SUBJECT_GET_TEMPLATE, &request, &req_id, &tmpl);
if (error == ERR_NOT_SUPPORTED) {
template_map.erase(name);
}
// called by context_trigger_rule_add_entry()
-bool ctx::rule_validator::check_option(ctx::json& item)
+bool ctx::rule_validator::check_option(ctx::Json& item)
{
std::string name;
item.get(NULL, CT_RULE_EVENT_ITEM, &name);
- ctx::json tmpl = get_template(name);
+ ctx::Json tmpl = get_template(name);
IF_FAIL_RETURN(tmpl != EMPTY_JSON_OBJECT, false);
// No option needed
- ctx::json opt_tmpl;
+ ctx::Json opt_tmpl;
tmpl.get(NULL, KEY_OPTION, &opt_tmpl);
std::list<std::string> opt_keys;
- IF_FAIL_RETURN(opt_tmpl.get_keys(&opt_keys), false);
+ IF_FAIL_RETURN(opt_tmpl.getKeys(&opt_keys), false);
if (opt_keys.size() <= 0) {
return true;
}
// called by context_trigger_rule_entry_add_option_int()
bool ctx::rule_validator::check_option_int(std::string name, std::string key, int value)
{
- ctx::json tmpl = get_template(name);
+ ctx::Json tmpl = get_template(name);
IF_FAIL_RETURN(tmpl != EMPTY_JSON_OBJECT, false);
- ctx::json opt_tmpl;
+ ctx::Json opt_tmpl;
tmpl.get(NULL, KEY_OPTION, &opt_tmpl);
// Err: Item with no option
std::list<std::string> opt_keys;
- IF_FAIL_RETURN(opt_tmpl.get_keys(&opt_keys), false);
+ IF_FAIL_RETURN(opt_tmpl.getKeys(&opt_keys), false);
IF_FAIL_RETURN(opt_keys.size() > 0, false);
// Err: Invalid option key or Invalid value type
// called by context_trigger_rule_entry_add_option_string()
bool ctx::rule_validator::check_option_string(std::string name, std::string key, std::string value)
{
- ctx::json tmpl = get_template(name);
+ ctx::Json tmpl = get_template(name);
IF_FAIL_RETURN(tmpl != EMPTY_JSON_OBJECT, false);
- ctx::json opt_tmpl;
+ ctx::Json opt_tmpl;
tmpl.get(NULL, KEY_OPTION, &opt_tmpl);
// Err: ';' for SQL injection
// Err: Item with no option
std::list<std::string> opt_keys;
- IF_FAIL_RETURN(opt_tmpl.get_keys(&opt_keys), false);
+ IF_FAIL_RETURN(opt_tmpl.getKeys(&opt_keys), false);
IF_FAIL_RETURN(opt_keys.size() > 0, false);
// Err: Invalid option key or Invalid value type
// called by context_trigger_rule_entry_add_comparison_int()
bool ctx::rule_validator::check_comparison_int(std::string name, std::string key, std::string op, int value)
{
- ctx::json tmpl = get_template(name);
+ ctx::Json tmpl = get_template(name);
IF_FAIL_RETURN(tmpl != EMPTY_JSON_OBJECT, false);
- ctx::json attr_tmpl;
+ ctx::Json attr_tmpl;
tmpl.get(NULL, KEY_ATTR, &attr_tmpl);
// Err: Invalid attribute key or Invalid value type
// called by context_trigger_rule_entry_add_comparison_string()
bool ctx::rule_validator::check_comparison_string(std::string name, std::string key, std::string op, std::string value)
{
- ctx::json tmpl = get_template(name);
- IF_FAIL_RETURN(tmpl != ctx::json(EMPTY_JSON_OBJECT), false);
+ ctx::Json tmpl = get_template(name);
+ IF_FAIL_RETURN(tmpl != ctx::Json(EMPTY_JSON_OBJECT), false);
- ctx::json attr_tmpl;
+ ctx::Json attr_tmpl;
tmpl.get(NULL, KEY_ATTR, &attr_tmpl);
// Err: ';' for SQL injection
bool ctx::rule_validator::check_valid_key(std::string type, std::string name, std::string key)
{
- ctx::json tmpl = get_template(name);
+ ctx::Json tmpl = get_template(name);
IF_FAIL_RETURN(tmpl != EMPTY_JSON_OBJECT, false);
// Err: Invalid key
- ctx::json tmp;
+ ctx::Json tmp;
bool ret = tmpl.get(type.c_str(), key.c_str(), &tmp);
IF_FAIL_RETURN(ret, false);
return true;
}
-bool check_value_int(ctx::json& tmpl, std::string key, int value)
+bool check_value_int(ctx::Json& tmpl, std::string key, int value)
{
int min, max;
return true;
}
-bool check_value_string(ctx::json& tmpl, std::string key, std::string value)
+bool check_value_string(ctx::Json& tmpl, std::string key, std::string value)
{
// case1: any value is accepted
- if (tmpl.array_get_size(key.c_str(), KEY_VALUES) <= 0)
+ if (tmpl.getSize(key.c_str(), KEY_VALUES) <= 0)
return true;
// case2: check acceptable value
std::string t_val;
- for (int i = 0; tmpl.get_array_elem(key.c_str(), KEY_VALUES, i, &t_val); i++) {
+ for (int i = 0; tmpl.getAt(key.c_str(), KEY_VALUES, i, &t_val); i++) {
if (t_val == value)
return true;
}
// called by context_trigger_rule_entry_add_comparison()
// called by context_trigger_rule_entry_add_option()
-bool ctx::rule_validator::set_ref_info(std::string type, ctx::json* jref, std::string name, std::string key, std::string ref_data)
+bool ctx::rule_validator::set_ref_info(std::string type, ctx::Json* jref, std::string name, std::string key, std::string ref_data)
{
- ctx::json tmpl = get_template(name);
+ ctx::Json tmpl = get_template(name);
IF_FAIL_RETURN(tmpl != EMPTY_JSON_OBJECT, false);
- ctx::json detailed_tmpl;
+ ctx::Json detailed_tmpl;
tmpl.get(NULL, type.c_str(), &detailed_tmpl);
std::string dt;
bool ret = detailed_tmpl.get(key.c_str(), KEY_TYPE, &dt);
IF_FAIL_RETURN(ret, false);
- ctx::json temp;
+ ctx::Json temp;
temp.set(NULL, KEY_NAME, name);
temp.set(NULL, KEY_KEY, key);
temp.set(NULL, KEY_TYPE, dt);
temp.set(NULL, KEY_REF, ref_data);
if (type == TYPE_OPTION_STR) {
- jref->array_append(NULL, KEY_OPTION, temp);
+ jref->append(NULL, KEY_OPTION, temp);
} else if (type == TYPE_ATTR_STR) {
- jref->array_append(NULL, KEY_ATTR, temp);
+ jref->append(NULL, KEY_ATTR, temp);
} else {
return false;
}
// called by context_trigger_rule_entry_add_comparison()
std::string ctx::rule_validator::get_data_type(std::string type, std::string name, std::string key)
{
- ctx::json tmpl = get_template(name);
+ ctx::Json tmpl = get_template(name);
IF_FAIL_RETURN(tmpl != EMPTY_JSON_OBJECT, false);
- ctx::json detailed_tmpl;
+ ctx::Json detailed_tmpl;
tmpl.get(NULL, type.c_str(), &detailed_tmpl);
std::string dt;
}
// called by context_trigger_rule_add_entry()
-bool ctx::rule_validator::check_referential_data(std::string name, ctx::json& ref_info)
+bool ctx::rule_validator::check_referential_data(std::string name, ctx::Json& ref_info)
{
std::map<std::string, std::string> type_map;
- ctx::json ref_data;
- for (int i = 0; ref_info.get_array_elem(NULL, KEY_OPTION, i, &ref_data); i++) {
+ ctx::Json ref_data;
+ for (int i = 0; ref_info.getAt(NULL, KEY_OPTION, i, &ref_data); i++) {
std::string ref_key;
ref_data.get(NULL, KEY_REF, &ref_key);
std::string cond_type;
return false;
}
- for (int i = 0; ref_info.get_array_elem(NULL, KEY_ATTR, i, &ref_data); i++) {
+ for (int i = 0; ref_info.getAt(NULL, KEY_ATTR, i, &ref_data); i++) {
std::string ref_key;
ref_data.get(NULL, KEY_REF, &ref_key);
std::string cond_type;
}
// For custom item template
-bool ctx::rule_validator::is_valid_template(ctx::json& attr_template)
+bool ctx::rule_validator::is_valid_template(ctx::Json& attr_template)
{
- IF_FAIL_RETURN_TAG(attr_template != EMPTY_JSON_OBJECT, false, _E, "Custom template: empty json");
+ IF_FAIL_RETURN_TAG(attr_template != EMPTY_JSON_OBJECT, false, _E, "Custom template: empty Json");
bool ret;
std::list<std::string> keys;
- attr_template.get_keys(&keys);
+ attr_template.getKeys(&keys);
for (std::list<std::string>::iterator it = keys.begin(); it != keys.end(); it++) {
std::string key = *it;
IF_FAIL_RETURN_TAG(ret, false, _E, "Custom template: type missing");
IF_FAIL_RETURN_TAG(type == CT_CUSTOM_INT || type == CT_CUSTOM_STRING, false, _E, "Custom template: invalid data type");
- ctx::json elem;
+ ctx::Json elem;
attr_template.get(NULL, key.c_str(), &elem);
std::list<std::string> elem_keys;
- elem.get_keys(&elem_keys);
+ elem.getKeys(&elem_keys);
for (std::list<std::string>::iterator it2 = elem_keys.begin(); it2 != elem_keys.end(); it2++) {
std::string elem_key = *it2;
} else if (elem_key == CT_CUSTOM_VALUES) {
IF_FAIL_RETURN_TAG(type == CT_CUSTOM_STRING, false, _E, "Custom template: string type support values");
- int size = attr_template.array_get_size(key.c_str(), CT_CUSTOM_VALUES);
+ int size = attr_template.getSize(key.c_str(), CT_CUSTOM_VALUES);
if (size > 0) {
std::string val_str;
for (int i = 0; i < size; i++) {
- ret = attr_template.get_array_elem(key.c_str(), CT_CUSTOM_VALUES, i, &val_str);
+ ret = attr_template.getAt(key.c_str(), CT_CUSTOM_VALUES, i, &val_str);
IF_FAIL_RETURN_TAG(ret, false, _E, "Custom template: failed to get string type value");
}
}
#ifndef __CONTEXT_RULE_VALIDATOR_H__
#define __CONTEXT_RULE_VALIDATOR_H__
-#include <json.h>
+#include <Json.h>
namespace ctx {
namespace rule_validator {
int request_template(std::string name, bool mandatory = false);
void remove_template(std::string name);
- bool check_option(ctx::json &item);
+ bool check_option(ctx::Json &item);
bool check_option_int(std::string name, std::string key, int value);
bool check_option_string(std::string name, std::string key, std::string value);
- bool check_option_reference(std::string event, ctx::json &item);
+ bool check_option_reference(std::string event, ctx::Json &item);
bool check_comparison_int(std::string name, std::string key, std::string op, int value);
bool check_comparison_string(std::string name, std::string key, std::string op, std::string value);
bool check_valid_key(std::string type, std::string name, std::string key);
- bool set_ref_info(std::string type, ctx::json *jref, std::string name, std::string key, std::string ref_key);
+ bool set_ref_info(std::string type, ctx::Json *jref, std::string name, std::string key, std::string ref_key);
std::string get_data_type(std::string type, std::string name, std::string key);
- bool check_referential_data(std::string name, ctx::json &ref_info);
+ bool check_referential_data(std::string name, ctx::Json &ref_info);
bool is_valid_operator(std::string type, std::string op);
- bool is_valid_template(ctx::json& attr_template);
+ bool is_valid_template(ctx::Json& attr_template);
}
} /* namespace ctx */
bool bool_val = false;
bool skip_tc = false;
bool newline_after_tcname = false;
- ctx::json json_val = EMPTY_JSON_OBJECT;
+ ctx::Json json_val = EMPTY_JSON_OBJECT;
std::string str_val = "";
}
}
#include <string>
#include <glib.h>
#include <types_internal.h>
-#include <json.h>
+#include <Json.h>
#define CALLBACK_COUNT 5
extern bool bool_val;
extern bool skip_tc;
extern bool newline_after_tcname;
- extern ctx::json json_val;
+ extern ctx::Json json_val;
extern std::string str_val;
void start_mainloop();
return app_id;
}
-static bool __trigger_cond_app_use_freq_base(ctx::json option)
+static bool __trigger_cond_app_use_freq_base(ctx::Json option)
{
if (!__support(CONTEXT_TRIGGER_CONDITION_APP_USE_FREQUENCY)) return false;
bool _trigger_cond_app_use_freq1()
{
/* Case 1: App ID only */
- ctx::json option;
+ ctx::Json option;
option.set(NULL, CONTEXT_TRIGGER_APP_ID, __get_objective_app_id());
return __trigger_cond_app_use_freq_base(option);
bool _trigger_cond_app_use_freq2()
{
/* Case 2: App ID, Day of Week */
- ctx::json option;
+ ctx::Json option;
option.set(NULL, CONTEXT_TRIGGER_APP_ID, __get_objective_app_id());
option.set(NULL, CONTEXT_TRIGGER_DAY_OF_WEEK, CONTEXT_TRIGGER_WEEKDAY);
bool _trigger_cond_app_use_freq3()
{
/* Case 3: App ID, Time of Day */
- ctx::json option;
+ ctx::Json option;
option.set(NULL, CONTEXT_TRIGGER_APP_ID, __get_objective_app_id());
option.set(NULL, CONTEXT_TRIGGER_TIME_OF_DAY, "10-16");
bool _trigger_cond_app_use_freq4()
{
/* Case 3: App ID, Time of Day, Day of Week */
- ctx::json option;
+ ctx::Json option;
option.set(NULL, CONTEXT_TRIGGER_APP_ID, __get_objective_app_id());
option.set(NULL, CONTEXT_TRIGGER_DAY_OF_WEEK, CONTEXT_TRIGGER_WEEKDAY);
option.set(NULL, CONTEXT_TRIGGER_TIME_OF_DAY, "10-16");
return address;
}
-static bool __trigger_cond_comm_freq_base(ctx::json option)
+static bool __trigger_cond_comm_freq_base(ctx::Json option)
{
if (!__support(CONTEXT_TRIGGER_CONDITION_COMMUNICATION_FREQUENCY)) return false;
bool _trigger_cond_comm_freq1()
{
/* Case 1: Address only */
- ctx::json option;
+ ctx::Json option;
option.set(NULL, CONTEXT_TRIGGER_ADDRESS, __get_objective_address());
return __trigger_cond_comm_freq_base(option);
bool _trigger_cond_comm_freq2()
{
/* Case 2: Address, Day of Week */
- ctx::json option;
+ ctx::Json option;
option.set(NULL, CONTEXT_TRIGGER_ADDRESS, __get_objective_address());
option.set(NULL, CONTEXT_TRIGGER_DAY_OF_WEEK, CONTEXT_TRIGGER_WEEKDAY);
bool _trigger_cond_comm_freq3()
{
/* Case 3: Address, Time of Day */
- ctx::json option;
+ ctx::Json option;
option.set(NULL, CONTEXT_TRIGGER_ADDRESS, __get_objective_address());
option.set(NULL, CONTEXT_TRIGGER_TIME_OF_DAY, "10-16");
bool _trigger_cond_comm_freq4()
{
/* Case 4: Address, Day of Week, Time of Day */
- ctx::json option;
+ ctx::Json option;
option.set(NULL, CONTEXT_TRIGGER_ADDRESS, __get_objective_address());
option.set(NULL, CONTEXT_TRIGGER_DAY_OF_WEEK, CONTEXT_TRIGGER_WEEKDAY);
option.set(NULL, CONTEXT_TRIGGER_TIME_OF_DAY, "10-16");
return __trigger_cond_comm_freq_base(option);
}
-static bool __trigger_cond_media_freq_base(context_trigger_condition_e item, const char *item_str, ctx::json option)
+static bool __trigger_cond_media_freq_base(context_trigger_condition_e item, const char *item_str, ctx::Json option)
{
if (!__support(item)) return false;
bool _trigger_cond_music_freq1()
{
- ctx::json option;
+ ctx::Json option;
return __trigger_cond_media_freq_base(
CONTEXT_TRIGGER_CONDITION_MUSIC_PLAYBACK_FREQUENCY,
bool _trigger_cond_music_freq2()
{
- ctx::json option;
+ ctx::Json option;
option.set(NULL, CONTEXT_TRIGGER_DAY_OF_WEEK, CONTEXT_TRIGGER_WEEKDAY);
return __trigger_cond_media_freq_base(
bool _trigger_cond_music_freq3()
{
- ctx::json option;
+ ctx::Json option;
option.set(NULL, CONTEXT_TRIGGER_TIME_OF_DAY, "10-16");
return __trigger_cond_media_freq_base(
bool _trigger_cond_music_freq4()
{
- ctx::json option;
+ ctx::Json option;
option.set(NULL, CONTEXT_TRIGGER_DAY_OF_WEEK, CONTEXT_TRIGGER_WEEKDAY);
option.set(NULL, CONTEXT_TRIGGER_TIME_OF_DAY, "10-16");
bool _trigger_cond_video_freq1()
{
- ctx::json option;
+ ctx::Json option;
return __trigger_cond_media_freq_base(
CONTEXT_TRIGGER_CONDITION_VIDEO_PLAYBACK_FREQUENCY,
bool _trigger_cond_video_freq2()
{
- ctx::json option;
+ ctx::Json option;
option.set(NULL, CONTEXT_TRIGGER_DAY_OF_WEEK, CONTEXT_TRIGGER_WEEKDAY);
return __trigger_cond_media_freq_base(
bool _trigger_cond_video_freq3()
{
- ctx::json option;
+ ctx::Json option;
option.set(NULL, CONTEXT_TRIGGER_TIME_OF_DAY, "10-16");
return __trigger_cond_media_freq_base(
bool _trigger_cond_video_freq4()
{
- ctx::json option;
+ ctx::Json option;
option.set(NULL, CONTEXT_TRIGGER_DAY_OF_WEEK, CONTEXT_TRIGGER_WEEKDAY);
option.set(NULL, CONTEXT_TRIGGER_TIME_OF_DAY, "10-16");
using namespace ctx::test;
-static void __domain_cb(const char *item, int rid, int error, ctx::json data)
+static void __domain_cb(const char *item, int rid, int error, ctx::Json data)
{
g_print("[%d] %s: Error=%#x, Data=%s\n", callback_count--, item, error, data.str().c_str());
{
if (!__support(CONTEXT_TRIGGER_EVENT_PLACE)) return false;
- ctx::json option;
+ ctx::Json option;
option.set(NULL, CONTEXT_TRIGGER_PLACE_ID, 2); /* 2 => office */
err = ctx::request_handler::subscribe(CT_EVENT_PLACE, &option, &req_id, NULL);