Browse Source

A daemon based on dbus-1-tqt to replace the old tde_dbus_hardwarecontrol daemon

Signed-off-by: Emanoil Kotsev <deloptes@gmail.com>
Emanoil Kotsev 1 year ago
parent
commit
c2804a0792
  1. 3
      tdecore/tdehw/hwlibdaemons/CMakeLists.txt
  2. 72
      tdecore/tdehw/hwlibdaemons/tdedbus/BrightnessService.cpp
  3. 49
      tdecore/tdehw/hwlibdaemons/tdedbus/BrightnessService.h
  4. 74
      tdecore/tdehw/hwlibdaemons/tdedbus/CMakeLists.txt
  5. 73
      tdecore/tdehw/hwlibdaemons/tdedbus/CPUGovernorService.cpp
  6. 46
      tdecore/tdehw/hwlibdaemons/tdedbus/CPUGovernorService.h
  7. 68
      tdecore/tdehw/hwlibdaemons/tdedbus/DeviceServiceBase.cpp
  8. 45
      tdecore/tdehw/hwlibdaemons/tdedbus/DeviceServiceBase.h
  9. 118
      tdecore/tdehw/hwlibdaemons/tdedbus/HardwareControl.cpp
  10. 81
      tdecore/tdehw/hwlibdaemons/tdedbus/HardwareControl.h
  11. 112
      tdecore/tdehw/hwlibdaemons/tdedbus/InputEventsService.cpp
  12. 51
      tdecore/tdehw/hwlibdaemons/tdedbus/InputEventsService.h
  13. 277
      tdecore/tdehw/hwlibdaemons/tdedbus/PowerService.cpp
  14. 73
      tdecore/tdehw/hwlibdaemons/tdedbus/PowerService.h
  15. 63
      tdecore/tdehw/hwlibdaemons/tdedbus/PropertiesService.cpp
  16. 56
      tdecore/tdehw/hwlibdaemons/tdedbus/PropertiesService.h
  17. 123
      tdecore/tdehw/hwlibdaemons/tdedbus/hardwarecontrolService.cpp
  18. 114
      tdecore/tdehw/hwlibdaemons/tdedbus/hardwarecontrolService.h
  19. 52
      tdecore/tdehw/hwlibdaemons/tdedbus/interfaces/CMakeLists.txt
  20. 96
      tdecore/tdehw/hwlibdaemons/tdedbus/interfaces/org.trinitydesktop.hardwarecontrol.xml
  21. 31
      tdecore/tdehw/hwlibdaemons/tdedbus/main.cpp
  22. 62
      tdecore/tdehw/hwlibdaemons/tdedbus/org.trinitydesktop.hardwarecontrol.conf
  23. 4
      tdecore/tdehw/hwlibdaemons/tdedbus/org.trinitydesktop.hardwarecontrol.service.cmake

3
tdecore/tdehw/hwlibdaemons/CMakeLists.txt

@ -10,4 +10,5 @@
#################################################
add_subdirectory( dbus )
#add_subdirectory( dbus )
add_subdirectory( tdedbus )

72
tdecore/tdehw/hwlibdaemons/tdedbus/BrightnessService.cpp

@ -0,0 +1,72 @@
/*
* BrightnessService.cpp
*
* Created on: Feb 1, 2021
* Author: emanoil
*
* hardwarecontrol Copyright (C) 2021 trinity desktop development team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <tqregexp.h>
#include "BrightnessService.h"
BrightnessService::BrightnessService(TQT_DBusConnection &conn)
: DeviceServiceBase(conn)
{
// TODO Auto-generated constructor stub
}
BrightnessService::~BrightnessService()
{
// TODO Auto-generated destructor stub
}
/*!
* Implement virtual methods
*
*/
bool BrightnessService::CanSetBrightness(const TQString& device, bool& value, TQT_DBusError& error) {
if (device.find( TQRegExp("^/sys/devices.*/brightness$"),0) == 0 ) {
value = canSetDeviceValue(device, error);
} else {
error = TQT_DBusError::stdInvalidArgs(TQString ("Invalid argument for device: " + device));
}
if (error.isValid()) {
tqDebug(error.message().local8Bit());
return false;
}
return true;
}
bool BrightnessService::SetBrightness(const TQString& device, const TQString& brightness, bool& value, TQT_DBusError& error) {
if (device.find( TQRegExp("^/sys/devices.*/brightness$"),0) == 0) {
value = setDeviceValue(device, brightness, error);
} else {
error = TQT_DBusError::stdInvalidArgs(TQString ("Invalid argument for device: " + device));
}
if (error.isValid()) {
tqDebug(error.message().local8Bit());
return false;
}
return true;
}
void BrightnessService::handleMethodReply(const TQT_DBusMessage& reply) {
m_connection->send(reply);
}

