Added TelldusService. A Windows system service responsible for handling TellStick and TellStick Duo
This commit is contained in:
parent
3ad1a9bcce
commit
9b08c7310c
16 changed files with 992 additions and 77 deletions
|
@ -1,70 +1,75 @@
|
|||
PROJECT( telldus-core )
|
||||
|
||||
CMAKE_MINIMUM_REQUIRED( VERSION 2.6.0 )
|
||||
|
||||
IF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
||||
INCLUDE_DIRECTORIES(/usr/local/include)
|
||||
LINK_DIRECTORIES(/usr/local/lib)
|
||||
ENDIF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
||||
|
||||
cmake_policy(SET CMP0003 NEW)
|
||||
|
||||
SET(PACKAGE_VERSION 2.0.0)
|
||||
SET(PACKAGE_SUBVERSION)
|
||||
SET(PACKAGE_SOVERSION 2)
|
||||
|
||||
IF (PACKAGE_SUBVERSION)
|
||||
SET(DISPLAYED_VERSION "${PACKAGE_VERSION}_${PACKAGE_SUBVERSION}")
|
||||
ELSE (PACKAGE_SUBVERSION)
|
||||
SET(DISPLAYED_VERSION ${PACKAGE_VERSION})
|
||||
ENDIF(PACKAGE_SUBVERSION)
|
||||
|
||||
SET(BUILD_LIBTELLDUS-CORE TRUE CACHE BOOL "Build libtelldus-core")
|
||||
SET(SUPPORT_TELLSTICK_DUO FALSE CACHE BOOL "Include support for TellStick Duo")
|
||||
IF (UNIX AND NOT CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
||||
SET(SUPPORT_USB FALSE CACHE BOOL "Build support for usb-devices")
|
||||
ELSE (UNIX AND NOT CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
||||
SET(SUPPORT_USB TRUE CACHE BOOL "Build support for usb-devices")
|
||||
ENDIF(UNIX AND NOT CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
||||
SET(USE_QT_SETTINGS_BACKEND FALSE CACHE BOOL "Use QT as settings backend instead of the native one")
|
||||
|
||||
SET(BUILD_RFCMD TRUE CACHE BOOL "Build rfcmd")
|
||||
IF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
||||
SET(BUILD_RFCMD_WITH_LIBFTDI TRUE CACHE BOOL "Enable support for using rfcmd with libftdi (does not need kernel-driver)")
|
||||
SET(BUILD_RFCMD_WITH_SEMAPHORES FALSE CACHE BOOL "Enable support for using rfcmd with semaphores (Requires special kernel-config)")
|
||||
ELSE(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
||||
SET(BUILD_RFCMD_WITH_LIBFTDI FALSE CACHE BOOL "Enable support for using rfcmd with libftdi (does not need kernel-driver)")
|
||||
SET(BUILD_RFCMD_WITH_SEMAPHORES TRUE CACHE BOOL "Enable support for using rfcmd with semaphores")
|
||||
ENDIF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
||||
SET(BUILD_TDTOOL TRUE CACHE BOOL "Build tdtool")
|
||||
|
||||
SET(GENERATE_MAN FALSE CACHE BOOL "Enable generation of man-files")
|
||||
|
||||
ADD_SUBDIRECTORY(driver)
|
||||
|
||||
if(BUILD_TDTOOL)
|
||||
ADD_SUBDIRECTORY(tdtool)
|
||||
endif(BUILD_TDTOOL)
|
||||
|
||||
if(BUILD_RFCMD)
|
||||
ADD_SUBDIRECTORY(rfcmd)
|
||||
endif(BUILD_RFCMD)
|
||||
|
||||
########## CPack #############
|
||||
SET(CPACK_PACKAGE_NAME ${CMAKE_PROJECT_NAME})
|
||||
SET(CPACK_PACKAGE_VERSION "${PACKAGE_VERSION}${PACKAGE_SUBVERSION}")
|
||||
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
|
||||
SET(CPACK_PACKAGE_CONTACT "Micke Prag <micke.prag@telldus.se>")
|
||||
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Utilities for a Telldus TellStick")
|
||||
SET(CPACK_PACKAGE_DESCRIPTION "Utilities and driver to control NEXA and other RF remote receivers through a TellStick USB interface")
|
||||
SET(CPACK_PACKAGE_VENDOR "Telldus Technologies AB")
|
||||
SET(CPACK_STRIP_FILES "usr/bin/tdtool;usr/bin/rfcmd")
|
||||
# SET(CPACK_PACKAGE_INSTALL_DIRECTORY "")
|
||||
# SET(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
|
||||
|
||||
#### .deb ####
|
||||
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.7-1), libconfuse0 (>=2.6-2), udev")
|
||||
SET(CPACK_DEBIAN_PACKAGE_SECTION "utils")
|
||||
SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/debian/postinst;${CMAKE_CURRENT_SOURCE_DIR}/debian/postrm")
|
||||
|
||||
INCLUDE(CPack)
|
||||
PROJECT( telldus-core )
|
||||
|
||||
CMAKE_MINIMUM_REQUIRED( VERSION 2.6.0 )
|
||||
|
||||
IF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
||||
INCLUDE_DIRECTORIES(/usr/local/include)
|
||||
LINK_DIRECTORIES(/usr/local/lib)
|
||||
ENDIF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
||||
|
||||
cmake_policy(SET CMP0003 NEW)
|
||||
|
||||
SET(PACKAGE_VERSION 2.0.0)
|
||||
SET(PACKAGE_SUBVERSION)
|
||||
SET(PACKAGE_SOVERSION 2)
|
||||
|
||||
IF (PACKAGE_SUBVERSION)
|
||||
SET(DISPLAYED_VERSION "${PACKAGE_VERSION}_${PACKAGE_SUBVERSION}")
|
||||
ELSE (PACKAGE_SUBVERSION)
|
||||
SET(DISPLAYED_VERSION ${PACKAGE_VERSION})
|
||||
ENDIF(PACKAGE_SUBVERSION)
|
||||
|
||||
SET(BUILD_LIBTELLDUS-CORE TRUE CACHE BOOL "Build libtelldus-core")
|
||||
SET(BUILD_LIBTELLDUS-CORE_AS_SERVICE TRUE CACHE BOOL "Build libtelldus-core as a service on Windows")
|
||||
SET(SUPPORT_TELLSTICK_DUO FALSE CACHE BOOL "Include support for TellStick Duo")
|
||||
IF (UNIX AND NOT CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
||||
SET(SUPPORT_USB FALSE CACHE BOOL "Build support for usb-devices")
|
||||
ELSE (UNIX AND NOT CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
||||
SET(SUPPORT_USB TRUE CACHE BOOL "Build support for usb-devices")
|
||||
ENDIF(UNIX AND NOT CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
||||
SET(USE_QT_SETTINGS_BACKEND FALSE CACHE BOOL "Use QT as settings backend instead of the native one")
|
||||
|
||||
SET(BUILD_RFCMD TRUE CACHE BOOL "Build rfcmd")
|
||||
IF (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
||||
SET(BUILD_RFCMD_WITH_LIBFTDI TRUE CACHE BOOL "Enable support for using rfcmd with libftdi (does not need kernel-driver)")
|
||||
SET(BUILD_RFCMD_WITH_SEMAPHORES FALSE CACHE BOOL "Enable support for using rfcmd with semaphores (Requires special kernel-config)")
|
||||
ELSE(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
||||
SET(BUILD_RFCMD_WITH_LIBFTDI FALSE CACHE BOOL "Enable support for using rfcmd with libftdi (does not need kernel-driver)")
|
||||
SET(BUILD_RFCMD_WITH_SEMAPHORES TRUE CACHE BOOL "Enable support for using rfcmd with semaphores")
|
||||
ENDIF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
||||
SET(BUILD_TDTOOL TRUE CACHE BOOL "Build tdtool")
|
||||
|
||||
SET(GENERATE_MAN FALSE CACHE BOOL "Enable generation of man-files")
|
||||
|
||||
ADD_SUBDIRECTORY(driver)
|
||||
|
||||
IF(BUILD_LIBTELLDUS-CORE_AS_SERVICE AND WIN32)
|
||||
ADD_SUBDIRECTORY(telldus-service)
|
||||
ENDIF(BUILD_LIBTELLDUS-CORE_AS_SERVICE AND WIN32)
|
||||
|
||||
if(BUILD_TDTOOL)
|
||||
ADD_SUBDIRECTORY(tdtool)
|
||||
endif(BUILD_TDTOOL)
|
||||
|
||||
if(BUILD_RFCMD)
|
||||
ADD_SUBDIRECTORY(rfcmd)
|
||||
endif(BUILD_RFCMD)
|
||||
|
||||
########## CPack #############
|
||||
SET(CPACK_PACKAGE_NAME ${CMAKE_PROJECT_NAME})
|
||||
SET(CPACK_PACKAGE_VERSION "${PACKAGE_VERSION}${PACKAGE_SUBVERSION}")
|
||||
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
|
||||
SET(CPACK_PACKAGE_CONTACT "Micke Prag <micke.prag@telldus.se>")
|
||||
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Utilities for a Telldus TellStick")
|
||||
SET(CPACK_PACKAGE_DESCRIPTION "Utilities and driver to control NEXA and other RF remote receivers through a TellStick USB interface")
|
||||
SET(CPACK_PACKAGE_VENDOR "Telldus Technologies AB")
|
||||
SET(CPACK_STRIP_FILES "usr/bin/tdtool;usr/bin/rfcmd")
|
||||
# SET(CPACK_PACKAGE_INSTALL_DIRECTORY "")
|
||||
# SET(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
|
||||
|
||||
#### .deb ####
|
||||
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.7-1), libconfuse0 (>=2.6-2), udev")
|
||||
SET(CPACK_DEBIAN_PACKAGE_SECTION "utils")
|
||||
SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/debian/postinst;${CMAKE_CURRENT_SOURCE_DIR}/debian/postrm")
|
||||
|
||||
INCLUDE(CPack)
|
||||
|
|
|
@ -122,11 +122,23 @@ IF (APPLE)
|
|||
)
|
||||
ELSEIF (WIN32)
|
||||
#### Windows ####
|
||||
SET( telldus-core_TARGET TelldusCore )
|
||||
IF(BUILD_LIBTELLDUS-CORE_AS_SERVICE)
|
||||
SET( telldus-core_TARGET TelldusCoreLib )
|
||||
SET( telldus-core_SRCS
|
||||
${telldus-core_SRCS}
|
||||
libtelldus-core_service.def
|
||||
)
|
||||
ELSE(BUILD_LIBTELLDUS-CORE_AS_SERVICE)
|
||||
SET( telldus-core_TARGET TelldusCore )
|
||||
SET( telldus-core_SRCS
|
||||
${telldus-core_SRCS}
|
||||
libtelldus-core.def
|
||||
)
|
||||
ENDIF(BUILD_LIBTELLDUS-CORE_AS_SERVICE)
|
||||
|
||||
SET( telldus-core_SRCS
|
||||
${telldus-core_SRCS}
|
||||
win/Device.cpp
|
||||
libtelldus-core.def
|
||||
)
|
||||
ADD_DEFINITIONS(
|
||||
-D_WINDOWS
|
||||
|
|
|
@ -26,11 +26,11 @@ Settings::Settings(void)
|
|||
d = new privateVars();
|
||||
d->strRegPathDevice = "SOFTWARE\\Telldus\\Devices\\";
|
||||
d->strRegPath = "SOFTWARE\\Telldus\\";
|
||||
if (storeGlobal(d)) {
|
||||
d->rootKey = HKEY_LOCAL_MACHINE;
|
||||
} else {
|
||||
d->rootKey = HKEY_CURRENT_USER;
|
||||
}
|
||||
//if (storeGlobal(d)) {
|
||||
d->rootKey = HKEY_LOCAL_MACHINE;
|
||||
//} else {
|
||||
// d->rootKey = HKEY_CURRENT_USER;
|
||||
//}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
19
telldus-core/telldus-service/CMakeLists.txt
Normal file
19
telldus-core/telldus-service/CMakeLists.txt
Normal file
|
@ -0,0 +1,19 @@
|
|||
PROJECT( telldus-service )
|
||||
|
||||
CMAKE_MINIMUM_REQUIRED( VERSION 2.6.0 )
|
||||
|
||||
SET(PACKAGE_VERSION 2.99.0)
|
||||
SET(PACKAGE_SOVERSION 2)
|
||||
|
||||
SET(BUILD_SERVICE TRUE CACHE BOOL "Build the service")
|
||||
SET(BUILD_CLIENT FALSE CACHE BOOL "Build the client")
|
||||
|
||||
|
||||
if(BUILD_SERVICE)
|
||||
ADD_SUBDIRECTORY(service)
|
||||
endif(BUILD_SERVICE)
|
||||
|
||||
IF (BUILD_CLIENT)
|
||||
ADD_SUBDIRECTORY(client)
|
||||
ENDIF (BUILD_CLIENT)
|
||||
|
90
telldus-core/telldus-service/client/CMakeLists.txt
Normal file
90
telldus-core/telldus-service/client/CMakeLists.txt
Normal file
|
@ -0,0 +1,90 @@
|
|||
FIND_PACKAGE( Qt4 REQUIRED )
|
||||
SET(QT_USE_QTNETWORK TRUE)
|
||||
INCLUDE( ${QT_USE_FILE} )
|
||||
|
||||
IF(COMMAND cmake_policy)
|
||||
CMAKE_POLICY(SET CMP0003 NEW)
|
||||
ENDIF(COMMAND cmake_policy)
|
||||
|
||||
######## Non configurable options ########
|
||||
SET( telldus-client_SRCS
|
||||
main.cpp
|
||||
Manager.cpp
|
||||
../common/Message.cpp
|
||||
)
|
||||
|
||||
SET( telldus-client_HDRS
|
||||
../common/Message.h
|
||||
)
|
||||
|
||||
SET( telldus-client_MOC_HDRS
|
||||
Manager.h
|
||||
)
|
||||
|
||||
SET( telldus-client_LIBRARIES
|
||||
${QT_LIBRARIES}
|
||||
)
|
||||
|
||||
QT4_WRAP_CPP( telldus-client_MOC_SRCS ${telldus-client_MOC_HDRS} )
|
||||
QT4_AUTOMOC ( ${telldus-client_SRCS} )
|
||||
|
||||
######## Configurable options for the platform ########
|
||||
|
||||
|
||||
######## Platforms-specific, non configurable ########
|
||||
|
||||
SET( telldus-client_TARGET TelldusClient )
|
||||
|
||||
IF (APPLE) #### Mac OS X ####
|
||||
|
||||
ELSEIF (WIN32) #### Windows ####
|
||||
#### Windows ####
|
||||
SET( telldus-client_TARGET TelldusCore )
|
||||
SET( telldus-client_SRCS
|
||||
${telldus-client_SRCS}
|
||||
../../driver/libtelldus-core/libtelldus-core.def
|
||||
)
|
||||
ADD_DEFINITIONS(
|
||||
-D_WINDOWS
|
||||
-DTELLDUSCORE_EXPORTS
|
||||
)
|
||||
INCLUDE_DIRECTORIES(
|
||||
${CMAKE_SOURCE_DIR}/driver
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../common
|
||||
)
|
||||
ADD_DEFINITIONS( -DUNICODE )
|
||||
SET(CMAKE_EXE_LINKER_FLAGS
|
||||
"${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:CONSOLE"
|
||||
)
|
||||
|
||||
ELSE (APPLE) #### Linux ####
|
||||
|
||||
ENDIF (APPLE)
|
||||
|
||||
|
||||
######## Configuring ########
|
||||
|
||||
|
||||
ADD_LIBRARY(${telldus-client_TARGET} SHARED
|
||||
${telldus-client_SRCS}
|
||||
${telldus-client_HDRS}
|
||||
${telldus-client_MOC_HDRS}
|
||||
${telldus-client_MOC_SRCS}
|
||||
)
|
||||
SET_SOURCE_FILES_PROPERTIES(${telldus-service_RESOURCES} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
|
||||
|
||||
TARGET_LINK_LIBRARIES( ${telldus-client_TARGET} ${telldus-client_LIBRARIES} )
|
||||
|
||||
SET_TARGET_PROPERTIES(${telldus-service_TARGET} PROPERTIES
|
||||
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist
|
||||
)
|
||||
IF (APPLE)
|
||||
SET_TARGET_PROPERTIES(${telldus-service_TARGET} PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||
)
|
||||
ELSEIF (UNIX)
|
||||
SET_TARGET_PROPERTIES(${telldus-service_TARGET} PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/TelldusClient
|
||||
)
|
||||
ENDIF (APPLE)
|
||||
|
34
telldus-core/telldus-service/client/Manager.H
Normal file
34
telldus-core/telldus-service/client/Manager.H
Normal file
|
@ -0,0 +1,34 @@
|
|||
#ifndef MANAGER_H
|
||||
#define MANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QByteArray>
|
||||
#include <QVariant>
|
||||
#include "Message.h"
|
||||
|
||||
class ManagerPrivate;
|
||||
|
||||
class Manager : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
~Manager(void);
|
||||
|
||||
static Manager *getInstance();
|
||||
static void close();
|
||||
|
||||
QVariant send(const Message &, const QVariant &);
|
||||
|
||||
int numberOfDevices();
|
||||
QString deviceName(int deviceId);
|
||||
|
||||
private slots:
|
||||
void dataReceived();
|
||||
|
||||
private:
|
||||
Manager(void);
|
||||
|
||||
ManagerPrivate *d;
|
||||
static Manager *instance;
|
||||
};
|
||||
|
||||
#endif MANAGER_H
|
71
telldus-core/telldus-service/client/Manager.cpp
Normal file
71
telldus-core/telldus-service/client/Manager.cpp
Normal file
|
@ -0,0 +1,71 @@
|
|||
|
||||
#include <QLocalSocket>
|
||||
#include "Manager.h"
|
||||
#include "Message.h"
|
||||
|
||||
class ManagerPrivate {
|
||||
public:
|
||||
int numberOfDevices;
|
||||
QLocalSocket s;
|
||||
};
|
||||
|
||||
Manager *Manager::instance = 0;
|
||||
|
||||
Manager::Manager(void) {
|
||||
d = new ManagerPrivate;
|
||||
d->numberOfDevices = -1;
|
||||
//connect(&d->s, SIGNAL(readyRead()), this, SLOT(dataReceived()));
|
||||
d->s.connectToServer( "TelldusCore" );
|
||||
d->s.waitForConnected();
|
||||
}
|
||||
|
||||
Manager::~Manager(void) {
|
||||
delete d;
|
||||
}
|
||||
|
||||
Manager *Manager::getInstance() {
|
||||
if (Manager::instance == 0) {
|
||||
Manager::instance = new Manager();
|
||||
}
|
||||
return Manager::instance;
|
||||
}
|
||||
|
||||
|
||||
void Manager::close() {
|
||||
if (Manager::instance != 0) {
|
||||
delete Manager::instance;
|
||||
}
|
||||
}
|
||||
|
||||
int Manager::numberOfDevices() {
|
||||
if (d->numberOfDevices >= 0) {
|
||||
return d->numberOfDevices;
|
||||
}
|
||||
Message message("tdGetNumberOfDevices");
|
||||
d->numberOfDevices = this->send(message, 0).toInt();
|
||||
return d->numberOfDevices;
|
||||
}
|
||||
|
||||
QString Manager::deviceName(int deviceId) {
|
||||
Message message("tdGetName");
|
||||
message.addArgument(deviceId);
|
||||
return this->send(message, "").toString();
|
||||
}
|
||||
|
||||
void Manager::dataReceived() {
|
||||
|
||||
}
|
||||
|
||||
QVariant Manager::send(const Message &message, const QVariant &default) {
|
||||
if (d->s.state() != QLocalSocket::ConnectedState) {
|
||||
return default;
|
||||
}
|
||||
d->s.write(message);
|
||||
if (d->s.waitForReadyRead(1000)) {
|
||||
QVariant retval(d->s.readLine());
|
||||
return retval;
|
||||
}
|
||||
return default;
|
||||
|
||||
}
|
||||
|
198
telldus-core/telldus-service/client/main.cpp
Normal file
198
telldus-core/telldus-service/client/main.cpp
Normal file
|
@ -0,0 +1,198 @@
|
|||
|
||||
#include <libtelldus-core/telldus-core.h>
|
||||
#include <string>
|
||||
#include <libtelldus-core/common.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "Manager.h"
|
||||
|
||||
void WINAPI tdInit(void) {
|
||||
Manager::getInstance(); //Create the manager-object
|
||||
}
|
||||
|
||||
int WINAPI tdRegisterDeviceEvent( TDDeviceEvent eventFunction, void *context ) {
|
||||
/* Manager *manager = Manager::getInstance();
|
||||
return manager->registerDeviceEvent( eventFunction, context );*/
|
||||
return 1;
|
||||
}
|
||||
|
||||
int WINAPI tdRegisterRawDeviceEvent( TDRawDeviceEvent eventFunction, void *context ) {
|
||||
/* Manager *manager = Manager::getInstance();
|
||||
return manager->registerRawDeviceEvent( eventFunction, context );*/
|
||||
return 1;
|
||||
}
|
||||
|
||||
void WINAPI tdClose(void) {
|
||||
Manager::close();
|
||||
}
|
||||
|
||||
void WINAPI tdReleaseString(char *string) {
|
||||
free(string);
|
||||
}
|
||||
|
||||
int WINAPI tdTurnOn(int intDeviceId){
|
||||
Manager *manager = Manager::getInstance();
|
||||
Message message("tdTurnOn");
|
||||
message.addArgument(intDeviceId);
|
||||
return manager->send(message, TELLSTICK_ERROR_UNKNOWN).toInt();
|
||||
}
|
||||
|
||||
int WINAPI tdTurnOff(int intDeviceId){
|
||||
Manager *manager = Manager::getInstance();
|
||||
Message message("tdTurnOff");
|
||||
message.addArgument(intDeviceId);
|
||||
return manager->send(message, TELLSTICK_ERROR_UNKNOWN).toInt();
|
||||
}
|
||||
|
||||
int WINAPI tdBell(int intDeviceId){
|
||||
Manager *manager = Manager::getInstance();
|
||||
Message message("tdBell");
|
||||
message.addArgument(intDeviceId);
|
||||
return manager->send(message, TELLSTICK_ERROR_UNKNOWN).toInt();
|
||||
}
|
||||
|
||||
int WINAPI tdDim(int intDeviceId, unsigned char level){
|
||||
Manager *manager = Manager::getInstance();
|
||||
Message message("tdDim");
|
||||
message.addArgument(intDeviceId);
|
||||
return manager->send(message, TELLSTICK_ERROR_UNKNOWN).toInt();
|
||||
}
|
||||
|
||||
int WINAPI tdLearn(int intDeviceId) {
|
||||
Manager *manager = Manager::getInstance();
|
||||
Message message("tdLearn");
|
||||
message.addArgument(intDeviceId);
|
||||
return manager->send(message, TELLSTICK_ERROR_UNKNOWN).toInt();
|
||||
}
|
||||
|
||||
int WINAPI tdLastSentCommand( int intDeviceId, int methodsSupported ) {
|
||||
Manager *manager = Manager::getInstance();
|
||||
Message message("tdLastSentCommand");
|
||||
message.addArgument(intDeviceId);
|
||||
message.addArgument(methodsSupported);
|
||||
return manager->send(message, TELLSTICK_TURNOFF).toInt();
|
||||
}
|
||||
|
||||
char * WINAPI tdLastSentValue( int intDeviceId ) {
|
||||
Manager *manager = Manager::getInstance();
|
||||
Message message("tdLastSentValue");
|
||||
message.addArgument(intDeviceId);
|
||||
return wrapStdString(manager->send(message, "0").toString().toStdString());
|
||||
}
|
||||
|
||||
int WINAPI tdGetNumberOfDevices(void){
|
||||
//We go through the Manager so we can cache the value
|
||||
Manager *manager = Manager::getInstance();
|
||||
return manager->numberOfDevices();
|
||||
}
|
||||
|
||||
int WINAPI tdGetDeviceId(int intDeviceIndex){
|
||||
Manager *manager = Manager::getInstance();
|
||||
Message message("tdGetDeviceId");
|
||||
message.addArgument(intDeviceIndex);
|
||||
return manager->send(message, -1).toInt();
|
||||
}
|
||||
|
||||
int WINAPI tdGetDeviceType(int intDeviceId) {
|
||||
Manager *manager = Manager::getInstance();
|
||||
Message message("tdGetDeviceType");
|
||||
message.addArgument(intDeviceId);
|
||||
return manager->send(message, TELLSTICK_TYPE_DEVICE).toInt();
|
||||
}
|
||||
|
||||
char * WINAPI tdGetName(int intDeviceId){
|
||||
Manager *manager = Manager::getInstance();
|
||||
QString name = manager->deviceName(intDeviceId);
|
||||
return wrapStdString(name.toStdString());
|
||||
}
|
||||
|
||||
bool WINAPI tdSetName(int intDeviceId, const char* strNewName){
|
||||
Manager *manager = Manager::getInstance();
|
||||
Message message("tdSetName");
|
||||
message.addArgument(intDeviceId);
|
||||
message.addArgument(strNewName);
|
||||
return manager->send(message, 0).toBool();
|
||||
}
|
||||
|
||||
char* WINAPI tdGetProtocol(int intDeviceId){
|
||||
Manager *manager = Manager::getInstance();
|
||||
Message message("tdGetProtocol");
|
||||
message.addArgument(intDeviceId);
|
||||
return wrapStdString(manager->send(message, "arctech").toString().toStdString());
|
||||
}
|
||||
|
||||
bool WINAPI tdSetProtocol(int intDeviceId, const char* strProtocol){
|
||||
Manager *manager = Manager::getInstance();
|
||||
Message message("tdSetProtocol");
|
||||
message.addArgument(intDeviceId);
|
||||
message.addArgument(strProtocol);
|
||||
return manager->send(message, 0).toBool();
|
||||
}
|
||||
|
||||
char* WINAPI tdGetModel(int intDeviceId){
|
||||
Manager *manager = Manager::getInstance();
|
||||
Message message("tdGetModel");
|
||||
message.addArgument(intDeviceId);
|
||||
return wrapStdString(manager->send(message, "").toString().toStdString());
|
||||
}
|
||||
|
||||
bool WINAPI tdSetModel(int intDeviceId, const char *strModel){
|
||||
Manager *manager = Manager::getInstance();
|
||||
Message message("tdSetModel");
|
||||
message.addArgument(intDeviceId);
|
||||
message.addArgument(strModel);
|
||||
return manager->send(message, 0).toBool();
|
||||
}
|
||||
|
||||
bool WINAPI tdSetDeviceParameter(int intDeviceId, const char *strName, const char *strValue){
|
||||
Manager *manager = Manager::getInstance();
|
||||
Message message("tdSetDeviceParameter");
|
||||
message.addArgument(intDeviceId);
|
||||
message.addArgument(strName);
|
||||
message.addArgument(strValue);
|
||||
return manager->send(message, 0).toBool();
|
||||
}
|
||||
|
||||
char * WINAPI tdGetDeviceParameter(int intDeviceId, const char *strName, const char *defaultValue){
|
||||
Manager *manager = Manager::getInstance();
|
||||
Message message("tdGetDeviceParameter");
|
||||
message.addArgument(intDeviceId);
|
||||
message.addArgument(strName);
|
||||
message.addArgument(defaultValue);
|
||||
return wrapStdString(manager->send(message, defaultValue).toString().toStdString());
|
||||
}
|
||||
|
||||
int WINAPI tdAddDevice(){
|
||||
Manager *manager = Manager::getInstance();
|
||||
Message message("tdAddDevice");
|
||||
return manager->send(message, -1).toInt();
|
||||
}
|
||||
|
||||
bool WINAPI tdRemoveDevice(int intDeviceId){
|
||||
Manager *manager = Manager::getInstance();
|
||||
Message message("tdRemoveDevice");
|
||||
return manager->send(message, 0).toBool();
|
||||
}
|
||||
|
||||
int WINAPI tdMethods(int id, int methodsSupported){
|
||||
Manager *manager = Manager::getInstance();
|
||||
Message message("tdMethods");
|
||||
message.addArgument(id);
|
||||
message.addArgument(methodsSupported);
|
||||
return manager->send(message, 0).toInt();
|
||||
}
|
||||
|
||||
char * WINAPI tdGetErrorString(int intErrorNo) {
|
||||
Manager *manager = Manager::getInstance();
|
||||
Message message("tdGetErrorString");
|
||||
message.addArgument(intErrorNo);
|
||||
return wrapStdString(manager->send(message, "Unknown error").toString().toStdString());
|
||||
}
|
||||
|
||||
int WINAPI tdSendRawCommand(const char *command, int reserved) {
|
||||
Manager *manager = Manager::getInstance();
|
||||
Message message("tdSendRawCommand");
|
||||
message.addArgument(command);
|
||||
message.addArgument(reserved);
|
||||
return manager->send(message, TELLSTICK_ERROR_UNKNOWN).toInt();
|
||||
}
|
68
telldus-core/telldus-service/common/Message.cpp
Normal file
68
telldus-core/telldus-service/common/Message.cpp
Normal file
|
@ -0,0 +1,68 @@
|
|||
|
||||
#include "Message.h"
|
||||
|
||||
/*class MesssagePrivate {
|
||||
public:
|
||||
};*/
|
||||
|
||||
Message::Message()
|
||||
:QByteArray()
|
||||
{
|
||||
}
|
||||
|
||||
Message::Message(const QByteArray &functionName)
|
||||
:QByteArray()
|
||||
{
|
||||
this->addArgument(functionName);
|
||||
}
|
||||
|
||||
Message::~Message(void) {
|
||||
//delete d;
|
||||
}
|
||||
|
||||
void Message::addArgument(const QByteArray &value) {
|
||||
this->append(QByteArray::number(value.length()));
|
||||
this->append(":");
|
||||
this->append(value);
|
||||
}
|
||||
|
||||
void Message::addArgument(int value) {
|
||||
this->append("i");
|
||||
this->append(QByteArray::number(value));
|
||||
this->append("e");
|
||||
}
|
||||
|
||||
void Message::addArgument(const QVariant &value) {
|
||||
if (value.type() == QVariant::Int) {
|
||||
this->addArgument(value.toInt());
|
||||
} else {
|
||||
this->addArgument(value.toByteArray());
|
||||
}
|
||||
}
|
||||
|
||||
void Message::addArgument(const char *value) {
|
||||
this->addArgument(QByteArray(value));
|
||||
}
|
||||
|
||||
|
||||
|
||||
QVariant Message::takeFirst(QByteArray *message) {
|
||||
if (message->length() == 0) {
|
||||
return QVariant();
|
||||
}
|
||||
QChar first = message->at(0);
|
||||
if (first.isDigit()) { //String
|
||||
int index = message->indexOf(':');
|
||||
int length = message->left(index).toInt();
|
||||
QByteArray retval(message->mid(index+1, length));
|
||||
message->remove(0, index+length+1);
|
||||
return retval;
|
||||
}
|
||||
if (first == 'i') {
|
||||
int index = message->indexOf('e');
|
||||
int value = message->mid(1, index - 1).toInt();
|
||||
message->remove(0, index+1);
|
||||
return value;
|
||||
}
|
||||
return QVariant();
|
||||
}
|
25
telldus-core/telldus-service/common/Message.h
Normal file
25
telldus-core/telldus-service/common/Message.h
Normal file
|
@ -0,0 +1,25 @@
|
|||
#ifndef MESSAGE_H
|
||||
#define MESSAGE_H
|
||||
|
||||
#include <QByteArray>
|
||||
#include <QVariant>
|
||||
|
||||
//class MessagePrivate;
|
||||
|
||||
class Message : public QByteArray {
|
||||
public:
|
||||
Message();
|
||||
Message(const QByteArray &);
|
||||
~Message(void);
|
||||
|
||||
void addArgument(const QByteArray &);
|
||||
void addArgument(int);
|
||||
void addArgument(const QVariant &);
|
||||
void addArgument(const char *);
|
||||
|
||||
static QVariant takeFirst(QByteArray *);
|
||||
|
||||
//MessagePrivate *d;
|
||||
};
|
||||
|
||||
#endif //MESSAGE_H
|
91
telldus-core/telldus-service/service/CMakeLists.txt
Normal file
91
telldus-core/telldus-service/service/CMakeLists.txt
Normal file
|
@ -0,0 +1,91 @@
|
|||
FIND_PACKAGE( Qt4 REQUIRED )
|
||||
SET(QT_USE_QTNETWORK TRUE)
|
||||
INCLUDE( ${QT_USE_FILE} )
|
||||
|
||||
IF(COMMAND cmake_policy)
|
||||
CMAKE_POLICY(SET CMP0003 NEW)
|
||||
ENDIF(COMMAND cmake_policy)
|
||||
|
||||
######## Non configurable options ########
|
||||
SET( telldus-service_SRCS
|
||||
main.cpp
|
||||
TelldusCore.cpp
|
||||
Manager.cpp
|
||||
../common/Message.cpp
|
||||
${QTSERVICE_PATH}/src/qtservice.cpp
|
||||
)
|
||||
|
||||
SET( telldus-service_MOC_HDRS
|
||||
TelldusCore.h
|
||||
Manager.h
|
||||
)
|
||||
|
||||
SET( telldus-service_LIBRARIES
|
||||
${QT_LIBRARIES}
|
||||
)
|
||||
|
||||
######## Configurable options for the platform ########
|
||||
|
||||
SET(QTSERVICE_PATH CACHE PATH "Path to qtservice")
|
||||
|
||||
######## Platforms-specific, non configurable ########
|
||||
|
||||
SET( telldus-service_TARGET TelldusService )
|
||||
|
||||
IF (APPLE) #### Mac OS X ####
|
||||
|
||||
ELSEIF (WIN32) #### Windows ####
|
||||
ADD_DEFINITIONS( -DUNICODE )
|
||||
INCLUDE_DIRECTORIES(
|
||||
${CMAKE_SOURCE_DIR}/driver
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../common
|
||||
${QTSERVICE_PATH}/src
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
SET(CMAKE_EXE_LINKER_FLAGS
|
||||
"${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:CONSOLE"
|
||||
)
|
||||
SET( telldus-service_LIBRARIES
|
||||
${telldus-service_LIBRARIES}
|
||||
${LIBRARY_OUTPUT_PATH}/Release/TelldusCoreLib.lib
|
||||
)
|
||||
SET(telldus-service_SRCS
|
||||
${telldus-service_SRCS}
|
||||
${QTSERVICE_PATH}/src/qtservice_win.cpp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/qtservice.moc
|
||||
${CMAKE_CURRENT_BINARY_DIR}/qtservice_win.moc
|
||||
)
|
||||
QT4_GENERATE_MOC( ${QTSERVICE_PATH}/src/qtservice_win.cpp ${CMAKE_CURRENT_BINARY_DIR}/qtservice_win.moc )
|
||||
|
||||
ELSE (APPLE) #### Linux ####
|
||||
|
||||
ENDIF (APPLE)
|
||||
|
||||
|
||||
######## Configuring ########
|
||||
|
||||
QT4_GENERATE_MOC( ${QTSERVICE_PATH}/src/qtservice.cpp ${CMAKE_CURRENT_BINARY_DIR}/qtservice.moc )
|
||||
QT4_WRAP_CPP( telldus-service_MOC_SRCS ${telldus-service_MOC_HDRS} )
|
||||
|
||||
|
||||
ADD_EXECUTABLE(${telldus-service_TARGET}
|
||||
${telldus-service_SRCS}
|
||||
${telldus-service_MOC_SRCS}
|
||||
)
|
||||
SET_SOURCE_FILES_PROPERTIES(${telldus-service_RESOURCES} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
|
||||
|
||||
TARGET_LINK_LIBRARIES( ${telldus-service_TARGET} ${telldus-service_LIBRARIES} )
|
||||
|
||||
SET_TARGET_PROPERTIES(${telldus-service_TARGET} PROPERTIES
|
||||
MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/Info.plist
|
||||
)
|
||||
IF (APPLE)
|
||||
SET_TARGET_PROPERTIES(${telldus-service_TARGET} PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||
)
|
||||
ELSEIF (UNIX)
|
||||
SET_TARGET_PROPERTIES(${telldus-service_TARGET} PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/TelldusCenter
|
||||
)
|
||||
ENDIF (APPLE)
|
||||
|
23
telldus-core/telldus-service/service/Manager.H
Normal file
23
telldus-core/telldus-service/service/Manager.H
Normal file
|
@ -0,0 +1,23 @@
|
|||
#ifndef MANAGER_H
|
||||
#define MANAGER_H
|
||||
|
||||
#include <QThread>
|
||||
|
||||
class ManagerPrivate;
|
||||
class QLocalSocket;
|
||||
|
||||
class Manager : public QThread {
|
||||
Q_OBJECT
|
||||
public:
|
||||
Manager(QLocalSocket *s, QObject *parent);
|
||||
~Manager(void);
|
||||
|
||||
protected:
|
||||
virtual void run();
|
||||
QVariant parseMessage(const QByteArray &message);
|
||||
|
||||
private:
|
||||
ManagerPrivate *d;
|
||||
};
|
||||
|
||||
#endif MANAGER_H
|
158
telldus-core/telldus-service/service/Manager.cpp
Normal file
158
telldus-core/telldus-service/service/Manager.cpp
Normal file
|
@ -0,0 +1,158 @@
|
|||
|
||||
#include <QLocalSocket>
|
||||
#include <libtelldus-core/telldus-core.h>
|
||||
#include "Manager.h"
|
||||
#include "Message.h"
|
||||
|
||||
class ManagerPrivate {
|
||||
public:
|
||||
QLocalSocket *s;
|
||||
};
|
||||
|
||||
Manager::Manager(QLocalSocket *s, QObject *parent)
|
||||
:QThread(parent)
|
||||
{
|
||||
d = new ManagerPrivate;
|
||||
d->s = s;
|
||||
this->start();
|
||||
}
|
||||
|
||||
Manager::~Manager(void) {
|
||||
delete d;
|
||||
}
|
||||
|
||||
void Manager::run() {
|
||||
while(1) {
|
||||
if (d->s->waitForReadyRead()) {
|
||||
QVariant response(this->parseMessage(d->s->readLine()));
|
||||
d->s->write(response.toByteArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QVariant Manager::parseMessage(const QByteArray &message) {
|
||||
QByteArray msg = message; //Copy
|
||||
QVariant function(Message::takeFirst(&msg));
|
||||
if (function == "tdTurnOn") {
|
||||
int intDeviceId = Message::takeFirst(&msg).toInt();
|
||||
return tdTurnOn(intDeviceId);
|
||||
|
||||
} else if (function == "tdTurnOff") {
|
||||
int intDeviceId = Message::takeFirst(&msg).toInt();
|
||||
return tdTurnOff(intDeviceId);
|
||||
|
||||
} else if (function == "tdBell") {
|
||||
int intDeviceId = Message::takeFirst(&msg).toInt();
|
||||
return tdBell(intDeviceId);
|
||||
|
||||
} else if (function == "tdDim") {
|
||||
int intDeviceId = Message::takeFirst(&msg).toInt();
|
||||
int level = Message::takeFirst(&msg).toInt();
|
||||
return tdDim(intDeviceId, level);
|
||||
|
||||
} else if (function == "tdLearn") {
|
||||
int intDeviceId = Message::takeFirst(&msg).toInt();
|
||||
return tdLearn(intDeviceId);
|
||||
|
||||
} else if (function == "tdLastSentCommand") {
|
||||
int intDeviceId = Message::takeFirst(&msg).toInt();
|
||||
int methodsSupported = Message::takeFirst(&msg).toInt();
|
||||
return tdLastSentCommand(intDeviceId, methodsSupported);
|
||||
|
||||
} else if (function == "tdLastSentValue") {
|
||||
int intDeviceId = Message::takeFirst(&msg).toInt();
|
||||
char *value = tdLastSentValue(intDeviceId);
|
||||
QByteArray retval(value);
|
||||
tdReleaseString(value);
|
||||
return retval;
|
||||
|
||||
} else if (function == "tdGetNumberOfDevices") {
|
||||
return tdGetNumberOfDevices();
|
||||
|
||||
} else if (function == "tdGetDeviceId") {
|
||||
int intDeviceIndex = Message::takeFirst(&msg).toInt();
|
||||
return tdGetDeviceId(intDeviceIndex);
|
||||
|
||||
} else if (function == "tdGetDeviceType") {
|
||||
int intDeviceId = Message::takeFirst(&msg).toInt();
|
||||
return tdGetDeviceType(intDeviceId);
|
||||
|
||||
} else if (function == "tdGetName") {
|
||||
int intDeviceId = Message::takeFirst(&msg).toInt();
|
||||
char *name = tdGetName(intDeviceId);
|
||||
QByteArray retval(name);
|
||||
tdReleaseString(name);
|
||||
return retval;
|
||||
|
||||
} else if (function == "tdSetName") {
|
||||
int intDeviceId = Message::takeFirst(&msg).toInt();
|
||||
QString name = Message::takeFirst(&msg).toString();
|
||||
return tdSetName(intDeviceId, name.toLocal8Bit());
|
||||
|
||||
} else if (function == "tdGetProtocol") {
|
||||
int intDeviceId = Message::takeFirst(&msg).toInt();
|
||||
char *protocol = tdGetProtocol(intDeviceId);
|
||||
QByteArray retval(protocol);
|
||||
tdReleaseString(protocol);
|
||||
return retval;
|
||||
|
||||
} else if (function == "tdSetProtocol") {
|
||||
int intDeviceId = Message::takeFirst(&msg).toInt();
|
||||
QString protocol = Message::takeFirst(&msg).toString();
|
||||
return tdSetProtocol(intDeviceId, protocol.toLocal8Bit());
|
||||
|
||||
} else if (function == "tdGetModel") {
|
||||
int intDeviceId = Message::takeFirst(&msg).toInt();
|
||||
char *model = tdGetModel(intDeviceId);
|
||||
QByteArray retval(model);
|
||||
tdReleaseString(model);
|
||||
return retval;
|
||||
|
||||
} else if (function == "tdSetModel") {
|
||||
int intDeviceId = Message::takeFirst(&msg).toInt();
|
||||
QString model = Message::takeFirst(&msg).toString();
|
||||
return tdSetModel(intDeviceId, model.toLocal8Bit());
|
||||
|
||||
} else if (function == "tdSetDeviceParameter") {
|
||||
int intDeviceId = Message::takeFirst(&msg).toInt();
|
||||
QString name = Message::takeFirst(&msg).toString();
|
||||
QString value = Message::takeFirst(&msg).toString();
|
||||
return tdSetDeviceParameter(intDeviceId, name.toLocal8Bit(), value.toLocal8Bit());
|
||||
|
||||
} else if (function == "tdGetDeviceParameter") {
|
||||
int intDeviceId = Message::takeFirst(&msg).toInt();
|
||||
QString name = Message::takeFirst(&msg).toString();
|
||||
QString defaultValue = Message::takeFirst(&msg).toString();
|
||||
char *value = tdGetDeviceParameter(intDeviceId, name.toLocal8Bit(), defaultValue.toLocal8Bit());
|
||||
QByteArray retval(value);
|
||||
tdReleaseString(value);
|
||||
return retval;
|
||||
|
||||
} else if (function == "tdAddDevice") {
|
||||
return tdAddDevice();
|
||||
|
||||
} else if (function == "tdRemoveDevice") {
|
||||
int intDeviceId = Message::takeFirst(&msg).toInt();
|
||||
return tdRemoveDevice(intDeviceId);
|
||||
|
||||
} else if (function == "tdMethods") {
|
||||
int intDeviceId = Message::takeFirst(&msg).toInt();
|
||||
int intMethodsSupported = Message::takeFirst(&msg).toInt();
|
||||
return tdMethods(intDeviceId, intMethodsSupported);
|
||||
|
||||
} else if (function == "tdGetErrorString") {
|
||||
int intErrorNo = Message::takeFirst(&msg).toInt();
|
||||
char *response = tdGetErrorString(intErrorNo);
|
||||
QByteArray retval(response);
|
||||
tdReleaseString(response);
|
||||
return retval;
|
||||
|
||||
} else if (function == "tdSendRawCommand") {
|
||||
QString command = Message::takeFirst(&msg).toString();
|
||||
int reserved = Message::takeFirst(&msg).toInt();
|
||||
return tdSendRawCommand(command.toLocal8Bit(), reserved);
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
37
telldus-core/telldus-service/service/TelldusCore.cpp
Normal file
37
telldus-core/telldus-service/service/TelldusCore.cpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
#include "TelldusCore.h"
|
||||
#include "Manager.h"
|
||||
#include <libtelldus-core/telldus-core.h>
|
||||
#include <QLocalServer>
|
||||
#include <QLocalSocket>
|
||||
#include <QDebug>
|
||||
|
||||
void WINAPI deviceEvent(int deviceId, int method, const char *, int, void *) {
|
||||
qDebug() << "DeviceEvent" << deviceId << method;
|
||||
}
|
||||
|
||||
class TelldusCorePrivate {
|
||||
public:
|
||||
QLocalServer server;
|
||||
};
|
||||
|
||||
TelldusCore::TelldusCore(void)
|
||||
:QObject(),
|
||||
d(new TelldusCorePrivate)
|
||||
{
|
||||
tdInit();
|
||||
|
||||
connect(&d->server, SIGNAL(newConnection()), this, SLOT(newConnection()));
|
||||
d->server.listen("TelldusCore");
|
||||
|
||||
tdRegisterDeviceEvent( reinterpret_cast<TDDeviceEvent>(&deviceEvent), 0);
|
||||
}
|
||||
|
||||
TelldusCore::~TelldusCore(void) {
|
||||
tdClose();
|
||||
delete d;
|
||||
}
|
||||
|
||||
void TelldusCore::newConnection() {
|
||||
QLocalSocket *s = d->server.nextPendingConnection();
|
||||
Manager *m = new Manager(s, this);
|
||||
}
|
21
telldus-core/telldus-service/service/TelldusCore.h
Normal file
21
telldus-core/telldus-service/service/TelldusCore.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef TELLDUS_CORE_H
|
||||
#define TELLDUS_CORE_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class TelldusCorePrivate;
|
||||
|
||||
class TelldusCore : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
TelldusCore(void);
|
||||
~TelldusCore(void);
|
||||
|
||||
private slots:
|
||||
void newConnection();
|
||||
|
||||
private:
|
||||
TelldusCorePrivate * const d;
|
||||
};
|
||||
|
||||
#endif
|
63
telldus-core/telldus-service/service/main.cpp
Normal file
63
telldus-core/telldus-service/service/main.cpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QDebug>
|
||||
#include "qtservice.h"
|
||||
|
||||
#include "TelldusCore.h"
|
||||
|
||||
class TelldusService : public QtService<QCoreApplication> {
|
||||
public:
|
||||
TelldusService(int argc, char **argv);
|
||||
~TelldusService();
|
||||
|
||||
protected:
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
void pause();
|
||||
void resume();
|
||||
void processCommand(int code);
|
||||
|
||||
private:
|
||||
TelldusCore *tc;
|
||||
};
|
||||
|
||||
TelldusService::TelldusService(int argc, char **argv)
|
||||
: QtService<QCoreApplication>(argc, argv, "TelldusCore"),
|
||||
tc(0)
|
||||
{
|
||||
setServiceDescription("A Telldus service for managing TellStick Duo.");
|
||||
}
|
||||
|
||||
TelldusService::~TelldusService()
|
||||
{
|
||||
}
|
||||
|
||||
void TelldusService::start() {
|
||||
QCoreApplication *app = application();
|
||||
|
||||
tc = new TelldusCore();
|
||||
|
||||
logMessage("TService started", QtServiceBase::Error);
|
||||
//app->quit();
|
||||
|
||||
}
|
||||
|
||||
void TelldusService::stop() {
|
||||
delete tc;
|
||||
tc = 0;
|
||||
}
|
||||
|
||||
void TelldusService::pause() {
|
||||
}
|
||||
|
||||
void TelldusService::resume() {
|
||||
}
|
||||
|
||||
void TelldusService::processCommand(int code) {
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
TelldusService service(argc, argv);
|
||||
return service.exec();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue