API implementations use DBusClient directly, and request_handler is moved to the testsuite.
Change-Id: Ib897e2c3a335a2f6587139b9780bcf31c1c6dc6f
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
#include <Json.h>
#include <context_history.h>
#include <context_history_types_internal.h>
-#include "request_handler.h"
+#include "DBusClient.h"
#define TYPE_INT 0
#define TYPE_STRING 1
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);
#include <context_trigger_internal.h>
#include <context_trigger_types_internal.h>
#include <pkgmgr-info.h>
-#include "request_handler.h"
+#include "DBusClient.h"
#include "rule_validator.h"
#define INITIAL_RULE "{ \"ID\" : -1, \"DESCRIPTION\" : \"\", \"DETAILS\" : { } }"
#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);
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);
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;
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;
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;
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;
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;
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);
}
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
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;
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;
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;
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;
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;
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/* TODO: Remove this request_handler. All APIs and the testsuite should use DBusClient directly. */
-
-#include <string>
-#include <map>
-
-#include <Types.h>
-#include <ScopeMutex.h>
-#include "DBusClient.h"
-#include "request_handler.h"
-
-using namespace ctx;
-
-class DBusClientListenerImpl : public IDBusClientListener {
-public:
- DBusClientListenerImpl() {}
- ~DBusClientListenerImpl() {}
- void setCb(std::string subject, request_handler::subject_response_cb cb);
- void onPublish(std::string subject, int reqId, int error, Json event);
-private:
- std::map<std::string, request_handler::subject_response_cb> __callbackMap;
-};
-
-void DBusClientListenerImpl::setCb(std::string subject, request_handler::subject_response_cb cb)
-{
- __callbackMap[subject] = cb;
-}
-
-void DBusClientListenerImpl::onPublish(std::string subject, int reqId, int error, Json event)
-{
- auto it = __callbackMap.find(subject);
- IF_FAIL_VOID_TAG(it != __callbackMap.end(), _W, "Unregistered subject");
- it->second(subject.c_str(), reqId, error, event);
-}
-
-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)
-{
- return __dbusClient.subscribe(subject, option ? *option : NULL, req_id, request_result);
-}
-
-SO_EXPORT 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)
-{
- 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)
-{
- return __dbusClient.readSync(subject, option ? *option : NULL, req_id, data_read);
-}
-
-SO_EXPORT 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)
-{
- return __dbusClient.write(subject, *data, request_result);
-}
-
-SO_EXPORT int ctx::request_handler::is_supported(const char* subject)
-{
- return __dbusClient.isSupported(subject);
-}
-
-SO_EXPORT 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)
-{
- __dbusListener.setCb(subject, callback);
- __dbusClient.addListener(subject, &__dbusListener);
- return true;
-}
+++ /dev/null
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __CONTEXT_LIB_REQUEST_HANDLER_H__
-#define __CONTEXT_LIB_REQUEST_HANDLER_H__
-
-#include <Json.h>
-
-namespace ctx { namespace request_handler {
-
- /*
- */
- typedef void(* subject_response_cb)(const char* subject, int req_id, int error, ctx::Json response);
-
- /*
- */
- bool register_callback(const char* subject, subject_response_cb callback);
-
- /*
- */
- int subscribe(const char* subject, ctx::Json* option, int* req_id, ctx::Json* request_result = NULL);
-
- /*
- */
- int unsubscribe(const char* subject, int req_id);
-
- /*
- */
- int read(const char* subject, ctx::Json* option, int* req_id, ctx::Json* request_result = NULL);
-
- /*
- */
- int read_sync(const char* subject, ctx::Json* option, int* req_id, ctx::Json* data_read);
-
- /*
- */
- int write(const char* subject, ctx::Json* data);
-
- /*
- */
- int write_with_reply(const char* subject, ctx::Json* data, ctx::Json* request_result = NULL);
-
- /*
- */
- int is_supported(const char* subject);
-
- int call(const char* method);
-
-} } /* namespace ctx::request_handler */
-
-#endif // __CONTEXT_LIB_REQUEST_HANDLER_H__
#include <Types.h>
#include <context_trigger.h>
#include <context_trigger_types_internal.h>
-#include "request_handler.h"
+#include "DBusClient.h"
#include "rule_validator.h"
#define KEY_TEMPLATE "templates"
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");
# Source List
FILE(GLOB_RECURSE TEST_SRCS src/*.cpp)
+SET(TEST_SRCS ${TEST_SRCS} ../src/DBusClient.cpp)
INCLUDE_DIRECTORIES(
${CMAKE_SOURCE_DIR}/src
)
* limitations under the License.
*/
-#include <request_handler.h>
#include <context_trigger.h>
#include <context_trigger_types_internal.h>
#include <context_history.h>
#include "../shared.h"
+#include "request_handler.h"
#include "condition.h"
using namespace ctx::test;
*/
#include <time.h>
-#include <request_handler.h>
#include <context_trigger.h>
#include <context_trigger_types_internal.h>
#include "../shared.h"
+#include "request_handler.h"
#include "event.h"
using namespace ctx::test;
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* TODO: Remove this request_handler. All APIs and the testsuite should use DBusClient directly. */
+
+#include <string>
+#include <map>
+
+#include <Types.h>
+#include <ScopeMutex.h>
+#include <DBusClient.h>
+#include "request_handler.h"
+
+using namespace ctx;
+
+class DBusClientListenerImpl : public IDBusClientListener {
+public:
+ DBusClientListenerImpl() {}
+ ~DBusClientListenerImpl() {}
+ void setCb(std::string subject, request_handler::subject_response_cb cb);
+ void onPublish(std::string subject, int reqId, int error, Json event);
+private:
+ std::map<std::string, request_handler::subject_response_cb> __callbackMap;
+};
+
+void DBusClientListenerImpl::setCb(std::string subject, request_handler::subject_response_cb cb)
+{
+ __callbackMap[subject] = cb;
+}
+
+void DBusClientListenerImpl::onPublish(std::string subject, int reqId, int error, Json event)
+{
+ auto it = __callbackMap.find(subject);
+ IF_FAIL_VOID_TAG(it != __callbackMap.end(), _W, "Unregistered subject");
+ it->second(subject.c_str(), reqId, error, event);
+}
+
+static DBusClientListenerImpl __dbusListener;
+static DBusClient __dbusClient;
+
+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);
+}
+
+int ctx::request_handler::unsubscribe(const char* subject, int req_id)
+{
+ return __dbusClient.unsubscribe(subject, req_id);
+}
+
+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);
+}
+
+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);
+}
+
+int ctx::request_handler::write(const char* subject, ctx::Json* data)
+{
+ return __dbusClient.write(subject, *data);
+}
+
+int ctx::request_handler::write_with_reply(const char* subject, ctx::Json* data, ctx::Json* request_result)
+{
+ return __dbusClient.write(subject, *data, request_result);
+}
+
+int ctx::request_handler::is_supported(const char* subject)
+{
+ return __dbusClient.isSupported(subject);
+}
+
+int ctx::request_handler::call(const char* method)
+{
+ return __dbusClient.call(method);
+}
+
+bool ctx::request_handler::register_callback(const char* subject, subject_response_cb callback)
+{
+ __dbusListener.setCb(subject, callback);
+ __dbusClient.addListener(subject, &__dbusListener);
+ return true;
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __CONTEXT_LIB_REQUEST_HANDLER_H__
+#define __CONTEXT_LIB_REQUEST_HANDLER_H__
+
+#include <Json.h>
+
+namespace ctx { namespace request_handler {
+
+ /*
+ */
+ typedef void(* subject_response_cb)(const char* subject, int req_id, int error, ctx::Json response);
+
+ /*
+ */
+ bool register_callback(const char* subject, subject_response_cb callback);
+
+ /*
+ */
+ int subscribe(const char* subject, ctx::Json* option, int* req_id, ctx::Json* request_result = NULL);
+
+ /*
+ */
+ int unsubscribe(const char* subject, int req_id);
+
+ /*
+ */
+ int read(const char* subject, ctx::Json* option, int* req_id, ctx::Json* request_result = NULL);
+
+ /*
+ */
+ int read_sync(const char* subject, ctx::Json* option, int* req_id, ctx::Json* data_read);
+
+ /*
+ */
+ int write(const char* subject, ctx::Json* data);
+
+ /*
+ */
+ int write_with_reply(const char* subject, ctx::Json* data, ctx::Json* request_result = NULL);
+
+ /*
+ */
+ int is_supported(const char* subject);
+
+ int call(const char* method);
+
+} } /* namespace ctx::request_handler */
+
+#endif // __CONTEXT_LIB_REQUEST_HANDLER_H__