49
tdecore/tdehw/hwlibdaemons/tdedbus/BrightnessService.h

@ -0,0 +1,49 @@
/*
* BrightnessService.h
*
* Created on: Feb 1, 2021
* Author: emanoil
*
* hardwarecontrol Copyright (C) 2021 trinity desktop development team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef BRIGHTNESSSERVICE_H_
#define BRIGHTNESSSERVICE_H_
#include <tqdbusconnection.h>
#include "interfaces/brightnessInterface.h"
#include "DeviceServiceBase.h"
class BrightnessService: public org::trinitydesktop::hardwarecontrol::BrightnessInterface,
public DeviceServiceBase
{
public:
BrightnessService(TQT_DBusConnection&);
virtual ~BrightnessService();
protected:
virtual bool CanSetBrightness(const TQString& device, bool& value, TQT_DBusError& error);
virtual bool SetBrightness(const TQString& device, const TQString& brightness, bool& value, TQT_DBusError& error);
protected: // implement sending replies
void handleMethodReply(const TQT_DBusMessage& reply);
//
// virtual void BrightnessServiceAsync(int asyncCallId, const TQT_DBusObjectPath& device, const TQString& uuid);
};
#endif /* BRIGHTNESSSERVICE_H_ */

74
tdecore/tdehw/hwlibdaemons/tdedbus/CMakeLists.txt

