From: Lukasz Foniok Date: Tue, 9 Jun 2015 14:52:29 +0000 (+0200) Subject: [Common] Moving GDBus base class to common module X-Git-Tag: submit/tizen/20150702.103311^2~2^2~58^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bba705df980d5780737f5b426feb3160d1ea2bb7;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Common] Moving GDBus base class to common module [Verification] Messaging test should not degradate Change-Id: Ia344144c9afa609c27f93133f99457ab396a5ea1 Signed-off-by: Lukasz Foniok --- diff --git a/src/common/GDBus/connection.cpp b/src/common/GDBus/connection.cpp new file mode 100644 index 00000000..c5a115d8 --- /dev/null +++ b/src/common/GDBus/connection.cpp @@ -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 + +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 index 00000000..29475fbe --- /dev/null +++ b/src/common/GDBus/connection.h @@ -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 + +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 index 00000000..4f6eeddc --- /dev/null +++ b/src/common/GDBus/proxy.cpp @@ -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 + +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(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(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 index 00000000..ed00283b --- /dev/null +++ b/src/common/GDBus/proxy.h @@ -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 +#include +#include +#include +#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 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(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__ diff --git a/src/common/common.gyp b/src/common/common.gyp index 24337873..b44c3af0 100644 --- a/src/common/common.gyp +++ b/src/common/common.gyp @@ -39,6 +39,10 @@ '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 index d912671d..00000000 --- a/src/messaging/DBus/Connection.cpp +++ /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 -#include -#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 index 07084e32..00000000 --- a/src/messaging/DBus/Connection.h +++ /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 -#include -#include - -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 index 00000000..1a6489d3 --- /dev/null +++ b/src/messaging/DBus/DBusTypes.cpp @@ -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 index 00000000..0c9c56f0 --- /dev/null +++ b/src/messaging/DBus/DBusTypes.h @@ -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 diff --git a/src/messaging/DBus/EmailSignalProxy.cpp b/src/messaging/DBus/EmailSignalProxy.cpp index ab80f51b..f00a37d5 100644 --- a/src/messaging/DBus/EmailSignalProxy.cpp +++ b/src/messaging/DBus/EmailSignalProxy.cpp @@ -22,6 +22,7 @@ #include "EmailSignalProxy.h" #include "common/logger.h" #include +#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) { } diff --git a/src/messaging/DBus/EmailSignalProxy.h b/src/messaging/DBus/EmailSignalProxy.h index 9791f4b3..01687a17 100644 --- a/src/messaging/DBus/EmailSignalProxy.h +++ b/src/messaging/DBus/EmailSignalProxy.h @@ -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 EmailSignalProxyPtr; -class EmailSignalProxy : public Proxy { +class EmailSignalProxy : public common::dbus::Proxy { public: virtual ~EmailSignalProxy(); diff --git a/src/messaging/DBus/MessageProxy.cpp b/src/messaging/DBus/MessageProxy.cpp index b986adef..536435d8 100644 --- a/src/messaging/DBus/MessageProxy.cpp +++ b/src/messaging/DBus/MessageProxy.cpp @@ -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 #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) { } diff --git a/src/messaging/DBus/MessageProxy.h b/src/messaging/DBus/MessageProxy.h index 81e8a3bc..04a89683 100644 --- a/src/messaging/DBus/MessageProxy.h +++ b/src/messaging/DBus/MessageProxy.h @@ -25,7 +25,7 @@ #include #include #include -#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 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 index 2dddfb1b..00000000 --- a/src/messaging/DBus/Proxy.cpp +++ /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 -#include -#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(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(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 index 81622511..00000000 --- a/src/messaging/DBus/Proxy.h +++ /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 -#include -#include -#include -#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 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(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__ diff --git a/src/messaging/DBus/SendProxy.cpp b/src/messaging/DBus/SendProxy.cpp index be938411..7e567a96 100644 --- a/src/messaging/DBus/SendProxy.cpp +++ b/src/messaging/DBus/SendProxy.cpp @@ -21,6 +21,7 @@ #include #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) { } diff --git a/src/messaging/DBus/SyncProxy.cpp b/src/messaging/DBus/SyncProxy.cpp index 070e16f9..29dcd09b 100644 --- a/src/messaging/DBus/SyncProxy.cpp +++ b/src/messaging/DBus/SyncProxy.cpp @@ -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(), response->serialize() diff --git a/src/messaging/email_manager.cc b/src/messaging/email_manager.cc index 7a831cab..6af99f0b 100755 --- a/src/messaging/email_manager.cc +++ b/src/messaging/email_manager.cc @@ -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) { diff --git a/src/messaging/email_manager.h b/src/messaging/email_manager.h index 73b4c4a2..a2f752de 100755 --- a/src/messaging/email_manager.h +++ b/src/messaging/email_manager.h @@ -33,13 +33,13 @@ #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" diff --git a/src/messaging/messaging.gyp b/src/messaging/messaging.gyp index e65e98f3..a92e4340 100644 --- a/src/messaging/messaging.gyp +++ b/src/messaging/messaging.gyp @@ -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', @@ -68,12 +66,12 @@ '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',