From e251949c58ca4312ac4fa4794e8949337c74c95d Mon Sep 17 00:00:00 2001 From: Mu-Woong Lee Date: Fri, 20 May 2016 20:04:49 +0900 Subject: [PATCH] Remove request_handler from the API library implementation API implementations use DBusClient directly, and request_handler is moved to the testsuite. Change-Id: Ib897e2c3a335a2f6587139b9780bcf31c1c6dc6f Signed-off-by: Mu-Woong Lee --- src/context_history.cpp | 6 ++-- src/context_trigger.cpp | 32 ++++++++++--------- src/rule_validator.cpp | 5 +-- testsuite/CMakeLists.txt | 1 + testsuite/src/trigger/condition.cpp | 2 +- testsuite/src/trigger/event.cpp | 2 +- .../src/trigger}/request_handler.cpp | 20 ++++++------ .../src/trigger}/request_handler.h | 0 8 files changed, 37 insertions(+), 31 deletions(-) rename {src => testsuite/src/trigger}/request_handler.cpp (71%) rename {src => testsuite/src/trigger}/request_handler.h (100%) diff --git a/src/context_history.cpp b/src/context_history.cpp index 8db3ba6..3f90f42 100644 --- a/src/context_history.cpp +++ b/src/context_history.cpp @@ -18,7 +18,7 @@ #include #include #include -#include "request_handler.h" +#include "DBusClient.h" #define TYPE_INT 0 #define TYPE_STRING 1 @@ -153,7 +153,9 @@ SO_EXPORT int context_history_get_list(context_history_h handle, context_history int req_id; ctx::Json tmp_list; - int err = ctx::request_handler::read_sync(data_type_str.c_str(), (filter)? &filter->jfilter : NULL, &req_id, &tmp_list); + ctx::DBusClient dbusClient; + + int err = dbusClient.readSync(data_type_str, filter ? filter->jfilter : NULL, &req_id, &tmp_list); IF_FAIL_RETURN_TAG(err == ERR_NONE, err, _E, "Getting list failed"); _J("Read response", tmp_list); diff --git a/src/context_trigger.cpp b/src/context_trigger.cpp index 7ad7df5..2cc7262 100644 --- a/src/context_trigger.cpp +++ b/src/context_trigger.cpp @@ -26,7 +26,7 @@ #include #include #include -#include "request_handler.h" +#include "DBusClient.h" #include "rule_validator.h" #define INITIAL_RULE "{ \"ID\" : -1, \"DESCRIPTION\" : \"\", \"DETAILS\" : { } }" @@ -35,6 +35,8 @@ #define EVENT_DATA_KEY_PREFIX_STR std::string("?") //#define DOUBLE_PRECISION 2 +static ctx::DBusClient __dbusClient; + static int context_trigger_rule_event_create_internal(const char* event_item, context_trigger_logical_type_e logical_type, context_trigger_rule_entry_h* entry, bool is_custom = false); static int context_trigger_rule_condition_create_internal(const char* condition_item, context_trigger_logical_type_e logical_type, context_trigger_rule_entry_h* entry, bool is_custom = false); static std::string convert_event_to_string(context_trigger_event_e item); @@ -86,7 +88,7 @@ SO_EXPORT int context_trigger_add_rule(context_trigger_rule_h rule, int* rule_id return CONTEXT_TRIGGER_ERROR_INVALID_RULE; ctx::Json jrule_id; - int error = ctx::request_handler::write_with_reply(CONTEXT_TRIGGER_SUBJECT_ADD, &(rule->jrule), &jrule_id); + int error = __dbusClient.write(CONTEXT_TRIGGER_SUBJECT_ADD, rule->jrule, &jrule_id); if (error == ERR_NONE) { jrule_id.get(NULL, CT_RULE_ID, rule_id); @@ -105,7 +107,7 @@ SO_EXPORT int context_trigger_remove_rule(int rule_id) ctx::Json jrule_id; jrule_id.set(NULL, CT_RULE_ID, rule_id); - int error = ctx::request_handler::write_with_reply(CONTEXT_TRIGGER_SUBJECT_REMOVE, &jrule_id, NULL); + int error = __dbusClient.write(CONTEXT_TRIGGER_SUBJECT_REMOVE, jrule_id, NULL); if (error == ERR_ALREADY_STARTED) { // Rule is still enabled. return CONTEXT_TRIGGER_ERROR_RULE_ENABLED; @@ -127,7 +129,7 @@ SO_EXPORT int context_trigger_enable_rule(int rule_id) jrule_id.set(NULL, CT_RULE_ID, rule_id); int req_id; // Useless in context_trigger - int error = ctx::request_handler::subscribe(CONTEXT_TRIGGER_SUBJECT_ENABLE, &jrule_id, &req_id, NULL); + int error = __dbusClient.subscribe(CONTEXT_TRIGGER_SUBJECT_ENABLE, jrule_id, &req_id, NULL); if (error == ERR_NO_DATA) { return CONTEXT_TRIGGER_ERROR_RULE_NOT_EXIST; @@ -145,7 +147,7 @@ SO_EXPORT int context_trigger_disable_rule(int rule_id) ctx::Json jrule_id; jrule_id.set(NULL, CT_RULE_ID, rule_id); - int error = ctx::request_handler::write_with_reply(CONTEXT_TRIGGER_SUBJECT_DISABLE, &jrule_id, NULL); + int error = __dbusClient.write(CONTEXT_TRIGGER_SUBJECT_DISABLE, jrule_id, NULL); if (error == ERR_NO_DATA) { return CONTEXT_TRIGGER_ERROR_RULE_NOT_EXIST; @@ -161,7 +163,7 @@ SO_EXPORT int context_trigger_get_own_rule_ids(int** enabled_rule_ids, int* enab int req_id; ctx::Json data_read; - int error = ctx::request_handler::read_sync(CONTEXT_TRIGGER_SUBJECT_GET_RULE_IDS, NULL, &req_id, &data_read); + int error = __dbusClient.readSync(CONTEXT_TRIGGER_SUBJECT_GET_RULE_IDS, NULL, &req_id, &data_read); if (error != ERR_NONE) { return error; @@ -212,7 +214,7 @@ SO_EXPORT int context_trigger_get_rule_by_id(int rule_id, context_trigger_rule_h int req_id; ctx::Json data_read; - int error = ctx::request_handler::read_sync(CONTEXT_TRIGGER_SUBJECT_GET, &option, &req_id, &data_read); + int error = __dbusClient.readSync(CONTEXT_TRIGGER_SUBJECT_GET, option, &req_id, &data_read); if (error == ERR_NO_DATA) { return CONTEXT_TRIGGER_ERROR_RULE_NOT_EXIST; @@ -352,11 +354,11 @@ SO_EXPORT int context_trigger_rule_set_action_app_control(context_trigger_rule_h int error; // Privilege check - error = ctx::request_handler::call(METHOD_CHK_PRIV_APPLAUNCH); + error = __dbusClient.call(METHOD_CHK_PRIV_APPLAUNCH); IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "Privilege checking failed (%#x)", error); if (is_call_operation(app_control)) { - error = ctx::request_handler::call(METHOD_CHK_PRIV_CALL); + error = __dbusClient.call(METHOD_CHK_PRIV_CALL); IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "Privilege checking failed (%#x)", error); } @@ -414,7 +416,7 @@ SO_EXPORT int context_trigger_rule_set_action_notification(context_trigger_rule_ ASSERT_NOT_NULL(rule && title && content); // Privilege check - int error = ctx::request_handler::call(METHOD_CHK_PRIV_NOTIFICATION); + int error = __dbusClient.call(METHOD_CHK_PRIV_NOTIFICATION); IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "Privilege checking failed (%#x)", error); // if action arleady exists @@ -582,7 +584,7 @@ SO_EXPORT int context_trigger_rule_event_is_supported(context_trigger_event_e ev return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER; } - int error = ctx::request_handler::is_supported(eitem_str.c_str()); + int error = __dbusClient.isSupported(eitem_str); if (error == ERR_NONE) *supported = true; @@ -657,7 +659,7 @@ SO_EXPORT int context_trigger_rule_condition_is_supported(context_trigger_condit return CONTEXT_TRIGGER_ERROR_INVALID_PARAMETER; } - int error = ctx::request_handler::is_supported(citem_str.c_str()); + int error = __dbusClient.isSupported(citem_str); if (error == ERR_NONE) *supported = true; @@ -929,7 +931,7 @@ SO_EXPORT int context_trigger_add_custom_item(const char* name, const char* attr data.set(NULL, CT_CUSTOM_NAME, name); data.set(NULL, CT_CUSTOM_ATTRIBUTES, jattr_template); - int error = ctx::request_handler::write_with_reply(CONTEXT_TRIGGER_SUBJECT_CUSTOM_ADD, &data, NULL); + int error = __dbusClient.write(CONTEXT_TRIGGER_SUBJECT_CUSTOM_ADD, data, NULL); IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "Failed to add custom item: %#x", error); return error; @@ -944,7 +946,7 @@ SO_EXPORT int context_trigger_remove_custom_item(const char* name) data.set(NULL, CT_CUSTOM_NAME, name); ctx::Json subj; - int error = ctx::request_handler::write_with_reply(CONTEXT_TRIGGER_SUBJECT_CUSTOM_REMOVE, &data, &subj); + int error = __dbusClient.write(CONTEXT_TRIGGER_SUBJECT_CUSTOM_REMOVE, data, &subj); IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "Failed to remove custom item: %#x", error); std::string subject; @@ -967,7 +969,7 @@ SO_EXPORT int context_trigger_publish_custom_item(const char* name, const char* data.set(NULL, CT_CUSTOM_NAME, name); data.set(NULL, CT_CUSTOM_FACT, jfact); - int error = ctx::request_handler::write_with_reply(CONTEXT_TRIGGER_SUBJECT_CUSTOM_PUBLISH, &data, NULL); + int error = __dbusClient.write(CONTEXT_TRIGGER_SUBJECT_CUSTOM_PUBLISH, data, NULL); IF_FAIL_RETURN_TAG(error == ERR_NONE, error, _E, "Failed to publish custom data"); return error; diff --git a/src/rule_validator.cpp b/src/rule_validator.cpp index 09aa833..dfee6fe 100644 --- a/src/rule_validator.cpp +++ b/src/rule_validator.cpp @@ -20,7 +20,7 @@ #include #include #include -#include "request_handler.h" +#include "DBusClient.h" #include "rule_validator.h" #define KEY_TEMPLATE "templates" @@ -72,7 +72,8 @@ int ctx::rule_validator::request_template(std::string name, bool mandatory) int req_id; ctx::Json tmpl; - int error = ctx::request_handler::read_sync(CONTEXT_TRIGGER_SUBJECT_GET_TEMPLATE, &request, &req_id, &tmpl); + ctx::DBusClient dbusClient; + int error = dbusClient.readSync(CONTEXT_TRIGGER_SUBJECT_GET_TEMPLATE, request, &req_id, &tmpl); if (error == ERR_NOT_SUPPORTED) { template_map.erase(name); _E("Failed to get request: not supported"); diff --git a/testsuite/CMakeLists.txt b/testsuite/CMakeLists.txt index 30e85d2..514be5f 100644 --- a/testsuite/CMakeLists.txt +++ b/testsuite/CMakeLists.txt @@ -4,6 +4,7 @@ SET(TEST_EXEC context-test) # Source List FILE(GLOB_RECURSE TEST_SRCS src/*.cpp) +SET(TEST_SRCS ${TEST_SRCS} ../src/DBusClient.cpp) INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/src ) diff --git a/testsuite/src/trigger/condition.cpp b/testsuite/src/trigger/condition.cpp index 4cadf47..5ee470f 100644 --- a/testsuite/src/trigger/condition.cpp +++ b/testsuite/src/trigger/condition.cpp @@ -14,12 +14,12 @@ * limitations under the License. */ -#include #include #include #include #include "../shared.h" +#include "request_handler.h" #include "condition.h" using namespace ctx::test; diff --git a/testsuite/src/trigger/event.cpp b/testsuite/src/trigger/event.cpp index 9d843c8..0dee837 100644 --- a/testsuite/src/trigger/event.cpp +++ b/testsuite/src/trigger/event.cpp @@ -15,11 +15,11 @@ */ #include -#include #include #include #include "../shared.h" +#include "request_handler.h" #include "event.h" using namespace ctx::test; diff --git a/src/request_handler.cpp b/testsuite/src/trigger/request_handler.cpp similarity index 71% rename from src/request_handler.cpp rename to testsuite/src/trigger/request_handler.cpp index b827d98..6969aff 100644 --- a/src/request_handler.cpp +++ b/testsuite/src/trigger/request_handler.cpp @@ -21,7 +21,7 @@ #include #include -#include "DBusClient.h" +#include #include "request_handler.h" using namespace ctx; @@ -51,47 +51,47 @@ void DBusClientListenerImpl::onPublish(std::string subject, int reqId, int error static DBusClientListenerImpl __dbusListener; static DBusClient __dbusClient; -SO_EXPORT int ctx::request_handler::subscribe(const char* subject, ctx::Json* option, int* req_id, ctx::Json* request_result) +int ctx::request_handler::subscribe(const char* subject, ctx::Json* option, int* req_id, ctx::Json* request_result) { return __dbusClient.subscribe(subject, option ? *option : NULL, req_id, request_result); } -SO_EXPORT int ctx::request_handler::unsubscribe(const char* subject, int req_id) +int ctx::request_handler::unsubscribe(const char* subject, int req_id) { return __dbusClient.unsubscribe(subject, req_id); } -SO_EXPORT int ctx::request_handler::read(const char* subject, ctx::Json* option, int* req_id, ctx::Json* request_result) +int ctx::request_handler::read(const char* subject, ctx::Json* option, int* req_id, ctx::Json* request_result) { return __dbusClient.read(subject, option ? *option : NULL, req_id, request_result); } -SO_EXPORT int ctx::request_handler::read_sync(const char* subject, ctx::Json* option, int* req_id, ctx::Json* data_read) +int ctx::request_handler::read_sync(const char* subject, ctx::Json* option, int* req_id, ctx::Json* data_read) { return __dbusClient.readSync(subject, option ? *option : NULL, req_id, data_read); } -SO_EXPORT int ctx::request_handler::write(const char* subject, ctx::Json* data) +int ctx::request_handler::write(const char* subject, ctx::Json* data) { return __dbusClient.write(subject, *data); } -SO_EXPORT int ctx::request_handler::write_with_reply(const char* subject, ctx::Json* data, ctx::Json* request_result) +int ctx::request_handler::write_with_reply(const char* subject, ctx::Json* data, ctx::Json* request_result) { return __dbusClient.write(subject, *data, request_result); } -SO_EXPORT int ctx::request_handler::is_supported(const char* subject) +int ctx::request_handler::is_supported(const char* subject) { return __dbusClient.isSupported(subject); } -SO_EXPORT int ctx::request_handler::call(const char* method) +int ctx::request_handler::call(const char* method) { return __dbusClient.call(method); } -SO_EXPORT bool ctx::request_handler::register_callback(const char* subject, subject_response_cb callback) +bool ctx::request_handler::register_callback(const char* subject, subject_response_cb callback) { __dbusListener.setCb(subject, callback); __dbusClient.addListener(subject, &__dbusListener); diff --git a/src/request_handler.h b/testsuite/src/trigger/request_handler.h similarity index 100% rename from src/request_handler.h rename to testsuite/src/trigger/request_handler.h -- 2.34.1