@ -0,0 +1,74 @@
#################################################
#
# (C) 2020 Emanoil Kotsev
# deloptes (AT) gmail.com
#
# Improvements and feedback are welcome
#
# This file is released under GPL >= 3
#
#################################################
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TQT_CXX_FLAGS}" )
set( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined" )
#-Wl,--whole-archive
set( CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--no-undefined" )
##### configure checks ##########################
if( NOT DBUS_SYS_DIR )
set( DBUS_SYS_DIR ${SYSCONF_INSTALL_DIR}/dbus-1/system.d )
endif( )
if( WITH_GCC_VISIBILITY )
if( NOT UNIX )
tde_message_fatal(FATAL_ERROR "\ngcc visibility support was requested, but your system is not *NIX" )
endif( NOT UNIX )
set( __KDE_HAVE_GCC_VISIBILITY 1 )
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden")
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden")
endif( )
add_definitions(
# -DQT_THREAD_SUPPORT
${TQT_CFLAGS_OTHER}
)
add_subdirectory( interfaces )
include_directories(
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_SOURCE_DIR}
${CMAKE_BINARY_DIR}
${CMAKE_BINARY_DIR}/interfaces
${TDE_INCLUDE_DIR}
${TQT_INCLUDE_DIRS}
${DBUS_TQT_INCLUDE_DIRS}
)
link_directories(
${TQT_LIBRARY_DIRS}
${TDE_LIB_DIR}
)
##### tde_dbus_hardwarecontrol ##################
tde_add_executable( tde_dbus_hardwarecontrol AUTOMOC
SOURCES HardwareControl.cpp main.cpp hardwarecontrolService.cpp
BrightnessService.cpp CPUGovernorService.cpp DeviceServiceBase.cpp
InputEventsService.cpp PowerService.cpp PropertiesService.cpp
LINK ${DBUS_TQT_LIBRARIES} hwcontrolinterfaces-static tdecore-shared
DESTINATION ${BIN_INSTALL_DIR}
)
##### other data ################################
configure_file( org.trinitydesktop.hardwarecontrol.service.cmake org.trinitydesktop.hardwarecontrol.service @ONLY )
install( FILES
org.trinitydesktop.hardwarecontrol.conf
DESTINATION ${DBUS_SYSTEM_CONF_DIRECTORY} )
install( FILES
${CMAKE_CURRENT_BINARY_DIR}/org.trinitydesktop.hardwarecontrol.service
DESTINATION ${DBUS_SERVICE_DIRECTORY} )

73
tdecore/tdehw/hwlibdaemons/tdedbus/CPUGovernorService.cpp

@ -0,0 +1,73 @@
/*
* CPUGovernorService.cpp
*
* Created on: Feb 1, 2021
* Author: emanoil
*
* hardwarecontrol Copyright (C) 2021 trinity desktop development team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "CPUGovernorService.h"
CPUGovernorService::CPUGovernorService(TQT_DBusConnection &conn)
: DeviceServiceBase(conn)
{
// TODO Auto-generated constructor stub
}
CPUGovernorService::~CPUGovernorService()
{
// TODO Auto-generated destructor stub
}
/*!
* Implement virtual methods
*
*/
bool CPUGovernorService::CanSetCPUGovernor(TQ_INT32 cpu, bool& value, TQT_DBusError& error) {
// do something
TQString dev = TQString("/sys/devices/system/cpu/cpu%1/cpufreq/scaling_governor").arg(cpu);
if ((cpu>-1)) {
value = canSetDeviceValue(dev, error);
} else {
error = TQT_DBusError::stdInvalidArgs(TQString ("Invalid argument cpu: %1, governor: %2").arg(cpu).arg(dev));
}
if (error.isValid()) {
tqDebug(error.message().local8Bit());
return false;
}
return true;
}
bool CPUGovernorService::SetCPUGovernor(TQ_INT32 cpu, const TQString& governor, bool& value, TQT_DBusError& error) {
TQString dev = TQString("/sys/devices/system/cpu/cpu%1/cpufreq/scaling_governor").arg(cpu);
if ((cpu>-1) && !governor.isEmpty()) {
value = setDeviceValue(dev, governor, error);
} else {
error = TQT_DBusError::stdInvalidArgs(TQString ("Invalid argument cpu: %1, governor: %2").arg(cpu).arg(governor));
}
if (error.isValid()) {
tqDebug(error.message().local8Bit());
return false;
}
return true;
}
void CPUGovernorService::handleMethodReply(const TQT_DBusMessage& reply) {
m_connection->send(reply);
}

46
tdecore/tdehw/hwlibdaemons/tdedbus/CPUGovernorService.h

@ -0,0 +1,46 @@
/*
* CPUGovernorService.h
*
* Created on: Feb 1, 2021
* Author: emanoil
*
* hardwarecontrol Copyright (C) 2021 trinity desktop development team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef CPUGOVERNORSERVICE_H_
#define CPUGOVERNORSERVICE_H_
#include "interfaces/cpugovernorInterface.h"
#include "DeviceServiceBase.h"
class CPUGovernorService: public org::trinitydesktop::hardwarecontrol::CPUGovernorInterface,
public DeviceServiceBase
{
public:
CPUGovernorService(TQT_DBusConnection&);
virtual ~CPUGovernorService();
protected:
virtual bool CanSetCPUGovernor(TQ_INT32 cpu, bool& value, TQT_DBusError& error) ;
virtual bool SetCPUGovernor(TQ_INT32 cpu, const TQString& governor, bool& value, TQT_DBusError& error);
protected: // implement sending replies
void handleMethodReply(const TQT_DBusMessage& reply);
//
// virtual void CPUGovernorServiceAsync(int asyncCallId, const TQT_DBusObjectPath& device, const TQString& uuid);
};
#endif /* CPUGOVERNORSERVICE_H_ */

68
tdecore/tdehw/hwlibdaemons/tdedbus/DeviceServiceBase.cpp

@ -0,0 +1,68 @@
/*
* DeviceServiceBase.cpp
*
* Created on: Feb 1, 2021
* Author: emanoil
*
* hardwarecontrol Copyright (C) 2021 trinity desktop development team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <unistd.h>
#include <tqfile.h>
#include <tqtextstream.h>
#include <tqdbuserror.h>
#include "DeviceServiceBase.h"
DeviceServiceBase::DeviceServiceBase(TQT_DBusConnection &conn)
: m_connection(&conn)
{
// TODO Auto-generated constructor stub
}
DeviceServiceBase::~DeviceServiceBase()
{
if (m_connection)
delete m_connection;
}
bool DeviceServiceBase::canSetDeviceValue(const TQString& device, TQT_DBusError& error) {
// check if path is writable
int rval = access (device.latin1(), W_OK);
if (rval != 0)
return false;
return true;
}
bool DeviceServiceBase::setDeviceValue(const TQString& device, const TQString& param, TQT_DBusError& error) {
// make sure path is writable
if (canSetDeviceValue(device, error)) {
TQFile file(device);
if (!file.open( IO_WriteOnly ) ) {
error = TQT_DBusError::stdFailed(TQString ("Could not open device %1").arg(device));
return false;
}
TQTextStream stream( &file );
stream << param;
file.close();
} else {
error = TQT_DBusError::stdFailed(TQString ("Could not access device %1").arg(device));
return false;
}
return true;
}

45
tdecore/tdehw/hwlibdaemons/tdedbus/DeviceServiceBase.h

@ -0,0 +1,45 @@
/*
* DeviceServiceBase.h
*
* Created on: Feb 1, 2021
* Author: emanoil
*
* hardwarecontrol Copyright (C) 2021 trinity desktop development team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef DEVICESERVICEBASE_H_
#define DEVICESERVICEBASE_H_
#include <tqstring.h>
#include <tqdbusconnection.h>
class DeviceServiceBase
{
public:
DeviceServiceBase(TQT_DBusConnection&);
virtual ~DeviceServiceBase();
protected:
bool canSetDeviceValue(const TQString& device, TQT_DBusError& error);
bool setDeviceValue(const TQString& device, const TQString& param, TQT_DBusError& error);
protected: // implement sending replies
virtual void handleMethodReply(const TQT_DBusMessage& reply) = 0;
protected:
TQT_DBusConnection *m_connection;
};
#endif /* DEVICESERVICEBASE_H_ */

118
tdecore/tdehw/hwlibdaemons/tdedbus/HardwareControl.cpp

@ -0,0 +1,118 @@
/*
* HardwareControl.cpp
*
* Created on: Feb 2, 2021
* Author: emanoil
*
* hardwarecontrol Copyright (C) 2021 trinity desktop development team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <tqtimer.h>
#include <tqdbusmessage.h>
#include "HardwareControl.h"
#define DBUS_HWCTRL_SERVICE_NAME "org.trinitydesktop.hardwarecontrol"
#define DBUS_CONNECTION_TIMEOUT 4000
#define DBUS_CONNECTION_RETRY 3
HardwareControl::HardwareControl(int &argc, char **argv, bool GUIenabled, bool SMenabled) :
TQApplication(argc, argv, GUIenabled, SMenabled)
{
retryCount=0;
// init session connection to dbus
if (!initDBUS()) {
tqDebug("Failed to initialize the connection to DBus");
TQTimer::singleShot(DBUS_CONNECTION_TIMEOUT, this, TQT_SLOT(slotReconnect()));
retryCount++;
}
}
HardwareControl::~HardwareControl()
{
// close D-Bus connection
close();
delete hardwarecontrolService;
delete trinitydesktopService;
delete orgService;
delete rootService;
}
bool HardwareControl::initDBUS(){
m_connection = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus, DBUS_HWCTRL_SERVICE_NAME);
if ( !m_connection.isConnected() ) {
tqDebug("Failed to open connection to system message bus: "
+ m_connection.lastError().message());
return false;
}
// try to get a specific service name
if (!m_connection.requestName(DBUS_HWCTRL_SERVICE_NAME, TQT_DBusConnection::NoReplace))
return false;
m_connection.scheduleDispatch();
m_connection.connect(this, TQT_SLOT(slotDbusSignal(const TQT_DBusMessage&)));
TQTimer::singleShot(10, this, TQT_SLOT(slotConnectionCheck()));
return true;
}
void HardwareControl::close() {
if(m_connection.isConnected()) {
m_connection.disconnect(this, TQT_SLOT(slotDbusSignal(const TQT_DBusMessage&)));
m_connection.closeConnection(DBUS_HWCTRL_SERVICE_NAME);
}
}
void HardwareControl::slotReconnect() {
close();
if (!initDBUS()) {
if (DBUS_CONNECTION_RETRY > retryCount) {
tqFatal("Failed to initialize the connection to DBus");
}
TQTimer::singleShot(DBUS_CONNECTION_TIMEOUT, this, TQT_SLOT(slotReconnect()));
retryCount++;
}
}
void HardwareControl::slotDbusSignal(const TQT_DBusMessage& message) {
if (message.interface() != TQString("org.freedesktop.DBus"))
return;
if (message.member() != TQString("NameAcquired"))
return;
tqDebug("Name acquired: " + message[0].toString());
serviceName = message[0].toString();
}
void HardwareControl::slotConnectionCheck() {
if (serviceName != DBUS_HWCTRL_SERVICE_NAME) {
tqFatal("TDEHW service already running or no unique name possible.");
}
rootService = new RootNodeService(m_connection);
orgService = new OrgNodeService(m_connection);
trinitydesktopService = new TrinityDesktopNodeService(m_connection);
hardwarecontrolService = new HardwareControlNodeService(m_connection);
tqDebug("TDEHW service setup done.");
}
#include "HardwareControl.moc"

81
tdecore/tdehw/hwlibdaemons/tdedbus/HardwareControl.h

@ -0,0 +1,81 @@
/*
* HardwareControl.h
*
* Created on: Feb 2, 2021
* Author: emanoil
*
* hardwarecontrol Copyright (C) 2021 trinity desktop development team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef HARDWARECONTROL_H_
#define HARDWARECONTROL_H_
#include <tqapplication.h>
#include "hardwarecontrolService.h"
class HardwareControl: public TQApplication
{
TQ_OBJECT
public:
HardwareControl(int &argc, char **argv, bool GUIenabled, bool SMenabled);
virtual ~HardwareControl();
private:
/*!
* This function initialise the connection to the D-Bus daemon.
* \return boolean with the result of the operation
* \retval true if successful initialised D-Bus connection
* \retval false if unsuccessful
*/
bool initDBUS();
//! to close the connection to D-Bus
void close();
RootNodeService *rootService;
OrgNodeService *orgService;
TrinityDesktopNodeService *trinitydesktopService;
HardwareControlNodeService *hardwarecontrolService;
int retryCount;
TQString serviceName;
TQT_DBusConnection m_connection;
private slots:
/*!
* This function does a reconnect to D-Bus.
* \return void
*/
void slotReconnect();
/*!
* This function is to process D-Bus signals.
* \return void
*/
void slotDbusSignal(const TQT_DBusMessage&);
/*!
* This function is to check D-Bus connection.
* and if the name is the unique name prepare the receivers
* If the name is not the unique name it mans the service
* is already running or unique name can not be obtained from
* DBus. In this latter case the application will terminate.
*
* \return void
*/
void slotConnectionCheck();
};
#endif /* HARDWARECONTROL_H_ */

