Modified trigger to use package id for rule management 33/59433/1
authorSomin Kim <somin926.kim@samsung.com>
Mon, 15 Feb 2016 11:13:21 +0000 (20:13 +0900)
committerSomin Kim <somin926.kim@samsung.com>
Mon, 15 Feb 2016 11:13:21 +0000 (20:13 +0900)
- request get_app_id() removed

Change-Id: Iaef20e72b9a13974bc5ec246e461a9db99589e2b
Signed-off-by: Somin Kim <somin926.kim@samsung.com>
13 files changed:
src/access_control/peer_creds.cpp
src/access_control/peer_creds.h
src/client_request.cpp
src/client_request.h
src/context_trigger/action_manager.cpp
src/context_trigger/action_manager.h
src/context_trigger/rule.cpp
src/context_trigger/rule.h
src/context_trigger/rule_manager.cpp
src/context_trigger/rule_manager.h
src/context_trigger/trigger.cpp
src/request.cpp
src/request.h

index c8641bc554c0121a6ed8df0ae511770b1c42a6ea..5d42a81bc67a85a1c14dd9cc35610551d1d24e8a 100644 (file)
@@ -21,8 +21,7 @@
 #include <types_internal.h>
 #include "peer_creds.h"
 
-ctx::credentials::credentials(char *_app_id, char *_package_id, char *_client, char *_session, char *_user) :
-       app_id(_app_id),
+ctx::credentials::credentials(char *_package_id, char *_client, char *_session, char *_user) :
        package_id(_package_id),
        client(_client),
        session(_session),
