From 3c32b869c2208758c2027d094c8930592370858a Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Sun, 15 Apr 2012 17:53:42 -0500 Subject: Rename dbusHAL class to something more sensible --- src/dbusInterface.h | 160 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 src/dbusInterface.h (limited to 'src/dbusInterface.h') diff --git a/src/dbusInterface.h b/src/dbusInterface.h new file mode 100644 index 0000000..b0eb0b4 --- /dev/null +++ b/src/dbusInterface.h @@ -0,0 +1,160 @@ + /************************************************************************** + * Copyright (C) 2006-2007 by Danny Kukawka * + * , * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of version 2 of the GNU General Public License * + * as published by the Free Software Foundation. * + * * + * This program 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +/*! +* \file dbusInterface.h +* \brief Headerfile for dbusInterface.cpp and the class \ref dbusInterface. +*/ +/*! +* \class dbusInterface +* \brief class for connection to HAL via D-Bus +* \author Danny Kukawka, , +* \date 2006-2007 +*/ + +#ifndef _DBUSHAL_H_ +#define _DBUSHAL_H_ + +#ifndef DBUS_API_SUBJECT_TO_CHANGE +#define DBUS_API_SUBJECT_TO_CHANGE +#endif + +// Global Header +#ifdef HAVE_CONFIG_H +#include +#endif + +// QT - Header +#include + +// D-Bus Header +#include // needed for dbus_bool_t +#include +#include + +// kpowersave - Header +#include "kpowersave_debug.h" + +#define CK_SERVICE "org.freedesktop.ConsoleKit" +#define CK_MANAGER_IFACE "org.freedesktop.ConsoleKit.Manager" +#define CK_MANAGER_OBJECT "/org/freedesktop/ConsoleKit/Manager" +#define CK_SESSION_IFACE "org.freedesktop.ConsoleKit.Session" + +enum msg_type { + ACPI_EVENT, + DBUS_EVENT, + HAL_DEVICE, + HAL_PROPERTY_CHANGED, + HAL_CONDITION, + CONSOLEKIT_SESSION_ACTIVE, + POLICY_POWER_OWNER_CHANGED +}; + +class dbusInterface : public TQObject{ + Q_OBJECT + + +private: + + //! QT connection to D-Bus + DBusQt::Connection* m_dBusQtConnection; + //! real connection to D-Bus + DBusConnection *dbus_connection; + + //! to store information if KPowersave is connected to D-Bus + /*! + * This boolean represent information about the state of the connection to D-Bus + * \li true: if connected + * \li false: if disconnected + */ + bool dbus_is_connected; + + //! if we could claim the org.freedesktop.Policy.Power interface + /*! + * This boolean represent information if KPowersave could claim the + * org.freedesktop.Policy.Power interface from the D-Bus + * \li true: if aquired + * \li false: if not + */ + bool aquiredPolicyPower; + + /* D-Bus helper functions */ + //! to initialise the connection to D-Bus + bool initDBUS(); + //! to call a methode on a dbus interface with reply + bool dbusMethodCall( TQString interface, TQString path, TQString object, TQString method, + DBusBusType dbus_type, void *retvalue, int retval_type, + int first_arg_type, va_list var_args); + +public: + + //! default constructor + dbusInterface(); + //! default destructor + ~dbusInterface(); + + //! to reconnect to D-Bus and HAL + bool reconnect(); + //! to close the connection to D-Bus and HAL + bool close(); + + //! to aquire the org.freedesktop.Policy.Power interface + bool aquirePolicyPowerIface(); + //! to release the org.freedesktop.Policy.Power interface + bool releasePolicyPowerIface(); + //! to check if the org.freedesktop.Policy.Power interface has an owner + bool isPolicyPowerIfaceOwned(); + + // --- helper to get private members of the class --- // + //! to get information if KPowersave is connected to D-Bus + bool isConnectedToDBUS(); + //! to get info about claim org.freedesktop.Policy.Power interface + bool aquiredPolicyPowerInterface(); + + //! return the current DBus connection + DBusConnection *get_DBUS_connection(); + + /* D-Bus helper functions */ + + /* functions to call methodes */ + //! to call a methode on a dbus system bus method without reply + bool dbusSystemMethodCall( TQString interface, TQString path, TQString object, TQString method, + int first_arg_type, ... ); + //! to call a methode on a dbus system bus method with reply + bool dbusSystemMethodCall( TQString interface, TQString path, TQString object, TQString method, + void *retvalue, int retval_type, int first_arg_type, ... ); + + /* PolicyKit call helper */ + //! check if the user has a requested privilege + int isUserPrivileged( TQString privilege, TQString udi, TQString ressource = "", TQString user = TQString()); + + //! wrapper to emit a signal with a event from HAL + void emitMsgReceived( msg_type type, TQString message, TQString string ); + +signals: + //! signal with message to forward from D-Bus to HAL + void msgReceived_withStringString( msg_type, TQString, TQString ); + //! signal if we resumed! + void backFromSuspend( int result ); +}; + +//! filter function to filter out needed information from D-Bus messages +DBusHandlerResult filterFunction (DBusConnection *connection, DBusMessage *message, void *data); + +#endif -- cgit v1.2.3