112
tdecore/tdehw/hwlibdaemons/tdedbus/InputEventsService.cpp

@ -0,0 +1,112 @@
/*
* InputEventsService.cpp
*
* Created on: Feb 1, 2021
* Author: emanoil
*
* hardwarecontrol Copyright (C) 2021 trinity desktop development team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <unistd.h>
#include <tqfile.h>
#include <tqtextstream.h>
// Input devices
#include <linux/input.h>
#include <tqvaluelist.h>
#include "InputEventsService.h"
#define BITS_PER_LONG (sizeof(long) * 8)
#define NUM_BITS(x) ((((x) - 1) / BITS_PER_LONG) + 1)
InputEventsService::InputEventsService(TQT_DBusConnection &conn)
: m_connection(&conn)
{
// TODO Auto-generated constructor stub
}
InputEventsService::~InputEventsService()
{
if (m_connection)
delete m_connection;
}
/*!
* Implement virtual methods
*
*/
TQValueList< TQ_UINT32 > InputEventsService::getSwitches(const TQString& device, bool active, TQT_DBusError& error) {
int r;
unsigned long switches[NUM_BITS(EV_CNT)];
TQValueList< TQ_UINT32 > value = TQValueList< TQ_UINT32 >();
if (!device.isEmpty() && (device.find("/dev/input/event") == 0) ) {
TQFile file( device );
if ( !file.open( IO_ReadOnly ) ) {
error = TQT_DBusError::stdFailed(TQString ("Could not open device %1").arg(device));
return value;
}
if( active ) {
r = ioctl(file.handle(), EVIOCGSW(sizeof(switches)), switches);
}
else {
r = ioctl(file.handle(), EVIOCGBIT(EV_SW, EV_CNT), switches);
}
if( r > 0 ) {
// add the arguments to the reply
for( int i = 0; i < sizeof(switches)/sizeof(switches[0]); i++ ) {
value.append( switches[i] );
}
}
else {
error = TQT_DBusError::stdFailed(TQString ("Failed to handle IOCTL for device: " + device));
}
file.close();
} else {
error = TQT_DBusError::stdInvalidArgs(TQString ("Invalid argument for device: " + device));
}
return value;
}
bool InputEventsService::GetProvidedSwitches(const TQString& device, TQValueList< TQ_UINT32 >& value, TQT_DBusError& error) {
value = getSwitches(device, false, error);
if (error.isValid()) {
tqDebug(error.message().local8Bit());
return false;
}
return true;
}
bool InputEventsService::GetActiveSwitches(const TQString& device, TQValueList< TQ_UINT32 >& value, TQT_DBusError& error) {
value = getSwitches(device, true, error);
if (error.isValid()) {
tqDebug(error.message().local8Bit());
return false;
}
return true;
}
void InputEventsService::handleMethodReply(const TQT_DBusMessage& reply) {
m_connection->send(reply);
}

