diff --git a/CMakeLists.txt b/CMakeLists.txt index 9326894b3f11223b7fc2933cfbdd668c0613b0b1..aa88fe04fc43dc4610ab1a0ee60a9a60181399f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -295,6 +295,7 @@ SET( libringclient_LIB_SRCS src/pixmapmanipulatordefault.cpp src/profilepersisterdefault.cpp src/shortcutcreatordefault.cpp + src/dbuserrorhandlerdefault.cpp #Other src/categorizedcompositenode.cpp @@ -400,6 +401,7 @@ SET( libringclient_LIB_HDRS src/pixmapmanipulatordefault.h src/profilepersisterdefault.h src/shortcutcreatordefault.h + src/dbuserrorhandlerdefault.h ) SET(libringclient_video_LIB_HDRS @@ -450,6 +452,7 @@ SET(libringclient_interface_LIB_HDRS src/interfaces/pixmapmanipulatori.h src/interfaces/profilepersisteri.h src/interfaces/shortcutcreatori.h + src/interfaces/dbuserrorhandleri.h ) SET( libringclient_extra_LIB_HDRS diff --git a/src/dbus/callmanager.cpp b/src/dbus/callmanager.cpp index 8a061082ec05015c922a54b49ef28125dbe4279c..dfd4ac695d8d30bfb60d5183ff23a80f915855d0 100644 --- a/src/dbus/callmanager.cpp +++ b/src/dbus/callmanager.cpp @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (C) 2009-2014 by Savoir-Faire Linux * + * Copyright (C) 2009-2015 by Savoir-faire Linux * * Author : Jérémy Quentin <jeremy.quentin@savoirfairelinux.com> * * Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> * * * @@ -18,21 +18,29 @@ ***************************************************************************/ #include "callmanager.h" +#include "../globalinstances.h" +#include "../interfaces/dbuserrorhandleri.h" + CallManagerInterface * DBus::CallManager::interface = nullptr; CallManagerInterface & DBus::CallManager::instance(){ #ifdef ENABLE_LIBWRAP - if (!interface) + if (!interface) interface = new CallManagerInterface(); #else - if (!dbus_metaTypeInit) registerCommTypes(); - if (!interface) - interface = new CallManagerInterface( "cx.ring.Ring", "/cx/ring/Ring/CallManager", QDBusConnection::sessionBus()); - if(!interface->connection().isConnected()) - throw "Error : dring not connected. Service " + interface->service() + " not connected. From call manager interface."; - if (!interface->isValid()) - throw "Dring daemon not available, be sure it running"; + if (!dbus_metaTypeInit) registerCommTypes(); + if (!interface) + interface = new CallManagerInterface( "cx.ring.Ring", "/cx/ring/Ring/CallManager", QDBusConnection::sessionBus()); + if(!interface->connection().isConnected()) { + GlobalInstances::dBusErrorHandler().connectionError( + "Error : dring not connected. Service " + interface->service() + " not connected. From call manager interface." + ); + } if (!interface->isValid()) { + GlobalInstances::dBusErrorHandler().invalidInterfaceError( + "Error : dring is not available, make sure it is running" + ); + } #endif - return *interface; + return *interface; } diff --git a/src/dbus/configurationmanager.cpp b/src/dbus/configurationmanager.cpp index 348321f5a058adcc86146d792dd383ac35ef929d..ec7dc25be5d6104c46933c4a8dda52b8f6855edc 100644 --- a/src/dbus/configurationmanager.cpp +++ b/src/dbus/configurationmanager.cpp @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (C) 2009-2014 by Savoir-Faire Linux * + * Copyright (C) 2009-2015 by Savoir-faire Linux * * Author : Jérémy Quentin <jeremy.quentin@savoirfairelinux.com> * * Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> * * * @@ -18,24 +18,31 @@ ***************************************************************************/ #include "configurationmanager.h" +#include "../globalinstances.h" +#include "../interfaces/dbuserrorhandleri.h" + ConfigurationManagerInterface* DBus::ConfigurationManager::interface = nullptr; ConfigurationManagerInterface& DBus::ConfigurationManager::instance() { #ifdef ENABLE_LIBWRAP - if (!interface) { + if (!interface) { interface = new ConfigurationManagerInterface(); } #else - if (!dbus_metaTypeInit) registerCommTypes(); - if (!interface) - interface = new ConfigurationManagerInterface("cx.ring.Ring", "/cx/ring/Ring/ConfigurationManager", QDBusConnection::sessionBus()); - if(!interface->connection().isConnected()) { - qDebug() << "Error : dring not connected. Service " << interface->service() << " not connected. From configuration manager interface."; - throw "Error : dring not connected. Service " + interface->service() + " not connected. From configuration manager interface."; - } - if (!interface->isValid()) - throw "DRing daemon not available, be sure it running"; + if (!dbus_metaTypeInit) registerCommTypes(); + if (!interface) + interface = new ConfigurationManagerInterface("cx.ring.Ring", "/cx/ring/Ring/ConfigurationManager", QDBusConnection::sessionBus()); + if(!interface->connection().isConnected()) { + GlobalInstances::dBusErrorHandler().connectionError( + "Error : dring not connected. Service " + interface->service() + " not connected. From configuration manager interface." + ); + } + if (!interface->isValid()) { + GlobalInstances::dBusErrorHandler().invalidInterfaceError( + "Error : dring is not available, make sure it is running" + ); + } #endif - return *interface; + return *interface; } diff --git a/src/dbus/instancemanager.cpp b/src/dbus/instancemanager.cpp index 8f50b31d29916a28b3948fa99e1bafeaea11fb9f..88f30eb3056c8f9e53cac1c6201ceb25a659e49e 100644 --- a/src/dbus/instancemanager.cpp +++ b/src/dbus/instancemanager.cpp @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (C) 2009-2014 by Savoir-Faire Linux * + * Copyright (C) 2009-2015 by Savoir-faire Linux * * Author : Jérémy Quentin <jeremy.quentin@savoirfairelinux.com> * * Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> * * * @@ -18,8 +18,12 @@ ***************************************************************************/ #include "instancemanager.h" + #include <unistd.h> +#include "../globalinstances.h" +#include "../interfaces/dbuserrorhandleri.h" + InstanceInterface* DBus::InstanceManager::interface = nullptr; InstanceInterface& DBus::InstanceManager::instance() @@ -28,18 +32,25 @@ InstanceInterface& DBus::InstanceManager::instance() if (!interface) interface = new InstanceInterface(); #else - if (!dbus_metaTypeInit) registerCommTypes(); - if (!interface) - interface = new InstanceInterface("cx.ring.Ring", "/cx/ring/Ring/Instance", QDBusConnection::sessionBus()); - if(!interface->connection().isConnected()) { - throw "Error : dring not connected. Service " + interface->service() + " not connected. From instance interface."; - } - static bool registered = false; - if (!registered) { - QDBusPendingReply<QString> reply = interface->Register(getpid(), ""); - registered = true; - reply.waitForFinished(); - } + if (!dbus_metaTypeInit) registerCommTypes(); + if (!interface) + interface = new InstanceInterface("cx.ring.Ring", "/cx/ring/Ring/Instance", QDBusConnection::sessionBus()); + if (!interface->connection().isConnected()) { + GlobalInstances::dBusErrorHandler().connectionError( + "Error : dring not connected. Service " + interface->service() + " not connected. From instance interface." + ); + } + static bool registered = false; + if (!registered) { + QDBusPendingReply<QString> reply = interface->Register(getpid(), ""); + registered = true; + reply.waitForFinished(); + } + if (!interface->isValid()) { + GlobalInstances::dBusErrorHandler().invalidInterfaceError( + "Error : dring is not available, make sure it is running" + ); + } #endif - return *interface; + return *interface; } diff --git a/src/dbus/presencemanager.cpp b/src/dbus/presencemanager.cpp index 77a0c3f29123b26b0b5fb10f38414269b27d1851..94e6743eae60d0080bbae7bc28e21b132bc8da9d 100644 --- a/src/dbus/presencemanager.cpp +++ b/src/dbus/presencemanager.cpp @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (C) 2013-2014 by Savoir-Faire Linux * + * Copyright (C) 2013-2015 by Savoir-faire Linux * * Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> * * * * This library is free software; you can redistribute it and/or * @@ -17,21 +17,30 @@ ***************************************************************************/ #include "presencemanager.h" +#include "../globalinstances.h" +#include "../interfaces/dbuserrorhandleri.h" + PresenceManagerInterface* DBus::PresenceManager::interface = nullptr; PresenceManagerInterface& DBus::PresenceManager::instance() { #ifdef ENABLE_LIBWRAP - if (!interface) - interface = new PresenceManagerInterface(); + if (!interface) + interface = new PresenceManagerInterface(); #else - if (!dbus_metaTypeInit) registerCommTypes(); - if (!interface) - interface = new PresenceManagerInterface("cx.ring.Ring", "/cx/ring/Ring/PresenceManager", QDBusConnection::sessionBus()); - - if(!interface->connection().isConnected()) { - throw "Error : dring not connected. Service " + interface->service() + " not connected. From instance interface."; - } + if (!dbus_metaTypeInit) registerCommTypes(); + if (!interface) + interface = new PresenceManagerInterface("cx.ring.Ring", "/cx/ring/Ring/PresenceManager", QDBusConnection::sessionBus()); + if (!interface->connection().isConnected()) { + GlobalInstances::dBusErrorHandler().connectionError( + "Error : dring not connected. Service " + interface->service() + " not connected. From presence interface." + ); + } + if (!interface->isValid()) { + GlobalInstances::dBusErrorHandler().invalidInterfaceError( + "Error : dring is not available, make sure it is running" + ); + } #endif - return *interface; + return *interface; } diff --git a/src/dbus/videomanager.cpp b/src/dbus/videomanager.cpp index 03d770f623151f1c4130e6232a5d846146bc8e67..713f085cefcc18a9bd0ba94844a4e91e8013e586 100644 --- a/src/dbus/videomanager.cpp +++ b/src/dbus/videomanager.cpp @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (C) 2012-2014 by Savoir-Faire Linux * + * Copyright (C) 2012-2015 by Savoir-faire Linux * * Author : Emmanuel Lepage Vallee <emmanuel.lepage@savoirfairelinux.com> * * * * This library is free software; you can redistribute it and/or * @@ -17,20 +17,30 @@ ***************************************************************************/ #include "videomanager.h" +#include "../globalinstances.h" +#include "../interfaces/dbuserrorhandleri.h" + VideoManagerInterface* DBus::VideoManager::interface = nullptr; VideoManagerInterface& DBus::VideoManager::instance() { #ifdef ENABLE_LIBWRAP - if (!interface) - interface = new VideoManagerInterface(); + if (!interface) + interface = new VideoManagerInterface(); #else - if (!dbus_metaTypeInit) registerCommTypes(); - if (!interface) - interface = new VideoManagerInterface("cx.ring.Ring", "/cx/ring/Ring/VideoManager", QDBusConnection::sessionBus()); - if(!interface->connection().isConnected()) { - throw "Error : dring not connected. Service " + interface->service() + " not connected. From instance interface."; - } + if (!dbus_metaTypeInit) registerCommTypes(); + if (!interface) + interface = new VideoManagerInterface("cx.ring.Ring", "/cx/ring/Ring/VideoManager", QDBusConnection::sessionBus()); + if (!interface->connection().isConnected()) { + GlobalInstances::dBusErrorHandler().connectionError( + "Error : dring not connected. Service " + interface->service() + " not connected. From video manager interface." + ); + } + if (!interface->isValid()) { + GlobalInstances::dBusErrorHandler().invalidInterfaceError( + "Error : dring is not available, make sure it is running" + ); + } #endif return *interface; } diff --git a/src/dbuserrorhandlerdefault.cpp b/src/dbuserrorhandlerdefault.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4fe3781bd7396f6aa4baf59aaee3c82100cdd43e --- /dev/null +++ b/src/dbuserrorhandlerdefault.cpp @@ -0,0 +1,36 @@ +/**************************************************************************** + * Copyright (C) 2015 by Savoir-faire Linux * + * Author : Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ +#include "dbuserrorhandlerdefault.h" + +namespace Interfaces { + +void +DBusErrorHandlerDefault::connectionError(const QString& error) +{ + qDebug() << error; + throw error.toLatin1().constData(); +} + +void +DBusErrorHandlerDefault::invalidInterfaceError(const QString& error) +{ + qDebug() << error; + throw error.toLatin1().constData(); +} + +} // namespace Interfaces diff --git a/src/dbuserrorhandlerdefault.h b/src/dbuserrorhandlerdefault.h new file mode 100644 index 0000000000000000000000000000000000000000..aca17b589e8e5692e0e3787598d3725413045de1 --- /dev/null +++ b/src/dbuserrorhandlerdefault.h @@ -0,0 +1,35 @@ +/**************************************************************************** + * Copyright (C) 2015 by Savoir-faire Linux * + * Author : Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ +#pragma once + +#include <typedefs.h> + +#include "interfaces/dbuserrorhandleri.h" + +namespace Interfaces { + +/** + * This implementation of the DBusErrorHandler interface throws an exception with the given message. + */ +class LIB_EXPORT DBusErrorHandlerDefault : public DBusErrorHandlerI { +public: + [[noreturn]] void connectionError(const QString& error) override; + [[noreturn]] void invalidInterfaceError(const QString& error) override; +}; + +} // namespace Interfaces diff --git a/src/globalinstances.cpp b/src/globalinstances.cpp index 9a073cedba75b39a4f9a9dba64d2ed15eb55638b..ce99c507d9a7fcdff0398643261b0da07969bdc6 100644 --- a/src/globalinstances.cpp +++ b/src/globalinstances.cpp @@ -21,6 +21,7 @@ #include "interfaces/accountlistcolorizeri.h" #include "interfaces/contactmethodselectori.h" +#include "interfaces/dbuserrorhandleri.h" #include "interfaces/itemmodelstateserializeri.h" #include "interfaces/pixmapmanipulatori.h" #include "interfaces/presenceserializeri.h" @@ -28,6 +29,7 @@ #include "interfaces/shortcutcreatori.h" #include "accountlistcolorizerdefault.h" +#include "dbuserrorhandlerdefault.h" #include "pixmapmanipulatordefault.h" #include "presenceserializerdefault.h" #include "shortcutcreatordefault.h" @@ -36,13 +38,14 @@ namespace GlobalInstances { struct InstanceManager { - std::unique_ptr<Interfaces::AccountListColorizerI> m_accountListColorizer; - std::unique_ptr<Interfaces::ContactMethodSelectorI> m_contactMethodSelector; - std::unique_ptr<Interfaces::ItemModelStateSerializerI> m_itemModelStateSerializer; - std::unique_ptr<Interfaces::PixmapManipulatorI> m_pixmapManipulator; - std::unique_ptr<Interfaces::PresenceSerializerI> m_presenceSerializer; - std::unique_ptr<Interfaces::ProfilePersisterI> m_profilePersister; - std::unique_ptr<Interfaces::ShortcutCreatorI> m_shortcutCreator; + std::unique_ptr<Interfaces::AccountListColorizerI> m_accountListColorizer; + std::unique_ptr<Interfaces::ContactMethodSelectorI> m_contactMethodSelector; + std::unique_ptr<Interfaces::DBusErrorHandlerI> m_dBusErrorHandler; + std::unique_ptr<Interfaces::ItemModelStateSerializerI> m_itemModelStateSerializer; + std::unique_ptr<Interfaces::PixmapManipulatorI> m_pixmapManipulator; + std::unique_ptr<Interfaces::PresenceSerializerI> m_presenceSerializer; + std::unique_ptr<Interfaces::ProfilePersisterI> m_profilePersister; + std::unique_ptr<Interfaces::ShortcutCreatorI> m_shortcutCreator; }; static InstanceManager& @@ -94,6 +97,25 @@ setContactMethodSelector(std::unique_ptr<Interfaces::ContactMethodSelectorI> ins instanceManager().m_contactMethodSelector = std::move(instance); } +Interfaces::DBusErrorHandlerI& +dBusErrorHandler() +{ + if (!instanceManager().m_dBusErrorHandler) + instanceManager().m_dBusErrorHandler.reset(new Interfaces::DBusErrorHandlerDefault); + return *instanceManager().m_dBusErrorHandler; +} + +void +setDBusErrorHandler(std::unique_ptr<Interfaces::DBusErrorHandlerI> instance) +{ + // do not allow empty pointers + if (!instance) { + qWarning() << "ignoring empty unique_ptr"; + return; + } + instanceManager().m_dBusErrorHandler = std::move(instance); +} + /** * LRC does not provide a default implementation of this interface, thus an exception will be thrown * if this getter is called without an instance being set by the client @@ -221,6 +243,7 @@ void setInterfaceInternal(I* i)\ REGISTER_INTERFACE(Interfaces::AccountListColorizerI , m_accountListColorizer ) REGISTER_INTERFACE(Interfaces::ContactMethodSelectorI , m_contactMethodSelector ) +REGISTER_INTERFACE(Interfaces::DBusErrorHandlerI , m_dBusErrorHandler ) REGISTER_INTERFACE(Interfaces::ItemModelStateSerializerI, m_itemModelStateSerializer) REGISTER_INTERFACE(Interfaces::PixmapManipulatorI , m_pixmapManipulator ) REGISTER_INTERFACE(Interfaces::PresenceSerializerI , m_presenceSerializer ) diff --git a/src/globalinstances.h b/src/globalinstances.h index c173df8aa3e884237c722166c0939bf739d8aaf3..2a88772a6bea369de150d4adf31fbbf1fa389773 100644 --- a/src/globalinstances.h +++ b/src/globalinstances.h @@ -24,6 +24,7 @@ namespace Interfaces { class AccountListColorizerI; class ContactMethodSelectorI; +class DBusErrorHandlerI; class ItemModelStateSerializerI; class PixmapManipulatorI; class PresenceSerializerI; @@ -51,6 +52,9 @@ void setAccountListColorizer(std::unique_ptr<Interfaces::AccountListColorizerI> Interfaces::ContactMethodSelectorI& contactMethodSelector(); void setContactMethodSelector(std::unique_ptr<Interfaces::ContactMethodSelectorI> instance); +Interfaces::DBusErrorHandlerI& dBusErrorHandler(); +void setDBusErrorHandler(std::unique_ptr<Interfaces::DBusErrorHandlerI> instance); + /** * LRC does not provide a default implementation of this interface, thus an exception will be thrown * if this getter is called without an instance being set by the client @@ -79,6 +83,7 @@ void setShortcutCreatorI(std::unique_ptr<Interfaces::ShortcutCreatorI> instance) //Private use only void setInterfaceInternal(Interfaces::AccountListColorizerI *); void setInterfaceInternal(Interfaces::ContactMethodSelectorI *); +void setInterfaceInternal(Interfaces::DBusErrorHandlerI *); void setInterfaceInternal(Interfaces::ItemModelStateSerializerI*); void setInterfaceInternal(Interfaces::PixmapManipulatorI *); void setInterfaceInternal(Interfaces::PresenceSerializerI *); diff --git a/src/interfaces/dbuserrorhandleri.h b/src/interfaces/dbuserrorhandleri.h new file mode 100644 index 0000000000000000000000000000000000000000..8426ae8669e996cb27f2985161c49a5c0dad992d --- /dev/null +++ b/src/interfaces/dbuserrorhandleri.h @@ -0,0 +1,35 @@ +/**************************************************************************** + * Copyright (C) 2015 by Savoir-faire Linux * + * Author : Stepan Salenikovich <stepan.salenikovich@savoirfairelinux.com>* + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ +#pragma once + +#include <typedefs.h> + +namespace Interfaces { + +/** + * Some clients may not have a nice way to generally handle exceptions event wide (ie: handle any + * exception which may occur during an itteration or an event on the main loop). This interface + * gives them the option to implement various ways to handle dbus errors. + */ +class DBusErrorHandlerI { +public: + virtual void connectionError(const QString& error) = 0; + virtual void invalidInterfaceError(const QString& error) = 0; +}; + +} // namespace Interfaces