[Common] Moving GDBus base class to common module
authorLukasz Foniok <l.foniok@samsung.com>
Tue, 9 Jun 2015 14:52:29 +0000 (16:52 +0200)
committerLukasz Foniok <l.foniok@samsung.com>
Thu, 11 Jun 2015 09:31:06 +0000 (11:31 +0200)
[Verification]
Messaging test should not degradate

Change-Id: Ia344144c9afa609c27f93133f99457ab396a5ea1
Signed-off-by: Lukasz Foniok <l.foniok@samsung.com>
20 files changed:
src/common/GDBus/connection.cpp [new file with mode: 0644]
src/common/GDBus/connection.h [new file with mode: 0644]
src/common/GDBus/proxy.cpp [new file with mode: 0644]
src/common/GDBus/proxy.h [new file with mode: 0644]
src/common/common.gyp
src/messaging/DBus/Connection.cpp [deleted file]
src/messaging/DBus/Connection.h [deleted file]
src/messaging/DBus/DBusTypes.cpp [new file with mode: 0644]
src/messaging/DBus/DBusTypes.h [new file with mode: 0644]
src/messaging/DBus/EmailSignalProxy.cpp
src/messaging/DBus/EmailSignalProxy.h
src/messaging/DBus/MessageProxy.cpp
src/messaging/DBus/MessageProxy.h
src/messaging/DBus/Proxy.cpp [deleted file]
src/messaging/DBus/Proxy.h [deleted file]
src/messaging/DBus/SendProxy.cpp
src/messaging/DBus/SyncProxy.cpp
src/messaging/email_manager.cc
src/messaging/email_manager.h
src/messaging/messaging.gyp