51
tdecore/tdehw/hwlibdaemons/tdedbus/InputEventsService.h

@ -0,0 +1,51 @@
/*
* InputEventsService.h
*
* Created on: Feb 1, 2021
* Author: emanoil
*
* hardwarecontrol Copyright (C) 2021 trinity desktop development team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef INPUTEVENTSSERVICE_H_
#define INPUTEVENTSSERVICE_H_
#include <tqdbusconnection.h>
#include "interfaces/inputeventsInterface.h"
class InputEventsService: public org::trinitydesktop::hardwarecontrol::InputEventsInterface
{
public:
InputEventsService(TQT_DBusConnection&);
virtual ~InputEventsService();
protected:
TQValueList< TQ_UINT32 > getSwitches(const TQString& device, bool active, TQT_DBusError& error);
virtual bool GetProvidedSwitches(const TQString& device, TQValueList< TQ_UINT32 >& value, TQT_DBusError& error);
virtual bool GetActiveSwitches(const TQString& device, TQValueList< TQ_UINT32 >& value, TQT_DBusError& error);
protected: // implement sending replies
virtual void handleMethodReply(const TQT_DBusMessage& reply);
//
// virtual void InputEventsServiceAsync(int asyncCallId, const TQT_DBusObjectPath& device, const TQString& uuid);
private:
TQT_DBusConnection *m_connection;
};
#endif /* INPUTEVENTSSERVICE_H_ */

