D-Bus server: simplified server class

Instad of having three of the helper classes as members,
only store pointers to them in Server. The advantage is
that including Server.h becomes simpler for .cpp files
which do not need to use these classes and that they
can be constructed/destructed more explicitly. This is
particularly important because they get access to the
Server instance which is still in the process of
initializing itself.
This commit is contained in:
Patrick Ohly 2012-08-13 22:12:55 +02:00
parent de44e4b8cd
commit f0c7a3e2da
6 changed files with 55 additions and 19 deletions

View file

@ -21,6 +21,7 @@
#include "session.h"
#include "server.h"
#include "dbus-callbacks.h"
#include "presence-status.h"
#include <glib.h>
#include <glib/gi18n.h>

View file

@ -19,6 +19,7 @@
#include "connman-client.h"
#include "server.h"
#include "presence-status.h"
SE_BEGIN_CXX

View file

@ -20,6 +20,7 @@
#include "network-manager-client.h"
#include "server.h"
#include "presence-status.h"
SE_BEGIN_CXX

View file

@ -33,6 +33,9 @@
#include "restart.h"
#include "client.h"
#include "auto-sync-manager.h"
#include "connman-client.h"
#include "network-manager-client.h"
#include "presence-status.h"
#include <boost/pointer_cast.hpp>
@ -207,7 +210,7 @@ void Server::checkPresence(const std::string &server,
std::string &status,
std::vector<std::string> &transports)
{
return m_presence.checkPresence(server, status, transports);
return getPresenceStatus().checkPresence(server, status, transports);
}
void Server::getSessions(std::vector<DBusObject_t> &sessions)
@ -246,9 +249,6 @@ Server::Server(GMainLoop *loop,
configChanged(*this, "ConfigChanged"),
infoRequest(*this, "InfoRequest"),
logOutput(*this, "LogOutput"),
m_presence(*this),
m_connman(*this),
m_networkManager(*this),
m_autoTerm(m_loop, m_shutdownRequested, duration),
m_parentLogger(LoggerBase::instance())
{
@ -280,26 +280,40 @@ Server::Server(GMainLoop *loop,
add(infoRequest);
add(logOutput);
// log entering and leaving idle state
m_idleSignal.connect(boost::bind(logIdle, _1));
// connect ConfigChanged signal to source for that information
m_configChangedSignal.connect(boost::bind(boost::ref(configChanged)));
}
void Server::activate()
{
// Activate our D-Bus object *before* interacting with D-Bus
// any further. Otherwise GIO D-Bus will start processing
// messages for us while we start up and reject them because
// out object isn't visible to it yet.
GDBusCXX::DBusObjectHelper::activate();
LoggerBase::pushLogger(this);
setLevel(LoggerBase::DEBUG);
m_presence.reset(new PresenceStatus(*this));
// Assume that Bluetooth is available. Neither ConnMan nor Network
// manager can tell us about that. The "Bluetooth" ConnMan technology
// is about IP connection via Bluetooth - not what we need.
getPresenceStatus().updatePresenceStatus(true, PresenceStatus::BT_TRANSPORT);
if (!m_connman.isAvailable() &&
!m_networkManager.isAvailable()) {
m_connman.reset(new ConnmanClient(*this));
m_networkManager.reset(new NetworkManagerClient(*this));
if ((!m_connman || !m_connman->isAvailable()) &&
(!m_networkManager || !m_networkManager->isAvailable())) {
// assume that we are online if no network manager was found at all
getPresenceStatus().updatePresenceStatus(true, PresenceStatus::HTTP_TRANSPORT);
}
// log entering and leaving idle state
m_idleSignal.connect(boost::bind(logIdle, _1));
// connect ConfigChanged signal to source for that information
m_configChangedSignal.connect(boost::bind(boost::ref(configChanged)));
// create auto sync manager, now that server is ready
m_autoSync = AutoSyncManager::createAutoSyncManager(*this);
}
@ -314,6 +328,9 @@ Server::~Server()
m_infoReqMap.clear();
m_timeouts.clear();
m_delayDeletion.clear();
m_connman.reset();
m_networkManager.reset();
m_presence.reset();
LoggerBase::popLogger();
}
@ -760,6 +777,14 @@ void Server::removeInfoReq(const std::string &id)
m_infoReqMap.erase(id);
}
PresenceStatus &Server::getPresenceStatus()
{
if (!m_presence) {
SE_THROW("internal error: Server::getPresenceStatus() called while server has no instance");
}
return *m_presence;
}
void Server::getDeviceList(SyncConfig::DeviceList &devices)
{
//wait bluez or other device managers

View file

@ -26,13 +26,13 @@
#include <boost/weak_ptr.hpp>
#include <boost/signals2.hpp>
#include <syncevo/SyncConfig.h>
#include "exceptions.h"
#include "auto-term.h"
#include "connman-client.h"
#include "network-manager-client.h"
#include "presence-status.h"
#include "timeout.h"
#include "dbus-callbacks.h"
#include "read-operations.h"
#include <syncevo/declarations.h>
SE_BEGIN_CXX
@ -46,6 +46,12 @@ class Restart;
class Client;
class GLibNotify;
class AutoSyncManager;
class PresenceStatus;
class ConnmanClient;
class NetworkManagerClient;
// TODO: avoid polluting namespace
using namespace std;
/**
* Implements the main org.syncevolution.Server interface.
@ -345,9 +351,9 @@ class Server : public GDBusCXX::DBusObjectHelper,
/** remove InfoReq from hash map */
void removeInfoReq(const std::string &infoReqId);
PresenceStatus m_presence;
ConnmanClient m_connman;
NetworkManagerClient m_networkManager;
boost::scoped_ptr<PresenceStatus> m_presence;
boost::scoped_ptr<ConnmanClient> m_connman;
boost::scoped_ptr<NetworkManagerClient> m_networkManager;
/** Manager to automatic sync */
boost::shared_ptr<AutoSyncManager> m_autoSync;
@ -381,6 +387,7 @@ public:
boost::shared_ptr<Restart> &restart,
const GDBusCXX::DBusConnectionPtr &conn,
int duration);
void activate();
~Server();
/** access to the GMainLoop reference used by this Server instance */
@ -558,7 +565,7 @@ public:
/** poll_nm callback for connman, used for presence detection*/
void connmanCallback(const std::map <std::string, boost::variant <std::vector <std::string> > >& props, const string &error);
PresenceStatus& getPresenceStatus() {return m_presence;}
PresenceStatus& getPresenceStatus();
void clearPeerTempls() { m_matchedTempls.clear(); }
void addPeerTempl(const string &templName, const boost::shared_ptr<SyncConfig::TemplateDescription> peerTempl);

View file

@ -25,6 +25,7 @@
#include "info-req.h"
#include "session-common.h"
#include "dbus-callbacks.h"
#include "presence-status.h"
#include <syncevo/ForkExec.h>
#include <syncevo/SyncContext.h>