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

Signed-off-by: Emanoil Kotsev <deloptes@gmail.com>
feat/new_hwcontrol
Emanoil Kotsev 4 years ago
parent b02c573742
commit b0364451f7

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

@ -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);
}

@ -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_ */

@ -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} )

@ -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);
}

@ -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_ */

@ -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;
}

@ -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_ */

@ -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"

@ -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_ */

@ -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);
}

@ -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_ */

@ -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);
}

@ -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_ */

@ -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);
}

@ -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_ */

@ -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];
}
/*
* Org Node
*/
OrgNodeService::OrgNodeService(TQT_DBusConnection &connection )
: DBusBaseNode(), m_connection(connection)
{
addChildNode(TQString("trinitydesktop"));
registerObject(m_connection,TQString("/org"));
}
OrgNodeService::~OrgNodeService(){
}
TQT_DBusObjectBase* OrgNodeService::createInterface(const TQString& interfaceName)
{
return (TQT_DBusObjectBase*) m_interfaces[interfaceName];
}
/*
* TrinityDesktop Node
*/
TrinityDesktopNodeService::TrinityDesktopNodeService(TQT_DBusConnection &connection )
: DBusBaseNode(), m_connection(connection)
{
addChildNode(TQString("hardwarecontrol"));
registerObject(m_connection,TQString("/org/trinitydesktop"));
}
TrinityDesktopNodeService::~TrinityDesktopNodeService(){
}
TQT_DBusObjectBase* TrinityDesktopNodeService::createInterface(const TQString& interfaceName)
{
return (TQT_DBusObjectBase*) m_interfaces[interfaceName];
}
/*
* HardwareControl Node
*/
HardwareControlNodeService::HardwareControlNodeService(TQT_DBusConnection &conn)
: org::trinitydesktop::hardwarecontrolNode(),
m_connection(conn)
{
m_interfaces.insert("org.freedesktop.DBus.Introspectable", this);
m_interfaces.insert("org.freedesktop.DBus.Properties", new PropertiesService(m_connection));
m_interfaces.insert("org.trinitydesktop.hardwarecontrol.Brightness", new BrightnessService(m_connection));
m_interfaces.insert("org.trinitydesktop.hardwarecontrol.CPUGovernor", new CPUGovernorService(m_connection));
m_interfaces.insert("org.trinitydesktop.hardwarecontrol.InputEvents", new InputEventsService(m_connection));
m_interfaces.insert("org.trinitydesktop.hardwarecontrol.Power", new PowerService(m_connection));
registerObject(m_connection,TQString(DBUS_HWCTRL_SERVICE_PATH));
}
HardwareControlNodeService::~HardwareControlNodeService(){
}
TQT_DBusObjectBase* HardwareControlNodeService::createInterface(const TQString& interfaceName)
{
return (TQT_DBusObjectBase*) m_interfaces[interfaceName];
}

@ -0,0 +1,114 @@
/*
*
* 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
*
*/
#ifndef HARDWARECONTROLSERVICE_H
#define HARDWARECONTROLSERVICE_H
#include <tqmap.h>
#include <tqdbusconnection.h>
#include "interfaces/hardwarecontrolNode.h"
#include "interfaces/dbusbaseNode.h"
/**
* RootNodeService
* Service: -
* Path : /
* Children: org
*/
class RootNodeService : public DBusBaseNode
{
public:
RootNodeService(TQT_DBusConnection&);
~RootNodeService();
protected:
virtual TQT_DBusObjectBase* createInterface(const TQString&);
private:
TQMap<TQString, TQT_DBusObjectBase*> m_interfaces;
TQT_DBusConnection m_connection;
};
/**
* OrgNodeService
* Service: -
* Path : /org
* Children: trinitydesktop
*/
class OrgNodeService : public DBusBaseNode
{
public:
OrgNodeService(TQT_DBusConnection&);
~OrgNodeService();
protected:
virtual TQT_DBusObjectBase* createInterface(const TQString&);
private:
TQMap<TQString, TQT_DBusObjectBase*> m_interfaces;
TQT_DBusConnection m_connection;
};
/**
* TrinityDesktopNodeService
* Service: -
* Path : /org/trinitydesktop
* Children: hardwarecontrol
*/
class TrinityDesktopNodeService : public DBusBaseNode
{
public:
TrinityDesktopNodeService(TQT_DBusConnection&);
~TrinityDesktopNodeService();
protected:
virtual TQT_DBusObjectBase* createInterface(const TQString&);
private:
TQMap<TQString, TQT_DBusObjectBase*> m_interfaces;
TQT_DBusConnection m_connection;
};
/*
* HardwareControlNodeService
* Service: org.freedesktop.DBus.Introspectable
* Service: org.freedesktop.DBus.Properties
* Service: org.trinitydesktop.hardwarecontrol.Brightness
* Service: org.trinitydesktop.hardwarecontrol.CPUGovernor
* Service: org.trinitydesktop.hardwarecontrol.InputEvents
* Service: org.trinitydesktop.hardwarecontrol.Power
* Path : /org/trinitydesktop/hardwarecontrol
* Children: -
*/
class HardwareControlNodeService : public org::trinitydesktop::hardwarecontrolNode
{
public:
HardwareControlNodeService(TQT_DBusConnection&);
~HardwareControlNodeService();
protected:
virtual TQT_DBusObjectBase* createInterface(const TQString&);
private:
TQMap<TQString, TQT_DBusObjectBase*> m_interfaces;
TQT_DBusConnection m_connection;
};
#endif // HARDWARECONTROLSERVICE_H