277
tdecore/tdehw/hwlibdaemons/tdedbus/PowerService.cpp

@ -0,0 +1,277 @@
/*
* PowerService.cpp
*
* Created on: Feb 1, 2021
* Author: emanoil
*
* hardwarecontrol Copyright (C) 2021 trinity desktop development team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <unistd.h>
//#include <kdebug.h>
#include <tqfile.h>
#include <tqtextstream.h>
#include "PowerService.h"
#define POWER_STATE_PATH "/sys/power/state"
#define POWER_DISK_PATH "/sys/power/disk"
PowerService::PowerService(TQT_DBusConnection &conn)
: DeviceServiceBase(conn)
{
// TODO Auto-generated constructor stub
}
PowerService::~PowerService()
{
// TODO Auto-generated destructor stub
}
bool PowerService::canSetPower(TQString state, TQT_DBusError& error) {
bool method = false;
if (canSetDeviceValue(POWER_STATE_PATH,error)) {
TQFile file1( POWER_STATE_PATH );
if ( file1.open( IO_ReadOnly ) ) {
TQTextStream stream( &file1 );
TQString line = stream.readLine(); // line of text excluding '\n'
if ( line.find(state, 0) != -1 )
method = true;
file1.close();
} else {
error = TQT_DBusError::stdInvalidArgs(TQString ("Can not write device: ").append(POWER_STATE_PATH));
}
}
// send reply
return method;
}
bool PowerService::setPower(TQString state, TQT_DBusError& error) {
bool written = false;
if (canSetPower(state,error)) {
if ( setDeviceValue(POWER_STATE_PATH, state, error) ) {
written = true;
} else {
error = TQT_DBusError::stdFailed(TQString ("Can not set state: " + state));
}
} else {
error = TQT_DBusError::stdFailed(TQString ("Can not write device: ").append(POWER_STATE_PATH));
}
return written;
}
bool PowerService::canSetHibernation(TQString state, TQT_DBusError& error) {
// check if path is writable
bool state_writable = canSetDeviceValue(POWER_STATE_PATH,error);
bool disk_writable = canSetDeviceValue(POWER_DISK_PATH,error);
// check if method is supported
bool method1 = false, method2 = false;
if (state_writable && disk_writable) {
TQFile file1( POWER_STATE_PATH );
if ( file1.open( IO_ReadOnly ) ) {
TQTextStream stream( &file1 );
TQString line = stream.readLine(); // line of text excluding '\n'
if ( line.find("disk", 0) != -1 )
method1 = true;
file1.close();
// kdDebug() << "Method1 for " << state << " is " << method1 << "\n";
} else {
error = TQT_DBusError::stdInvalidArgs(TQString ("Could not open ").append(POWER_STATE_PATH));
return false;
}
TQFile file2(POWER_DISK_PATH);
if ( file2.open( IO_ReadOnly ) ) {
TQTextStream stream( &file2 );
TQString line = stream.readLine(); // line of text excluding '\n'
if ( line.find(state, 0) != -1 )
method2 = true;
file2.close();
} else {
error = TQT_DBusError::stdInvalidArgs(TQString ("Could not open ").append(POWER_DISK_PATH));
return false;
}
}
// send reply
return state_writable && disk_writable && method1 && method2;
}
bool PowerService::setHibernation(TQString state, TQT_DBusError& error) {
// set hibernation state
bool written1 = false, written2 = false;
if (canSetHibernation(state,error)) {
TQFile file1(POWER_DISK_PATH);
if (!file1.open( IO_WriteOnly ) ) {
error = TQT_DBusError::stdFailed(TQString ("Could not open device ").append(POWER_DISK_PATH));
return false;
}
TQTextStream stream1( &file1 );
stream1 << state;
file1.close();
written1 = true;
TQFile file2(POWER_STATE_PATH);
if (!file2.open( IO_WriteOnly ) ) {
error = TQT_DBusError::stdFailed(TQString ("Could not open device ").append(POWER_STATE_PATH));
return false;
}
TQTextStream stream2( &file2 );
stream2 << "disk";
file2.close();
written2 = true;
} else {
error = TQT_DBusError::stdFailed(TQString ("Could not set state: " + state));
return false;
}
return written1 && written2;
}
/*!
* Implement virtual methods
*
*/
bool PowerService::CanStandby(bool& value, TQT_DBusError& error) {
value = canSetPower("standby", error);
if (error.isValid()) {
tqDebug(error.message().local8Bit());
return false;
}
return true;
}
bool PowerService::Standby(bool& value, TQT_DBusError& error) {
value = setPower("standby", error);
if (error.isValid()) {
tqDebug(error.message().local8Bit());
return false;
}
return true;
}
bool PowerService::CanFreeze(bool& value, TQT_DBusError& error) {
value = canSetPower("freeze", error);
if (error.isValid()) {
tqDebug(error.message().local8Bit());
return false;
}
return true;
}
bool PowerService::Freeze(bool& value, TQT_DBusError& error) {
value = setPower("freeze", error);
if (error.isValid()) {
tqDebug(error.message().local8Bit());
return false;
}
return true;
}
bool PowerService::CanSuspend(bool& value, TQT_DBusError& error) {
value = canSetPower("mem", error);
if (error.isValid()) {
tqDebug(error.message().local8Bit());
return false;
}
return true;
}
bool PowerService::Suspend(bool& value, TQT_DBusError& error) {
value = setPower("mem", error);
if (error.isValid()) {
tqDebug(error.message().local8Bit());
return false;
}
return true;
}
bool PowerService::CanHibernate(bool& value, TQT_DBusError& error) {
value = canSetHibernation("platform", error);
if (error.isValid()) {
tqDebug(error.message().local8Bit());
return false;
}
return true;
}
bool PowerService::Hibernate(bool& value, TQT_DBusError& error) {
value = setHibernation("platform", error);
if (error.isValid()) {
tqDebug(error.message().local8Bit());
return false;
}
return true;
}
bool PowerService::CanHybridSuspend(bool& value, TQT_DBusError& error) {
value = canSetHibernation("suspend", error);
if (error.isValid()) {
tqDebug(error.message().local8Bit());
return false;
}
return true;
}
bool PowerService::HybridSuspend(bool& value, TQT_DBusError& error) {
value = setHibernation("suspend", error);
if (error.isValid()) {
tqDebug(error.message().local8Bit());
return false;
}
return true;
}
bool PowerService::CanSetHibernationMethod(bool& value, TQT_DBusError& error) {
value = canSetDeviceValue(POWER_DISK_PATH, error);
if (error.isValid()) {
tqDebug(error.message().local8Bit());
return false;
}
return true;
}
bool PowerService::SetHibernationMethod(const TQString& method, bool& value, TQT_DBusError& error) {
// set hibernation method
if (!method.isEmpty()) {
value = setDeviceValue(POWER_DISK_PATH, method, error);
}
else {
value = false;
error = TQT_DBusError::stdInvalidArgs(TQString ("Invalid argument for method: " + method));
}
if (error.isValid()) {
tqDebug(error.message().local8Bit());
return false;
}
return true;
}
void PowerService::handleMethodReply(const TQT_DBusMessage& reply) {
m_connection->send(reply);
}