diff --git a/src/common/GDBus/connection.cpp b/src/common/GDBus/connection.cpp
new file mode 100644 (file)
index 0000000..c5a115d
--- /dev/null
@@ -0,0 +1,52 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2013 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 "common/GDBus/connection.h"
+#include "common/logger.h"
+#include <cstring>
+
+namespace common {
+namespace dbus {
+
+Connection& Connection::getInstance()
+{
+    LoggerD("Entered");
+    static Connection instance;
+    return instance;
+}
+
+GDBusConnection* Connection::getDBus()
+{
+    return m_dbus;
+}
+
+Connection::Connection()
+{
+    m_dbus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &m_error);
+    if (!m_dbus || m_error) {
+        LoggerE("Could not get connection");
+    }
+    LoggerD("Connection set");
+}
+
+Connection::~Connection()
+{
+    g_object_unref(m_dbus);
+}
+
+} //namespace dbus
+} //namespace common
diff --git a/src/common/GDBus/connection.h b/src/common/GDBus/connection.h
new file mode 100644 (file)
index 0000000..29475fb
--- /dev/null
@@ -0,0 +1,45 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2013 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 __TIZEN_DBUS_CONNECTION_H__
+#define __TIZEN_DBUS_CONNECTION_H__
+
+#include <gio/gio.h>
+
+namespace common {
+namespace dbus {
+
+class Connection {
+public:
+    static Connection& getInstance();
+
+    GDBusConnection* getDBus();
+
+private:
+    Connection();
+    Connection(const Connection&);
+    void operator=(const Connection&);
+    virtual ~Connection();
+
+    GDBusConnection* m_dbus;
+    GError* m_error;
+};
+
+} //namespace dbus
+} //namespace common
+
+#endif
diff --git a/src/common/GDBus/proxy.cpp b/src/common/GDBus/proxy.cpp
new file mode 100644 (file)
index 0000000..4f6eedd
--- /dev/null
@@ -0,0 +1,142 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2013 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.
+//
+
+/**
+ * @file        proxy.cpp
+ */
+
+#include "common/GDBus/proxy.h"
+#include "common/logger.h"
+#include "common/platform_result.h"
+#include <cstring>
+
+namespace common {
+namespace dbus {
+
+using namespace common;
+
+Proxy::Proxy(const std::string& proxy_path,
+            const std::string& proxy_iface,
+            const std::string& signal_name,
+            const std::string& signal_path,
+            const std::string& signal_iface) :
+                m_conn(Connection::getInstance()),
+                m_sub_id(0),
+                m_path(proxy_path),
+                m_iface(proxy_iface),
+                m_signal_name(signal_name),
+                m_signal_path(signal_path),
+                m_signal_iface(signal_iface),
+                m_error(NULL),
+                m_dbus_signal_subscribed(false)
+{
+    LoggerD("Proxy:\n"
+            "  proxy_path: %s\n  proxy_iface: %s"
+            "  signal_name: %s\n signal_path:%s\n signal_iface:%s",
+            m_path.c_str(), m_iface.c_str(),
+            m_signal_name.c_str(), m_signal_path.c_str(), m_signal_iface.c_str());
+
+    const gchar* unique_name = g_dbus_connection_get_unique_name(m_conn.getDBus());
+    LoggerD("Generated unique name: %d", unique_name);
+
+    // path and interface are not obligatory to receive, but
+    // they should be set to send the signals.
+    m_proxy = g_dbus_proxy_new_sync(m_conn.getDBus(),
+            G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+            NULL, unique_name, m_path.c_str(), m_iface.c_str(), NULL, &m_error);
+}
+
+Proxy::~Proxy()
+{
+    signalUnsubscribe();
+}
+
+void Proxy::signalCallbackProxy(GDBusConnection *connection,
+        const gchar *sender_name,
+        const gchar *object_path,
+        const gchar *interface_name,
+        const gchar *signal_name,
+        GVariant *parameters,
+        gpointer user_data)
+{
+    Proxy* this_ptr = static_cast<Proxy*>(user_data);
+    if (!this_ptr) {
+        LoggerW("Proxy is null, nothing to do");
+        return;
+    }
+
+    //It is better to log this only when subclass is responsible of handling
+    //passed signal. If you need it put it into your signalCallback(...) method
+    //LoggerD("signal: %s from: %s path: %s interface: %s",
+    //        signal_name, sender_name, object_path, interface_name);
+    this_ptr->signalCallback(connection, sender_name, object_path, interface_name,
+            signal_name, parameters);
+}
+
+void Proxy::signalSubscribe()
+{
+    if(m_dbus_signal_subscribed) {
+        LoggerW("Proxy has already subscribed for listening DBus signal");
+        return;
+    }
+
+    const char* sender = NULL;
+    m_sub_id = g_dbus_connection_signal_subscribe(m_conn.getDBus(),
+            sender,
+            m_signal_iface.c_str(),
+            m_signal_name.c_str(),
+            m_signal_path.c_str(),
+            NULL,
+            G_DBUS_SIGNAL_FLAGS_NONE,
+            signalCallbackProxy,
+            static_cast<gpointer>(this),
+            NULL);
+    LoggerD("g_dbus_connection_signal_subscribe returned id: %d", m_sub_id);
+
+    m_dbus_signal_subscribed = true;
+}
+
+void Proxy::signalUnsubscribe()
+{
+    if (!m_dbus_signal_subscribed) {
+        LoggerW("Proxy hasn't subscribed for listening DBus signal");
+        return;
+    }
+
+    g_dbus_connection_signal_unsubscribe(m_conn.getDBus(), m_sub_id);
+    LoggerD("g_dbus_connection_signal_unsubscribe finished");
+
+    m_dbus_signal_subscribed = false;
+}
+
+const std::string& Proxy::getSignalName() const
+{
+    return m_signal_name;
+}
+
+const std::string& Proxy::getSignalPath() const
+{
+    return m_signal_path;
+}
+
+const std::string& Proxy::getSignalInterfaceName() const
+{
+    return m_signal_iface;
+}
+
+} //namespace dbus
+} //namespace common
diff --git a/src/common/GDBus/proxy.h b/src/common/GDBus/proxy.h
new file mode 100644 (file)
index 0000000..ed00283
--- /dev/null
@@ -0,0 +1,115 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2013 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.
+//
+
+/**
+ * @file        Proxy.h
+ */
+
+#ifndef __TIZEN_DBUS_PROXY_H__
+#define __TIZEN_DBUS_PROXY_H__
+
+#include "common/GDBus/connection.h"
+#include <memory>
+#include <string>
+#include <mutex>
+#include <map>
+#include "common/callback_user_data.h"
+#include "common/picojson.h"
+#include "common/platform_result.h"
+
+namespace common {
+namespace dbus {
+
+
+class Proxy;
+typedef std::shared_ptr<Proxy> ProxyPtr;
+
+/**
+ * This is generic dbus signal listener proxy.
+ */
+class Proxy {
+public:
+
+    virtual ~Proxy();
+    bool isNotProxyGot() { return !m_proxy || m_error; };
+
+    void signalSubscribe();
+    void signalUnsubscribe();
+
+    const std::string& getSignalName() const;
+    const std::string& getSignalPath() const;
+    const std::string& getSignalInterfaceName() const;
+
+protected:
+    /**
+     * @param proxy_path - path of this proxy
+     * @param proxy_iface - interface name of this proxy
+     *
+     * @param signal_name - expected signal name
+     * @param signal_path - expected signal path
+     * @param signal_iface - expected signal interface name
+     */
+    Proxy(const std::string& proxy_path,
+            const std::string& proxy_iface,
+            const std::string& signal_name,
+            const std::string& signal_path,
+            const std::string& signal_iface);
+    /**
+     * Please implement this method in subclass to handle signal.
+     * Executed by static void signalCallbackProxy(...).
+     */
+    virtual void signalCallback(GDBusConnection *connection,
+            const gchar *sender_name,
+            const gchar *object_path,
+            const gchar *interface_name,
+            const gchar *signal_name,
+            GVariant *parameters) = 0;
+
+private:
+    /**
+     * This method (registered with g_dbus_connection_signal_subscribe) is executed by
+     * DBus when signal is received. It calls
+     * (static_cast<Proxy*>(user_data))->signalCallback(...)
+     */
+
+    static void signalCallbackProxy(GDBusConnection *connection,
+            const gchar *sender_name,
+            const gchar *object_path,
+            const gchar *interface_name,
+            const gchar *signal_name,
+            GVariant *parameters,
+            gpointer user_data);
+
+    Connection& m_conn;
+    guint m_sub_id;
+
+    std::string m_path;
+    std::string m_iface;
+
+    std::string m_signal_name;
+    std::string m_signal_path;
+    std::string m_signal_iface;
+
+    GError* m_error;
+    GDBusProxy* m_proxy;
+    bool m_dbus_signal_subscribed;
+};
+
+} //namespace dbus
+} //namespace common
+
+#endif // __TIZEN_DBUS_PROXY_H__
index 24337873a137b0691d9a68db38caf0670b5ab51b..b44c3af03f9f8fdaf2891377116db5d0bed87181 100644 (file)
         'assert.h',
         'virtual_fs.cc',
         'virtual_fs.h',