@ -0,0 +1,52 @@
#################################################
#
# (C) 2020 Emanoil Kotsev
# deloptes (AT) gmail.com
#
# Improvements and feedback are welcome
#
# This file is released under GPL >= 3
#
#################################################
include_directories(
${CMAKE_CURRENT_BINARY_DIR}
${TQT_INCLUDE_DIRS}
${DBUS_TQT_INCLUDE_DIRS}
)
set( INTROSPECTIONPATH ${CMAKE_SOURCE_DIR}/tdecore/tdehw/hwlibdaemons/tdedbus/interfaces )
set( DBUSXML2QT3_EXECUTABLE dbusxml2qt3 )
set( HardwareControl_HDRS brightnessInterface.h brightnessProxy.h cpugovernorInterface.h cpugovernorProxy.h dbusbaseNode.h hardwarecontrolNode.h inputeventsInterface.h inputeventsProxy.h introspectableInterface.h powerInterface.h powerProxy.h propertiesInterface.h propertiesProxy.h )
set( HardwareControl_SRCS brightnessInterface.cpp brightnessProxy.cpp cpugovernorInterface.cpp cpugovernorProxy.cpp dbusbaseNode.cpp hardwarecontrolNode.cpp inputeventsInterface.cpp inputeventsProxy.cpp introspectableInterface.cpp powerInterface.cpp powerProxy.cpp propertiesInterface.cpp propertiesProxy.cpp)
function( make_moc fileinput )
add_custom_command( OUTPUT ${fileinput}.moc
COMMAND ${TMOC_EXECUTABLE} ${fileinput}.h -o ${fileinput}.moc
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${fileinput}.h
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
set_property( SOURCE ${CMAKE_CURRENT_BINARY_DIR}/${fileinput}.cpp APPEND
PROPERTY OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${fileinput}.moc )
endfunction( )
##### HardwareControl #########################
add_custom_command(
OUTPUT ${HardwareControl_HDRS} ${HardwareControl_SRCS}
COMMAND ${DBUSXML2QT3_EXECUTABLE} ${INTROSPECTIONPATH}/org.trinitydesktop.hardwarecontrol.xml 2>/dev/null
DEPENDS ${INTROSPECTIONPATH}/org.trinitydesktop.hardwarecontrol.xml
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
make_moc ( brightnessProxy )
make_moc ( cpugovernorProxy )
make_moc ( inputeventsProxy)
make_moc ( powerProxy )
make_moc ( propertiesProxy )
tde_add_library( hwcontrolinterfaces STATIC_PIC
SOURCES ${HardwareControl_SRCS}
LINK ${DBUS_TQT_LIBRARIES}
)

@ -0,0 +1,96 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node name="/org/trinitydesktop/hardwarecontrol">
<interface name="org.trinitydesktop.hardwarecontrol.Brightness">
<method name="CanSetBrightness">
<arg name="device" direction="in" type="s" />
<arg name="value" direction="out" type="b" />
</method>
<method name="SetBrightness">
<arg name="device" direction="in" type="s" />
<arg name="brightness" direction="in" type="s" />
<arg name="value" direction="out" type="b" />
</method>
</interface>
<interface name="org.trinitydesktop.hardwarecontrol.CPUGovernor">
<method name="CanSetCPUGovernor">
<arg name="cpu" direction="in" type="i" />
<arg name="value" direction="out" type="b" />
</method>
<method name="SetCPUGovernor">
<arg name="cpu" direction="in" type="i" />
<arg name="governor" direction="in" type="s" />
<arg name="value" direction="out" type="b" />
</method>
</interface>
<interface name="org.trinitydesktop.hardwarecontrol.InputEvents">
<method name="GetProvidedSwitches">
<arg name="device" direction="in" type="s" />
<arg name="value" direction="out" type="au" />
</method>
<method name="GetActiveSwitches">
<arg name="device" direction="in" type="s" />
<arg name="value" direction="out" type="au" />
</method>
</interface>
<interface name="org.trinitydesktop.hardwarecontrol.Power">
<method name="CanStandby">
<arg name="value" direction="out" type="b" />
</method>
<method name="Standby">
<arg name="value" direction="out" type="b" />
</method>
<method name="CanFreeze">
<arg name="value" direction="out" type="b" />
</method>
<method name="Freeze">
<arg name="value" direction="out" type="b" />
</method>
<method name="CanSuspend">
<arg name="value" direction="out" type="b" />
</method>
<method name="Suspend">
<arg name="value" direction="out" type="b" />
</method>
<method name="CanHibernate">
<arg name="value" direction="out" type="b" />
</method>
<method name="Hibernate">
<arg name="value" direction="out" type="b" />
</method>
<method name="CanHybridSuspend">
<arg name="value" direction="out" type="b" />
</method>
<method name="HybridSuspend">
<arg name="value" direction="out" type="b" />
</method>
<method name="CanSetHibernationMethod">
<arg name="value" direction="out" type="b" />
</method>
<method name="SetHibernationMethod">
<arg name="method" direction="in" type="s" />
<arg name="value" direction="out" type="b" />
</method>
</interface>
<interface name="org.freedesktop.DBus.Properties">
<method name="Get">
<arg name="interface" type="s" direction="in"/>
<arg name="name" type="s" direction="in"/>
<arg name="value" type="v" direction="out"/>
</method>
<method name="Set">
<arg name="interface" type="s" direction="in"/>
<arg name="name" type="s" direction="in"/>
<arg name="value" type="v" direction="in"/>
</method>
<method name="GetAll">
<arg name="interface" type="s" direction="in"/>
<arg name="properties" type="a{sv}" direction="out"/>
</method>
<signal name="PropertiesChanged">
<arg name="interface" type="s"/>
<arg name="changed_properties" type="a{sv}"/>
<arg name="invalidated_properties" type="as"/>
</signal>
</interface>
</node>

@ -0,0 +1,31 @@
/*
* 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
*/
#include <iostream>
#include "HardwareControl.h"
int main(int argc, char *argv[])
{
HardwareControl a( argc, argv, false, false ) ;// no gui and session management
return a.exec();
}

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?> <!-- -*- XML -*- -->
<!DOCTYPE busconfig PUBLIC
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
<busconfig>
<!-- Only root can own the service -->
<policy user="root">
<allow own="org.trinitydesktop.hardwarecontrol"/>
</policy>
<policy at_console="true">
<!-- Users with physical access to the machine are allowed access -->
<allow send_destination="org.trinitydesktop.hardwarecontrol"
send_interface="org.freedesktop.DBus.Introspectable"/>
<allow send_destination="org.trinitydesktop.hardwarecontrol"
send_interface="org.freedesktop.DBus.Properties"/>
<allow send_destination="org.trinitydesktop.hardwarecontrol"
send_interface="org.trinitydesktop.hardwarecontrol"/>
<allow send_destination="org.trinitydesktop.hardwarecontrol"
send_interface="org.trinitydesktop.hardwarecontrol.Brightness"/>
<allow send_destination="org.trinitydesktop.hardwarecontrol"
send_interface="org.trinitydesktop.hardwarecontrol.CPUGovernor"/>
<allow send_destination="org.trinitydesktop.hardwarecontrol"
send_interface="org.trinitydesktop.hardwarecontrol.InputEvents"/>
<allow send_destination="org.trinitydesktop.hardwarecontrol"
send_interface="org.trinitydesktop.hardwarecontrol.Power"/>
</policy>
<policy group="plugdev">
<!-- Users who are members of the plugdev group are allowed access -->
<allow send_destination="org.trinitydesktop.hardwarecontrol"
send_interface="org.freedesktop.DBus.Introspectable"/>
<allow send_destination="org.trinitydesktop.hardwarecontrol"
send_interface="org.freedesktop.DBus.Properties"/>
<allow send_destination="org.trinitydesktop.hardwarecontrol"
send_interface="org.trinitydesktop.hardwarecontrol"/>
<allow send_destination="org.trinitydesktop.hardwarecontrol"
send_interface="org.trinitydesktop.hardwarecontrol.Brightness"/>
<allow send_destination="org.trinitydesktop.hardwarecontrol"
send_interface="org.trinitydesktop.hardwarecontrol.CPUGovernor"/>
<allow send_destination="org.trinitydesktop.hardwarecontrol"
send_interface="org.trinitydesktop.hardwarecontrol.InputEvents"/>
<allow send_destination="org.trinitydesktop.hardwarecontrol"
send_interface="org.trinitydesktop.hardwarecontrol.Power"/>
</policy>
<policy context="default">
<!-- Everyone else is denied access -->
<deny own="org.trinitydesktop.hardwarecontrol"/>
<deny send_destination="org.trinitydesktop.hardwarecontrol"/>
<!-- Allow to read input switches -->
<allow send_destination="org.trinitydesktop.hardwarecontrol"
send_interface="org.trinitydesktop.hardwarecontrol.InputEvents"/>
</policy>
</busconfig>

@ -0,0 +1,4 @@
[D-BUS Service]
Name=org.trinitydesktop.hardwarecontrol
Exec=@BIN_INSTALL_DIR@/tde_dbus_hardwarecontrol
User=root
Loading…
Cancel
Save