73
tdecore/tdehw/hwlibdaemons/tdedbus/PowerService.h

@ -0,0 +1,73 @@
/*
* PowerService.h
*
* Created on: Feb 1, 2021
* Author: emanoil
*
* hardwarecontrol Copyright (C) 2021 trinity desktop development team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef POWERSERVICE_H_
#define POWERSERVICE_H_
#include "interfaces/powerInterface.h"
#include "DeviceServiceBase.h"
class PowerService: public org::trinitydesktop::hardwarecontrol::PowerInterface,
public DeviceServiceBase
{
public:
PowerService(TQT_DBusConnection&);
virtual ~PowerService();
protected:
bool canSetPower(TQString state, TQT_DBusError& error);
bool setPower(TQString state, TQT_DBusError& error);
bool canSetHibernation(TQString state, TQT_DBusError& error);
bool setHibernation(TQString state, TQT_DBusError& error);
virtual bool CanStandby(bool& value, TQT_DBusError& error);
virtual bool Standby(bool& value, TQT_DBusError& error);
virtual bool CanFreeze(bool& value, TQT_DBusError& error);
virtual bool Freeze(bool& value, TQT_DBusError& error);
virtual bool CanSuspend(bool& value, TQT_DBusError& error);
virtual bool Suspend(bool& value, TQT_DBusError& error);
virtual bool CanHibernate(bool& value, TQT_DBusError& error);
virtual bool Hibernate(bool& value, TQT_DBusError& error);
virtual bool CanHybridSuspend(bool& value, TQT_DBusError& error);
virtual bool HybridSuspend(bool& value, TQT_DBusError& error);
virtual bool CanSetHibernationMethod(bool& value, TQT_DBusError& error);
virtual bool SetHibernationMethod(const TQString& method, bool& value, TQT_DBusError& error);
protected: // implement sending replies
void handleMethodReply(const TQT_DBusMessage& reply);
//
// virtual void PowerServiceAsync(int asyncCallId, const TQT_DBusObjectPath& device, const TQString& uuid);
};
#endif /* POWERSERVICE_H_ */