+        'GDBus/connection.cpp',
+        'GDBus/connection.h',
+        'GDBus/proxy.cpp',
+        'GDBus/proxy.h',
       ],
       'cflags': [
         '-fvisibility=default',
diff --git a/src/messaging/DBus/Connection.cpp b/src/messaging/DBus/Connection.cpp
deleted file mode 100644 (file)
index d912671..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2013 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 "Connection.h"
-#include "common/logger.h"
-#include <cstring>
-#include <email-types.h>
-#include "../message_service.h"
-
-namespace extension {
-namespace messaging {
-namespace DBus {
-
-Connection& Connection::getInstance()
-{
-    LoggerD("Entered");
-    static Connection instance;
-    return instance;
-}
-
-GDBusConnection* Connection::getDBus()
-{
-    return m_dbus;
-}
-
-Connection::Connection()
-{
-    dbus_g_thread_init();
-    g_type_init();
-
-    m_dbus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &m_error);
-    if (!m_dbus || m_error) {
-        LoggerE("Could not get connection");
-    }
-    LoggerD("Connection set");
-}
-
-Connection::~Connection()
-{
-    g_object_unref(m_dbus);
-}
-
-} //namespace DBus
-} //namespace Messaging
-} //namespace DeviceAPI
diff --git a/src/messaging/DBus/Connection.h b/src/messaging/DBus/Connection.h
deleted file mode 100644 (file)
index 07084e3..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2013 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 __TIZEN_DBUS_CONNECTION_H__
-#define __TIZEN_DBUS_CONNECTION_H__
-
-#include <dbus/dbus.h>
-#include <dbus/dbus-glib.h>
-#include <gio/gio.h>
-
-namespace extension {
-namespace messaging {
-namespace DBus {
-
-class Connection {
-public:
-    static Connection& getInstance();
-
-    GDBusConnection* getDBus();
-
-private:
-    Connection();
-    Connection(const Connection&);
-    void operator=(const Connection&);
-    virtual ~Connection();
-
-    GDBusConnection* m_dbus;
-    GError* m_error;
-};
-
-} //namespace DBus
-} //namespace Messaging
-} //namespace DeviceAPI
-
-#endif
diff --git a/src/messaging/DBus/DBusTypes.cpp b/src/messaging/DBus/DBusTypes.cpp
new file mode 100644 (file)
index 0000000..1a6489d
--- /dev/null
@@ -0,0 +1,32 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2013 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 "messaging/DBus/DBusTypes.h"
+
+namespace extension {
+namespace messaging {
+namespace DBus {
+
+const char* kDBusPathNetworkStatus = "/User/Email/NetworkStatus";
+const char* kDBusIfaceNetworkStatus = "User.Email.NetworkStatus";
+const char* kDBusPathEmailStorageChange = "/User/Email/StorageChange";
+const char* kDBusIfaceEmailStorageChange = "User.Email.StorageChange";
+const char* kDBusNameSignalEmail = "email";
+
+} // namespace DBus
+} // namespace messaging
+} // namespace extension
diff --git a/src/messaging/DBus/DBusTypes.h b/src/messaging/DBus/DBusTypes.h
new file mode 100644 (file)
index 0000000..0c9c56f
--- /dev/null
@@ -0,0 +1,36 @@
+//
+// Tizen Web Device API
+// Copyright (c) 2013 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.
+//
+
+namespace extension {
+namespace messaging {
+namespace DBus {
+
+/**
+ * List of Tizen path and interface names:
+ */
+extern const char* kDBusPathNetworkStatus;
+extern const char* kDBusIfaceNetworkStatus;
+extern const char* kDBusPathEmailStorageChange;
+extern const char* kDBusIfaceEmailStorageChange;
+/**
+ * Name of email signal
+ */
+extern const char* kDBusNameSignalEmail;
+
+} // namespace DBus
+} // namespace messaging
+} // namespace extension
index ab80f51b826515ab40f5f45d7e6299037f2cfb8f..f00a37d5f165488aa7b42d8ea0c711d46e9f6709 100644 (file)
@@ -22,6 +22,7 @@
 #include "EmailSignalProxy.h"
 #include "common/logger.h"
 #include <cstring>
