return true;
}
-bool ctx::client_request::reply(int error, ctx::json& request_result)
+bool ctx::client_request::reply(int error, ctx::Json& request_result)
{
IF_FAIL_RETURN(__invocation, true);
IF_FAIL_RETURN(_type != REQ_READ_SYNC, true);
- char *result = request_result.dup_cstr();
- IF_FAIL_RETURN_TAG(result, false, _E, "Memory allocation failed");
+ std::string result = request_result.str();
+ IF_FAIL_RETURN(!result.empty(), false);
_I("Reply %#x", error);
- _SD("Result: %s", result);
+ _SD("Result: %s", result.c_str());
- g_dbus_method_invocation_return_value(__invocation, g_variant_new("(iss)", error, result, EMPTY_JSON_OBJECT));
+ g_dbus_method_invocation_return_value(__invocation, g_variant_new("(iss)", error, result.c_str(), EMPTY_JSON_OBJECT));
__invocation = NULL;
- g_free(result);
return true;
}
-bool ctx::client_request::reply(int error, ctx::json& request_result, ctx::json& data_read)
+bool ctx::client_request::reply(int error, ctx::Json& request_result, ctx::Json& data_read)
{
if (__invocation == NULL) {
return publish(error, data_read);
}
- char *result = NULL;
- char *data = NULL;
-
- result = request_result.dup_cstr();
- IF_FAIL_CATCH_TAG(result, _E, "Memory allocation failed");
-
- data = data_read.dup_cstr();
- IF_FAIL_CATCH_TAG(data, _E, "Memory allocation failed");
+ std::string result = request_result.str();
+ std::string data = data_read.str();
+ IF_FAIL_RETURN(!result.empty() && !data.empty(), false);
_I("Reply %#x", error);
- _SD("Result: %s", result);
- _SD("Data: %s", data);
+ _SD("Result: %s", result.c_str());
+ _SD("Data: %s", data.c_str());
- g_dbus_method_invocation_return_value(__invocation, g_variant_new("(iss)", error, result, data));
+ g_dbus_method_invocation_return_value(__invocation, g_variant_new("(iss)", error, result.c_str(), data.c_str()));
__invocation = NULL;
- g_free(result);
- g_free(data);
return true;
-
-CATCH:
- g_free(result);
- g_free(data);
- return false;
}
-bool ctx::client_request::publish(int error, ctx::json& data)
+bool ctx::client_request::publish(int error, ctx::Json& data)
{
DBusServer::publish(__dbus_sender, _req_id, _subject, error, data.str());
return true;
const char* get_package_id();
const char* get_client();
bool reply(int error);
- bool reply(int error, ctx::json &request_result);
- bool reply(int error, ctx::json &request_result, ctx::json &data_read);
- bool publish(int error, ctx::json &data);
+ bool reply(int error, ctx::Json &request_result);
+ bool reply(int error, ctx::Json &request_result, ctx::Json &data_read);
+ bool publish(int error, ctx::Json &data);
private:
credentials *__credentials;
#include <types_internal.h>
#include <context_trigger_types_internal.h>
-#include <json.h>
+#include <Json.h>
#include <provider_iface.h>
#include "server.h"
#include "access_control/privilege.h"
struct trigger_item_format_s {
std::string subject;
int operation;
- ctx::json attributes;
- ctx::json options;
+ ctx::Json attributes;
+ ctx::Json options;
std::string owner;
bool unregister;
- trigger_item_format_s(std::string subj, int ops, ctx::json attr, ctx::json opt, std::string own)
+ trigger_item_format_s(std::string subj, int ops, ctx::Json attr, ctx::Json opt, std::string own)
: subject(subj), operation(ops), attributes(attr), options(opt), owner(own)
{
unregister = false;
return true;
}
-bool ctx::context_manager_impl::register_trigger_item(const char *subject, int operation, ctx::json attributes, ctx::json options, const char* owner)
+bool ctx::context_manager_impl::register_trigger_item(const char *subject, int operation, ctx::Json attributes, ctx::Json options, const char* owner)
{
IF_FAIL_RETURN_TAG(subject, false, _E, "Invalid parameter");
__trigger_item_list.push_back(trigger_item_format_s(subject, operation, attributes, options, (owner)? owner : ""));
return true;
}
-bool ctx::context_manager_impl::pop_trigger_item(std::string &subject, int &operation, ctx::json &attributes, ctx::json &options, std::string& owner, bool& unregister)
+bool ctx::context_manager_impl::pop_trigger_item(std::string &subject, int &operation, ctx::Json &attributes, ctx::Json &options, std::string& owner, bool& unregister)
{
IF_FAIL_RETURN(!__trigger_item_list.empty(), false);
return it->second->is_allowed(creds);
}
-void ctx::context_manager_impl::_publish(const char* subject, ctx::json &option, int error, ctx::json &data_updated)
+void ctx::context_manager_impl::_publish(const char* subject, ctx::Json &option, int error, ctx::Json &data_updated)
{
_I("Publishing '%s'", subject);
_J("Option", option);
it->second->publish(option, error, data_updated);
}
-void ctx::context_manager_impl::_reply_to_read(const char* subject, ctx::json &option, int error, ctx::json &data_read)
+void ctx::context_manager_impl::_reply_to_read(const char* subject, ctx::Json &option, int error, ctx::Json &data_read)
{
_I("Sending data of '%s'", subject);
_J("Option", option);
ctx::context_manager_impl *mgr;
std::string subject;
int error;
- ctx::json option;
- ctx::json data;
- published_data_s(int t, ctx::context_manager_impl *m, const char* s, ctx::json& o, int e, ctx::json& d)
+ ctx::Json option;
+ ctx::Json data;
+ published_data_s(int t, ctx::context_manager_impl *m, const char* s, ctx::Json& o, int e, ctx::Json& d)
: type(t), mgr(m), subject(s), error(e)
{
option = o.str();
return FALSE;
}
-bool ctx::context_manager_impl::publish(const char* subject, ctx::json& option, int error, ctx::json& data_updated)
+bool ctx::context_manager_impl::publish(const char* subject, ctx::Json& option, int error, ctx::Json& data_updated)
{
IF_FAIL_RETURN_TAG(subject, false, _E, "Invalid parameter");
return true;
}
-bool ctx::context_manager_impl::reply_to_read(const char* subject, ctx::json& option, int error, ctx::json& data_read)
+bool ctx::context_manager_impl::reply_to_read(const char* subject, ctx::Json& option, int error, ctx::Json& data_read)
{
IF_FAIL_RETURN_TAG(subject, false, _E, "Invalid parameter");
return true;
}
- ctx::json desc = request->get_description();
+ ctx::Json desc = request->get_description();
std::string name;
desc.get(NULL, CT_CUSTOM_NAME, &name);
std::string subj = pkg_id + std::string("::") + name;
int error = ERR_NONE;
if (subject == CONTEXT_TRIGGER_SUBJECT_CUSTOM_ADD) {
- ctx::json tmpl;
+ ctx::Json tmpl;
desc.get(NULL, CT_CUSTOM_ATTRIBUTES, &tmpl);
error = ctx::custom_context_provider::add_item(subj, name, tmpl, pkg_id);
} else if (subject == CONTEXT_TRIGGER_SUBJECT_CUSTOM_REMOVE) {
error = ctx::custom_context_provider::remove_item(subj);
if (error == ERR_NONE) {
- ctx::json data;
+ ctx::Json data;
data.set(NULL, CT_CUSTOM_SUBJECT, subj);
request->reply(error, data);
}
} else if (subject == CONTEXT_TRIGGER_SUBJECT_CUSTOM_PUBLISH) {
- ctx::json fact;
+ ctx::Json fact;
desc.get(NULL, CT_CUSTOM_FACT, &fact);
error = ctx::custom_context_provider::publish_data(subj, fact);
void assign_request(ctx::request_info *request);
bool is_supported(const char *subject);
bool is_allowed(const credentials *creds, const char *subject);
- bool pop_trigger_item(std::string &subject, int &operation, ctx::json &attributes, ctx::json &options, std::string &owner, bool& unregister);
+ bool pop_trigger_item(std::string &subject, int &operation, ctx::Json &attributes, ctx::Json &options, std::string &owner, bool& unregister);
/* From the interface class */
bool register_provider(const char *subject, context_provider_info &provider_info);
bool unregister_provider(const char *subject);
- bool register_trigger_item(const char *subject, int operation, ctx::json attributes, ctx::json options, const char *owner = NULL);
+ bool register_trigger_item(const char *subject, int operation, ctx::Json attributes, ctx::Json options, const char *owner = NULL);
bool unregister_trigger_item(const char *subject);
- bool publish(const char *subject, ctx::json &option, int error, ctx::json &data_updated);
- bool reply_to_read(const char *subject, ctx::json &option, int error, ctx::json &data_read);
+ bool publish(const char *subject, ctx::Json &option, int error, ctx::Json &data_updated);
+ bool reply_to_read(const char *subject, ctx::Json &option, int error, ctx::Json &data_read);
private:
std::map<std::string, context_provider_handler*> provider_handle_map;
static gboolean thread_switcher(gpointer data);
- void _publish(const char *subject, ctx::json &option, int error, ctx::json &data_updated);
- void _reply_to_read(const char *subject, ctx::json &option, int error, ctx::json &data_read);
+ void _publish(const char *subject, ctx::Json &option, int error, ctx::Json &data_updated);
+ void _reply_to_read(const char *subject, ctx::Json &option, int error, ctx::Json &data_read);
/* For custom request */
bool handle_custom_request(ctx::request_info* request);
#include <runtime_info.h>
#include <system_settings.h>
#include <context_trigger_types_internal.h>
-#include <json.h>
+#include <Json.h>
#include "../DBusServer.h"
#include "action_manager.h"
-static void trigger_action_app_control(ctx::json& action);
-static void trigger_action_notification(ctx::json& action, std::string pkg_id);
-static void trigger_action_dbus_call(ctx::json& action);
+static void trigger_action_app_control(ctx::Json& action);
+static void trigger_action_notification(ctx::Json& action, std::string pkg_id);
+static void trigger_action_dbus_call(ctx::Json& action);
-void ctx::action_manager::trigger_action(ctx::json& action, std::string pkg_id)
+void ctx::action_manager::trigger_action(ctx::Json& action, std::string pkg_id)
{
std::string type;
action.get(NULL, CT_RULE_ACTION_TYPE, &type);
}
}
-void trigger_action_app_control(ctx::json& action)
+void trigger_action_app_control(ctx::Json& action)
{
int error;
std::string appctl_str;
}
}
-void trigger_action_notification(ctx::json& action, std::string pkg_id)
+void trigger_action_notification(ctx::Json& action, std::string pkg_id)
{
int error;
notification_h notification = notification_create(NOTIFICATION_TYPE_NOTI);
}
}
-void trigger_action_dbus_call(ctx::json& action)
+void trigger_action_dbus_call(ctx::Json& action)
{
std::string bus_name, object, iface, method;
GVariant *param = NULL;
namespace ctx {
- class json;
+ class Json;
namespace action_manager {
- void trigger_action(ctx::json& action, std::string pkg_id);
+ void trigger_action(ctx::Json& action, std::string pkg_id);
}
namespace ctx {
/* Forward Declaration */
- class json;
+ class Json;
class context_listener_iface {
public:
virtual ~context_listener_iface() {}
- virtual void on_event_received(std::string name, ctx::json option, ctx::json data) = 0;
+ virtual void on_event_received(std::string name, ctx::Json option, ctx::Json data) = 0;
- virtual void on_condition_received(std::string name, ctx::json option, ctx::json data) = 0;
+ virtual void on_condition_received(std::string name, ctx::Json option, ctx::Json data) = 0;
};
} /* namespace ctx */
}
}
-int ctx::context_monitor::subscribe(int rule_id, std::string subject, ctx::json option, context_listener_iface* listener)
+int ctx::context_monitor::subscribe(int rule_id, std::string subject, ctx::Json option, context_listener_iface* listener)
{
int req_id = _subscribe(subject.c_str(), &option, listener);
IF_FAIL_RETURN_TAG(req_id > 0, req_id, _E, "Subscribe event failed");
return ERR_NONE;
}
-int ctx::context_monitor::_subscribe(const char* subject, json* option, context_listener_iface* listener)
+int ctx::context_monitor::_subscribe(const char* subject, Json* option, context_listener_iface* listener)
{
IF_FAIL_RETURN(subject, ERR_INVALID_PARAMETER);
return rid;
}
-int ctx::context_monitor::unsubscribe(int rule_id, std::string subject, ctx::json option, context_listener_iface* listener)
+int ctx::context_monitor::unsubscribe(int rule_id, std::string subject, ctx::Json option, context_listener_iface* listener)
{
int rid = find_sub(REQ_SUBSCRIBE, subject.c_str(), &option);
if (rid < 0) {
remove_sub(REQ_SUBSCRIBE, subscription_id);
}
-int ctx::context_monitor::read(std::string subject, json option, context_listener_iface* listener)
+int ctx::context_monitor::read(std::string subject, Json option, context_listener_iface* listener)
{
int req_id = _read(subject.c_str(), &option, listener);
IF_FAIL_RETURN_TAG(req_id > 0, ERR_OPERATION_FAILED, _E, "Read condition failed");
return ERR_NONE;
}
-int ctx::context_monitor::_read(const char* subject, json* option, context_listener_iface* listener)
+int ctx::context_monitor::_read(const char* subject, Json* option, context_listener_iface* listener)
{
IF_FAIL_RETURN(subject, ERR_INVALID_PARAMETER);
return true;
}
-int ctx::context_monitor::find_sub(request_type type, const char* subject, json* option)
+int ctx::context_monitor::find_sub(request_type type, const char* subject, Json* option)
{
// @return request id
subscr_map_t* map = (type == REQ_SUBSCRIBE)? &subscr_map : &read_map;
- json opt_j;
+ Json opt_j;
if (option) {
opt_j = *option;
}
return -1;
}
-bool ctx::context_monitor::add_sub(request_type type, int sid, const char* subject, json* option, context_listener_iface* listener)
+bool ctx::context_monitor::add_sub(request_type type, int sid, const char* subject, Json* option, context_listener_iface* listener)
{
subscr_map_t* map = (type == REQ_SUBSCRIBE)? &subscr_map : &read_map;
return true;
}
-void ctx::context_monitor::remove_sub(request_type type, const char* subject, json* option)
+void ctx::context_monitor::remove_sub(request_type type, const char* subject, Json* option)
{
subscr_map_t* map = (type == REQ_SUBSCRIBE)? &subscr_map : &read_map;
- json opt_j;
+ Json opt_j;
if (option) {
opt_j = *option;
}
return info->listener_list.size();
}
-void ctx::context_monitor::reply_result(int req_id, int error, json* request_result)
+void ctx::context_monitor::reply_result(int req_id, int error, Json* request_result)
{
_D("Request result received: %d", req_id);
last_err = error;
}
-void ctx::context_monitor::reply_result(int req_id, int error, const char* subject, json* option, json* fact)
+void ctx::context_monitor::reply_result(int req_id, int error, const char* subject, Json* option, Json* fact)
{
_D(YELLOW("Condition received: subject(%s), option(%s), fact(%s)"), subject, option->str().c_str(), fact->str().c_str());
remove_sub(REQ_READ, req_id);
}
-void ctx::context_monitor::publish_fact(int req_id, int error, const char* subject, json* option, json* fact)
+void ctx::context_monitor::publish_fact(int req_id, int error, const char* subject, Json* option, Json* fact)
{
_D(YELLOW("Event received: subject(%s), option(%s), fact(%s)"), subject, option->str().c_str(), fact->str().c_str());
#include <list>
#include <map>
-#include <json.h>
+#include <Json.h>
namespace ctx {
static void set_context_manager(ctx::context_manager_impl* ctx_mgr);
static void destroy();
- int subscribe(int rule_id, std::string subject, ctx::json option, context_listener_iface* listener);
- int unsubscribe(int rule_id, std::string subject, ctx::json option, context_listener_iface* listener);
- int read(std::string subject, json option, context_listener_iface* listener);
+ int subscribe(int rule_id, std::string subject, ctx::Json option, context_listener_iface* listener);
+ int unsubscribe(int rule_id, std::string subject, ctx::Json option, context_listener_iface* listener);
+ int read(std::string subject, Json option, context_listener_iface* listener);
bool is_supported(std::string subject);
bool is_allowed(const char *client, const char *subject);
- void reply_result(int req_id, int error, json *request_result = NULL);
- void reply_result(int req_id, int error, const char *subject, ctx::json *option, ctx::json *fact);
- void publish_fact(int req_id, int error, const char *subject, ctx::json *option, ctx::json *fact);
+ void reply_result(int req_id, int error, Json *request_result = NULL);
+ void reply_result(int req_id, int error, const char *subject, ctx::Json *option, ctx::Json *fact);
+ void publish_fact(int req_id, int error, const char *subject, ctx::Json *option, ctx::Json *fact);
private:
context_monitor();
static context_monitor *_instance;
static context_manager_impl *_context_mgr;
- int _subscribe(const char* subject, ctx::json* option, context_listener_iface* listener);
+ int _subscribe(const char* subject, ctx::Json* option, context_listener_iface* listener);
void _unsubscribe(const char *subject, int subscription_id);
- int _read(const char *subject, ctx::json *option, context_listener_iface* listener);
+ int _read(const char *subject, ctx::Json *option, context_listener_iface* listener);
typedef std::list<context_listener_iface*> listener_list_t;
struct subscr_info_s {
int sid;
std::string subject;
- ctx::json option;
+ ctx::Json option;
listener_list_t listener_list;
- subscr_info_s(int id, const char *subj, ctx::json *opt)
+ subscr_info_s(int id, const char *subj, ctx::Json *opt)
: sid(id), subject(subj)
{
if (opt)
subscr_map_t subscr_map;
subscr_map_t read_map;
- int find_sub(request_type type, const char *subject, ctx::json *option);
- bool add_sub(request_type type, int sid, const char *subject, ctx::json *option, context_listener_iface* listener);
- void remove_sub(request_type type, const char *subject, ctx::json *option);
+ int find_sub(request_type type, const char *subject, ctx::Json *option);
+ bool add_sub(request_type type, int sid, const char *subject, ctx::Json *option, context_listener_iface* listener);
+ void remove_sub(request_type type, const char *subject, ctx::Json *option);
void remove_sub(request_type type, int sid);
int add_listener(request_type type, int sid, context_listener_iface* listener);
int remove_listener(request_type type, int sid, context_listener_iface* listener);
{
}
-ctx::context_fact::context_fact(int id, int err, const char* s, ctx::json& o, ctx::json& d)
+ctx::context_fact::context_fact(int id, int err, const char* s, ctx::Json& o, ctx::Json& d)
: req_id(id)
, error(err)
, subject(s)
subject = s;
}
-void ctx::context_fact::set_option(ctx::json& o)
+void ctx::context_fact::set_option(ctx::Json& o)
{
option = o;
}
-void ctx::context_fact::set_data(ctx::json& d)
+void ctx::context_fact::set_data(ctx::Json& d)
{
data = d;
}
return subject.c_str();
}
-ctx::json& ctx::context_fact::get_option()
+ctx::Json& ctx::context_fact::get_option()
{
return option;
}
-ctx::json& ctx::context_fact::get_data()
+ctx::Json& ctx::context_fact::get_data()
{
return data;
}
#define __CONTEXT_CONTEXT_TRIGGER_FACT_H__
#include <string>
-#include <json.h>
+#include <Json.h>
namespace ctx {
int req_id;
int error;
std::string subject;
- ctx::json option;
- ctx::json data;
+ ctx::Json option;
+ ctx::Json data;
public:
context_fact();
- context_fact(int id, int err, const char* s, ctx::json& o, ctx::json& d);
+ context_fact(int id, int err, const char* s, ctx::Json& o, ctx::Json& d);
~context_fact();
void set_req_id(int id);
void set_error(int err);
void set_subject(const char* s);
- void set_option(ctx::json& o);
- void set_data(ctx::json& d);
+ void set_option(ctx::Json& o);
+ void set_data(ctx::Json& d);
int get_req_id();
int get_error();
const char* get_subject();
- ctx::json& get_option();
- ctx::json& get_data();
+ ctx::Json& get_option();
+ ctx::Json& get_data();
};
} /* namespace ctx */
return true;
}
-bool ctx::fact_request::reply(int error, ctx::json& request_result)
+bool ctx::fact_request::reply(int error, ctx::Json& request_result)
{
IF_FAIL_RETURN(!replied && _ctx_monitor, true);
_ctx_monitor->reply_result(_req_id, error, &request_result);
return true;
}
-bool ctx::fact_request::reply(int error, ctx::json& request_result, ctx::json& data_read)
+bool ctx::fact_request::reply(int error, ctx::Json& request_result, ctx::Json& data_read)
{
IF_FAIL_RETURN(!replied && _ctx_monitor, true);
_ctx_monitor->reply_result(_req_id, error, _subject.c_str(), &get_description(), &data_read);
return (replied = true);
}
-bool ctx::fact_request::publish(int error, ctx::json& data)
+bool ctx::fact_request::publish(int error, ctx::Json& data)
{
IF_FAIL_RETURN(_ctx_monitor, true);
_ctx_monitor->publish_fact(_req_id, error, _subject.c_str(), &get_description(), &data);
const char* get_client();
bool reply(int error);
- bool reply(int error, ctx::json& request_result);
- bool reply(int error, ctx::json& request_result, ctx::json& data_read);
- bool publish(int error, ctx::json& data);
+ bool reply(int error, ctx::Json& request_result);
+ bool reply(int error, ctx::Json& request_result, ctx::Json& data_read);
+ bool publish(int error, ctx::Json& data);
private:
context_monitor *_ctx_monitor;
ctx::rule_manager *ctx::trigger_rule::rule_mgr = NULL;
-ctx::trigger_rule::trigger_rule(int i, ctx::json& d, const char* p, rule_manager* rm)
+ctx::trigger_rule::trigger_rule(int i, ctx::Json& d, const char* p, rule_manager* rm)
: result(EMPTY_JSON_OBJECT)
, id(i)
, pkg_id(p)
statement = d.str();
// Event
- ctx::json e;
+ ctx::Json e;
d.get(NULL, CT_RULE_EVENT, &e);
event = new(std::nothrow) context_item_s(e);
// Condition
- int cond_num = d.array_get_size(NULL, CT_RULE_CONDITION);
+ int cond_num = d.getSize(NULL, CT_RULE_CONDITION);
for (int j = 0; j < cond_num; j++) {
- ctx::json c;
- d.get_array_elem(NULL, CT_RULE_CONDITION, j, &c);
+ ctx::Json c;
+ d.getAt(NULL, CT_RULE_CONDITION, j, &c);
condition.push_back(new(std::nothrow) context_item_s(c));
}
// Action
- ctx::json a;
+ ctx::Json a;
d.get(NULL, CT_RULE_ACTION, &a);
action = a.str();
}
return error;
}
-bool ctx::trigger_rule::set_condition_option_based_on_event(ctx::json& option)
+bool ctx::trigger_rule::set_condition_option_based_on_event(ctx::Json& option)
{
// Set condition option if it references event data
std::list<std::string> option_keys;
- option.get_keys(&option_keys);
+ option.getKeys(&option_keys);
for (std::list<std::string>::iterator it = option_keys.begin(); it != option_keys.end(); ++it) {
std::string opt_key = (*it);
return true;
}
-void ctx::trigger_rule::on_event_received(std::string name, ctx::json option, ctx::json data)
+void ctx::trigger_rule::on_event_received(std::string name, ctx::Json option, ctx::Json data)
{
if (result != EMPTY_JSON_OBJECT) {
clear_result();
// Request read conditions
for (std::list<context_item_t>::iterator it = condition.begin(); it != condition.end(); ++it) {
- ctx::json cond_option = (*it)->option.str();
+ ctx::Json cond_option = (*it)->option.str();
if (!set_condition_option_based_on_event(cond_option)) { // cond_option should be copy of original option.
clear_result();
return;
// TODO timer set
}
-void ctx::trigger_rule::on_condition_received(std::string name, ctx::json option, ctx::json data)
+void ctx::trigger_rule::on_condition_received(std::string name, ctx::Json option, ctx::Json data)
{
_D("Rule%d received condition data", id);
// Set condition data
- ctx::json item;
+ ctx::Json item;
item.set(NULL, CONTEXT_FACT_NAME, name);
item.set(NULL, CONTEXT_FACT_OPTION, option);
item.set(NULL, CONTEXT_FACT_DATA, data);
- result.array_append(NULL, CONTEXT_FACT_CONDITION, item);
+ result.append(NULL, CONTEXT_FACT_CONDITION, item);
- if (result.array_get_size(NULL, CONTEXT_FACT_CONDITION) == (int) condition.size()) {
+ if (result.getSize(NULL, CONTEXT_FACT_CONDITION) == (int) condition.size()) {
on_context_data_prepared();
}
}
#define __CONTEXT_TRIGGER_RULE_H__
#include <string>
-#include <json.h>
+#include <Json.h>
#include "context_listener_iface.h"
namespace ctx {
private:
struct context_item_s {
std::string name;
- ctx::json option;
- context_item_s(ctx::json item) {
+ ctx::Json option;
+ context_item_s(ctx::Json item) {
std::string n;
item.get(NULL, CT_RULE_EVENT_ITEM, &n);
name = n;
- ctx::json o;
+ ctx::Json o;
if (item.get(NULL, CT_RULE_EVENT_OPTION, &o))
option = o.str();
}
};
typedef struct context_item_s* context_item_t;
- ctx::json statement;
+ ctx::Json statement;
context_item_t event;
std::list<context_item_t> condition;
- ctx::json action;
- ctx::json result;
+ ctx::Json action;
+ ctx::Json result;
static rule_manager* rule_mgr;
void clear_result(void);
- bool set_condition_option_based_on_event(ctx::json& option);
+ bool set_condition_option_based_on_event(ctx::Json& option);
void on_context_data_prepared(void);
static gboolean handle_uninstalled_rule(gpointer data);
int id;
std::string pkg_id;
- trigger_rule(int i, ctx::json& d, const char* p, rule_manager* rm);
+ trigger_rule(int i, ctx::Json& d, const char* p, rule_manager* rm);
~trigger_rule();
int start(void);
int stop(void);
- void on_event_received(std::string name, ctx::json option, ctx::json data);
- void on_condition_received(std::string name, ctx::json option, ctx::json data);
+ void on_event_received(std::string name, ctx::Json option, ctx::Json data);
+ void on_condition_received(std::string name, ctx::Json option, ctx::Json data);
};
* limitations under the License.
*/
-#include <json.h>
+#include <Json.h>
#include <types_internal.h>
#include <context_trigger_types_internal.h>
#include "rule_evaluator.h"
}
}
-bool ctx::rule_evaluator::replace_data_references(ctx::json& rule_data_arr, ctx::json event_fact_data)
+bool ctx::rule_evaluator::replace_data_references(ctx::Json& rule_data_arr, ctx::Json event_fact_data)
{
std::string arr_string;
std::string event_reference_string;
int event_reference_int;
- for (int i = 0; i < rule_data_arr.array_get_size(NULL, CT_RULE_DATA_VALUE_ARR); i++) {
- if (!rule_data_arr.get_array_elem(NULL, CT_RULE_DATA_VALUE_ARR, i, &arr_string)) {
+ for (int i = 0; i < rule_data_arr.getSize(NULL, CT_RULE_DATA_VALUE_ARR); i++) {
+ if (!rule_data_arr.getAt(NULL, CT_RULE_DATA_VALUE_ARR, i, &arr_string)) {
continue;
}
if (arr_string.substr(0, 1) != EVENT_REFERENCE) {
std::string event_key = arr_string.substr(1, arr_string.length() - 1);
if (event_fact_data.get(NULL, event_key.c_str(), &event_reference_string)) {
- rule_data_arr.array_set_at(NULL, CT_RULE_DATA_VALUE_ARR, i, event_reference_string);
+ rule_data_arr.setAt(NULL, CT_RULE_DATA_VALUE_ARR, i, event_reference_string);
} else if (event_fact_data.get(NULL, event_key.c_str(), &event_reference_int)) {
- rule_data_arr.array_set_at(NULL, CT_RULE_DATA_VALUE_ARR, i, event_reference_int);
+ rule_data_arr.setAt(NULL, CT_RULE_DATA_VALUE_ARR, i, event_reference_int);
} else {
_W("Option %s not found in event_data", event_key.c_str());
}
return true;
}
-bool ctx::rule_evaluator::replace_option_references(ctx::json& rule_option, ctx::json event_fact_data)
+bool ctx::rule_evaluator::replace_option_references(ctx::Json& rule_option, ctx::Json event_fact_data)
{
std::list<std::string> key_list;
- rule_option.get_keys(&key_list);
+ rule_option.getKeys(&key_list);
for (std::list<std::string>::iterator it = key_list.begin(); it != key_list.end(); ++it) {
std::string option_key = *it;
return true;
}
-bool ctx::rule_evaluator::replace_event_references(ctx::json& rule, ctx::json& fact)
+bool ctx::rule_evaluator::replace_event_references(ctx::Json& rule, ctx::Json& fact)
{
- ctx::json event_fact_data;
+ ctx::Json event_fact_data;
if (!fact.get(CONTEXT_FACT_EVENT, CONTEXT_FACT_DATA, &event_fact_data)) {
_E("No event data found, error");
return false;
}
- ctx::json rule_condition;
- for (int i = 0; rule.get_array_elem(NULL, CT_RULE_CONDITION, i, &rule_condition); i++) {
- ctx::json rule_data_arr;
- for (int j = 0; rule_condition.get_array_elem(NULL, CT_RULE_DATA_ARR, j, &rule_data_arr); j++) {
+ ctx::Json rule_condition;
+ for (int i = 0; rule.getAt(NULL, CT_RULE_CONDITION, i, &rule_condition); i++) {
+ ctx::Json rule_data_arr;
+ for (int j = 0; rule_condition.getAt(NULL, CT_RULE_DATA_ARR, j, &rule_data_arr); j++) {
replace_data_references(rule_data_arr, event_fact_data);
}
- ctx::json rule_option;
+ ctx::Json rule_option;
if (rule_condition.get(NULL, CT_RULE_CONDITION_OPTION, &rule_option)) {
replace_option_references(rule_option, event_fact_data);
}
return true;
}
-bool ctx::rule_evaluator::evaluate_data_string(ctx::json& rule_data_arr, std::string fact_value_str)
+bool ctx::rule_evaluator::evaluate_data_string(ctx::Json& rule_data_arr, std::string fact_value_str)
{
std::string operate_internal;
rule_data_arr.get(NULL, CT_RULE_DATA_KEY_OPERATOR, &operate_internal);
}
std::string operator_str;
- for (int j = 0; rule_data_arr.get_array_elem(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR, j, &operator_str); j++) {
+ for (int j = 0; rule_data_arr.getAt(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR, j, &operator_str); j++) {
bool data_arr_vale_match;
std::string get_str_val;
- rule_data_arr.get_array_elem(NULL, CT_RULE_DATA_VALUE_ARR, j, &get_str_val);
+ rule_data_arr.getAt(NULL, CT_RULE_DATA_VALUE_ARR, j, &get_str_val);
data_arr_vale_match = compare_string(operator_str, fact_value_str, get_str_val);
if (is_and && !data_arr_vale_match) {
return is_and;
}
-bool ctx::rule_evaluator::evaluate_data_int(ctx::json& rule_data_arr, int fact_value_int)
+bool ctx::rule_evaluator::evaluate_data_int(ctx::Json& rule_data_arr, int fact_value_int)
{
std::string operate_internal;
rule_data_arr.get(NULL, CT_RULE_DATA_KEY_OPERATOR, &operate_internal);
}
std::string operator_str;
- for (int j = 0; rule_data_arr.get_array_elem(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR, j, &operator_str); j++) {
+ for (int j = 0; rule_data_arr.getAt(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR, j, &operator_str); j++) {
bool data_arr_vale_match;
int get_int_val;
- if (!rule_data_arr.get_array_elem(NULL, CT_RULE_DATA_VALUE_ARR, j, &get_int_val)) {
+ if (!rule_data_arr.getAt(NULL, CT_RULE_DATA_VALUE_ARR, j, &get_int_val)) {
data_arr_vale_match = false;
}
data_arr_vale_match = compare_int(operator_str, fact_value_int, get_int_val);
return is_and;
}
-bool ctx::rule_evaluator::evaluate_item(ctx::json& rule_item, ctx::json& fact_item)
+bool ctx::rule_evaluator::evaluate_item(ctx::Json& rule_item, ctx::Json& fact_item)
{
- ctx::json rule_data_arr;
- if (rule_item.array_get_size(NULL, CT_RULE_DATA_ARR) == 0) {
+ ctx::Json rule_data_arr;
+ if (rule_item.getSize(NULL, CT_RULE_DATA_ARR) == 0) {
return true;
}
is_and = true;
}
- for (int i = 0; rule_item.get_array_elem(NULL, CT_RULE_DATA_ARR, i, &rule_data_arr); i++) {
+ for (int i = 0; rule_item.getAt(NULL, CT_RULE_DATA_ARR, i, &rule_data_arr); i++) {
std::string data_key;
rule_data_arr.get(NULL, CT_RULE_DATA_KEY, &data_key);
std::string fact_value_str;
return is_and;
}
-bool ctx::rule_evaluator::check_rule_event(ctx::json& rule, ctx::json& fact)
+bool ctx::rule_evaluator::check_rule_event(ctx::Json& rule, ctx::Json& fact)
{
- ctx::json fact_item;
+ ctx::Json fact_item;
fact.get(NULL, CONTEXT_FACT_EVENT, &fact_item);
- ctx::json rule_item;
+ ctx::Json rule_item;
rule.get(NULL, CT_RULE_EVENT, &rule_item);
return evaluate_item(rule_item, fact_item);
}
-ctx::json ctx::rule_evaluator::find_condition_fact(ctx::json& rule_condition, ctx::json& fact)
+ctx::Json ctx::rule_evaluator::find_condition_fact(ctx::Json& rule_condition, ctx::Json& fact)
{
- ctx::json fact_condition;
+ ctx::Json fact_condition;
std::string item_name_rule_condition;
rule_condition.get(NULL, CT_RULE_CONDITION_ITEM, &item_name_rule_condition);
std::string item_name_fact_condition;
- for (int i = 0; fact.get_array_elem(NULL, CONTEXT_FACT_CONDITION, i, &fact_condition); i++) {
+ for (int i = 0; fact.getAt(NULL, CONTEXT_FACT_CONDITION, i, &fact_condition); i++) {
fact_condition.get(NULL, CONTEXT_FACT_NAME, &item_name_fact_condition);
if (item_name_fact_condition != item_name_rule_condition) {
continue;
}
- ctx::json rule_condition_option;
- ctx::json fact_condition_option;
+ ctx::Json rule_condition_option;
+ ctx::Json fact_condition_option;
rule_condition.get(NULL, CT_RULE_CONDITION_OPTION, &rule_condition_option);
fact_condition.get(NULL, CONTEXT_FACT_OPTION, &fact_condition_option);
if (fact_condition_option == rule_condition_option) {
return EMPTY_JSON_OBJECT;
}
-bool ctx::rule_evaluator::check_rule_condition(ctx::json& rule, ctx::json& fact)
+bool ctx::rule_evaluator::check_rule_condition(ctx::Json& rule, ctx::Json& fact)
{
- ctx::json rule_condition;
- ctx::json fact_condition;
+ ctx::Json rule_condition;
+ ctx::Json fact_condition;
std::string operate;
rule.get(NULL, CT_RULE_OPERATOR, &operate);
is_and = true;
}
- for (int i = 0; rule.get_array_elem(NULL, CT_RULE_CONDITION, i, &rule_condition); i++) {
+ for (int i = 0; rule.getAt(NULL, CT_RULE_CONDITION, i, &rule_condition); i++) {
fact_condition = find_condition_fact(rule_condition, fact);
bool condition_satisfied;
if (fact_condition == EMPTY_JSON_OBJECT) {
return is_and;
}
-bool ctx::rule_evaluator::evaluate_rule(ctx::json rule, ctx::json fact)
+bool ctx::rule_evaluator::evaluate_rule(ctx::Json rule, ctx::Json fact)
{
_D("Rule is %s ", rule.str().c_str());
_D("fact is %s ", fact.str().c_str());
rule_evaluator eval;
bool ret;
- ctx::json temp_json;
+ ctx::Json temp_json;
if (fact.get(NULL, CT_RULE_CONDITION, &temp_json)) {
- ctx::json rule_copy(rule.str());
+ ctx::Json rule_copy(rule.str());
if (!eval.replace_event_references(rule_copy, fact)) {
_W("Replace failed");
}
namespace ctx {
- class json;
+ class Json;
class rule_evaluator {
private:
rule_evaluator();
- bool evaluate_item(ctx::json& rule_item, ctx::json& fact_item);
+ bool evaluate_item(ctx::Json& rule_item, ctx::Json& fact_item);
bool compare_int(std::string operation, int rule_var, int fact_var);
bool compare_string(std::string operation, std::string rule_var, std::string fact_var);
- bool check_rule_event(ctx::json& rule, ctx::json& fact);
- ctx::json find_condition_fact(ctx::json& rule_condition, ctx::json& fact);
- bool check_rule_condition(ctx::json& rule, ctx::json& fact);
- bool replace_data_references(ctx::json& rule_data_arr, ctx::json event_fact_data);
- bool replace_option_references(ctx::json& rule_option, ctx::json event_fact_data);
- bool replace_event_references(ctx::json& rule, ctx::json& fact);
- bool evaluate_data_string(ctx::json& rule_data_arr, std::string fact_value_str);
- bool evaluate_data_int(ctx::json& rule_data_arr, int fact_value_int);
+ bool check_rule_event(ctx::Json& rule, ctx::Json& fact);
+ ctx::Json find_condition_fact(ctx::Json& rule_condition, ctx::Json& fact);
+ bool check_rule_condition(ctx::Json& rule, ctx::Json& fact);
+ bool replace_data_references(ctx::Json& rule_data_arr, ctx::Json event_fact_data);
+ bool replace_option_references(ctx::Json& rule_option, ctx::Json event_fact_data);
+ bool replace_event_references(ctx::Json& rule, ctx::Json& fact);
+ bool evaluate_data_string(ctx::Json& rule_data_arr, std::string fact_value_str);
+ bool evaluate_data_int(ctx::Json& rule_data_arr, int fact_value_int);
public:
- static bool evaluate_rule(ctx::json rule, ctx::json data);
+ static bool evaluate_rule(ctx::Json rule, ctx::Json data);
};
} /* namespace ctx */
*/
#include <sstream>
-#include <json.h>
+#include <Json.h>
#include <context_trigger_types_internal.h>
#include <db_mgr.h>
#include <package_manager.h>
// Return number of uninstalled apps
std::string q1 = "SELECT DISTINCT package_id FROM context_trigger_rule";
- std::vector<json> record;
+ std::vector<Json> record;
bool ret = db_manager::execute_sync(q1.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, -1, _E, "Query package ids of registered rules failed");
- std::vector<json>::iterator vec_end = record.end();
- for (std::vector<json>::iterator vec_pos = record.begin(); vec_pos != vec_end; ++vec_pos) {
- ctx::json elem = *vec_pos;
+ std::vector<Json>::iterator vec_end = record.end();
+ for (std::vector<Json>::iterator vec_pos = record.begin(); vec_pos != vec_end; ++vec_pos) {
+ ctx::Json elem = *vec_pos;
std::string pkg_id;
elem.get(NULL, "package_id", &pkg_id);
q1 += pkg_list;
q1 += ")";
- std::vector<json> record;
+ std::vector<Json> record;
ret = db_manager::execute_sync(q1.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, ERR_OPERATION_FAILED, _E, "Failed to query enabled rules of uninstalled packages");
- std::vector<json>::iterator vec_end = record.end();
- for (std::vector<json>::iterator vec_pos = record.begin(); vec_pos != vec_end; ++vec_pos) {
- ctx::json elem = *vec_pos;
+ std::vector<Json>::iterator vec_end = record.end();
+ for (std::vector<Json>::iterator vec_pos = record.begin(); vec_pos != vec_end; ++vec_pos) {
+ ctx::Json elem = *vec_pos;
int rule_id;
elem.get(NULL, "row_id", &rule_id);
error = disable_rule(rule_id);
// Delete rules of uninstalled packages from DB
std::string q2 = "DELETE FROM context_trigger_rule WHERE " + pkg_list;
- std::vector<json> dummy;
+ std::vector<Json> dummy;
ret = db_manager::execute_sync(q2.c_str(), &dummy);
IF_FAIL_RETURN_TAG(ret, ERR_OPERATION_FAILED, _E, "Failed to remove rules from db");
_D("Uninstalled packages' rules are deleted from db");
int ctx::rule_manager::pause_rule_with_item(std::string& subject)
{
std::string q = "SELECT row_id FROM context_trigger_rule WHERE (status=2) AND (details LIKE '%\"ITEM_NAME\":\"" + subject + "\"%');";
- std::vector<json> record;
+ std::vector<Json> record;
bool ret = db_manager::execute_sync(q.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, ERR_OPERATION_FAILED, _E, "Failed to query row_ids to be paused");
IF_FAIL_RETURN(record.size() > 0, ERR_NONE);
_D("Pause rules related to %s", subject.c_str());
- std::vector<json>::iterator vec_end = record.end();
- for (std::vector<json>::iterator vec_pos = record.begin(); vec_pos != vec_end; ++vec_pos) {
- ctx::json elem = *vec_pos;
+ std::vector<Json>::iterator vec_end = record.end();
+ for (std::vector<Json>::iterator vec_pos = record.begin(); vec_pos != vec_end; ++vec_pos) {
+ ctx::Json elem = *vec_pos;
int row_id;
elem.get(NULL, "row_id", &row_id);
int ctx::rule_manager::resume_rule_with_item(std::string& subject)
{
std::string q = "SELECT row_id FROM context_trigger_rule WHERE (status=1) AND (details LIKE '%\"ITEM_NAME\":\"" + subject + "\"%');";
- std::vector<json> record;
+ std::vector<Json> record;
bool ret = db_manager::execute_sync(q.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, ERR_OPERATION_FAILED, _E, "Query paused rule ids failed");
IF_FAIL_RETURN(record.size() > 0, ERR_NONE);
_D("Resume rules related to %s", subject.c_str());
std::string q_rowid;
- std::vector<json>::iterator vec_end = record.end();
- for (std::vector<json>::iterator vec_pos = record.begin(); vec_pos != vec_end; ++vec_pos) {
- ctx::json elem = *vec_pos;
+ std::vector<Json>::iterator vec_end = record.end();
+ for (std::vector<Json>::iterator vec_pos = record.begin(); vec_pos != vec_end; ++vec_pos) {
+ ctx::Json elem = *vec_pos;
int row_id;
elem.get(NULL, "row_id", &row_id);
int error;
std::string q = "SELECT row_id FROM context_trigger_rule WHERE status = 2";
- std::vector<json> record;
+ std::vector<Json> record;
bool ret = db_manager::execute_sync(q.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, false, _E, "Query row_ids of enabled rules failed");
IF_FAIL_RETURN_TAG(record.size() > 0, true, _D, "No rule to re-enable");
std::string q_rowid;
q_rowid.clear();
- std::vector<json>::iterator vec_end = record.end();
- for (std::vector<json>::iterator vec_pos = record.begin(); vec_pos != vec_end; ++vec_pos) {
- ctx::json elem = *vec_pos;
+ std::vector<Json>::iterator vec_end = record.end();
+ for (std::vector<Json>::iterator vec_pos = record.begin(); vec_pos != vec_end; ++vec_pos) {
+ ctx::Json elem = *vec_pos;
int row_id;
elem.get(NULL, "row_id", &row_id);
// For rules which is failed to re-enable
std::string q_update = "UPDATE context_trigger_rule SET status = 1 WHERE " + q_rowid;
- std::vector<json> record2;
+ std::vector<Json> record2;
ret = db_manager::execute_sync(q_update.c_str(), &record2);
IF_FAIL_RETURN_TAG(ret, false, _E, "Failed to update rules as paused");
return true;
}
-bool ctx::rule_manager::rule_data_arr_elem_equals(ctx::json& lelem, ctx::json& relem)
+bool ctx::rule_manager::rule_data_arr_elem_equals(ctx::Json& lelem, ctx::Json& relem)
{
std::string lkey, rkey;
lelem.get(NULL, CT_RULE_DATA_KEY, &lkey);
return false;
int lvc, rvc, lvoc, rvoc;
- lvc = lelem.array_get_size(NULL, CT_RULE_DATA_VALUE_ARR);
- rvc = relem.array_get_size(NULL, CT_RULE_DATA_VALUE_ARR);
- lvoc = lelem.array_get_size(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR);
- rvoc = relem.array_get_size(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR);
+ lvc = lelem.getSize(NULL, CT_RULE_DATA_VALUE_ARR);
+ rvc = relem.getSize(NULL, CT_RULE_DATA_VALUE_ARR);
+ lvoc = lelem.getSize(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR);
+ rvoc = relem.getSize(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR);
if (!((lvc == rvc) && (lvc == lvoc) && (lvc && rvoc)))
return false;
for (int i = 0; i < lvc; i++) {
bool found = false;
std::string lv, lvo;
- lelem.get_array_elem(NULL, CT_RULE_DATA_VALUE_ARR, i, &lv);
- lelem.get_array_elem(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR, i, &lvo);
+ lelem.getAt(NULL, CT_RULE_DATA_VALUE_ARR, i, &lv);
+ lelem.getAt(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR, i, &lvo);
for (int j = 0; j < lvc; j++) {
std::string rv, rvo;
- relem.get_array_elem(NULL, CT_RULE_DATA_VALUE_ARR, j, &rv);
- relem.get_array_elem(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR, j, &rvo);
+ relem.getAt(NULL, CT_RULE_DATA_VALUE_ARR, j, &rv);
+ relem.getAt(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR, j, &rvo);
if (!lv.compare(rv) && !lvo.compare(rvo)) {
found = true;
return true;
}
-bool ctx::rule_manager::rule_item_equals(ctx::json& litem, ctx::json& ritem)
+bool ctx::rule_manager::rule_item_equals(ctx::Json& litem, ctx::Json& ritem)
{
// Compare item name
std::string lei, rei;
return false;
// Compare option
- ctx::json loption, roption;
+ ctx::Json loption, roption;
litem.get(NULL, CT_RULE_EVENT_OPTION, &loption);
ritem.get(NULL, CT_RULE_EVENT_OPTION, &roption);
if (loption != roption)
return false;
int ledac, redac;
- ledac = litem.array_get_size(NULL, CT_RULE_DATA_ARR);
- redac = ritem.array_get_size(NULL, CT_RULE_DATA_ARR);
+ ledac = litem.getSize(NULL, CT_RULE_DATA_ARR);
+ redac = ritem.getSize(NULL, CT_RULE_DATA_ARR);
if (ledac != redac)
return false;
for (int i = 0; i < ledac; i++) {
bool found = false;
- ctx::json lelem;
- litem.get_array_elem(NULL, CT_RULE_DATA_ARR, i, &lelem);
+ ctx::Json lelem;
+ litem.getAt(NULL, CT_RULE_DATA_ARR, i, &lelem);
for (int j = 0; j < ledac; j++) {
- ctx::json relem;
- ritem.get_array_elem(NULL, CT_RULE_DATA_ARR, j, &relem);
+ ctx::Json relem;
+ ritem.getAt(NULL, CT_RULE_DATA_ARR, j, &relem);
if (rule_data_arr_elem_equals(lelem, relem)) {
found = true;
return true;
}
-bool ctx::rule_manager::rule_equals(ctx::json& lrule, ctx::json& rrule)
+bool ctx::rule_manager::rule_equals(ctx::Json& lrule, ctx::Json& rrule)
{
// Compare event
- ctx::json le, re;
+ ctx::Json le, re;
lrule.get(NULL, CT_RULE_EVENT, &le);
rrule.get(NULL, CT_RULE_EVENT, &re);
if (!rule_item_equals(le, re))
// Compare conditions
int lcc, rcc;
- lcc = lrule.array_get_size(NULL, CT_RULE_CONDITION);
- rcc = rrule.array_get_size(NULL, CT_RULE_CONDITION);
+ lcc = lrule.getSize(NULL, CT_RULE_CONDITION);
+ rcc = rrule.getSize(NULL, CT_RULE_CONDITION);
if (lcc != rcc)
return false;
for (int i = 0; i < lcc; i++) {
bool found = false;
- ctx::json lc;
- lrule.get_array_elem(NULL, CT_RULE_CONDITION, i, &lc);
+ ctx::Json lc;
+ lrule.getAt(NULL, CT_RULE_CONDITION, i, &lc);
for (int j = 0; j < lcc; j++) {
- ctx::json rc;
- rrule.get_array_elem(NULL, CT_RULE_CONDITION, j, &rc);
+ ctx::Json rc;
+ rrule.getAt(NULL, CT_RULE_CONDITION, j, &rc);
if (rule_item_equals(lc, rc)) {
found = true;
}
// Compare action
- ctx::json laction, raction;
+ ctx::Json laction, raction;
lrule.get(NULL, CT_RULE_ACTION, &laction);
rrule.get(NULL, CT_RULE_ACTION, &raction);
if (laction != raction)
return true;
}
-int64_t ctx::rule_manager::get_duplicated_rule_id(std::string pkg_id, ctx::json& rule)
+int64_t ctx::rule_manager::get_duplicated_rule_id(std::string pkg_id, ctx::Json& rule)
{
std::string q = "SELECT row_id, description, details FROM context_trigger_rule WHERE package_id = '";
q += pkg_id;
q += "'";
- std::vector<json> d_record;
+ std::vector<Json> d_record;
bool ret = db_manager::execute_sync(q.c_str(), &d_record);
IF_FAIL_RETURN_TAG(ret, false, _E, "Query row_id, details by package id failed");
- ctx::json r_details;
+ ctx::Json r_details;
rule.get(NULL, CT_RULE_DETAILS, &r_details);
std::string r_desc;
rule.get(NULL, CT_RULE_DESCRIPTION, &r_desc);
- std::vector<json>::iterator vec_end = d_record.end();
+ std::vector<Json>::iterator vec_end = d_record.end();
- for (std::vector<json>::iterator vec_pos = d_record.begin(); vec_pos != vec_end; ++vec_pos) {
- ctx::json elem = *vec_pos;
+ for (std::vector<Json>::iterator vec_pos = d_record.begin(); vec_pos != vec_end; ++vec_pos) {
+ ctx::Json elem = *vec_pos;
std::string details;
- ctx::json d_details;
+ ctx::Json d_details;
elem.get(NULL, "details", &details);
d_details = details;
// Only description is changed
std::string q_update = "UPDATE context_trigger_rule SET description='" + r_desc + "' WHERE row_id = " + int_to_string(row_id);
- std::vector<json> record;
+ std::vector<Json> record;
ret = db_manager::execute_sync(q_update.c_str(), &record);
if (ret) {
_D("Rule%lld description is updated", row_id);
return -1;
}
-int ctx::rule_manager::verify_rule(ctx::json& rule, const char* creator)
+int ctx::rule_manager::verify_rule(ctx::Json& rule, const char* creator)
{
- ctx::json details;
+ ctx::Json details;
rule.get(NULL, CT_RULE_DETAILS, &details);
std::string e_name;
}
}
- ctx::json it;
- for (int i = 0; rule.get_array_elem(CT_RULE_DETAILS, CT_RULE_CONDITION, i, &it); i++){
+ ctx::Json it;
+ for (int i = 0; rule.getAt(CT_RULE_DETAILS, CT_RULE_CONDITION, i, &it); i++){
std::string c_name;
it.get(NULL, CT_RULE_CONDITION_ITEM, &c_name);
return ERR_NONE;
}
-int ctx::rule_manager::add_rule(std::string creator, const char* pkg_id, ctx::json rule, ctx::json* rule_id)
+int ctx::rule_manager::add_rule(std::string creator, const char* pkg_id, ctx::Json rule, ctx::Json* rule_id)
{
apply_templates();
bool ret;
}
// Insert rule to rule table, get rule id
- ctx::json r_record;
+ ctx::Json r_record;
std::string description;
- ctx::json details;
+ ctx::Json details;
rule.get(NULL, CT_RULE_DESCRIPTION, &description);
rule.get(NULL, CT_RULE_DETAILS, &details);
r_record.set(NULL, "creator", creator);
std::string query = "DELETE FROM 'context_trigger_rule' where row_id = ";
query += int_to_string(rule_id);
- std::vector<json> record;
+ std::vector<Json> record;
ret = db_manager::execute_sync(query.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, ERR_OPERATION_FAILED, _E, "Remove rule from db failed");
apply_templates();
int error;
std::string query;
- std::vector<json> rule_record;
- std::vector<json> record;
+ std::vector<Json> rule_record;
+ std::vector<Json> record;
std::string pkg_id;
- ctx::json jrule;
+ ctx::Json jrule;
std::string tmp;
std::string id_str = int_to_string(rule_id);
trigger_rule* rule;
- // Get rule json by rule id;
+ // Get rule Json by rule id;
query = "SELECT details, package_id FROM context_trigger_rule WHERE row_id = ";
query += id_str;
error = (db_manager::execute_sync(query.c_str(), &rule_record))? ERR_NONE : ERR_OPERATION_FAILED;
// Update db to set 'disabled' // TODO skip while clear uninstalled rule
std::string query = "UPDATE context_trigger_rule SET status = 0 WHERE row_id = ";
query += int_to_string(rule_id);
- std::vector<json> record;
+ std::vector<Json> record;
ret = db_manager::execute_sync(query.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, ERR_OPERATION_FAILED, _E, "Update db failed");
std::string query = "UPDATE context_trigger_rule SET status = 1 WHERE row_id = ";
query += int_to_string(rule_id);
- std::vector<json> record;
+ std::vector<Json> record;
ret = db_manager::execute_sync(query.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, ERR_OPERATION_FAILED, _E, "Update db failed");
std::string q = "SELECT package_id FROM context_trigger_rule WHERE row_id =";
q += int_to_string(rule_id);
- std::vector<json> record;
+ std::vector<Json> record;
bool ret = db_manager::execute_sync(q.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, false, _E, "Query package id by rule id failed");
std::string q = "SELECT status FROM context_trigger_rule WHERE row_id =";
q += int_to_string(rule_id);
- std::vector<json> record;
+ std::vector<Json> record;
bool ret = db_manager::execute_sync(q.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, false, _E, "Query enabled by rule id failed");
return (status != 0);
}
-int ctx::rule_manager::get_rule_by_id(std::string pkg_id, int rule_id, ctx::json* request_result)
+int ctx::rule_manager::get_rule_by_id(std::string pkg_id, int rule_id, ctx::Json* request_result)
{
apply_templates();
std::string q = "SELECT description FROM context_trigger_rule WHERE (package_id = '";
q += int_to_string(rule_id);
q += ")";
- std::vector<json> record;
+ std::vector<Json> record;
bool ret = db_manager::execute_sync(q.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, false, _E, "Query rule by rule id failed");
return ERR_NONE;
}
-int ctx::rule_manager::get_rule_ids(std::string pkg_id, ctx::json* request_result)
+int ctx::rule_manager::get_rule_ids(std::string pkg_id, ctx::Json* request_result)
{
(*request_result) = "{ \"" CT_RULE_ARRAY_ENABLED "\" : [ ] , \"" CT_RULE_ARRAY_DISABLED "\" : [ ] }";
q += pkg_id;
q += "')";
- std::vector<json> record;
+ std::vector<Json> record;
bool ret = db_manager::execute_sync(q.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, ERR_OPERATION_FAILED, _E, "Query rules failed");
- std::vector<json>::iterator vec_end = record.end();
- for (std::vector<json>::iterator vec_pos = record.begin(); vec_pos != vec_end; ++vec_pos) {
- ctx::json elem = *vec_pos;
+ std::vector<Json>::iterator vec_end = record.end();
+ for (std::vector<Json>::iterator vec_pos = record.begin(); vec_pos != vec_end; ++vec_pos) {
+ ctx::Json elem = *vec_pos;
std::string id;
int status;
elem.get(NULL, "status", &status);
if (status >= 1) {
- (*request_result).array_append(NULL, CT_RULE_ARRAY_ENABLED, string_to_int(id));
+ (*request_result).append(NULL, CT_RULE_ARRAY_ENABLED, string_to_int(id));
} else if (status == 0) {
- (*request_result).array_append(NULL, CT_RULE_ARRAY_DISABLED, string_to_int(id));
+ (*request_result).append(NULL, CT_RULE_ARRAY_DISABLED, string_to_int(id));
}
}
namespace ctx {
- class json;
+ class Json;
class context_trigger;
class trigger_rule;
~rule_manager();
bool init();
- int add_rule(std::string creator, const char* pkg_id, ctx::json rule, ctx::json* rule_id);
+ int add_rule(std::string creator, const char* pkg_id, ctx::Json rule, ctx::Json* rule_id);
int remove_rule(int rule_id);
int enable_rule(int rule_id);
int disable_rule(int rule_id);
- int get_rule_by_id(std::string pkg_id, int rule_id, ctx::json* request_result);
- int get_rule_ids(std::string pkg_id, ctx::json* request_result);
+ int get_rule_by_id(std::string pkg_id, int rule_id, ctx::Json* request_result);
+ int get_rule_ids(std::string pkg_id, ctx::Json* request_result);
int check_rule(std::string pkg_id, int rule_id);
bool is_rule_enabled(int rule_id);
int pause_rule_with_item(std::string& subject);
private:
bool reenable_rule(void);
- int verify_rule(ctx::json& rule, const char* creator);
- int64_t get_duplicated_rule_id(std::string pkg_id, ctx::json& rule);
- bool rule_data_arr_elem_equals(ctx::json& lelem, ctx::json& relem);
- bool rule_item_equals(ctx::json& litem, ctx::json& ritem);
- bool rule_equals(ctx::json& lrule, ctx::json& rrule);
+ int verify_rule(ctx::Json& rule, const char* creator);
+ int64_t get_duplicated_rule_id(std::string pkg_id, ctx::Json& rule);
+ bool rule_data_arr_elem_equals(ctx::Json& lelem, ctx::Json& relem);
+ bool rule_item_equals(ctx::Json& litem, ctx::Json& ritem);
+ bool rule_equals(ctx::Json& lrule, ctx::Json& rrule);
int get_uninstalled_app(void);
int clear_rule_of_uninstalled_package(bool is_init = false);
void apply_templates(void);
+ "(name TEXT DEFAULT '' NOT NULL PRIMARY KEY, operation INTEGER DEFAULT 3 NOT NULL, "
+ "attributes TEXT DEFAULT '' NOT NULL, options TEXT DEFAULT '' NOT NULL, owner TEXT DEFAULT '' NOT NULL)";
- std::vector<json> record;
+ std::vector<Json> record;
bool ret = db_manager::execute_sync(q.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, false, _E, "Create template table failed");
{
std::string subject;
int operation;
- ctx::json attributes;
- ctx::json options;
+ ctx::Json attributes;
+ ctx::Json options;
std::string owner;
bool unregister;
std::string query;
}
IF_FAIL_VOID(!query.empty());
- std::vector<json> record;
+ std::vector<Json> record;
bool ret = db_manager::execute_sync(query.c_str(), &record);
IF_FAIL_VOID_TAG(ret, _E, "Update template db failed");
}
-std::string ctx::template_manager::add_template(std::string &subject, int &operation, ctx::json &attributes, ctx::json &options, std::string &owner)
+std::string ctx::template_manager::add_template(std::string &subject, int &operation, ctx::Json &attributes, ctx::Json &options, std::string &owner)
{
_D("[Add template] Subject: %s, Ops: %d, Owner: %s", subject.c_str(), operation, owner.c_str());
_J("Attr", attributes);
return query;
}
-int ctx::template_manager::get_template(std::string &subject, ctx::json* tmpl)
+int ctx::template_manager::get_template(std::string &subject, ctx::Json* tmpl)
{
// Update latest template information
apply_templates();
std::string q = "SELECT * FROM context_trigger_template WHERE name = '" + subject + "'";
- std::vector<json> record;
+ std::vector<Json> record;
bool ret = db_manager::execute_sync(q.c_str(), &record);
IF_FAIL_RETURN_TAG(ret, ERR_OPERATION_FAILED, _E, "Query template failed");
IF_FAIL_RETURN_TAG(record.size() > 0, ERR_NOT_SUPPORTED, _E, "Template(%s) not found", subject.c_str());
tmpl->get(NULL, TYPE_OPTION_STR, &opt_str);
tmpl->get(NULL, TYPE_ATTR_STR, &attr_str);
- ctx::json opt = opt_str;
- ctx::json attr = attr_str;
+ ctx::Json opt = opt_str;
+ ctx::Json attr = attr_str;
tmpl->set(NULL, TYPE_OPTION_STR, opt);
tmpl->set(NULL, TYPE_ATTR_STR, attr);
#ifndef __TEMPLATE_MANAGER_H__
#define __TEMPLATE_MANAGER_H__
-#include <json.h>
+#include <Json.h>
namespace ctx {
bool init();
void apply_templates();
- int get_template(std::string &subject, ctx::json* tmpl);
+ int get_template(std::string &subject, ctx::Json* tmpl);
private:
template_manager();
static context_manager_impl *_context_mgr;
static rule_manager *_rule_mgr;
- std::string add_template(std::string &subject, int &operation, ctx::json &attributes, ctx::json &options, std::string &owner);
+ std::string add_template(std::string &subject, int &operation, ctx::Json &attributes, ctx::Json &options, std::string &owner);
std::string remove_template(std::string &subject);
}; /* class template_manager */
#define TIMER_DAY_OF_WEEK "DayOfWeek"
#define TIMER_TIME_OF_DAY "TimeOfDay"
-static int arrange_day_of_week(ctx::json day_info)
+static int arrange_day_of_week(ctx::Json day_info)
{
int result = 0;
}
std::string tmp_d;
- for (int i = 0; day_info.get_array_elem(NULL, CT_RULE_DATA_VALUE_ARR, i, &tmp_d); i++) {
+ for (int i = 0; day_info.getAt(NULL, CT_RULE_DATA_VALUE_ARR, i, &tmp_d); i++) {
int dow = ctx::timer_util::convert_day_of_week_string_to_int(tmp_d);
std::string op;
- day_info.get_array_elem(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR, i, &op);
+ day_info.getAt(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR, i, &op);
if (op.compare(CONTEXT_TRIGGER_NOT_EQUAL_TO) == 0) {
dow = ctx::timer_util::convert_day_of_week_string_to_int(TIMER_TYPES_EVERYDAY) & ~dow;
return result;
}
-void ctx::trigger_timer::handle_timer_event(ctx::json& rule)
+void ctx::trigger_timer::handle_timer_event(ctx::Json& rule)
{
- ctx::json event;
+ ctx::Json event;
rule.get(NULL, CT_RULE_EVENT, &event);
std::string e_name;
return;
}
- ctx::json day_info;
- ctx::json it;
+ ctx::Json day_info;
+ ctx::Json it;
int dow;
- for (int i = 0; event.get_array_elem(NULL, CT_RULE_DATA_ARR, i, &it); i++) {
+ for (int i = 0; event.getAt(NULL, CT_RULE_DATA_ARR, i, &it); i++) {
std::string key;
it.get(NULL, CT_RULE_DATA_KEY, &key);
int d = 0x01 << j;
if (dow & d) {
std::string day = ctx::timer_util::convert_day_of_week_int_to_string(d);
- day_info.array_append(NULL, CT_RULE_DATA_VALUE_ARR, day);
- day_info.array_append(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR, CONTEXT_TRIGGER_EQUAL_TO);
+ day_info.append(NULL, CT_RULE_DATA_VALUE_ARR, day);
+ day_info.append(NULL, CT_RULE_DATA_VALUE_OPERATOR_ARR, CONTEXT_TRIGGER_EQUAL_TO);
// Set option
- event.array_append(CT_RULE_EVENT_OPTION, TIMER_DAY_OF_WEEK, day);
+ event.append(CT_RULE_EVENT_OPTION, TIMER_DAY_OF_WEEK, day);
}
}
- event.array_set_at(NULL, CT_RULE_DATA_ARR, i, day_info);
+ event.setAt(NULL, CT_RULE_DATA_ARR, i, day_info);
} else if (key.compare(TIMER_TIME_OF_DAY) == 0) {
int time;
- for (int j = 0; it.get_array_elem(NULL, CT_RULE_DATA_VALUE_ARR, j, &time); j++) {
- event.array_append(CT_RULE_EVENT_OPTION, TIMER_TIME_OF_DAY, time);
+ for (int j = 0; it.getAt(NULL, CT_RULE_DATA_VALUE_ARR, j, &time); j++) {
+ event.append(CT_RULE_EVENT_OPTION, TIMER_TIME_OF_DAY, time);
}
}
}
#ifndef __CONTEXT_CONTEXT_TRIGGER_TIMER_H__
#define __CONTEXT_CONTEXT_TRIGGER_TIMER_H__
-#include <json.h>
+#include <Json.h>
namespace ctx {
namespace trigger_timer {
- void handle_timer_event(ctx::json& rule);
+ void handle_timer_event(ctx::Json& rule);
};
void ctx::context_trigger::add_rule(ctx::request_info* request)
{
- ctx::json rule_id;
+ ctx::Json rule_id;
const char* client = request->get_client();
if (client == NULL) {
const char* pkg_id = request->get_package_id();
- ctx::json rule_id = request->get_description();
+ ctx::Json rule_id = request->get_description();
rule_id.get(NULL, CT_RULE_ID, &id);
error = rule_mgr->check_rule((pkg_id)? pkg_id : "", id);
const char* pkg_id = request->get_package_id();
- ctx::json rule_id = request->get_description();
+ ctx::Json rule_id = request->get_description();
rule_id.get(NULL, CT_RULE_ID, &id);
error = rule_mgr->check_rule((pkg_id)? pkg_id : "", id);
const char* pkg_id = request->get_package_id();
- ctx::json rule_id = request->get_description();
+ ctx::Json rule_id = request->get_description();
rule_id.get(NULL, CT_RULE_ID, &id);
error = rule_mgr->check_rule((pkg_id)? pkg_id : "", id);
{
int error;
- ctx::json option = request->get_description();
+ ctx::Json option = request->get_description();
int id;
option.get(NULL, CT_RULE_ID, &id);
const char* pkg_id = request->get_package_id();
- ctx::json read_data;
+ ctx::Json read_data;
error = rule_mgr->get_rule_by_id((pkg_id)? pkg_id : "", id, &read_data);
- ctx::json dummy;
+ ctx::Json dummy;
request->reply(error, dummy, read_data);
}
const char* pkg_id = request->get_package_id();
- ctx::json read_data;
+ ctx::Json read_data;
error = rule_mgr->get_rule_ids((pkg_id)? pkg_id : "", &read_data);
- ctx::json dummy;
+ ctx::Json dummy;
request->reply(error, dummy, read_data);
}
{
int error;
- ctx::json option = request->get_description();
+ ctx::Json option = request->get_description();
std::string name;
option.get(NULL, SUBJECT_STR, &name);
return;
}
- ctx::json tmpl;
+ ctx::Json tmpl;
error = tmpl_mgr->get_template(name, &tmpl);
- ctx::json dummy;
+ ctx::Json dummy;
request->reply(error, dummy, tmpl);
}
return true;
}
-std::string ctx::db_manager_impl::compose_insert_query(const char* table_name, json& record)
+std::string ctx::db_manager_impl::compose_insert_query(const char* table_name, Json& record)
{
std::list<std::string> keys;
- IF_FAIL_RETURN_TAG(record.get_keys(&keys), "", _E, "Invalid record");
+ IF_FAIL_RETURN_TAG(record.getKeys(&keys), "", _E, "Invalid record");
std::ostringstream colstream;
std::ostringstream valstream;
return query;
}
-bool ctx::db_manager_impl::insert(unsigned int query_id, const char* table_name, json& record, db_listener_iface* listener)
+bool ctx::db_manager_impl::insert(unsigned int query_id, const char* table_name, Json& record, db_listener_iface* listener)
{
IF_FAIL_RETURN_TAG(initialized, false, _E, "Not initialized");
IF_FAIL_VOID_TAG(db_handle, _E, "DB not opened");
_SD("SQL(%d): %s", query_id, query);
- std::vector<json> *query_result = new(std::nothrow) std::vector<json>;
+ std::vector<Json> *query_result = new(std::nothrow) std::vector<Json>;
IF_FAIL_VOID_TAG(query_result, _E, "Memory allocation failed");
char *err = NULL;
int ctx::db_manager_impl::execution_result_cb(void *user_data, int dim, char **value, char **column)
{
- std::vector<json> *records = static_cast<std::vector<json>*>(user_data);
- json row;
+ std::vector<Json> *records = static_cast<std::vector<Json>*>(user_data);
+ Json row;
bool column_null = false;
for (int i=0; i<dim; ++i) {
return 0;
}
-void ctx::db_manager_impl::send_result(int query_type, unsigned int query_id, db_listener_iface* listener, int error, std::vector<json>* result)
+void ctx::db_manager_impl::send_result(int query_type, unsigned int query_id, db_listener_iface* listener, int error, std::vector<Json>* result)
{
query_result_s *qr = new(std::nothrow) query_result_s();
IF_FAIL_VOID_TAG(qr, _E, "Memory allocation failed");
return true;
}
-bool ctx::db_manager_impl::insert_sync(const char* table_name, json& record, int64_t* row_id)
+bool ctx::db_manager_impl::insert_sync(const char* table_name, Json& record, int64_t* row_id)
{
IF_FAIL_RETURN_TAG(db_handle, false, _E, "DB not opened");
IF_FAIL_RETURN_TAG(table_name && row_id, false, _E, "Invalid parameter");
IF_FAIL_RETURN(!query.empty(), false);
_SD("SQL: %s", query.c_str());
- std::vector<json> query_result;
+ std::vector<Json> query_result;
char *err = NULL;
int ret;
{
return true;
}
-bool ctx::db_manager_impl::execute_sync(const char* query, std::vector<json>* records)
+bool ctx::db_manager_impl::execute_sync(const char* query, std::vector<Json>* records)
{
IF_FAIL_RETURN_TAG(db_handle, false, _E, "DB not opened");
IF_FAIL_RETURN_TAG(query && records, false, _E, "Invalid parameter");
#define __CONTEXT_DB_MANAGER_IMPL_H__
#include <vector>
-#include <json.h>
+#include <Json.h>
#include <sqlite3.h>
#include <EventDrivenThread.h>
unsigned int id;
int error;
db_listener_iface* listener;
- std::vector<json>* result;
+ std::vector<Json>* result;
};
sqlite3 *db_handle;
void close();
std::string compose_create_query(const char* table_name, const char* columns, const char* option);
- std::string compose_insert_query(const char* table_name, json& record);
+ std::string compose_insert_query(const char* table_name, Json& record);
void _execute(int query_type, unsigned int query_id, const char* query, db_listener_iface* listener);
- void send_result(int query_type, unsigned int query_id, db_listener_iface* listener, int error, std::vector<json>* result);
+ void send_result(int query_type, unsigned int query_id, db_listener_iface* listener, int error, std::vector<Json>* result);
static int execution_result_cb(void *user_data, int dim, char **value, char **column);
static gboolean _send_result(gpointer data);
void release();
bool create_table(unsigned int query_id, const char* table_name, const char* columns, const char* option = NULL, db_listener_iface* listener = NULL);
- bool insert(unsigned int query_id, const char* table_name, json& record, db_listener_iface* listener = NULL);
+ bool insert(unsigned int query_id, const char* table_name, Json& record, db_listener_iface* listener = NULL);
bool execute(unsigned int query_id, const char* query, db_listener_iface* listener);
bool create_table_sync(const char* table_name, const char* columns, const char* option = NULL);
- bool insert_sync(const char* table_name, json& record, int64_t* row_id);
- bool execute_sync(const char* query, std::vector<json>* records);
+ bool insert_sync(const char* table_name, Json& record, int64_t* row_id);
+ bool execute_sync(const char* query, std::vector<Json>* records);
}; /* class db_manager */
}
#include <glib.h>
#include <types_internal.h>
-#include <json.h>
+#include <Json.h>
#include "access_control/privilege.h"
#include "server.h"
#include "request.h"
context_provider_iface *provider = get_provider(request);
IF_FAIL_VOID(provider);
- ctx::json request_result;
+ ctx::Json request_result;
int error = provider->subscribe(subject, request->get_description().str(), &request_result);
if (!request->reply(error, request_result) || error != ERR_NONE) {
context_provider_iface *provider = get_provider(request);
IF_FAIL_VOID(provider);
- ctx::json request_result;
+ ctx::Json request_result;
int error = provider->read(subject, request->get_description().str(), &request_result);
if (!request->reply(error, request_result) || error != ERR_NONE) {
context_provider_iface *provider = get_provider(request);
IF_FAIL_VOID(provider);
- ctx::json request_result;
+ ctx::Json request_result;
int error = provider->write(subject, request->get_description(), &request_result);
request->reply(error, request_result);
delete request;
}
-bool ctx::context_provider_handler::publish(ctx::json &option, int error, ctx::json &data_updated)
+bool ctx::context_provider_handler::publish(ctx::Json &option, int error, ctx::Json &data_updated)
{
auto end = subscribe_requests.end();
auto target = find_request(subscribe_requests.begin(), end, option);
return true;
}
-bool ctx::context_provider_handler::reply_to_read(ctx::json &option, int error, ctx::json &data_read)
+bool ctx::context_provider_handler::reply_to_read(ctx::Json &option, int error, ctx::Json &data_read)
{
auto end = read_requests.end();
auto target = find_request(read_requests.begin(), end, option);
auto prev = target;
- ctx::json dummy;
+ ctx::Json dummy;
while (target != end) {
(*target)->reply(error, dummy, data_read);
}
ctx::context_provider_handler::request_list_t::iterator
-ctx::context_provider_handler::find_request(request_list_t &r_list, json &option)
+ctx::context_provider_handler::find_request(request_list_t &r_list, Json &option)
{
return find_request(r_list.begin(), r_list.end(), option);
}
}
ctx::context_provider_handler::request_list_t::iterator
-ctx::context_provider_handler::find_request(request_list_t::iterator begin, request_list_t::iterator end, json &option)
+ctx::context_provider_handler::find_request(request_list_t::iterator begin, request_list_t::iterator end, Json &option)
{
for (auto it = begin; it != end; ++it) {
if (option == (*it)->get_description()) {
namespace ctx {
- class json;
+ class Json;
class credentials;
class request_info;
void read(request_info *request);
void write(request_info *request);
- bool publish(ctx::json &option, int error, ctx::json &data_updated);
- bool reply_to_read(ctx::json &option, int error, ctx::json &data_read);
+ bool publish(ctx::Json &option, int error, ctx::Json &data_updated);
+ bool reply_to_read(ctx::Json &option, int error, ctx::Json &data_read);
private:
const char *subject;
request_list_t read_requests;
context_provider_iface* get_provider(request_info *request);
- request_list_t::iterator find_request(request_list_t &r_list, json &option);
+ request_list_t::iterator find_request(request_list_t &r_list, Json &option);
request_list_t::iterator find_request(request_list_t &r_list, std::string client, int req_id);
- request_list_t::iterator find_request(request_list_t::iterator begin, request_list_t::iterator end, json &option);
+ request_list_t::iterator find_request(request_list_t::iterator begin, request_list_t::iterator end, Json &option);
}; /* class context_provider_handler */
return _subject.c_str();
}
-ctx::json& ctx::request_info::get_description()
+ctx::Json& ctx::request_info::get_description()
{
return _description;
}
#define __CONTEXT_REQUEST_INFO_H__
#include <string>
-#include <json.h>
+#include <Json.h>
namespace ctx {
int get_type();
int get_id();
const char* get_subject();
- ctx::json& get_description();
+ ctx::Json& get_description();
virtual const credentials* get_credentials();
virtual const char* get_package_id();
/* TODO: remove this get_client() */
virtual const char* get_client();
virtual bool reply(int error) = 0;
- virtual bool reply(int error, ctx::json &request_result) = 0;
- virtual bool reply(int error, ctx::json &request_result, ctx::json &data_read) = 0;
- virtual bool publish(int error, ctx::json &data) = 0;
+ virtual bool reply(int error, ctx::Json &request_result) = 0;
+ virtual bool reply(int error, ctx::Json &request_result, ctx::Json &data_read) = 0;
+ virtual bool publish(int error, ctx::Json &data) = 0;
protected:
int _type;
int _req_id;
std::string _subject;
- ctx::json _description;
+ ctx::Json _description;
};
} /* namespace ctx */