using namespace ctx;
-ComparisonConverter::ComparisonConverter(const char* type, Json& info) :
+ComparisonConverter::ComparisonConverter(const char* type, CtxJson1& info) :
__completed(false),
__size(0),
__logicalOp(TRIG_RULE_LOGICAL_DISJUNCTION),
__size = __info.getSize(NULL, OLD_TRIG_RULE_KEY_DATA_VALUE_ARR);
}
-int ComparisonConverter::getResult(Json* result)
+int ComparisonConverter::getResult(CtxJson1* result)
{
if (__result == EMPTY_JSON_OBJECT)
return ERR_INVALID_RULE;
{
IF_FAIL_RETURN(__size == 0, false);
- Json temp = EMPTY_JSON_OBJECT;
+ CtxJson1 temp = EMPTY_JSON_OBJECT;
__result.set(NULL, __key.c_str(), temp);
return true;
#ifndef _CONTEXT_COMPARISON_CONVERTER_H_
#define _CONTEXT_COMPARISON_CONVERTER_H_
-#include <Json.h>
+#include <CtxJson1.h>
#include "TriggerOldRuleTypes.h"
namespace ctx {
public:
virtual ~ComparisonConverter() {};
- int getResult(Json* result);
+ int getResult(CtxJson1* result);
protected:
bool __completed;
int __size;
std::string __logicalOp;
std::string __type;
- Json __info;
- Json __result;
+ CtxJson1 __info;
+ CtxJson1 __result;
std::string __key;
- ComparisonConverter(const char* type, Json& info);
+ ComparisonConverter(const char* type, CtxJson1& info);
void __convertComparison();
virtual int __getOperatorCount(std::string op) = 0;
virtual bool __checkEtc();
using namespace ctx;
-IntComparisonConverter::IntComparisonConverter(Json info) :
+IntComparisonConverter::IntComparisonConverter(CtxJson1 info) :
ComparisonConverter(TRIG_TMPL_TYPE_INTEGER, info)
{
if (__size >= 2) {
#define _CONTEXT_INT_COMPARISON_CONVERTER_H_
#include <list>
-#include <Json.h>
+#include <CtxJson1.h>
#include "ComparisonConverter.h"
namespace ctx {
typedef std::map<std::string, IntList> IntComparisonMap; // { operator, IntList }
public:
- IntComparisonConverter(Json info);
+ IntComparisonConverter(CtxJson1 info);
~IntComparisonConverter() {};
private:
using namespace ctx;
-StringComparisonConverter::StringComparisonConverter(Json info) :
+StringComparisonConverter::StringComparisonConverter(CtxJson1 info) :
ComparisonConverter(TRIG_TMPL_TYPE_STRING, info)
{
if (__size >= 2) {
#define _CONTEXT_STRING_COMPARISON_CONVERTER_H_
#include <map>
-#include <Json.h>
+#include <CtxJson1.h>
#include "ComparisonConverter.h"
namespace ctx {
typedef std::map<std::string, int> StringComparisonMap;
public:
- StringComparisonConverter(Json info);
+ StringComparisonConverter(CtxJson1 info);
~StringComparisonConverter() {};
private:
#include <map>
#include <ContextTypes.h>
-#include <Json.h>
+#include <CtxJson.h>
#include <Tuple.h>
#include <app_history_internal.h>
#include <app_history_types_internal.h>
} _cx_history_handle;
typedef struct _context_history_filter_handle_s {
- ctx::Json jfilter;
+ ctx::CtxJson jfilter;
} _cx_history_filter_handle;
typedef struct _context_history_list_handle_s {
#include <context_trigger_internal.h>
#include <Types.h>
#include <DBusTypes.h>
-#include <Json.h>
+#include <CtxJson1.h>
#include <DBusClient.h>
#include <TriggerTypes.h>
#include <TriggerRuleTypes.h>
//static std::string double_to_string(int value);
typedef struct _context_trigger_rule_s {
- ctx::Json jold_rule;
- ctx::Json jrule; // description, event{}, condition[], action{}, _extra{}
- ctx::Json jref;
+ ctx::CtxJson1 jold_rule;
+ ctx::CtxJson1 jrule; // description, event{}, condition[], action{}, _extra{}
+ ctx::CtxJson1 jref;
_context_trigger_rule_s() {
jold_rule = EMPTY_JSON_OBJECT;
typedef struct _context_trigger_rule_entry_s {
int type;
- ctx::Json jentry;
- ctx::Json jref;
+ ctx::CtxJson1 jentry;
+ ctx::CtxJson1 jref;
_context_trigger_rule_entry_s(int t): type(t) {
jentry = OLD_INITIAL_ENTRY;
(rule->jrule).set(_TRIG_RULE_KEY_EXTRA, _TRIG_RULE_KEY_RULE_LOGICAL_OP, TRIG_RULE_LOGICAL_CONJUNCTION);
}
- ctx::Json jrule_id;
+ ctx::CtxJson1 jrule_id;
int error = __dbusClient.write(SUBJ_TRIGGER_ADD, rule->jrule, &jrule_id);
if (error == ERR_NONE) {
if (rule_id <= 0)
return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER;
- ctx::Json jrule_id;
+ ctx::CtxJson1 jrule_id;
jrule_id.set(NULL, TRIG_KEY_RULE_ID, rule_id);
int error = __dbusClient.write(SUBJ_TRIGGER_REMOVE, jrule_id, NULL);
if (rule_id <= 0)
return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER;
- ctx::Json jrule_id;
+ ctx::CtxJson1 jrule_id;
jrule_id.set(NULL, TRIG_KEY_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::CtxJson1 jrule_id;
jrule_id.set(NULL, TRIG_KEY_RULE_ID, rule_id);
int error = __dbusClient.write(SUBJ_TRIGGER_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::CtxJson1 data_read;
int error = __dbusClient.readSync(SUBJ_TRIGGER_GET_RULE_IDS, NULL, &req_id, &data_read);
if (error != ERR_NONE) {
if (rule_id <= 0)
return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER;
- ctx::Json option;
+ ctx::CtxJson1 option;
option.set(NULL, TRIG_KEY_RULE_ID, rule_id);
int req_id;
- ctx::Json data_read;
+ ctx::CtxJson1 data_read;
int error = __dbusClient.readSync(SUBJ_TRIGGER_GET, option, &req_id, &data_read);
if (error == ERR_NO_DATA) {
ASSERT_NOT_NULL(rule && entry);
// Check if rule handle is created
- ctx::Json extra;
+ ctx::CtxJson1 extra;
bool ret = (rule->jrule).get(NULL, _TRIG_RULE_KEY_EXTRA, &extra);
IF_FAIL_RETURN(ret, CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER);
if (entry->type == TYPE_EVENT) {
// Err: More than one event
- ctx::Json elem;
+ ctx::CtxJson1 elem;
if ((rule->jold_rule).get(NULL, OLD_TRIG_RULE_KEY_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::CtxJson1 temp = (entry->jentry).str();
ret = (rule->jold_rule).set(NULL, OLD_TRIG_RULE_KEY_EVENT, temp);
int error = ctx::rule_util::setEvent(entry->jentry, &(rule->jrule));
return CONTEXT_TRIGGER_ERROR_INVALID_RULE;
}
- ctx::Json elem;
+ ctx::CtxJson1 elem;
for (int i = 0; (entry->jentry).getAt(NULL, OLD_TRIG_RULE_KEY_DATA_ARR, i, &elem); i++) {
int val_arr_size = elem.getSize(NULL, OLD_TRIG_RULE_KEY_DATA_VALUE_ARR);
int op_arr_size = elem.getSize(NULL, OLD_TRIG_RULE_KEY_DATA_VALUE_OPERATOR_ARR);
IF_FAIL_RETURN(ret, CONTEXT_TRIGGER_ERROR_INVALID_RULE);
} else {
// If not, copy referential information to rule entry
- ctx::Json info;
+ ctx::CtxJson1 info;
for (int j = 0; (entry->jref).getAt(NULL, TYPE_OPTION, j, &info); j++) {
(rule->jref).append(NULL, TYPE_OPTION, info);
}
}
}
- ctx::Json temp = (entry->jentry).str();
+ ctx::CtxJson1 temp = (entry->jentry).str();
ret = (rule->jold_rule).append(NULL, OLD_TRIG_RULE_KEY_CONDITION, temp);
ctx::rule_util::addCondition(entry->jentry, &(rule->jrule));
IF_FAIL_RETURN(ret, CONTEXT_TRIGGER_ERROR_INVALID_RULE);
// Err: Comparison key is already added
- ctx::Json elem;
+ ctx::CtxJson1 elem;
for (int i = 0; (entry->jentry).getAt(NULL, OLD_TRIG_RULE_KEY_DATA_ARR, i, &elem); i++) {
std::string elem_item;
elem.get(NULL, OLD_TRIG_RULE_KEY_DATA_KEY, &elem_item);
}
}
- ctx::Json data;
+ ctx::CtxJson1 data;
data.set(NULL, OLD_TRIG_RULE_KEY_DATA_KEY, key);
data.set(NULL, OLD_TRIG_RULE_KEY_DATA_KEY_OPERATOR, logical_str);
(entry->jentry).append(NULL, OLD_TRIG_RULE_KEY_DATA_ARR, data);
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;
+ ctx::CtxJson1 elem;
for (int i = 0; (entry->jentry).getAt(NULL, OLD_TRIG_RULE_KEY_DATA_ARR, i, &elem); i++) {
std::string elem_item;
elem.get(NULL, OLD_TRIG_RULE_KEY_DATA_KEY, &elem_item);
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;
+ ctx::CtxJson1 elem;
for (int i = 0; (entry->jentry).getAt(NULL, OLD_TRIG_RULE_KEY_DATA_ARR, i, &elem); i++) {
std::string elem_item;
elem.get(NULL, OLD_TRIG_RULE_KEY_DATA_KEY, &elem_item);
_D("BEGIN");
ASSERT_NOT_NULL(name && attr_template);
- // Err: Invalid Json
- ctx::Json jattr_template = attr_template;
+ // Err: Invalid CtxJson1
+ ctx::CtxJson1 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::CtxJson1 data;
data.set(NULL, TRIG_CUSTOM_KEY_REQ, TRIG_CUSTOM_REQ_ADD);
data.set(NULL, TRIG_CUSTOM_KEY_NAME, name);
data.set(NULL, TRIG_TMPL_KEY_ATTRIBUTE, jattr_template);
_D("BEGIN");
ASSERT_NOT_NULL(name);
- ctx::Json data;
+ ctx::CtxJson1 data;
data.set(NULL, TRIG_CUSTOM_KEY_REQ, TRIG_CUSTOM_REQ_REMOVE);
data.set(NULL, TRIG_CUSTOM_KEY_NAME, name);
- ctx::Json subj;
+ ctx::CtxJson1 subj;
int error = __dbusClient.write(SUBJ_TRIGGER_CUSTOM, 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_PARAMETER, _E, "Cannot parse fact Json");
+ // Err: Invalid CtxJson1
+ ctx::CtxJson1 jfact = fact;
+ IF_FAIL_RETURN_TAG(jfact.valid(), CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER, _E, "Cannot parse fact CtxJson1");
- ctx::Json data;
+ ctx::CtxJson1 data;
data.set(NULL, TRIG_CUSTOM_KEY_REQ, TRIG_CUSTOM_REQ_PUBLISH);
data.set(NULL, TRIG_CUSTOM_KEY_NAME, name);
data.set(NULL, TRIG_CUSTOM_KEY_FACT, jfact);
using namespace ctx;
-static bool __handleTimerEvent(Json& event);
-static int __arrangeDayOfWeek(Json& dayInfo);
+static bool __handleTimerEvent(CtxJson1& event);
+static int __arrangeDayOfWeek(CtxJson1& dayInfo);
-int ctx::rule_util::setEvent(Json& entry, Json* rule)
+int ctx::rule_util::setEvent(CtxJson1& entry, CtxJson1* rule)
{
- Json tempEvent;
+ CtxJson1 tempEvent;
std::string subject;
entry.get(NULL, OLD_TRIG_RULE_KEY_EVENT_ITEM, &subject);
- Json option;
+ CtxJson1 option;
entry.get(NULL, OLD_TRIG_RULE_KEY_EVENT_OPTION, &option);
tempEvent.set(subject.c_str(), TRIG_RULE_KEY_OPTION, option);
- Json elem;
+ CtxJson1 elem;
for (int i = 0; entry.getAt(NULL, OLD_TRIG_RULE_KEY_DATA_ARR, i, &elem); i++) {
- Json newElem;
+ CtxJson1 newElem;
std::string key;
elem.get(NULL, OLD_TRIG_RULE_KEY_DATA_KEY, &key);
IF_FAIL_RETURN_TAG(converter, ERR_OUT_OF_MEMORY, _E, "Failed to create comparison converter");
converter->getResult(&newElem);
- Json detail;
+ CtxJson1 detail;
newElem.get(NULL, key.c_str(), &detail);
std::string path = subject + "." + TRIG_RULE_KEY_COMPARISON;
return ERR_NONE;
}
-int ctx::rule_util::addCondition(Json& entry, Json* rule)
+int ctx::rule_util::addCondition(CtxJson1& entry, CtxJson1* rule)
{
- Json tempCond;
+ CtxJson1 tempCond;
std::string subject;
entry.get(NULL, OLD_TRIG_RULE_KEY_CONDITION_ITEM, &subject);
- Json option;
+ CtxJson1 option;
entry.get(NULL, OLD_TRIG_RULE_KEY_CONDITION_OPTION, &option);
tempCond.set(subject.c_str(), TRIG_RULE_KEY_OPTION, option);
- Json elem;
+ CtxJson1 elem;
for (int i = 0; entry.getAt(NULL, OLD_TRIG_RULE_KEY_DATA_ARR, i, &elem); i++) {
- Json newElem;
+ CtxJson1 newElem;
std::string key;
elem.get(NULL, OLD_TRIG_RULE_KEY_DATA_KEY, &key);
return ERR_NONE;
}
-bool __handleTimerEvent(Json& event)
+bool __handleTimerEvent(CtxJson1& event)
{
- Json alarmComp;
+ CtxJson1 alarmComp;
bool ret = event.get(SUBJ_STATE_ALARM, TRIG_RULE_KEY_COMPARISON, &alarmComp);
IF_FAIL_RETURN_TAG(ret, false, _E, "Invalid EVENT_TIME event");
// Day processing
- Json dayInfo;
+ CtxJson1 dayInfo;
bool daySpecified = alarmComp.get(NULL, KEY_DAY_OF_WEEK, &dayInfo);
if (daySpecified) {
- Json newDayInfo;
+ CtxJson1 newDayInfo;
newDayInfo.set(NULL, TRIG_RULE_KEY_OPERATOR, TRIG_RULE_OP_ONE_OF);
int dow = __arrangeDayOfWeek(dayInfo);
}
// Time processing
- Json timeInfo;
+ CtxJson1 timeInfo;
alarmComp.get(NULL, KEY_TIME_OF_DAY, &timeInfo);
int time;
return true;
}
-int __arrangeDayOfWeek(Json& dayInfo)
+int __arrangeDayOfWeek(CtxJson1& dayInfo)
{
std::string dayOp;
if (!dayInfo.get(NULL, TRIG_RULE_KEY_OPERATOR, &dayOp)) {
return result;
}
-bool ctx::rule_util::isEventSet(Json& rule)
+bool ctx::rule_util::isEventSet(CtxJson1& rule)
{
- ctx::Json event;
+ ctx::CtxJson1 event;
if (rule.get(NULL, TRIG_RULE_KEY_EVENT, &event)) {
if (event != EMPTY_JSON_OBJECT) {
return true;
return false;
}
-bool ctx::rule_util::isActionSet(Json& rule)
+bool ctx::rule_util::isActionSet(CtxJson1& rule)
{
- ctx::Json action;
+ ctx::CtxJson1 action;
if (rule.get(NULL, TRIG_RULE_KEY_ACTION, &action)) {
if (action != EMPTY_JSON_OBJECT) {
return true;
#ifndef __CONTEXT_RULE_UTIL_H__
#define __CONTEXT_RULE_UTIL_H__
-#include <Json.h>
+#include <CtxJson1.h>
namespace ctx {
namespace rule_util {
- int setEvent(Json& entry, Json* rule);
- int addCondition(Json& entry, Json* rule);
- bool isEventSet(Json& rule);
- bool isActionSet(Json& rule);
+ int setEvent(CtxJson1& entry, CtxJson1* rule);
+ int addCondition(CtxJson1& entry, CtxJson1* rule);
+ bool isEventSet(CtxJson1& rule);
+ bool isActionSet(CtxJson1& rule);
}
} /* namespace ctx */
#define RULE_VALIDATOR_TYPE "type"
#define RULE_VALIDATOR_REF "ref"
-typedef std::map<std::string, Json> template_map_t;
+typedef std::map<std::string, CtxJson1> template_map_t;
template_map_t template_map; // <name, template>
static int string_to_int(std::string str);
-static bool check_value_int(Json& tmpl, std::string key, int value);
-static bool check_value_string(Json& tmpl, std::string key, std::string value);
-static bool check_value_enum(Json& tmpl, std::string key, std::string value);
-static Json get_template(std::string name);
-static bool check_template_int(Json& elem);
-static bool check_template_string(Json& elem);
-static bool check_template_enum(Json& elem);
-static std::string get_data_type(Json& elem, std::string& key);
+static bool check_value_int(CtxJson1& tmpl, std::string key, int value);
+static bool check_value_string(CtxJson1& tmpl, std::string key, std::string value);
+static bool check_value_enum(CtxJson1& tmpl, std::string key, std::string value);
+static CtxJson1 get_template(std::string name);
+static bool check_template_int(CtxJson1& elem);
+static bool check_template_string(CtxJson1& elem);
+static bool check_template_enum(CtxJson1& elem);
+static std::string get_data_type(CtxJson1& elem, std::string& key);
static bool is_equal_type(std::string& type1, std::string& type2);
int string_to_int(std::string str)
return i;
}
-Json get_template(std::string name)
+CtxJson1 get_template(std::string name)
{
rule_validator::request_template(name);
return template_map[name];
}
// Request template
- Json request;
+ CtxJson1 request;
request.set(NULL, TRIG_TMPL_KEY_SUBJECT, name);
int req_id;
- Json tmpl;
+ CtxJson1 tmpl;
DBusClient dbusClient;
int error = dbusClient.readSync(SUBJ_TRIGGER_GET_TEMPLATE, request, &req_id, &tmpl);
if (error == ERR_NOT_SUPPORTED) {
}
// called by context_trigger_rule_add_entry()
-bool rule_validator::check_option(Json& item)
+bool rule_validator::check_option(CtxJson1& item)
{
std::string name;
item.get(NULL, OLD_TRIG_RULE_KEY_EVENT_ITEM, &name);
- Json tmpl = get_template(name);
+ CtxJson1 tmpl = get_template(name);
IF_FAIL_RETURN(tmpl != EMPTY_JSON_OBJECT, false);
// No option needed
- Json opt_tmpl;
+ CtxJson1 opt_tmpl;
tmpl.get(NULL, TRIG_TMPL_KEY_OPTION, &opt_tmpl);
std::list<std::string> opt_keys;
// called by context_trigger_rule_entry_add_option_int()
bool rule_validator::check_option_int(std::string name, std::string key, int value)
{
- Json tmpl = get_template(name);
+ CtxJson1 tmpl = get_template(name);
IF_FAIL_RETURN(tmpl != EMPTY_JSON_OBJECT, false);
- Json opt_tmpl;
+ CtxJson1 opt_tmpl;
tmpl.get(NULL, TRIG_TMPL_KEY_OPTION, &opt_tmpl);
// Err: Item with no option
// called by context_trigger_rule_entry_add_option_string()
bool rule_validator::check_option_string(std::string name, std::string key, std::string value)
{
- Json tmpl = get_template(name);
+ CtxJson1 tmpl = get_template(name);
IF_FAIL_RETURN(tmpl != EMPTY_JSON_OBJECT, false);
- Json opt_tmpl;
+ CtxJson1 opt_tmpl;
tmpl.get(NULL, TRIG_TMPL_KEY_OPTION, &opt_tmpl);
// Err: ';' for SQL injection
// called by context_trigger_rule_entry_add_comparison_int()
bool rule_validator::check_comparison_int(std::string name, std::string key, std::string op, int value)
{
- Json tmpl = get_template(name);
+ CtxJson1 tmpl = get_template(name);
IF_FAIL_RETURN(tmpl != EMPTY_JSON_OBJECT, false);
- Json attr_tmpl;
+ CtxJson1 attr_tmpl;
tmpl.get(NULL, TRIG_TMPL_KEY_ATTRIBUTE, &attr_tmpl);
// Err: Invalid attribute key or Invalid value type
// called by context_trigger_rule_entry_add_comparison_string()
bool rule_validator::check_comparison_string(std::string name, std::string key, std::string op, std::string value)
{
- Json tmpl = get_template(name);
- IF_FAIL_RETURN(tmpl != Json(EMPTY_JSON_OBJECT), false);
+ CtxJson1 tmpl = get_template(name);
+ IF_FAIL_RETURN(tmpl != CtxJson1(EMPTY_JSON_OBJECT), false);
- Json attr_tmpl;
+ CtxJson1 attr_tmpl;
tmpl.get(NULL, TRIG_TMPL_KEY_ATTRIBUTE, &attr_tmpl);
// Err: ';' for SQL injection
bool rule_validator::check_valid_key(std::string type, std::string name, std::string key)
{
- Json tmpl = get_template(name);
+ CtxJson1 tmpl = get_template(name);
IF_FAIL_RETURN(tmpl != EMPTY_JSON_OBJECT, false);
// Err: Invalid key
- Json tmp;
+ CtxJson1 tmp;
bool ret = tmpl.get(type.c_str(), key.c_str(), &tmp);
IF_FAIL_RETURN(ret, false);
return true;
}
-bool check_value_int(Json& tmpl, std::string key, int value)
+bool check_value_int(CtxJson1& tmpl, std::string key, int value)
{
int min, max;
return true;
}
-bool check_value_string(Json& tmpl, std::string key, std::string value)
+bool check_value_string(CtxJson1& tmpl, std::string key, std::string value)
{
return true;
}
-bool check_value_enum(Json& tmpl, std::string key, std::string value)
+bool check_value_enum(CtxJson1& tmpl, std::string key, std::string value)
{
std::string t_val;
for (int i = 0; tmpl.getAt(key.c_str(), TRIG_TMPL_TYPE_ENUM, i, &t_val); i++) {
// called by context_trigger_rule_entry_add_comparison()
// called by context_trigger_rule_entry_add_option()
-bool rule_validator::set_ref_info(std::string type, Json* jref, std::string name, std::string key, std::string ref_data)
+bool rule_validator::set_ref_info(std::string type, CtxJson1* jref, std::string name, std::string key, std::string ref_data)
{
- Json tmpl = get_template(name);
+ CtxJson1 tmpl = get_template(name);
IF_FAIL_RETURN(tmpl != EMPTY_JSON_OBJECT, false);
- Json detailed_tmpl;
+ CtxJson1 detailed_tmpl;
tmpl.get(NULL, type.c_str(), &detailed_tmpl);
std::string dt = get_data_type(detailed_tmpl, key);
IF_FAIL_RETURN(dt == TRIG_TMPL_TYPE_INTEGER || dt == TRIG_TMPL_TYPE_STRING || dt == TRIG_TMPL_TYPE_ENUM, false);
- Json temp;
+ CtxJson1 temp;
temp.set(NULL, RULE_VALIDATOR_COND_NAME, name);
temp.set(NULL, RULE_VALIDATOR_KEY, key);
temp.set(NULL, RULE_VALIDATOR_TYPE, dt);
return true;;
}
-std::string get_data_type(Json& elem, std::string& key)
+std::string get_data_type(CtxJson1& elem, std::string& key)
{
std::string data_type;
bool ret = elem.get(key.c_str(), TRIG_TMPL_KEY_TYPE, &data_type);
// called by context_trigger_rule_entry_add_comparison()
std::string rule_validator::get_data_type_from_template(std::string type, std::string name, std::string key)
{
- Json tmpl = get_template(name);
+ CtxJson1 tmpl = get_template(name);
IF_FAIL_RETURN(tmpl != EMPTY_JSON_OBJECT, "");
- Json detailed_tmpl;
+ CtxJson1 detailed_tmpl;
tmpl.get(NULL, type.c_str(), &detailed_tmpl);
return get_data_type(detailed_tmpl, key);
}
// called by context_trigger_rule_add_entry()
-bool rule_validator::check_referential_data(std::string name, Json& ref_info)
+bool rule_validator::check_referential_data(std::string name, CtxJson1& ref_info)
{
std::map<std::string, std::string> type_map;
- Json ref_data;
+ CtxJson1 ref_data;
for (int i = 0; ref_info.getAt(NULL, TRIG_TMPL_KEY_OPTION, i, &ref_data); i++) {
std::string ref_key;
ref_data.get(NULL, RULE_VALIDATOR_REF, &ref_key);
}
// For custom item template
-bool rule_validator::is_valid_template(Json& attr_template)
+bool rule_validator::is_valid_template(CtxJson1& 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 CtxJson1");
bool ret;
std::list<std::string> keys;
IF_FAIL_RETURN_TAG(type == TRIG_TMPL_TYPE_INTEGER || type == TRIG_TMPL_TYPE_STRING || type == TRIG_TMPL_TYPE_ENUM,
false, _E, "Custom template: invalid data type");
- Json elem;
+ CtxJson1 elem;
attr_template.get(NULL, key.c_str(), &elem);
if (type == TRIG_TMPL_TYPE_INTEGER) {
ret = check_template_int(elem);
return true;
}
-bool check_template_int(Json& elem)
+bool check_template_int(CtxJson1& elem)
{
std::list<std::string> elem_keys;
elem.getKeys(&elem_keys);
return true;
}
-bool check_template_string(Json& elem)
+bool check_template_string(CtxJson1& elem)
{
std::list<std::string> elem_keys;
elem.getKeys(&elem_keys);
return true;
}
-bool check_template_enum(Json& elem)
+bool check_template_enum(CtxJson1& elem)
{
std::list<std::string> elem_keys;
elem.getKeys(&elem_keys);
#ifndef __CONTEXT_RULE_VALIDATOR_H__
#define __CONTEXT_RULE_VALIDATOR_H__
-#include <Json.h>
+#include <CtxJson1.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::CtxJson1 &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::CtxJson1 &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::CtxJson1 *jref, std::string name, std::string key, std::string ref_key);
std::string get_data_type_from_template(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::CtxJson1 &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::CtxJson1& 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::CtxJson1 json_val = EMPTY_JSON_OBJECT;
std::string str_val = "";
}
}
#include <string>
#include <glib.h>
#include <Types.h>
-#include <Json.h>
+#include <CtxJson1.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::CtxJson1 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::CtxJson1 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::CtxJson1 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::CtxJson1 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::CtxJson1 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::CtxJson1 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::CtxJson1 option)
{
if (!__support(CONTEXT_TRIGGER_CONDITION_COMMUNICATION_FREQUENCY)) return false;
bool _trigger_cond_comm_freq1()
{
/* Case 1: Address only */
- ctx::Json option;
+ ctx::CtxJson1 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::CtxJson1 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::CtxJson1 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::CtxJson1 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::CtxJson1 option)
{
if (!__support(item)) return false;
bool _trigger_cond_music_freq1()
{
- ctx::Json option;
+ ctx::CtxJson1 option;
return __trigger_cond_media_freq_base(
CONTEXT_TRIGGER_CONDITION_MUSIC_PLAYBACK_FREQUENCY,
bool _trigger_cond_music_freq2()
{
- ctx::Json option;
+ ctx::CtxJson1 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::CtxJson1 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::CtxJson1 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::CtxJson1 option;
return __trigger_cond_media_freq_base(
CONTEXT_TRIGGER_CONDITION_VIDEO_PLAYBACK_FREQUENCY,
bool _trigger_cond_video_freq2()
{
- ctx::Json option;
+ ctx::CtxJson1 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::CtxJson1 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::CtxJson1 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::CtxJson1 data)
{
g_print("[%d] %s: Error=%#x, Data=%s\n", callback_count--, item, error, data.str().c_str());
dow_str = CONTEXT_TRIGGER_WEEKDAY;
break;
}
- ctx::Json option;
+ ctx::CtxJson1 option;
option.append(NULL, CONTEXT_TRIGGER_DAY_OF_WEEK, dow_str);
option.append(NULL, CONTEXT_TRIGGER_TIME_OF_DAY, tod);
{
if (!__support(CONTEXT_TRIGGER_EVENT_PLACE)) return false;
- ctx::Json option;
+ ctx::CtxJson1 option;
option.set(NULL, CONTEXT_TRIGGER_PLACE_ID, 2); /* 2 => office */
err = ctx::request_handler::subscribe(SUBJ_PLACE_GEOFENCE, &option, &req_id, NULL);
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, CtxJson1 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, CtxJson1 event)
{
auto it = __callbackMap.find(subject);
IF_FAIL_VOID_TAG(it != __callbackMap.end(), _W, "Unregistered subject");
static DBusClientListenerImpl __dbusListener;
static DBusClient __dbusClient;
-int ctx::request_handler::subscribe(const char* subject, ctx::Json* option, int* req_id, ctx::Json* request_result)
+int ctx::request_handler::subscribe(const char* subject, ctx::CtxJson1* option, int* req_id, ctx::CtxJson1* request_result)
{
return __dbusClient.subscribe(subject, option ? *option : NULL, req_id, request_result);
}
return __dbusClient.unsubscribe(subject, req_id);
}
-int ctx::request_handler::read(const char* subject, ctx::Json* option, int* req_id, ctx::Json* request_result)
+int ctx::request_handler::read(const char* subject, ctx::CtxJson1* option, int* req_id, ctx::CtxJson1* request_result)
{
return __dbusClient.read(subject, option ? *option : NULL, req_id, request_result);
}
-int ctx::request_handler::read_sync(const char* subject, ctx::Json* option, int* req_id, ctx::Json* data_read)
+int ctx::request_handler::read_sync(const char* subject, ctx::CtxJson1* option, int* req_id, ctx::CtxJson1* data_read)
{
return __dbusClient.readSync(subject, option ? *option : NULL, req_id, data_read);
}
-int ctx::request_handler::write(const char* subject, ctx::Json* data)
+int ctx::request_handler::write(const char* subject, ctx::CtxJson1* data)
{
return __dbusClient.write(subject, *data);
}
-int ctx::request_handler::write_with_reply(const char* subject, ctx::Json* data, ctx::Json* request_result)
+int ctx::request_handler::write_with_reply(const char* subject, ctx::CtxJson1* data, ctx::CtxJson1* 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 <CtxJson1.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::CtxJson1 response);
/*
*/
/*
*/
- int subscribe(const char* subject, ctx::Json* option, int* req_id, ctx::Json* request_result = NULL);
+ int subscribe(const char* subject, ctx::CtxJson1* option, int* req_id, ctx::CtxJson1* 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::CtxJson1* option, int* req_id, ctx::CtxJson1* 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::CtxJson1* option, int* req_id, ctx::CtxJson1* data_read);
/*
*/
- int write(const char* subject, ctx::Json* data);
+ int write(const char* subject, ctx::CtxJson1* data);
/*
*/
- int write_with_reply(const char* subject, ctx::Json* data, ctx::Json* request_result = NULL);
+ int write_with_reply(const char* subject, ctx::CtxJson1* data, ctx::CtxJson1* request_result = NULL);
/*
*/