+#include "messaging/DBus/DBusTypes.h"
 
 namespace extension {
 namespace messaging {
@@ -29,11 +30,11 @@ namespace DBus {
 
 EmailSignalProxy::EmailSignalProxy(const std::string& proxy_path,
         const std::string& proxy_iface) :
-        Proxy (proxy_path,
+        common::dbus::Proxy (proxy_path,
                       proxy_iface,
-                      Proxy::DBUS_NAME_SIGNAL_EMAIL,   //specify email signal details
-                      DBUS_PATH_NETWORK_STATUS,
-                      DBUS_IFACE_NETWORK_STATUS)
+                      kDBusNameSignalEmail,   //specify email signal details
+                      kDBusPathNetworkStatus,
+                      kDBusIfaceNetworkStatus)
 {
 }
 
index 9791f4b3e02c6e04b8c934e4a9ca69a9f0868511..01687a1795c8312b7af67656c1b55464dd013bdf 100644 (file)
@@ -22,7 +22,7 @@
 #ifndef __TIZEN_DBUS_EMAIL_SIGNAL_PROXY_H__
 #define __TIZEN_DBUS_EMAIL_SIGNAL_PROXY_H__
 
-#include "Proxy.h"
+#include "common/GDBus/proxy.h"
 
 namespace extension {
 namespace messaging {
@@ -31,7 +31,7 @@ namespace DBus {
 class EmailSignalProxy;
 typedef std::shared_ptr<EmailSignalProxy> EmailSignalProxyPtr;
 
-class EmailSignalProxy : public Proxy {
+class EmailSignalProxy : public common::dbus::Proxy {
 public:
     virtual ~EmailSignalProxy();
 
index b986adefc33bc495599ed6bfeab2d0f7ae7cd517..536435d8860650e0c2b2dbff2fbda0ba3217ee05 100644 (file)
@@ -16,7 +16,7 @@
 //
 
 #include "MessageProxy.h"
-#include "Connection.h"
+#include "common/GDBus/connection.h"
 #include "common/logger.h"
 #include "../message.h"
 #include "../message_email.h"
@@ -24,6 +24,7 @@
 //#include <MessageFolder.h>
 #include "../change_listener_container.h"
 #include "../email_manager.h"
+#include "messaging/DBus/DBusTypes.h"
 
 namespace extension {
 namespace messaging {
@@ -32,11 +33,11 @@ namespace DBus {
 using namespace common;
 
 MessageProxy::MessageProxy():
-        Proxy(Proxy::DBUS_PATH_EMAIL_STORAGE_CHANGE,
-                     Proxy::DBUS_IFACE_EMAIL_STORAGE_CHANGE,
-                     Proxy::DBUS_NAME_SIGNAL_EMAIL,
-                     Proxy::DBUS_PATH_EMAIL_STORAGE_CHANGE,
-                     Proxy::DBUS_IFACE_EMAIL_STORAGE_CHANGE)
+        common::dbus::Proxy(kDBusPathEmailStorageChange,
+                     kDBusIfaceEmailStorageChange,
+                     kDBusNameSignalEmail,
+                     kDBusPathEmailStorageChange,
+                     kDBusIfaceEmailStorageChange)
 {
 }
 
index 81e8a3bc452d47b3c22c82b60f44fdc000ee9890..04a89683e945fcf5f099d08b9554638c1618af3d 100644 (file)
@@ -25,7 +25,7 @@
 #include <string>
 #include <sstream>
 #include <email-types.h>
-#include "Proxy.h"
+#include "common/GDBus/proxy.h"
 #include "common/platform_result.h"
 
 namespace extension {
@@ -35,7 +35,7 @@ namespace DBus {
 class MessageProxy;
 typedef std::shared_ptr<MessageProxy> MessageProxyPtr;
 
-class MessageProxy: public Proxy {
+class MessageProxy: public common::dbus::Proxy {
 public:
     virtual ~MessageProxy();
     static common::PlatformResult create(MessageProxyPtr* message_proxy);
diff --git a/src/messaging/DBus/Proxy.cpp b/src/messaging/DBus/Proxy.cpp
deleted file mode 100644 (file)
index 2dddfb1..0000000
+++ /dev/null
@@ -1,152 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2013 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.
-//
-
-/**
- * @file        Proxy.cpp
- */
-
-#include "Proxy.h"
-#include "common/logger.h"
-#include "common/platform_result.h"
-#include <cstring>
-#include <email-types.h>
-#include "../message_service.h"
-
-namespace extension {
-namespace messaging {
-namespace DBus {
-
-using namespace common;
-
-const char* Proxy::DBUS_PATH_NETWORK_STATUS = "/User/Email/NetworkStatus";
-const char* Proxy::DBUS_IFACE_NETWORK_STATUS = "User.Email.NetworkStatus";
-const char* Proxy::DBUS_PATH_EMAIL_STORAGE_CHANGE = "/User/Email/StorageChange";
-const char* Proxy::DBUS_IFACE_EMAIL_STORAGE_CHANGE = "User.Email.StorageChange";
-const char* Proxy::DBUS_NAME_SIGNAL_EMAIL = "email";
-
-Proxy::Proxy(const std::string& proxy_path,
-            const std::string& proxy_iface,
-            const std::string& signal_name,
-            const std::string& signal_path,
-            const std::string& signal_iface) :
-                m_conn(Connection::getInstance()),
-                m_sub_id(0),
-                m_path(proxy_path),
-                m_iface(proxy_iface),
-                m_signal_name(signal_name),
-                m_signal_path(signal_path),
-                m_signal_iface(signal_iface),
-                m_error(NULL),
-                m_dbus_signal_subscribed(false)
-{
-    LoggerD("Proxy:\n"
-            "  proxy_path: %s\n  proxy_iface: %s"
-            "  signal_name: %s\n signal_path:%s\n signal_iface:%s",
-            m_path.c_str(), m_iface.c_str(),
-            m_signal_name.c_str(), m_signal_path.c_str(), m_signal_iface.c_str());
-
-    const gchar* unique_name = g_dbus_connection_get_unique_name(m_conn.getDBus());
-    LoggerD("Generated unique name: %d", unique_name);
-
-    // path and interface are not obligatory to receive, but
-    // they should be set to send the signals.
-    m_proxy = g_dbus_proxy_new_sync(m_conn.getDBus(),
-            G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
-            NULL, unique_name, m_path.c_str(), m_iface.c_str(), NULL, &m_error);
-}
-
-Proxy::~Proxy()
-{
-    signalUnsubscribe();
-}
-
-void Proxy::signalCallbackProxy(GDBusConnection *connection,
-        const gchar *sender_name,
-        const gchar *object_path,
-        const gchar *interface_name,
-        const gchar *signal_name,
-        GVariant *parameters,
-        gpointer user_data)
-{
-    Proxy* this_ptr = static_cast<Proxy*>(user_data);
-    if (!this_ptr) {
-        LoggerW("Proxy is null, nothing to do");
-        return;
-    }
-
-    //It is better to log this only when subclass is responsible of handling
-    //passed signal. If you need it put it into your signalCallback(...) method
-    //LoggerD("signal: %s from: %s path: %s interface: %s",
-    //        signal_name, sender_name, object_path, interface_name);
-    this_ptr->signalCallback(connection, sender_name, object_path, interface_name,
-            signal_name, parameters);
-}
-
-void Proxy::signalSubscribe()
-{
-    if(m_dbus_signal_subscribed) {
-        LoggerW("Proxy has already subscribed for listening DBus signal");
-        return;
-    }
-
-    const char* sender = NULL;
-    m_sub_id = g_dbus_connection_signal_subscribe(m_conn.getDBus(),
-            sender,
-            m_signal_iface.c_str(),
-            m_signal_name.c_str(),
-            m_signal_path.c_str(),
-            NULL,
-            G_DBUS_SIGNAL_FLAGS_NONE,
-            signalCallbackProxy,
-            static_cast<gpointer>(this),
-            NULL);
-    LoggerD("g_dbus_connection_signal_subscribe returned id: %d", m_sub_id);
-
-    m_dbus_signal_subscribed = true;
-}
-
-void Proxy::signalUnsubscribe()
-{
-    if (!m_dbus_signal_subscribed) {
-        LoggerW("Proxy hasn't subscribed for listening DBus signal");
-        return;
-    }
-
-    g_dbus_connection_signal_unsubscribe(m_conn.getDBus(), m_sub_id);
-    LoggerD("g_dbus_connection_signal_unsubscribe finished");
-
-    m_dbus_signal_subscribed = false;
-}
-
-const std::string& Proxy::getSignalName() const
-{
-    return m_signal_name;
-}
-
-const std::string& Proxy::getSignalPath() const
-{
-    return m_signal_path;
-}
-
-const std::string& Proxy::getSignalInterfaceName() const
-{
-    return m_signal_iface;
-}
-
-} //namespace DBus
-} //namespace Messaging
-} //namespace DeviceAPI
diff --git a/src/messaging/DBus/Proxy.h b/src/messaging/DBus/Proxy.h
deleted file mode 100644 (file)
index 8162251..0000000
+++ /dev/null
@@ -1,128 +0,0 @@
-//
-// Tizen Web Device API
-// Copyright (c) 2013 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.
-//
-
-/**
- * @file        Proxy.h
- */
-
-#ifndef __TIZEN_DBUS_PROXY_H__
-#define __TIZEN_DBUS_PROXY_H__
-
-#include "Connection.h"
-#include <memory>
-#include <string>
-#include <mutex>
-#include <map>
-#include "common/callback_user_data.h"
-#include "common/picojson.h"
-#include "common/platform_result.h"
-#include "../messaging_instance.h"
-
-namespace extension {
-namespace messaging {
-namespace DBus {
-
-
-class Proxy;
-typedef std::shared_ptr<Proxy> ProxyPtr;
-
-/**
- * This is generic dbus signal listener proxy.
- */
-class Proxy {
-public:
-    /**
-     * List of Tizen path and interface names:
-     */
-    static const char* DBUS_PATH_NETWORK_STATUS;
-    static const char* DBUS_IFACE_NETWORK_STATUS;
-    static const char* DBUS_PATH_EMAIL_STORAGE_CHANGE;
-    static const char* DBUS_IFACE_EMAIL_STORAGE_CHANGE;
-    /**
-     * Name of email signal
-     */
-    static const char* DBUS_NAME_SIGNAL_EMAIL;
-    virtual ~Proxy();
-    bool isNotProxyGot() { return !m_proxy || m_error; };
-
-    void signalSubscribe();
-    void signalUnsubscribe();
-
-    const std::string& getSignalName() const;
-    const std::string& getSignalPath() const;
-    const std::string& getSignalInterfaceName() const;
-
-protected:
-    /**
-     * @param proxy_path - path of this proxy
-     * @param proxy_iface - interface name of this proxy
-     *
-     * @param signal_name - expected signal name
-     * @param signal_path - expected signal path
-     * @param signal_iface - expected signal interface name
-     */
-    Proxy(const std::string& proxy_path,
-            const std::string& proxy_iface,
-            const std::string& signal_name,
-            const std::string& signal_path,
-            const std::string& signal_iface);
-    /**
-     * Please implement this method in subclass to handle signal.
-     * Executed by static void signalCallbackProxy(...).
-     */
-    virtual void signalCallback(GDBusConnection *connection,
-            const gchar *sender_name,
-            const gchar *object_path,
-            const gchar *interface_name,
-            const gchar *signal_name,
-            GVariant *parameters) = 0;
-
-private:
-    /**
-     * This method (registered with g_dbus_connection_signal_subscribe) is executed by
-     * DBus when signal is received. It calls
-     * (static_cast<Proxy*>(user_data))->signalCallback(...)
-     */
-
-    static void signalCallbackProxy(GDBusConnection *connection,
-            const gchar *sender_name,
-            const gchar *object_path,
-            const gchar *interface_name,
-            const gchar *signal_name,
-            GVariant *parameters,
-            gpointer user_data);
-
-    Connection& m_conn;
-    guint m_sub_id;
-
-    std::string m_path;
-    std::string m_iface;
-
-    std::string m_signal_name;
-    std::string m_signal_path;
-    std::string m_signal_iface;
-
-    GError* m_error;
-    GDBusProxy* m_proxy;
-    bool m_dbus_signal_subscribed;
-};
-
-} //namespace DBus
-} //namespace Messaging
-} //namespace DeviceAPI
-
-#endif // __TIZEN_DBUS_PROXY_H__
index be938411315c08ce28d3c8aca5727e3805e4c580..7e567a96107e84b52040c409849978607798e5dc 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <email-types.h>
 #include "../email_manager.h"
+#include "messaging/DBus/DBusTypes.h"
 
 namespace extension {
 namespace messaging {
@@ -29,8 +30,8 @@ namespace DBus {
 using namespace common;
 
 SendProxy::SendProxy():
-        EmailSignalProxy(Proxy::DBUS_PATH_NETWORK_STATUS,
-                     Proxy::DBUS_IFACE_NETWORK_STATUS)
+        EmailSignalProxy(kDBusPathNetworkStatus,
+            kDBusIfaceNetworkStatus)
 {
 }
 
index 070e16f90f7a47b15e0df6e1ace71de9e2f708dd..29dcd09bb401533ba143967c7082f50c5500eb03 100644 (file)
@@ -138,8 +138,7 @@ void SyncProxy::handleEmailSignal(const int status,
         case NOTI_DOWNLOAD_FAIL:
         {
             LoggerD("Sync failed!");
-            common::UnknownException err("Sync failed!");
-            callback->setError(err.name(), err.message());
+            callback->setError("UnknownError", "Sync failed!");
             callback->getQueue().resolve(
                     obj.at(JSON_CALLBACK_ID).get<double>(),
                     response->serialize()
index 7a831cabb732e43e4aadb310a3968e55e46e2669..6af99f0b790d7ae66888d412727fcae7e6f2e6cf 100755 (executable)
@@ -58,6 +58,7 @@
 #include "MsgCommon/FilterIterator.h"
 
 #include "common/scope_exit.h"
+#include "messaging/DBus/DBusTypes.h"
 
 using namespace common;
 using namespace extension::tizen;
@@ -113,8 +114,8 @@ PlatformResult EmailManager::InitializeEmailService()
             instance.m_slot_size = slot_size;
         }
 
-        PlatformResult ret = DBus::SyncProxy::create(DBus::Proxy::DBUS_PATH_NETWORK_STATUS,
-                                                     DBus::Proxy::DBUS_IFACE_NETWORK_STATUS,
+        PlatformResult ret = DBus::SyncProxy::create(DBus::kDBusPathNetworkStatus,
+                                                     DBus::kDBusIfaceNetworkStatus,
                                                      &instance.m_proxy_sync);
         CHECK_ERROR(ret, "create sync proxy failed");
         if (!instance.m_proxy_sync) {
@@ -123,8 +124,8 @@ PlatformResult EmailManager::InitializeEmailService()
         }
         instance.m_proxy_sync->signalSubscribe();
 
-        ret = DBus::LoadBodyProxy::create(DBus::Proxy::DBUS_PATH_NETWORK_STATUS,
-                                          DBus::Proxy::DBUS_IFACE_NETWORK_STATUS,
+        ret = DBus::LoadBodyProxy::create(DBus::kDBusPathNetworkStatus,
+                                          DBus::kDBusIfaceNetworkStatus,
                                           &instance.m_proxy_load_body);
         CHECK_ERROR(ret, "create load body proxy failed");
         if (!instance.m_proxy_load_body) {
index 73b4c4a22a2379384bc50ca341c0f046c02f8e81..a2f752de415baaa56ec63e3d88653d89ac42a718 100755 (executable)
 #include "email-api-mailbox.h"
 
 #include "common/callback_user_data.h"
+#include "common/GDBus/connection.h"
 #include "common/platform_exception.h"
 #include "common/platform_result.h"
 
 #include "messaging_util.h"
 #include "message_service.h"
 
-#include "DBus/Connection.h"
 #include "DBus/SyncProxy.h"
 #include "DBus/LoadBodyProxy.h"
 #include "DBus/LoadAttachmentProxy.h"
index e65e98f3847fe1818b5199c6be2e8f84fcc2b8ba..a92e43409a4bbd834c11bf396d83977b23a119d7 100644 (file)
@@ -58,8 +58,6 @@
         'find_msg_callback_user_data.h',
         'messaging_database_manager.cc',
         'messaging_databese_manager.h',
-        'DBus/Connection.cpp',
-        'DBus/Connection.h',
         'DBus/EmailSignalProxy.cpp',
         'DBus/EmailSignalProxy.h',
         'DBus/LoadAttachmentProxy.cpp',
         'DBus/LoadBodyProxy.h',
         'DBus/MessageProxy.cpp',
         'DBus/MessageProxy.h',
-        'DBus/Proxy.cpp',
-        'DBus/Proxy.h',
         'DBus/SendProxy.cpp',
         'DBus/SendProxy.h',
         'DBus/SyncProxy.cpp',
         'DBus/SyncProxy.h',
+        'DBus/DBusTypes.h',
+        'DBus/DBusTypes.cpp',
         'MsgCommon/Any.cpp',
         'MsgCommon/Any.h',
         'MsgCommon/AbstractFilter.cpp',