@@ -32,7 +31,6 @@ ctx::credentials::credentials(char *_app_id, char *_package_id, char *_client, c
 
 ctx::credentials::~credentials()
 {
-       g_free(app_id);
        g_free(package_id);
        g_free(client);
        g_free(session);
@@ -65,7 +63,7 @@ bool ctx::peer_creds::get(GDBusConnection *connection, const char *unique_name,
        err = cynara_creds_gdbus_get_user(connection, unique_name, USER_METHOD_DEFAULT, &user);
        IF_FAIL_CATCH_TAG(err == CYNARA_API_SUCCESS, _E, "Peer credentialing failed");
 
-       *creds = new(std::nothrow) credentials(app_id, package_id, client, session, user);
+       *creds = new(std::nothrow) credentials(package_id, client, session, user);
        IF_FAIL_CATCH_TAG(*creds, _E, "Memory allocation failed");
 
        return true;
index 7889987ce87d57d714450f2588ef6b0f64e7e80e..4be816772bb68d68ed5e2ea741a902976f7480fa 100644 (file)
@@ -25,12 +25,11 @@ namespace ctx {
 
        class credentials {
        public:
-               char *app_id;
                char *package_id;
                char *client;   /* default: smack label */
                char *session;
                char *user;             /* default: UID */
-               credentials(char *_app_id, char *_package_id, char *_client, char *_session, char *_user);
+               credentials(char *_package_id, char *_client, char *_session, char *_user);
                ~credentials();
        };
 
index e164d6d15e56fe950bfeb9d85a30b65f91a8ecf2..4b218be6d24c49011ed95639cf09d6608f2bfe07 100644 (file)
@@ -44,14 +44,6 @@ const ctx::credentials* ctx::client_request::get_credentials()
        return __credentials;
 }
 
-const char* ctx::client_request::get_app_id()
-{
-       if (__credentials)
-               return __credentials->app_id;
-
-       return NULL;
-}
-
 const char* ctx::client_request::get_package_id()
 {
        if (__credentials)
index 6df5da7074eccc5cf26282d42853e0a5e4f9b0b1..9c137832dcaca6f5612ff2e41b5ebb65a219b5ee 100644 (file)
@@ -29,7 +29,6 @@ namespace ctx {
                ~client_request();
 
                const credentials* get_credentials();
-               const char* get_app_id();
                const char* get_package_id();
                const char* get_client();
                bool reply(int error);
index d035c5a1e24f81cd50d1fe833b89295446835126..b83971153f612cd231fc2137318353ed366064a0 100644 (file)
 #include "action_manager.h"
 
 static void trigger_action_app_control(ctx::json& action);
-static void trigger_action_notification(ctx::json& action, std::string app_id);        // TODO appid? creator?
+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 creator)
+void ctx::action_manager::trigger_action(ctx::json& action, std::string pkg_id)
 {
        std::string type;
        action.get(NULL, CT_RULE_ACTION_TYPE, &type);
@@ -39,7 +39,7 @@ void ctx::action_manager::trigger_action(ctx::json& action, std::string creator)
        if (type.compare(CT_RULE_ACTION_TYPE_APP_CONTROL) == 0) {
                trigger_action_app_control(action);
        } else if (type.compare(CT_RULE_ACTION_TYPE_NOTIFICATION) == 0) {
-               trigger_action_notification(action, creator);
+               trigger_action_notification(action, pkg_id);
        } else if (type.compare(CT_RULE_ACTION_TYPE_DBUS_CALL) == 0) {
                trigger_action_dbus_call(action);
        }
@@ -80,7 +80,7 @@ void trigger_action_app_control(ctx::json& action)
        }
 }
 
-void trigger_action_notification(ctx::json& action, std::string app_id)        // TODO appid? creator?
+void trigger_action_notification(ctx::json& action, std::string pkg_id)
 {
        int error;
        notification_h notification = notification_create(NOTIFICATION_TYPE_NOTI);
@@ -133,10 +133,10 @@ void trigger_action_notification(ctx::json& action, std::string app_id)   // TODO
                }
        }
 
-       if (!app_id.empty()) {
-               error = notification_set_pkgname(notification, app_id.c_str());
+       if (!pkg_id.empty()) {
+               error = notification_set_pkgname(notification, pkg_id.c_str());
                if (error != NOTIFICATION_ERROR_NONE) {
-                       _E("Set pkgname(%s) failed(%d)", app_id.c_str(), error);
+                       _E("Set package id(%s) failed(%#x)", pkg_id.c_str(), error);
                }
        }
 
index cc39c9b97051890fab55e213ca26826eb114d6e4..e8bf6dfbde808e7a07fa5bad9054e56c5bcfb11f 100644 (file)
@@ -23,7 +23,7 @@ namespace ctx {
 
        namespace action_manager {
 
-               void trigger_action(ctx::json& action, std::string creator);
+               void trigger_action(ctx::json& action, std::string pkg_id);
 
        }
 
index 5328f42c7958dcd473f200b0268ba54c93811b8e..34270ab238a4c391e8928da7fd144e2f5df4b49a 100644 (file)
 
 ctx::rule_manager *ctx::trigger_rule::rule_mgr = NULL;
 
-ctx::trigger_rule::trigger_rule(int i, ctx::json& d, const char* cr, 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)
-       , creator(cr)
+       , pkg_id(p)
 {
        // Rule manager
        if (!rule_mgr) {
@@ -126,10 +126,10 @@ void ctx::trigger_rule::on_event_received(std::string name, ctx::json option, ct
                clear_result();
        }
 
-       // Check if creator is uninstalled
-       if (ctx::rule_manager::is_uninstalled_package(creator)) {
-               _D("Creator(%s) of rule%d is uninstalled.", creator.c_str(), id);
-               g_idle_add(handle_uninstalled_rule, &creator);
+       // Check if creator package is uninstalled
+       if (ctx::rule_manager::is_uninstalled_package(pkg_id)) {
+               _D("Creator(%s) of rule%d is uninstalled.", pkg_id.c_str(), id);
+               g_idle_add(handle_uninstalled_rule, &pkg_id);
                return;
        }
 
@@ -187,15 +187,15 @@ void ctx::trigger_rule::clear_result()
 void ctx::trigger_rule::on_context_data_prepared(void)
 {
        if (ctx::rule_evaluator::evaluate_rule(statement, result)) {
-               ctx::action_manager::trigger_action(action, creator);
+               ctx::action_manager::trigger_action(action, pkg_id);
        }
        clear_result();
 }
 
 gboolean ctx::trigger_rule::handle_uninstalled_rule(gpointer data)
 {
-       std::string* app_id = static_cast<std::string*>(data);
-       rule_mgr->handle_rule_of_uninstalled_app(*app_id);
+       std::string* pkg_id = static_cast<std::string*>(data);
+       rule_mgr->handle_rule_of_uninstalled_package(*pkg_id);
 
        return FALSE;
 }
index 3fc3688f541f5908dfc957d465dc58797f7d9c62..b5829e009fb5ad817d958fe6f1bbe449ec48c4ce 100644 (file)
@@ -58,9 +58,9 @@ namespace ctx {
 
                public:
                        int id;
-                       std::string creator;
+                       std::string pkg_id;
 
-                       trigger_rule(int i, ctx::json& d, const char* c, rule_manager* rm);
+                       trigger_rule(int i, ctx::json& d, const char* p, rule_manager* rm);
                        ~trigger_rule();
 
                        int start(void);
index 61b745ec5b0af836e3c0b771d989f9f071e29453..815ed2e10ac1304bf94487301146d576d2539d67 100644 (file)
@@ -18,7 +18,7 @@
 #include <json.h>
 #include <context_trigger_types_internal.h>
 #include <db_mgr.h>
-#include <app_manager.h>
+#include <package_manager.h>
 #include "rule_manager.h"
 #include "template_manager.h"
 #include "context_monitor.h"
@@ -61,14 +61,14 @@ bool ctx::rule_manager::init()
 
        // Create tables into db (rule, template)
        std::string q1 = std::string("status INTEGER DEFAULT 0 NOT NULL, creator TEXT DEFAULT '' NOT NULL,")
-                       + "creator_app_id TEXT DEFAULT '' NOT NULL, description TEXT DEFAULT '',"
+                       + "package_id TEXT DEFAULT '' NOT NULL, description TEXT DEFAULT '',"
                        + "details TEXT DEFAULT '' NOT NULL";
        ret = db_manager::create_table(1, RULE_TABLE, q1.c_str(), NULL, NULL);
        IF_FAIL_RETURN_TAG(ret, false, _E, "Create rule table failed");
 
        // Before re-enable rules, handle uninstalled app's rules
        if (get_uninstalled_app() > 0) {
-               error = clear_rule_of_uninstalled_app(true);
+               error = clear_rule_of_uninstalled_package(true);
                IF_FAIL_RETURN_TAG(error == ERR_NONE, false, _E, "Failed to remove uninstalled apps' rules while initialization");
        }
        ret = reenable_rule();
@@ -76,84 +76,84 @@ bool ctx::rule_manager::init()
        return ret;
 }
 
-void ctx::rule_manager::handle_rule_of_uninstalled_app(std::string app_id)
+void ctx::rule_manager::handle_rule_of_uninstalled_package(std::string pkg_id)
 {
-       uninstalled_apps.insert(app_id);
-       clear_rule_of_uninstalled_app();
+       uninstalled_packages.insert(pkg_id);
+       clear_rule_of_uninstalled_package();
 }
 
 int ctx::rule_manager::get_uninstalled_app(void)
 {
        // Return number of uninstalled apps
-       std::string q1 = "SELECT DISTINCT creator_app_id FROM context_trigger_rule";
+       std::string q1 = "SELECT DISTINCT package_id FROM context_trigger_rule";
 
        std::vector<json> record;
        bool ret = db_manager::execute_sync(q1.c_str(), &record);
-       IF_FAIL_RETURN_TAG(ret, -1, _E, "Query creators of registered rules failed");
+       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::string app_id;
-               elem.get(NULL, "creator_app_id", &app_id);
+               std::string pkg_id;
+               elem.get(NULL, "package_id", &pkg_id);
 
-               if (is_uninstalled_package(app_id)) {
-                       uninstalled_apps.insert(app_id);
+               if (is_uninstalled_package(pkg_id)) {
+                       uninstalled_packages.insert(pkg_id);
                }
        }
 
-       return uninstalled_apps.size();
+       return uninstalled_packages.size();
 }
 
-bool ctx::rule_manager::is_uninstalled_package(std::string app_id)
+bool ctx::rule_manager::is_uninstalled_package(std::string pkg_id)
 {
-       IF_FAIL_RETURN_TAG(!app_id.empty(), false, _D, "Empty app id");
+       IF_FAIL_RETURN_TAG(!pkg_id.empty(), false, _D, "Empty package id");
 
-       app_info_h app_info;
-       int     error = app_manager_get_app_info(app_id.c_str(), &app_info);
+       package_info_h pkg_info;
+       int error = package_manager_get_package_info(pkg_id.c_str(), &pkg_info);
 
-       if (error == APP_MANAGER_ERROR_NONE) {
-               app_info_destroy(app_info);
-       } else if (error == APP_MANAGER_ERROR_NO_SUCH_APP) {
-               // Uninstalled app found
-               _D("Uninstalled app found: %s", app_id.c_str());
+       if (error == PACKAGE_MANAGER_ERROR_NONE) {
+               package_info_destroy(pkg_info);
+       } else if (error == PACKAGE_MANAGER_ERROR_NO_SUCH_PACKAGE) {
+               // Uninstalled package found
+               _D("Uninstalled package found: %s", pkg_id.c_str());
                return true;
        } else {
-               _E("Get app info(%s) failed: %d", app_id.c_str(), error);
+               _E("Failed to get package info(%s): %d", pkg_id.c_str(), error);
        }
 
        return false;
 }
 
-int ctx::rule_manager::clear_rule_of_uninstalled_app(bool is_init)
+int ctx::rule_manager::clear_rule_of_uninstalled_package(bool is_init)
 {
-       if (uninstalled_apps.size() <= 0) {
+       if (uninstalled_packages.size() <= 0) {
                return ERR_NONE;
        }
 
        int error;
        bool ret;
 
-       _D("Clear uninstalled apps' rule started");
-       // creator list
-       std::string creator_list = "(";
-       std::set<std::string>::iterator it = uninstalled_apps.begin();
-       creator_list += "creator_app_id = '" + *it + "'";
+       _D("Clear uninstalled packages' rule started");
+       // Package list
+       std::string pkg_list = "(";
+       std::set<std::string>::iterator it = uninstalled_packages.begin();
+       pkg_list += "package_id = '" + *it + "'";
        it++;
-       for (; it != uninstalled_apps.end(); ++it) {
-               creator_list += " OR creator_app_id = '" + *it + "'";
+       for (; it != uninstalled_packages.end(); ++it) {
+               pkg_list += " OR package_id = '" + *it + "'";
        }
-       creator_list += ")";
+       pkg_list += ")";
 
-       // After event received, disable all the enabled rules of uninstalled apps      // TODO register uninstalled apps app_id when before trigger
+       // After event received, disable all the enabled rules of uninstalled apps
        if (!is_init) {
                std::string q1 = "SELECT row_id FROM context_trigger_rule WHERE status = 2 and (";
-               q1 += creator_list;
+               q1 += pkg_list;
                q1 += ")";
 
                std::vector<json> record;
                ret = db_manager::execute_sync(q1.c_str(), &record);
-               IF_FAIL_RETURN_TAG(ret, ERR_OPERATION_FAILED, _E, "Query enabled rules of uninstalled apps failed");
+               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) {
@@ -163,17 +163,17 @@ int ctx::rule_manager::clear_rule_of_uninstalled_app(bool is_init)
                        error = disable_rule(rule_id);
                        IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "Failed to disable rule" );
                }
-               _D("Uninstalled apps' rules are disabled");
+               _D("Uninstalled packages' rules are disabled");
        }
 
-       // Delete rules of uninstalled apps from DB
-       std::string q2 = "DELETE FROM context_trigger_rule WHERE " + creator_list;
+       // Delete rules of uninstalled packages from DB
+       std::string q2 = "DELETE FROM context_trigger_rule WHERE " + pkg_list;
        std::vector<json> dummy;
        ret = db_manager::execute_sync(q2.c_str(), &dummy);
-       IF_FAIL_RETURN_TAG(ret, ERR_OPERATION_FAILED, _E, "Remove rule from db failed");
-       _D("Uninstalled apps's rule are deleted from db");
+       IF_FAIL_RETURN_TAG(ret, ERR_OPERATION_FAILED, _E, "Failed to remove rules from db");
+       _D("Uninstalled packages' rules are deleted from db");
 
-       uninstalled_apps.clear();
+       uninstalled_packages.clear();
 
        return ERR_NONE;
 }
@@ -413,15 +413,15 @@ bool ctx::rule_manager::rule_equals(ctx::json& lrule, ctx::json& rrule)
        return true;
 }
 
-int64_t ctx::rule_manager::get_duplicated_rule_id(std::string creator, 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 creator = '";
-       q += creator;
+       std::string q = "SELECT row_id, description, details FROM context_trigger_rule WHERE package_id = '";
+       q += pkg_id;
        q += "'";
 
        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 creator failed");
+       IF_FAIL_RETURN_TAG(ret, false, _E, "Query row_id, details by package id failed");
 
        ctx::json r_details;
        rule.get(NULL, CT_RULE_DETAILS, &r_details);
@@ -500,7 +500,7 @@ int ctx::rule_manager::verify_rule(ctx::json& rule, const char* creator)
        return ERR_NONE;
 }
 
-int ctx::rule_manager::add_rule(std::string creator, const char* app_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;
@@ -508,10 +508,10 @@ int ctx::rule_manager::add_rule(std::string creator, const char* app_id, ctx::js
 
        // Check if all items are supported && allowed to access
        int err = verify_rule(rule, creator.c_str());
-       IF_FAIL_RETURN(err==ERR_NONE, err);
+       IF_FAIL_RETURN(err == ERR_NONE, err);
 
        // Check if duplicated rule exits
-       if ((rid = get_duplicated_rule_id(creator, rule)) > 0) {
+       if ((rid = get_duplicated_rule_id(pkg_id, rule)) > 0) {
                // Save rule id
                rule_id->set(NULL, CT_RULE_ID, rid);
                _D("Duplicated rule found");
@@ -525,8 +525,8 @@ int ctx::rule_manager::add_rule(std::string creator, const char* app_id, ctx::js
        rule.get(NULL, CT_RULE_DESCRIPTION, &description);
        rule.get(NULL, CT_RULE_DETAILS, &details);
        r_record.set(NULL, "creator", creator);
-       if (app_id) {
-               r_record.set(NULL, "creator_app_id", app_id);
+       if (pkg_id) {
+               r_record.set(NULL, "package_id", pkg_id);
        }
        r_record.set(NULL, "description", description);
 
@@ -570,7 +570,7 @@ int ctx::rule_manager::enable_rule(int rule_id)
        std::string query;
        std::vector<json> rule_record;
        std::vector<json> record;
-       std::string creator_app_id;
+       std::string pkg_id;
        ctx::json jrule;
        std::string tmp;
        std::string id_str = int_to_string(rule_id);
@@ -578,17 +578,17 @@ int ctx::rule_manager::enable_rule(int rule_id)
        trigger_rule* rule;
 
        // Get rule json by rule id;
-       query = "SELECT details, creator_app_id FROM context_trigger_rule WHERE row_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;
        IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "Query rule by rule id failed");
 
        rule_record[0].get(NULL, "details", &tmp);
        jrule = tmp;
-       rule_record[0].get(NULL, "creator_app_id", &creator_app_id);
+       rule_record[0].get(NULL, "package_id", &pkg_id);
 
        // Create a rule instance
-       rule = new(std::nothrow) trigger_rule(rule_id, jrule, creator_app_id.c_str(), this);
+       rule = new(std::nothrow) trigger_rule(rule_id, jrule, pkg_id.c_str(), this);
        IF_FAIL_RETURN_TAG(rule, ERR_OUT_OF_MEMORY, _E, "Failed to create rule instance");
 
        // Start the rule
@@ -675,24 +675,24 @@ int ctx::rule_manager::pause_rule(int rule_id)
        return ERR_NONE;
 }
 
-int ctx::rule_manager::check_rule(std::string creator, int rule_id)
+int ctx::rule_manager::check_rule(std::string pkg_id, int rule_id)
 {
-       // Get creator app id
-       std::string q = "SELECT creator FROM context_trigger_rule WHERE row_id =";
+       // Get package id
+       std::string q = "SELECT package_id FROM context_trigger_rule WHERE row_id =";
        q += int_to_string(rule_id);
 
        std::vector<json> record;
        bool ret = db_manager::execute_sync(q.c_str(), &record);
-       IF_FAIL_RETURN_TAG(ret, false, _E, "Query creator by rule id failed");
+       IF_FAIL_RETURN_TAG(ret, false, _E, "Query package id by rule id failed");
 
        if (record.size() == 0) {
                return ERR_NO_DATA;
        }
 
-       std::string c;
-       record[0].get(NULL, "creator", &c);
+       std::string p;
+       record[0].get(NULL, "package_id", &p);
 
-       if (c.compare(creator) == 0){
+       if (p.compare(pkg_id) == 0){
                return ERR_NONE;
        }
 
@@ -714,11 +714,11 @@ bool ctx::rule_manager::is_rule_enabled(int rule_id)
        return (status != 0);
 }
 
-int ctx::rule_manager::get_rule_by_id(std::string creator, 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 (creator = '";
-       q += creator;
+       std::string q = "SELECT description FROM context_trigger_rule WHERE (package_id = '";
+       q += pkg_id;
        q += "') and (row_id = ";
        q += int_to_string(rule_id);
        q += ")";
@@ -742,12 +742,12 @@ int ctx::rule_manager::get_rule_by_id(std::string creator, int rule_id, ctx::jso
        return ERR_NONE;
 }
 
-int ctx::rule_manager::get_rule_ids(std::string creator, 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 "\" : [ ] }";
 
-       std::string q = "SELECT row_id, status FROM context_trigger_rule WHERE (creator = '";
-       q += creator;
+       std::string q = "SELECT row_id, status FROM context_trigger_rule WHERE (package_id = '";
+       q += pkg_id;
        q += "')";
 
        std::vector<json> record;
index bf054e9e6ff0ec525f66d7ddcc3f9a7c013f28a9..2b0b44e78dd9adddbb700a9979374422dd8addd9 100644 (file)
@@ -32,33 +32,33 @@ namespace ctx {
                        ~rule_manager();
 
                        bool init();
-                       int add_rule(std::string creator, const char* app_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 creator, int rule_id, ctx::json* request_result);
-                       int get_rule_ids(std::string creator, ctx::json* request_result);
-                       int check_rule(std::string creator, 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 check_rule(std::string pkg_id, int rule_id);
                        bool is_rule_enabled(int rule_id);
                        int pause_rule_with_item(std::string& subject);
                        int pause_rule(int rule_id);
                        int resume_rule_with_item(std::string& subject);
-                       void handle_rule_of_uninstalled_app(std::string app_id);
+                       void handle_rule_of_uninstalled_package(std::string pkg_id);
 
-                       static bool is_uninstalled_package(std::string app_id);
+                       static bool is_uninstalled_package(std::string pkg_id);
 
                private:
                        bool reenable_rule(void);
-                       int verify_rule(ctx::json& rule, const char* app_id);
-                       int64_t get_duplicated_rule_id(std::string creator, ctx::json& rule);
+                       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_app(bool is_init = false);
+                       int clear_rule_of_uninstalled_package(bool is_init = false);
                        void apply_templates(void);
 
-                       std::set<std::string> uninstalled_apps;
+                       std::set<std::string> uninstalled_packages;
 
                        typedef std::map<int, trigger_rule*> rule_map_t;
                        rule_map_t rule_map;
index 94b3f150c97d8a9b2e81a0c4f65d97a4853fbb98..d0b28e412795a58acd015691b50aa7a72e712004 100644 (file)
@@ -132,9 +132,9 @@ void ctx::context_trigger::add_rule(ctx::request_info* request)
                return;
        }
 
-       const char* app_id = request->get_app_id();
+       const char* pkg_id = request->get_package_id();
 
-       int error = rule_mgr->add_rule(client, app_id, request->get_description(), &rule_id);
+       int error = rule_mgr->add_rule(client, pkg_id, request->get_description(), &rule_id);
        _I("'%s' adds a rule (Error: %#x)", request->get_client(), error);
 
        request->reply(error, rule_id);
@@ -145,16 +145,12 @@ void ctx::context_trigger::remove_rule(ctx::request_info* request)
        int id;
        int error;
 
-       const char* app_id = request->get_client();
-       if (app_id == NULL) {
-               request->reply(ERR_OPERATION_FAILED);
-               return;
-       }
+       const char* pkg_id = request->get_package_id();
 
        ctx::json rule_id = request->get_description();
        rule_id.get(NULL, CT_RULE_ID, &id);
 
-       error = rule_mgr->check_rule(app_id, id);
+       error = rule_mgr->check_rule((pkg_id)? pkg_id : "", id);
        if (error != ERR_NONE) {
                request->reply(error);
                return;
@@ -176,16 +172,12 @@ void ctx::context_trigger::enable_rule(ctx::request_info* request)
        int id;
        int error;
 
-       const char* app_id = request->get_client();
-       if (app_id == NULL) {
-               request->reply(ERR_OPERATION_FAILED);
-               return;
-       }
+       const char* pkg_id = request->get_package_id();
 
        ctx::json rule_id = request->get_description();
        rule_id.get(NULL, CT_RULE_ID, &id);
 
-       error = rule_mgr->check_rule(app_id, id);
+       error = rule_mgr->check_rule((pkg_id)? pkg_id : "", id);
        if (error != ERR_NONE) {
                request->reply(error);
                return;
@@ -207,16 +199,12 @@ void ctx::context_trigger::disable_rule(ctx::request_info* request)
        int id;
        int error;
 
-       const char* app_id = request->get_client();
-       if (app_id == NULL) {
-               request->reply(ERR_OPERATION_FAILED);
-               return;
-       }
+       const char* pkg_id = request->get_package_id();
 
        ctx::json rule_id = request->get_description();
        rule_id.get(NULL, CT_RULE_ID, &id);
 
-       error = rule_mgr->check_rule(app_id, id);
+       error = rule_mgr->check_rule((pkg_id)? pkg_id : "", id);
        if (error != ERR_NONE) {
                request->reply(error);
                return;
@@ -241,14 +229,10 @@ void ctx::context_trigger::get_rule_by_id(ctx::request_info* request)
        int id;
        option.get(NULL, CT_RULE_ID, &id);
 
-       const char* app_id = request->get_client();
-       if (app_id == NULL) {
-               request->reply(ERR_OPERATION_FAILED);
-               return;
-       }
+       const char* pkg_id = request->get_package_id();
 
        ctx::json read_data;
-       error = rule_mgr->get_rule_by_id(app_id, id, &read_data);
+       error = rule_mgr->get_rule_by_id((pkg_id)? pkg_id : "", id, &read_data);
 
        ctx::json dummy;
        request->reply(error, dummy, read_data);
@@ -258,14 +242,10 @@ void ctx::context_trigger::get_rule_ids(ctx::request_info* request)
 {
        int error;
 
-       const char* app_id = request->get_client();
-       if (app_id == NULL) {
-               request->reply(ERR_OPERATION_FAILED);
-               return;
-       }
+       const char* pkg_id = request->get_package_id();
 
        ctx::json read_data;
-       error = rule_mgr->get_rule_ids(app_id, &read_data);
+       error = rule_mgr->get_rule_ids((pkg_id)? pkg_id : "", &read_data);
 
        ctx::json dummy;
        request->reply(error, dummy, read_data);
index 6bf9f43e70500336d5d78ac1935fab1662d904e8..61f158d5294581418ed557141d117025b9069073 100644 (file)
@@ -45,11 +45,6 @@ const ctx::credentials* ctx::request_info::get_credentials()
        return NULL;
 }
 
-const char* ctx::request_info::get_app_id()
-{
-       return NULL;
-}
-
 const char* ctx::request_info::get_package_id()
 {
        return NULL;
index 3faeb789c446ece0667ae980adbf8faf280aaa13..00de3be9168d05ba15ba54e4d3f041b11a39c96f 100644 (file)
@@ -36,7 +36,6 @@ namespace ctx {
                ctx::json& get_description();
 
                virtual const credentials* get_credentials();
-               virtual const char* get_app_id();
                virtual const char* get_package_id();
                /* TODO: remove this get_client() */
                virtual const char* get_client();