Skip to content
Snippets Groups Projects
Commit c09766a0 authored by Stepan Salenikovich's avatar Stepan Salenikovich
Browse files

dbus: add dbus error handler interface

The default implementation of this interface throws an exception,
as before, but the clients now have the option to implement an
alternative way to handle dbus errors.

Issue: #79654
Change-Id: I9e929e97b84e78432151d285199ccf09d90e4c01
parent bbbd227a
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
/****************************************************************************
* 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,6 +18,9 @@
***************************************************************************/
#include "callmanager.h"
#include "../globalinstances.h"
#include "../interfaces/dbuserrorhandleri.h"
CallManagerInterface * DBus::CallManager::interface = nullptr;
CallManagerInterface & DBus::CallManager::instance(){
......@@ -29,10 +32,15 @@ CallManagerInterface & DBus::CallManager::instance(){
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(!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;
}
/****************************************************************************
* 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,6 +18,9 @@
***************************************************************************/
#include "configurationmanager.h"
#include "../globalinstances.h"
#include "../interfaces/dbuserrorhandleri.h"
ConfigurationManagerInterface* DBus::ConfigurationManager::interface = nullptr;
ConfigurationManagerInterface& DBus::ConfigurationManager::instance()
......@@ -31,11 +34,15 @@ ConfigurationManagerInterface& DBus::ConfigurationManager::instance()
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.";
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"
);
}
if (!interface->isValid())
throw "DRing daemon not available, be sure it running";
#endif
return *interface;
}
/****************************************************************************
* 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()
......@@ -32,7 +36,9 @@ InstanceInterface& DBus::InstanceManager::instance()
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.";
GlobalInstances::dBusErrorHandler().connectionError(
"Error : dring not connected. Service " + interface->service() + " not connected. From instance interface."
);
}
static bool registered = false;
if (!registered) {
......@@ -40,6 +46,11 @@ InstanceInterface& DBus::InstanceManager::instance()
registered = true;
reply.waitForFinished();
}
if (!interface->isValid()) {
GlobalInstances::dBusErrorHandler().invalidInterfaceError(
"Error : dring is not available, make sure it is running"
);
}
#endif
return *interface;
}
/****************************************************************************
* 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,6 +17,9 @@
***************************************************************************/
#include "presencemanager.h"
#include "../globalinstances.h"
#include "../interfaces/dbuserrorhandleri.h"
PresenceManagerInterface* DBus::PresenceManager::interface = nullptr;
PresenceManagerInterface& DBus::PresenceManager::instance()
......@@ -28,9 +31,15 @@ PresenceManagerInterface& DBus::PresenceManager::instance()
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.";
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;
......
/****************************************************************************
* 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,6 +17,9 @@
***************************************************************************/
#include "videomanager.h"
#include "../globalinstances.h"
#include "../interfaces/dbuserrorhandleri.h"
VideoManagerInterface* DBus::VideoManager::interface = nullptr;
VideoManagerInterface& DBus::VideoManager::instance()
......@@ -29,7 +32,14 @@ VideoManagerInterface& DBus::VideoManager::instance()
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.";
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;
......
/****************************************************************************
* 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
/****************************************************************************
* 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
......@@ -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"
......@@ -38,6 +40,7 @@ struct InstanceManager
{
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;
......@@ -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 )
......
......@@ -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 *);
......
/****************************************************************************
* 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment