Remove DBusClient 96/72896/1
authorMu-Woong Lee <muwoong.lee@samsung.com>
Fri, 3 Jun 2016 02:27:39 +0000 (11:27 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Fri, 3 Jun 2016 02:27:39 +0000 (11:27 +0900)
Change-Id: Ibc40ad2d66acb694056baf524b5ffec2463b0f90
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
CMakeLists.txt
packaging/context.spec
src/DBusClient.cpp [deleted file]
src/DBusClient.h [deleted file]
src/IDBusClientListener.h [deleted file]
src/context_history.cpp
src/context_trigger.cpp
testsuite/CMakeLists.txt

index 03f39a1..fd8c38f 100644 (file)
@@ -12,11 +12,6 @@ MESSAGE("Sources: ${SRCS}")
 # Dependencies
 SET(DEPS "gio-2.0 context-common aul bundle capi-appfw-app-control pkgmgr-info")
 
-IF(${LEGACY_SECURITY})
-       SET(DEPS "${DEPS} security-server")
-       ADD_DEFINITIONS(-DLEGACY_SECURITY)
-ENDIF(${LEGACY_SECURITY})
-
 IF(${SYSTEM_SERVICE})
        ADD_DEFINITIONS(-DSYSTEM_SERVICE)
 ENDIF(${SYSTEM_SERVICE})
index 786c0cb..d35550e 100644 (file)
@@ -9,7 +9,6 @@ Source0:    %{name}-%{version}.tar.gz
 %define BUILD_PROFILE %{?profile}%{!?profile:%{?tizen_profile_name}}
 
 %define SYSTEM_SERVICE 0
-%define LEGACY_SECURITY        0
 %define LEGACY_APPFW   0
 
 %if "%{?BUILD_PROFILE}" == "tv"
@@ -24,10 +23,6 @@ BuildRequires: pkgconfig(bundle)
 BuildRequires: pkgconfig(capi-appfw-app-control)
 BuildRequires: pkgconfig(pkgmgr-info)
 
-%if %{LEGACY_SECURITY}
-BuildRequires: pkgconfig(security-server)
-%endif
-
 %description
 Tizen Context Framework Native API
 
@@ -65,7 +60,6 @@ export CXXFLAGS+=" -D_ALLOW_SERVICE_APP_TRIGGER_"
 cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DMAJORVER=${MAJORVER} -DFULLVER=%{version} \
                                                           -DPROFILE=%{?BUILD_PROFILE} \
                                                           -DSYSTEM_SERVICE=%{SYSTEM_SERVICE} \
-                                                          -DLEGACY_SECURITY=%{LEGACY_SECURITY} \
                                                           -DLEGACY_APPFW=%{LEGACY_APPFW}
 make %{?jobs:-j%jobs}
 
diff --git a/src/DBusClient.cpp b/src/DBusClient.cpp
deleted file mode 100644 (file)
index 6509950..0000000
+++ /dev/null
@@ -1,388 +0,0 @@
-/*
- * 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.
- */
-
-#include <Types.h>
-#include <DBusTypes.h>
-#include <ScopeMutex.h>
-#include "DBusClient.h"
-
-#ifdef LEGACY_SECURITY
-#include <security-server.h>
-
-static const char* __getCookie()
-{
-       static char *cookie = NULL;
-       static GMutex cookieMutex;
-
-       ctx::ScopeMutex sm(&cookieMutex);
-
-       if (cookie == NULL) {
-               int rawSize = security_server_get_cookie_size();
-               IF_FAIL_RETURN_TAG(rawSize > 0, NULL, _E, "Invalid cookie size");
-
-               char rawCookie[rawSize];
-               int ret = security_server_request_cookie(rawCookie, rawSize);
-               IF_FAIL_RETURN_TAG(ret >= 0, NULL, _E, "Failed to get the security cookie");
-
-               cookie = g_base64_encode(reinterpret_cast<guchar*>(rawCookie), rawSize);
-               IF_FAIL_RETURN_TAG(cookie, NULL, _E, "Failed to encode the cookie");
-       }
-
-       return cookie;
-}
-#endif
-
-using namespace ctx;
-
-static const gchar __introspection[] =
-       "<node>"
-       "       <interface name='" DBUS_IFACE "'>"
-       "               <method name='" METHOD_RESPOND "'>"
-       "                       <arg type='i' name='" ARG_REQID "' direction='in'/>"
-       "                       <arg type='s' name='" ARG_SUBJECT "' direction='in'/>"
-       "                       <arg type='i' name='" ARG_RESULT_ERR "' direction='in'/>"
-       "                       <arg type='s' name='" ARG_OUTPUT "' direction='in'/>"
-       "               </method>"
-       "       </interface>"
-       "</node>";
-
-GDBusConnection *DBusClient::__connection = NULL;
-GDBusNodeInfo *DBusClient::__nodeInfo = NULL;
-std::atomic_int DBusClient::__instanceCount(0);
-std::map<std::string, IDBusClientListener*> DBusClient::__listenerMap;
-
-DBusClient::DBusClient()
-{
-       ++__instanceCount;
-}
-
-DBusClient::~DBusClient()
-{
-       if (--__instanceCount == 0)
-               __release();
-}
-
-void DBusClient::__onMethodCalled(GDBusConnection *conn, const gchar *sender,
-                               const gchar *path, const gchar *iface, const gchar *name,
-                               GVariant *param, GDBusMethodInvocation *invocation, gpointer userData)
-{
-       IF_FAIL_VOID_TAG(STR_EQ(name, METHOD_RESPOND), _W, "Invalid method: %s", name);
-
-       gint reqId = 0;
-       const gchar *subject = NULL;
-       gint error = 0;
-       const gchar *data = NULL;
-
-       g_variant_get(param, "(i&si&s)", &reqId, &subject, &error, &data);
-       _D("[Response] ReqId: %d, Subject: %s, Error: %d", reqId, subject, error);
-       IF_FAIL_VOID_TAG(subject && data, _W, "Invalid parameter");
-
-       auto it = __listenerMap.find(subject);
-       it->second->onPublish(subject, reqId, error, data);
-
-       g_dbus_method_invocation_return_value(invocation, NULL);
-}
-
-bool DBusClient::__init()
-{
-       static GMutex mutex;
-       ScopeMutex sm(&mutex);
-
-       if (__connection)
-               return true;
-
-       GError *gerr = NULL;
-       gchar *addr = NULL;
-       GDBusInterfaceVTable vtable;
-       guint regId;
-
-       __nodeInfo = g_dbus_node_info_new_for_xml(__introspection, NULL);
-       IF_FAIL_RETURN_TAG(__nodeInfo != NULL, false, _E, "Initialization failed");
-
-#ifdef SYSTEM_SERVICE
-       addr = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM, NULL, &gerr);
-#else
-       addr = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SESSION, NULL, &gerr);
-#endif
-       HANDLE_GERROR(gerr);
-       IF_FAIL_CATCH_TAG(addr != NULL, _E, "Getting address failed");
-       _SD("Address: %s", addr);
-
-       __connection = g_dbus_connection_new_for_address_sync(addr,
-                       (GDBusConnectionFlags)(G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT | G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION),
-                       NULL, NULL, &gerr);
-       g_free(addr);
-       HANDLE_GERROR(gerr);
-       IF_FAIL_CATCH_TAG(__connection != NULL, _E, "Connection failed");
-
-       vtable.method_call = __onMethodCalled;
-       vtable.get_property = NULL;
-       vtable.set_property = NULL;
-
-       regId = g_dbus_connection_register_object(__connection, DBUS_PATH,
-                       __nodeInfo->interfaces[0], &vtable, NULL, NULL, &gerr);
-       HANDLE_GERROR(gerr);
-       IF_FAIL_CATCH_TAG(regId > 0, _E, "Object registration failed");
-
-       _I("DBus connection established");
-       _D("DBus name: %s", g_dbus_connection_get_unique_name(__connection));
-       return true;
-
-CATCH:
-       __release();
-       return false;
-}
-
-void DBusClient::__release()
-{
-       if (__connection) {
-               g_dbus_connection_flush_sync(__connection, NULL, NULL);
-               g_dbus_connection_close_sync(__connection, NULL, NULL);
-               g_object_unref(__connection);
-               __connection = NULL;
-       }
-
-       if (__nodeInfo) {
-               g_dbus_node_info_unref(__nodeInfo);
-               __nodeInfo = NULL;
-       }
-
-       _I("DBus connection released");
-}
-
-int DBusClient::__request(int type, int reqId, const char *subject, const char *input,
-               std::string *result, std::string *outputData)
-{
-       _D("Requesting: %d, %d, %s", type, reqId, subject);
-
-       if (input == NULL)
-               input = EMPTY_JSON_OBJECT;
-
-       /* FIXME: the second param is the security cookie, which is deprected in 3.0.
-        * We need to completely REMOVE this parameter from the dbus protocol. */
-       GVariant *param = g_variant_new("(isiss)", type, "", reqId, subject, input);
-       IF_FAIL_RETURN_TAG(param, ERR_OUT_OF_MEMORY, _E, "Memory allocation failed");
-
-       GError *err = NULL;
-       GVariant *response = g_dbus_connection_call_sync(__connection, DBUS_DEST, DBUS_PATH, DBUS_IFACE,
-                       METHOD_REQUEST, param, NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_TIMEOUT, NULL, &err);
-       HANDLE_GERROR(err);
-       IF_FAIL_RETURN_TAG(response, ERR_OPERATION_FAILED, _E, "Method call failed");
-
-       gint error = ERR_OPERATION_FAILED;
-       const gchar *resultStr = NULL;
-       const gchar *dataStr = NULL;
-
-       g_variant_get(response, "(i&s&s)", &error, &resultStr, &dataStr);
-
-       if (result && resultStr)
-               *result = resultStr;
-
-       if (outputData && dataStr)
-               *outputData = dataStr;
-
-       g_variant_unref(response);
-
-       return error;
-}
-
-int DBusClient::__request(int type, int reqId, const char* subject, const char* input)
-{
-       _D("Requesting: %d, %d, %s", type, reqId, subject);
-
-       if (input == NULL)
-               input = EMPTY_JSON_OBJECT;
-
-#ifdef LEGACY_SECURITY
-       const char *cookie = __getCookie();
-       IF_FAIL_RETURN_TAG(cookie, ERR_OPERATION_FAILED, _E, "Cookie generation failed");
-       GVariant *param = g_variant_new("(isiss)", type, cookie, reqId, subject, input);
-#else
-       GVariant *param = g_variant_new("(isiss)", type, "", reqId, subject, input);
-#endif
-       IF_FAIL_RETURN_TAG(param, ERR_OUT_OF_MEMORY, _E, "Memory allocation failed");
-
-       GError *err = NULL;
-       g_dbus_connection_call(__connection, DBUS_DEST, DBUS_PATH, DBUS_IFACE,
-                       METHOD_REQUEST, param, NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_TIMEOUT, NULL, NULL, &err);
-
-       if (err) {
-               HANDLE_GERROR(err);
-               return ERR_OPERATION_FAILED;
-       }
-
-       return ERR_NONE;
-}
-
-int DBusClient::__generateReqId()
-{
-       static GMutex mutex;
-       static int reqId = 0;
-
-       ctx::ScopeMutex sm(&mutex);
-
-       /* Overflow handling */
-       if (++reqId < 0)
-               reqId = 1;
-
-       return reqId;
-}
-
-void DBusClient::addListener(std::string subject, IDBusClientListener *listener)
-{
-       _D("Registering the listener for '%s'", subject.c_str());
-
-       static GMutex mutex;
-       ctx::ScopeMutex sm(&mutex);
-
-       __listenerMap[subject] = listener;
-}
-
-int DBusClient::isSupported(std::string subject)
-{
-       IF_FAIL_RETURN(__init(), ERR_OPERATION_FAILED);
-
-       return __request(REQ_SUPPORT, __generateReqId(), subject.c_str(), NULL, NULL, NULL);
-}
-
-int DBusClient::subscribe(std::string subject, Json option, int *reqId, Json *result)
-{
-       IF_FAIL_RETURN(__init(), ERR_OPERATION_FAILED);
-       ASSERT_NOT_NULL(reqId);
-
-       *reqId = __generateReqId();
-
-       _I("[Subscribe] ReqId: %d, Subject: %s", *reqId, subject.c_str());
-
-       std::string resultStr;
-       int error = __request(REQ_SUBSCRIBE, *reqId, subject.c_str(), option.str().c_str(), &resultStr, NULL);
-
-       if (result)
-               *result = resultStr;
-
-       _D("Error: %#x", error);
-       _SD("Result: %s", resultStr.c_str());
-
-       return error;
-}
-
-int DBusClient::unsubscribe(std::string subject, int reqId)
-{
-       IF_FAIL_RETURN(__init(), ERR_OPERATION_FAILED);
-
-       _I("[Unsubscribe] ReqId: %d, Subject: %s", reqId, subject.c_str());
-
-       return __request(REQ_UNSUBSCRIBE, reqId, subject.c_str(), NULL, NULL, NULL);
-}
-
-int DBusClient::read(std::string subject, Json option, int *reqId, Json *result)
-{
-       IF_FAIL_RETURN(__init(), ERR_OPERATION_FAILED);
-       ASSERT_NOT_NULL(reqId);
-
-       *reqId = __generateReqId();
-
-       _I("[Read] ReqId: %d, Subject: %s", *reqId, subject.c_str());
-
-       std::string resultStr;
-       int error = __request(REQ_READ, *reqId, subject.c_str(), option.str().c_str(), &resultStr, NULL);
-
-       if (result)
-               *result = resultStr;
-
-       _D("Error: %#x", error);
-       _SD("Result: %s", resultStr.c_str());
-
-       return error;
-}
-
-int DBusClient::readSync(std::string subject, Json option, int *reqId, Json *outputData)
-{
-       IF_FAIL_RETURN(__init(), ERR_OPERATION_FAILED);
-       ASSERT_NOT_NULL(reqId);
-       ASSERT_NOT_NULL(outputData);
-
-       *reqId = __generateReqId();
-
-       _I("[ReadSync] ReqId: %d, Subject: %s", *reqId, subject.c_str());
-
-       std::string output;
-       int error = __request(REQ_READ_SYNC, *reqId, subject.c_str(), option.str().c_str(), NULL, &output);
-
-       *outputData = output;
-
-       _D("Error: %#x", error);
-       _SD("Data: %s", output.c_str());
-
-       return error;
-}
-
-int DBusClient::write(std::string subject, Json inputData)
-{
-       IF_FAIL_RETURN(__init(), ERR_OPERATION_FAILED);
-
-       int reqId = __generateReqId();
-
-       _I("[Write] ReqId: %d, Subject: %s", reqId, subject.c_str());
-       _SD("Data: %s", inputData.str().c_str());
-
-       int error = __request(REQ_WRITE, reqId, subject.c_str(), inputData.str().c_str());
-       _D("Error: %#x", error);
-
-       return error;
-}
-
-int DBusClient::write(std::string subject, Json inputData, Json *result)
-{
-       IF_FAIL_RETURN(__init(), ERR_OPERATION_FAILED);
-
-       int reqId = __generateReqId();
-
-       _I("[Write with reply] ReqId: %d, Subject: %s", reqId, subject.c_str());
-       _SD("Data: %s", inputData.str().c_str());
-
-       std::string resultStr;
-       int error = __request(REQ_WRITE, reqId, subject.c_str(), inputData.str().c_str(), &resultStr, NULL);
-
-       if (result)
-               *result = resultStr;
-
-       _D("Error: %#x", error);
-       _SD("Result: %s", resultStr.c_str());
-
-       return error;
-}
-
-int DBusClient::call(const char *method)
-{
-       int ret = ERR_NONE;
-       GError *err = NULL;
-
-       GVariant *response = g_dbus_connection_call_sync(__connection, DBUS_DEST, DBUS_PATH, DBUS_IFACE,
-                       method, NULL, NULL, G_DBUS_CALL_FLAGS_NONE, DBUS_TIMEOUT, NULL, &err);
-
-       if (response) {
-               g_variant_unref(response);
-               return ERR_NONE;
-       }
-
-       ret = ERR_OPERATION_FAILED;
-       if (err->code == G_DBUS_ERROR_ACCESS_DENIED)
-               ret = ERR_PERMISSION_DENIED;
-
-       HANDLE_GERROR(err);
-       return ret;
-}
diff --git a/src/DBusClient.h b/src/DBusClient.h
deleted file mode 100644 (file)
index 76406b8..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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_DBUS_CLIENT_H_
-#define _CONTEXT_DBUS_CLIENT_H_
-
-#include <glib.h>
-#include <gio/gio.h>
-#include <string>
-#include <map>
-#include <atomic>
-#include "IDBusClientListener.h"
-
-namespace ctx {
-
-       class DBusClient {
-       public:
-               DBusClient();
-               ~DBusClient();
-
-               void addListener(std::string subject, IDBusClientListener *listener);
-
-               int isSupported(std::string subject);
-
-               int subscribe(std::string subject, Json option, int *reqId, Json *result);
-               int unsubscribe(std::string subject, int reqId);
-               int read(std::string subject, Json option, int *reqId, Json *result);
-               int readSync(std::string subject, Json option, int *reqId, Json *outputData);
-               int write(std::string subject, Json inputData);
-               int write(std::string subject, Json inputData, Json *result);
-
-               int call(const char *method);
-
-       private:
-               static void __onMethodCalled(GDBusConnection *conn, const gchar *sender,
-                               const gchar *path, const gchar *iface, const gchar *name,
-                               GVariant *param, GDBusMethodInvocation *invocation, gpointer userData);
-
-               bool __init();
-               void __release();
-               int __request(int type, int reqId, const char *subject, const char *input,
-                               std::string *result, std::string *outputData);
-               int __request(int type, int reqId, const char *subject, const char *input);
-               int __generateReqId();
-
-
-               static GDBusConnection *__connection;
-               static GDBusNodeInfo *__nodeInfo;
-               static std::atomic_int __instanceCount;
-               static std::map<std::string, IDBusClientListener*> __listenerMap;
-
-       };      /* class ctx::DBusClient */
-
-}      /* namespace ctx */
-
-#endif // _CONTEXT_DBUS_CLIENT_H_
diff --git a/src/IDBusClientListener.h b/src/IDBusClientListener.h
deleted file mode 100644 (file)
index 32c88c4..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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_I_DBUS_CLIENT_LISTENER_H_
-#define _CONTEXT_I_DBUS_CLIENT_LISTENER_H_
-
-#include <string>
-#include <Json.h>
-
-namespace ctx {
-
-       class IDBusClientListener {
-       public:
-               virtual ~IDBusClientListener() {}
-               virtual void onPublish(std::string subject, int reqId, int error, Json event) = 0;
-       };
-
-}      /* namespace ctx */
-
-#endif /* End of _CONTEXT_I_DBUS_CLIENT_LISTENER_H_ */
index 3f90f42..8fe1e12 100644 (file)
@@ -18,7 +18,7 @@
 #include <Json.h>
 #include <context_history.h>
 #include <context_history_types_internal.h>
-#include "DBusClient.h"
+#include <DBusClient.h>
 
 #define TYPE_INT 0
 #define TYPE_STRING 1
index 0e503f0..c6a2441 100644 (file)
@@ -30,7 +30,7 @@
 #include <context_trigger_internal.h>
 #include <context_trigger_types_internal.h>
 #include <pkgmgr-info.h>
-#include "DBusClient.h"
+#include <DBusClient.h>
 #include "rule_validator.h"
 
 #define INITIAL_RULE "{ \"ID\" : -1, \"DESCRIPTION\" : \"\", \"DETAILS\" : {  } }"
index 514be5f..30e85d2 100644 (file)
@@ -4,7 +4,6 @@ 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
 )