From bba705df980d5780737f5b426feb3160d1ea2bb7 Mon Sep 17 00:00:00 2001 From: Lukasz Foniok Date: Tue, 9 Jun 2015 16:52:29 +0200 Subject: [PATCH] [Common] Moving GDBus base class to common module [Verification] Messaging test should not degradate Change-Id: Ia344144c9afa609c27f93133f99457ab396a5ea1 Signed-off-by: Lukasz Foniok --- .../GDBus/connection.cpp} | 17 +++------ .../GDBus/connection.h} | 12 +++---- .../DBus/Proxy.cpp => common/GDBus/proxy.cpp} | 22 ++++-------- .../DBus/Proxy.h => common/GDBus/proxy.h} | 25 ++++--------- src/common/common.gyp | 4 +++ src/messaging/DBus/DBusTypes.cpp | 32 +++++++++++++++++ src/messaging/DBus/DBusTypes.h | 36 +++++++++++++++++++ src/messaging/DBus/EmailSignalProxy.cpp | 9 ++--- src/messaging/DBus/EmailSignalProxy.h | 4 +-- src/messaging/DBus/MessageProxy.cpp | 13 +++---- src/messaging/DBus/MessageProxy.h | 4 +-- src/messaging/DBus/SendProxy.cpp | 5 +-- src/messaging/DBus/SyncProxy.cpp | 3 +- src/messaging/email_manager.cc | 9 ++--- src/messaging/email_manager.h | 2 +- src/messaging/messaging.gyp | 6 ++-- 16 files changed, 121 insertions(+), 82 deletions(-) rename src/{messaging/DBus/Connection.cpp => common/GDBus/connection.cpp} (81%) rename src/{messaging/DBus/Connection.h => common/GDBus/connection.h} (85%) rename src/{messaging/DBus/Proxy.cpp => common/GDBus/proxy.cpp} (87%) rename src/{messaging/DBus/Proxy.h => common/GDBus/proxy.h} (84%) create mode 100644 src/messaging/DBus/DBusTypes.cpp create mode 100644 src/messaging/DBus/DBusTypes.h diff --git a/src/messaging/DBus/Connection.cpp b/src/common/GDBus/connection.cpp similarity index 81% rename from src/messaging/DBus/Connection.cpp rename to src/common/GDBus/connection.cpp index d912671d..c5a115d8 100644 --- a/src/messaging/DBus/Connection.cpp +++ b/src/common/GDBus/connection.cpp @@ -15,15 +15,12 @@ // limitations under the License. // -#include "Connection.h" +#include "common/GDBus/connection.h" #include "common/logger.h" #include -#include -#include "../message_service.h" -namespace extension { -namespace messaging { -namespace DBus { +namespace common { +namespace dbus { Connection& Connection::getInstance() { @@ -39,9 +36,6 @@ GDBusConnection* Connection::getDBus() 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"); @@ -54,6 +48,5 @@ Connection::~Connection() g_object_unref(m_dbus); } -} //namespace DBus -} //namespace Messaging -} //namespace DeviceAPI +} //namespace dbus +} //namespace common diff --git a/src/messaging/DBus/Connection.h b/src/common/GDBus/connection.h similarity index 85% rename from src/messaging/DBus/Connection.h rename to src/common/GDBus/connection.h index 07084e32..29475fbe 100644 --- a/src/messaging/DBus/Connection.h +++ b/src/common/GDBus/connection.h @@ -18,13 +18,10 @@ #ifndef __TIZEN_DBUS_CONNECTION_H__ #define __TIZEN_DBUS_CONNECTION_H__ -#include -#include #include -namespace extension { -namespace messaging { -namespace DBus { +namespace common { +namespace dbus { class Connection { public: @@ -42,8 +39,7 @@ private: GError* m_error; }; -} //namespace DBus -} //namespace Messaging -} //namespace DeviceAPI +} //namespace dbus +} //namespace common #endif diff --git a/src/messaging/DBus/Proxy.cpp b/src/common/GDBus/proxy.cpp similarity index 87% rename from src/messaging/DBus/Proxy.cpp rename to src/common/GDBus/proxy.cpp index 2dddfb1b..4f6eeddc 100644 --- a/src/messaging/DBus/Proxy.cpp +++ b/src/common/GDBus/proxy.cpp @@ -16,28 +16,19 @@ // /** - * @file Proxy.cpp + * @file proxy.cpp */ -#include "Proxy.h" +#include "common/GDBus/proxy.h" #include "common/logger.h" #include "common/platform_result.h" #include -#include -#include "../message_service.h" -namespace extension { -namespace messaging { -namespace DBus { +namespace common { +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, @@ -147,6 +138,5 @@ const std::string& Proxy::getSignalInterfaceName() const return m_signal_iface; } -} //namespace DBus -} //namespace Messaging -} //namespace DeviceAPI +} //namespace dbus +} //namespace common diff --git a/src/messaging/DBus/Proxy.h b/src/common/GDBus/proxy.h similarity index 84% rename from src/messaging/DBus/Proxy.h rename to src/common/GDBus/proxy.h index 81622511..ed00283b 100644 --- a/src/messaging/DBus/Proxy.h +++ b/src/common/GDBus/proxy.h @@ -22,7 +22,7 @@ #ifndef __TIZEN_DBUS_PROXY_H__ #define __TIZEN_DBUS_PROXY_H__ -#include "Connection.h" +#include "common/GDBus/connection.h" #include #include #include @@ -30,11 +30,9 @@ #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 { +namespace common { +namespace dbus { class Proxy; @@ -45,17 +43,7 @@ typedef std::shared_ptr ProxyPtr; */ 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; }; @@ -121,8 +109,7 @@ private: bool m_dbus_signal_subscribed; }; -} //namespace DBus -} //namespace Messaging -} //namespace DeviceAPI +} //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/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/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', -- 2.34.1