b34591dd62
DBusCallObject and friends were not used anywhere. Removed. DBusObject and DBusRemoteObject used pure virtual methods to let derived classes provide information about interface, path, destination, method and the connection. The idea behind that was that most of these strings are static and thus do not need to be copied. The downside is that one had to derive from these classes in order to provide the required information. The same class could not own two instances of the generic DBusObject to access two different destinations. It also sprinkled the code for setting up D-Bus operations into several different places (constructor, class definition). Now the information is passed to the DBus[Remote]Object constructor and stored in the classes, which are thus merely containers for the information and thus easier to use. Users of the classes still derive from them, to keep the change smaller, although that is no longer necessary. Removed plain DBusConnection pointers from the C++ interface, return DBusConnectionPtr instead. The exception is DBusObject, which still returns plain pointers owned by the instance (as before) to ease integration with the underlying D-Bus library. DBUS_CONNECTION_TYPE is not needed. This revealed that quite some code incorrectly took another reference to the connection when assigning to DBusConnectionPtr (assignment always increases the refcount, only in the constructor is that optional). As a result the private connections were never destructed. Apparently there were some global pointers to active connections, so that this (minor) resource leak didn't show up in valgrind. It also showed that the closing of the D-Bus connection never happened properly, although libdbus requires it. The ref counting mechanism cannot be used for this because it cannot be checked whether the last reference is about to be dropped. The slightly hackish solution is to designate one DBusObject as the "main owner" of the connection. When that object destructs, it closes the connection. There might still be some other references; they simply cannot (and shouldn't) send or receive messages anymore.
89 lines
2.5 KiB
C++
89 lines
2.5 KiB
C++
/*
|
|
* Copyright (C) 2011 Intel Corporation
|
|
*
|
|
* 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) version 3.
|
|
*
|
|
* 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 Lesser General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
* 02110-1301 USA
|
|
*/
|
|
|
|
#ifndef NETWORK_MANAGER_CLIENT_H
|
|
#define NETWORK_MANAGER_CLIENT_H
|
|
|
|
#include <boost/variant.hpp>
|
|
|
|
#include "gdbus-cxx-bridge.h"
|
|
|
|
#include <syncevo/declarations.h>
|
|
SE_BEGIN_CXX
|
|
|
|
class Server;
|
|
|
|
/**
|
|
* Client for org.freedesktop.NetworkManager
|
|
* The initial state of NetworkManager is queried via
|
|
* org.freedesktop.DBus.Properties. Dynamic changes are listened via
|
|
* org.freedesktop.NetworkManager - StateChanged signal
|
|
*/
|
|
class NetworkManagerClient : public GDBusCXX::DBusRemoteObject
|
|
{
|
|
public:
|
|
enum NM_State
|
|
{
|
|
NM_STATE_UNKNOWN = 0,
|
|
|
|
/* following values for NM < 0.9 */
|
|
NM_STATE_ASLEEP_DEPRECATED = 1,
|
|
NM_STATE_CONNECTING_DEPRECATED = 2,
|
|
NM_STATE_CONNECTED_DEPRECATED = 3,
|
|
NM_STATE_DISCONNECTED_DEPRECATED = 4,
|
|
|
|
/* following values for NM >= 0.9 */
|
|
NM_STATE_ASLEEP = 10,
|
|
NM_STATE_DISCONNECTED = 20,
|
|
NM_STATE_DISCONNECTING = 30,
|
|
NM_STATE_CONNECTING = 40,
|
|
NM_STATE_CONNECTED_LOCAL = 50,
|
|
NM_STATE_CONNECTED_SITE = 60,
|
|
NM_STATE_CONNECTED_GLOBAL = 70,
|
|
};
|
|
public:
|
|
NetworkManagerClient(Server& server);
|
|
|
|
void stateChanged(uint32_t uiState);
|
|
|
|
/** TRUE if watching Network Manager status */
|
|
bool isAvailable() { return getConnection() != NULL; }
|
|
|
|
private:
|
|
|
|
class NetworkManagerProperties : public DBusRemoteObject
|
|
{
|
|
public:
|
|
NetworkManagerProperties(NetworkManagerClient& manager);
|
|
|
|
void get();
|
|
void getCallback(const boost::variant<uint32_t, std::string> &prop,
|
|
const std::string &error);
|
|
private:
|
|
NetworkManagerClient &m_manager;
|
|
};
|
|
|
|
Server &m_server;
|
|
GDBusCXX::SignalWatch1<uint32_t> m_stateChanged;
|
|
NetworkManagerProperties m_properties;
|
|
};
|
|
|
|
SE_END_CXX
|
|
|
|
#endif // NETWORK_MANAGER_CLIENT_H
|