63
tdecore/tdehw/hwlibdaemons/tdedbus/PropertiesService.cpp

@ -0,0 +1,63 @@
/*
* PropertiesService.cpp
*
* Created on: Feb 7, 2021
* Author: emanoil
*
* hardwarecontrol Copyright (C) 2009 hardwarecontrol development team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "PropertiesService.h"
PropertiesService::PropertiesService(TQT_DBusConnection &conn)
: m_connection(&conn)
{
// TODO Auto-generated constructor stub
}
PropertiesService::~PropertiesService()
{
// TODO Auto-generated destructor stub
}
bool PropertiesService::handleSignalSend(const TQT_DBusMessage& reply) {
return true;
}
TQString PropertiesService::objectPath() const {
return TQString();
}
bool PropertiesService::Get(const TQString& interface, const TQString& name, TQT_DBusVariant& value, TQT_DBusError& error) {
return true;
}
bool PropertiesService::Set(const TQString& interface, const TQString& name, const TQT_DBusVariant& value, TQT_DBusError& error) {
return true;
}
bool PropertiesService::GetAll(const TQString& interface, TQMap< TQString, TQT_DBusVariant >& properties, TQT_DBusError& error) {
properties = TQMap< TQString, TQT_DBusVariant >();
return true;
}
void PropertiesService::handleMethodReply(const TQT_DBusMessage& reply){
m_connection->send(reply);
}

56
tdecore/tdehw/hwlibdaemons/tdedbus/PropertiesService.h

@ -0,0 +1,56 @@
/*
* PropertiesService.h
*
* Created on: Feb 7, 2021
* Author: emanoil
*
* hardwarecontrol Copyright (C) 2009 hardwarecontrol development team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef PROPERTIESSERVICE_H_
#define PROPERTIESSERVICE_H_
#include <tqmap.h>
#include <tqdbusconnection.h>
#include <tqdbusvariant.h>
#include "interfaces/propertiesInterface.h"
class PropertiesService: public org::freedesktop::DBus::PropertiesInterface
{
public:
PropertiesService(TQT_DBusConnection&);
virtual ~PropertiesService();
protected: // implement sending signals
virtual bool handleSignalSend(const TQT_DBusMessage& reply);
virtual TQString objectPath() const;
protected:
virtual bool Get(const TQString& interface, const TQString& name, TQT_DBusVariant& value, TQT_DBusError& error);
virtual bool Set(const TQString& interface, const TQString& name, const TQT_DBusVariant& value, TQT_DBusError& error);
virtual bool GetAll(const TQString& interface, TQMap< TQString, TQT_DBusVariant >& properties, TQT_DBusError& error);
protected: // implement sending replies
virtual void handleMethodReply(const TQT_DBusMessage& reply);
private:
TQT_DBusConnection *m_connection;
};
#endif /* PROPERTIESSERVICE_H_ */

123
tdecore/tdehw/hwlibdaemons/tdedbus/hardwarecontrolService.cpp

@ -0,0 +1,123 @@
/*
*
* HardwareControl DBus Service implementation
*
* Copyright (C) 2020 Emanoil Kotsev <deloptes@gmail.com>
*
*
* This file is part of tdecore/tdehw.
*
* hardwarecontrol is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* hardwarecontrol 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 tdelibs; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
// TQt includes
#include <tqdbusobjectpath.h>
#include "hardwarecontrolService.h"
#include "interfaces/introspectableInterface.h"
#include "interfaces/propertiesInterface.h"
#include "DeviceServiceBase.h"
#include "BrightnessService.h"
#include "CPUGovernorService.h"
#include "InputEventsService.h"
#include "PowerService.h"
#include "PropertiesService.h"
/*!
* Implementing node services for /org/trinitydesktop/hardwarecontrol
*/
#define DBUS_HWCTRL_SERVICE_PATH "/org/trinitydesktop/hardwarecontrol"
/*
* Root Node
*/
RootNodeService::RootNodeService(TQT_DBusConnection &connection )
: DBusBaseNode(), m_connection(connection)
{
addChildNode(TQString("org"));
registerObject(m_connection,TQString("/"));
}
RootNodeService::~RootNodeService(){
}
TQT_DBusObjectBase* RootNodeService::createInterface(const TQString& interfaceName)
{
return (TQT_DBusObjectBase*) m_interfaces[interfaceName];