{ should almost always be at the end of the previous line, according to Google style guidelines "whitespace/braces"

This commit is contained in:
Micke Prag 2012-02-28 22:19:02 +01:00
parent 78444e20b9
commit e1608f94a8
58 changed files with 323 additions and 403 deletions

View file

@ -12,8 +12,7 @@
using namespace TelldusCore;
TDEventDispatcher::TDEventDispatcher(EventDataRef cbd, CallbackStruct *cb, EventRef cbDone)
:Thread(), doneRunning(false), callbackData(cbd), callback(cb), callbackExecuted(cbDone)
{
:Thread(), doneRunning(false), callbackData(cbd), callback(cb), callbackExecuted(cbDone) {
this->startAndLock(&callback->mutex);
}

View file

@ -29,8 +29,7 @@ public:
};
CallbackMainDispatcher::CallbackMainDispatcher()
:Thread()
{
:Thread() {
d = new PrivateData;
d->stopEvent = d->eventHandler.addEvent();
d->generalCallbackEvent = d->eventHandler.addEvent();
@ -39,7 +38,7 @@ CallbackMainDispatcher::CallbackMainDispatcher()
d->lastCallbackId = 0;
}
CallbackMainDispatcher::~CallbackMainDispatcher(void){
CallbackMainDispatcher::~CallbackMainDispatcher(void) {
d->stopEvent->signal();
wait();
{
@ -48,7 +47,7 @@ CallbackMainDispatcher::~CallbackMainDispatcher(void){
delete d;
}
EventRef CallbackMainDispatcher::retrieveCallbackEvent(){
EventRef CallbackMainDispatcher::retrieveCallbackEvent() {
return d->generalCallbackEvent;
}
@ -88,14 +87,13 @@ int CallbackMainDispatcher::unregisterCallback(int callbackId) {
return TELLSTICK_ERROR_NOT_FOUND;
}
void CallbackMainDispatcher::run(){
while(!d->stopEvent->isSignaled()){
void CallbackMainDispatcher::run() {
while(!d->stopEvent->isSignaled()) {
if (!d->eventHandler.waitForAny()) {
continue;
}
if(d->generalCallbackEvent->isSignaled()){
if(d->generalCallbackEvent->isSignaled()) {
EventDataRef eventData = d->generalCallbackEvent->takeSignal();
CallbackData *cbd = dynamic_cast<CallbackData *>(eventData.get());

View file

@ -29,8 +29,7 @@ public:
Client *Client::instance = 0;
Client::Client()
: Thread()
{
: Thread() {
d = new PrivateData;
d->running = true;
d->sensorCached = false;
@ -83,16 +82,15 @@ int Client::registerEvent( CallbackStruct::CallbackType type, void *eventFunctio
return d->callbackMainDispatcher.registerCallback(type, eventFunction, context );
}
void Client::run(){
//listen here
void Client::run() {
// listen here
d->eventSocket.connect(L"TelldusEvents");
while(d->running){
if(!d->eventSocket.isConnected()){
d->eventSocket.connect(L"TelldusEvents"); //try to reconnect to service
if(!d->eventSocket.isConnected()){
//reconnect didn't succeed, wait a while and try again
while(d->running) {
if(!d->eventSocket.isConnected()) {
d->eventSocket.connect(L"TelldusEvents"); // try to reconnect to service
if(!d->eventSocket.isConnected()) {
// reconnect didn't succeed, wait a while and try again
msleep(2000);
continue;
}
@ -100,30 +98,30 @@ void Client::run(){
std::wstring clientMessage = d->eventSocket.read(1000); //testing 5 second timeout
while(clientMessage != L""){
//a message arrived
while(clientMessage != L"") {
// a message arrived
std::wstring type = Message::takeString(&clientMessage);
if(type == L"TDDeviceChangeEvent"){
if(type == L"TDDeviceChangeEvent") {
DeviceChangeEventCallbackData *data = new DeviceChangeEventCallbackData();
data->deviceId = Message::takeInt(&clientMessage);
data->changeEvent = Message::takeInt(&clientMessage);
data->changeType = Message::takeInt(&clientMessage);
d->callbackMainDispatcher.retrieveCallbackEvent()->signal(data);
} else if(type == L"TDDeviceEvent"){
} else if(type == L"TDDeviceEvent") {
DeviceEventCallbackData *data = new DeviceEventCallbackData();
data->deviceId = Message::takeInt(&clientMessage);
data->deviceState = Message::takeInt(&clientMessage);
data->deviceStateValue = TelldusCore::wideToString(Message::takeString(&clientMessage));
d->callbackMainDispatcher.retrieveCallbackEvent()->signal(data);
} else if(type == L"TDRawDeviceEvent"){
} else if(type == L"TDRawDeviceEvent") {
RawDeviceEventCallbackData *data = new RawDeviceEventCallbackData();
data->data = TelldusCore::wideToString(Message::takeString(&clientMessage));
data->controllerId = Message::takeInt(&clientMessage);
d->callbackMainDispatcher.retrieveCallbackEvent()->signal(data);
} else if(type == L"TDSensorEvent"){
} else if(type == L"TDSensorEvent") {
SensorEventCallbackData *data = new SensorEventCallbackData();
data->protocol = TelldusCore::wideToString(Message::takeString(&clientMessage));
data->model = TelldusCore::wideToString(Message::takeString(&clientMessage));
@ -152,9 +150,9 @@ std::wstring Client::sendToService(const Message &msg) {
int tries = 0;
std::wstring readData;
while(tries < 20){
while(tries < 20) {
tries++;
if(tries == 20){
if(tries == 20) {
TelldusCore::Message msg;
msg.addArgument(TELLSTICK_ERROR_CONNECTING_SERVICE);
return msg;
@ -170,8 +168,8 @@ std::wstring Client::sendToService(const Message &msg) {
msleep(500);
continue; //retry
}
readData = s.read(8000); //TODO changed to 10000 from 5000, how much does this do...?
if(readData == L""){
readData = s.read(8000); // TODO changed to 10000 from 5000, how much does this do...?
if(readData == L"") {
msleep(500);
continue; //TODO can we be really sure it SHOULD be anything?
//TODO perhaps break here instead?
@ -187,7 +185,7 @@ std::wstring Client::sendToService(const Message &msg) {
return readData;
}
void Client::stopThread(){
void Client::stopThread() {
d->running = false;
d->eventSocket.stopReadWait();
}

View file

@ -13,8 +13,7 @@
#include "common/Thread.h"
namespace TelldusCore {
class Client : public Thread
{
class Client : public Thread {
public:
~Client(void);

View file

@ -480,7 +480,7 @@ void WINAPI tdReleaseString(char *thestring) {
*
* @since Version 2.0.0
**/
int WINAPI tdTurnOn(int intDeviceId){
int WINAPI tdTurnOn(int intDeviceId) {
Message msg(L"tdTurnOn");
msg.addArgument(intDeviceId);
return Client::getIntegerFromService(msg);
@ -498,7 +498,7 @@ int WINAPI tdTurnOn(int intDeviceId){
*
* @since Version 2.0.0
**/
int WINAPI tdTurnOff(int intDeviceId){
int WINAPI tdTurnOff(int intDeviceId) {
Message msg(L"tdTurnOff");
msg.addArgument(intDeviceId);
return Client::getIntegerFromService(msg);
@ -516,7 +516,7 @@ int WINAPI tdTurnOff(int intDeviceId){
*
* @since Version 2.0.0
**/
int WINAPI tdBell(int intDeviceId){
int WINAPI tdBell(int intDeviceId) {
Message msg(L"tdBell");
msg.addArgument(intDeviceId);
return Client::getIntegerFromService(msg);
@ -536,7 +536,7 @@ int WINAPI tdBell(int intDeviceId){
*
* @since Version 2.0.0
**/
int WINAPI tdDim(int intDeviceId, unsigned char level){
int WINAPI tdDim(int intDeviceId, unsigned char level) {
Message msg(L"tdDim");
msg.addArgument(intDeviceId);
msg.addArgument(level);
@ -555,7 +555,7 @@ int WINAPI tdDim(int intDeviceId, unsigned char level){
*
* @since Version 2.1.0
**/
int WINAPI tdExecute(int intDeviceId){
int WINAPI tdExecute(int intDeviceId) {
Message msg(L"tdExecute");
msg.addArgument(intDeviceId);
return Client::getIntegerFromService(msg);
@ -573,7 +573,7 @@ int WINAPI tdExecute(int intDeviceId){
*
* @since Version 2.1.0
**/
int WINAPI tdUp(int intDeviceId){
int WINAPI tdUp(int intDeviceId) {
Message msg(L"tdUp");
msg.addArgument(intDeviceId);
return Client::getIntegerFromService(msg);
@ -591,7 +591,7 @@ int WINAPI tdUp(int intDeviceId){
*
* @since Version 2.1.0
**/
int WINAPI tdDown(int intDeviceId){
int WINAPI tdDown(int intDeviceId) {
Message msg(L"tdDown");
msg.addArgument(intDeviceId);
return Client::getIntegerFromService(msg);
@ -609,7 +609,7 @@ int WINAPI tdDown(int intDeviceId){
*
* @since Version 2.1.0
*/
int WINAPI tdStop(int intDeviceId){
int WINAPI tdStop(int intDeviceId) {
Message msg(L"tdStop");
msg.addArgument(intDeviceId);
return Client::getIntegerFromService(msg);
@ -683,7 +683,7 @@ char * WINAPI tdLastSentValue( int intDeviceId ) {
*
* @since Version 2.0.0
**/
int WINAPI tdGetNumberOfDevices(void){
int WINAPI tdGetNumberOfDevices(void) {
return Client::getIntegerFromService(Message(L"tdGetNumberOfDevices"));
}
@ -707,7 +707,7 @@ int WINAPI tdGetNumberOfDevices(void){
*
* @since Version 2.0.0
**/
int WINAPI tdGetDeviceId(int intDeviceIndex){
int WINAPI tdGetDeviceId(int intDeviceIndex) {
Message msg(L"tdGetDeviceId");
msg.addArgument(intDeviceIndex);
return Client::getIntegerFromService(msg);
@ -744,7 +744,7 @@ int WINAPI tdGetDeviceType(int intDeviceId) {
*
* @since Version 2.0.0
**/
char * WINAPI tdGetName(int intDeviceId){
char * WINAPI tdGetName(int intDeviceId) {
Message msg(L"tdGetName");
msg.addArgument(intDeviceId);
std::wstring strReturn = Client::getWStringFromService(msg);
@ -765,7 +765,7 @@ char * WINAPI tdGetName(int intDeviceId){
*
* @since Version 2.0.0
**/
bool WINAPI tdSetName(int intDeviceId, const char* strNewName){
bool WINAPI tdSetName(int intDeviceId, const char* strNewName) {
Message msg(L"tdSetName");
msg.addArgument(intDeviceId);
msg.addArgument(strNewName);
@ -784,7 +784,7 @@ bool WINAPI tdSetName(int intDeviceId, const char* strNewName){
*
* @since Version 2.0.0
**/
char* WINAPI tdGetProtocol(int intDeviceId){
char* WINAPI tdGetProtocol(int intDeviceId) {
Message msg(L"tdGetProtocol");
msg.addArgument(intDeviceId);
std::wstring strReturn = Client::getWStringFromService(msg);
@ -808,7 +808,7 @@ char* WINAPI tdGetProtocol(int intDeviceId){
*
* @since Version 2.0.0
**/
bool WINAPI tdSetProtocol(int intDeviceId, const char* strProtocol){
bool WINAPI tdSetProtocol(int intDeviceId, const char* strProtocol) {
Message msg(L"tdSetProtocol");
msg.addArgument(intDeviceId);
msg.addArgument(strProtocol);
@ -827,7 +827,7 @@ bool WINAPI tdSetProtocol(int intDeviceId, const char* strProtocol){
*
* @since Version 2.0.0
**/
char* WINAPI tdGetModel(int intDeviceId){
char* WINAPI tdGetModel(int intDeviceId) {
Message msg(L"tdGetModel");
msg.addArgument(intDeviceId);
std::wstring strReturn = Client::getWStringFromService(msg);
@ -848,7 +848,7 @@ char* WINAPI tdGetModel(int intDeviceId){
*
* @since Version 2.0.0
**/
bool WINAPI tdSetModel(int intDeviceId, const char *strModel){
bool WINAPI tdSetModel(int intDeviceId, const char *strModel) {
Message msg(L"tdSetModel");
msg.addArgument(intDeviceId);
msg.addArgument(strModel);
@ -871,7 +871,7 @@ bool WINAPI tdSetModel(int intDeviceId, const char *strModel){
*
* @since Version 2.0.0
**/
bool WINAPI tdSetDeviceParameter(int intDeviceId, const char *strName, const char *strValue){
bool WINAPI tdSetDeviceParameter(int intDeviceId, const char *strName, const char *strValue) {
Message msg(L"tdSetDeviceParameter");
msg.addArgument(intDeviceId);
msg.addArgument(strName);
@ -896,7 +896,7 @@ bool WINAPI tdSetDeviceParameter(int intDeviceId, const char *strName, const cha
*
* @since Version 2.0.0
**/
char * WINAPI tdGetDeviceParameter(int intDeviceId, const char *strName, const char *defaultValue){
char * WINAPI tdGetDeviceParameter(int intDeviceId, const char *strName, const char *defaultValue) {
Message msg(L"tdGetDeviceParameter");
msg.addArgument(intDeviceId);
msg.addArgument(strName);
@ -916,7 +916,7 @@ char * WINAPI tdGetDeviceParameter(int intDeviceId, const char *strName, const c
*
* @since Version 2.0.0
**/
int WINAPI tdAddDevice(){
int WINAPI tdAddDevice() {
Message msg(L"tdAddDevice");
return Client::getIntegerFromService(msg);
}
@ -932,7 +932,7 @@ int WINAPI tdAddDevice(){
*
* @since Version 2.0.0
**/
bool WINAPI tdRemoveDevice(int intDeviceId){
bool WINAPI tdRemoveDevice(int intDeviceId) {
Message msg(L"tdRemoveDevice");
msg.addArgument(intDeviceId);
return Client::getBoolFromService(msg);
@ -973,7 +973,7 @@ bool WINAPI tdRemoveDevice(int intDeviceId){
*
* @since Version 2.0.0
**/
int WINAPI tdMethods(int id, int methodsSupported){
int WINAPI tdMethods(int id, int methodsSupported) {
Message msg(L"tdMethods");
msg.addArgument(id);
msg.addArgument(methodsSupported);

View file

@ -48,12 +48,12 @@ EventRef EventHandler::addEvent() {
return event;
}
bool EventHandler::listIsSignalled(){
bool EventHandler::listIsSignalled() {
TelldusCore::MutexLocker locker(&d->listMutex);
std::list<EventRef>::const_iterator it = d->eventList.begin();
for(; it != d->eventList.end(); ++it) {
if((*it)->isSignaled()){
if((*it)->isSignaled()) {
return true;
}
}

View file

@ -15,7 +15,7 @@ public:
};
Event::Event(EventHandler *handler)
:EventBase(handler){
:EventBase(handler) {
d = new PrivateData;
}

View file

@ -15,13 +15,11 @@ using namespace TelldusCore;
Message::Message()
: std::wstring()
{
: std::wstring() {
}
Message::Message(const std::wstring &functionName)
:std::wstring()
{
:std::wstring() {
this->addArgument(functionName);
}

View file

@ -77,8 +77,7 @@ void LoggedMutex::unlock() {
}
MutexLocker::MutexLocker(Mutex *m)
:mutex(m)
{
:mutex(m) {
mutex->lock();
}

View file

@ -17,8 +17,7 @@
#endif
namespace TelldusCore {
class Socket
{
class Socket {
public:
Socket();
explicit Socket(SOCKET_T hPipe);

View file

@ -39,8 +39,7 @@ Socket::Socket() {
FD_ZERO(&d->infds);
}
Socket::Socket(SOCKET_T socket)
{
Socket::Socket(SOCKET_T socket) {
d = new PrivateData;
d->socket = socket;
FD_ZERO(&d->infds);
@ -48,7 +47,7 @@ Socket::Socket(SOCKET_T socket)
}
Socket::~Socket(void) {
if(d->socket){
if(d->socket) {
close(d->socket);
}
delete d;
@ -74,7 +73,7 @@ void Socket::connect(const std::wstring &server) {
d->connected = true;
}
bool Socket::isConnected(){
bool Socket::isConnected() {
TelldusCore::MutexLocker locker(&d->mutex);
return d->connected;
}
@ -102,10 +101,10 @@ std::wstring Socket::read(int timeout) {
}
int received = BUFSIZE;
while(received >= (BUFSIZE - 1)){
while(received >= (BUFSIZE - 1)) {
memset(inbuf, '\0', sizeof(inbuf));
received = recv(d->socket, inbuf, BUFSIZE - 1, 0);
if(received > 0){
if(received > 0) {
msg.append(std::string(inbuf));
}
}
@ -119,7 +118,7 @@ std::wstring Socket::read(int timeout) {
return TelldusCore::charToWstring(msg.c_str());
}
void Socket::stopReadWait(){
void Socket::stopReadWait() {
TelldusCore::MutexLocker locker(&d->mutex);
d->connected = false;
//TODO somehow signal the socket here?

View file

@ -73,7 +73,7 @@ std::wstring TelldusCore::charToWstring(const char *value) {
#endif
}
int TelldusCore::charToInteger(const char *input){
int TelldusCore::charToInteger(const char *input) {
std::stringstream inputstream;
inputstream << input;
int retval;
@ -150,7 +150,7 @@ std::wstring TelldusCore::intToWStringSafe(int value){
}
*/
uint64_t TelldusCore::hexTo64l(const std::string data){
uint64_t TelldusCore::hexTo64l(const std::string data) {
#ifdef _WINDOWS
return _strtoui64(data.c_str(), NULL, 16);
#elif defined(_MACOSX)
@ -160,7 +160,7 @@ uint64_t TelldusCore::hexTo64l(const std::string data){
#endif
}
int TelldusCore::wideToInteger(const std::wstring &input){
int TelldusCore::wideToInteger(const std::wstring &input) {
std::wstringstream inputstream;
inputstream << input;
int retval;

View file

@ -41,7 +41,7 @@ inline void dlog(const char *fmt, ...) {
fflush(stdout);
}
inline void debuglog(const int intMessage, const std::string strMessage){
inline void debuglog(const int intMessage, const std::string strMessage) {
#ifdef _WINDOWS
static bool firstRun = true;
std::ofstream file;

View file

@ -20,13 +20,11 @@ public:
ControllerManager *controllerManager;
};
ClientCommunicationHandler::ClientCommunicationHandler(){
ClientCommunicationHandler::ClientCommunicationHandler() {
}
ClientCommunicationHandler::ClientCommunicationHandler(TelldusCore::Socket *clientSocket, TelldusCore::EventRef event, DeviceManager *deviceManager, TelldusCore::EventRef deviceUpdateEvent, ControllerManager *controllerManager)
:Thread()
{
:Thread() {
d = new PrivateData;
d->clientSocket = clientSocket;
d->event = event;
@ -36,15 +34,14 @@ ClientCommunicationHandler::ClientCommunicationHandler(TelldusCore::Socket *clie
d->controllerManager = controllerManager;
}
ClientCommunicationHandler::~ClientCommunicationHandler(void)
{
ClientCommunicationHandler::~ClientCommunicationHandler(void) {
wait();
delete(d->clientSocket);
delete d;
}
void ClientCommunicationHandler::run(){
//run thread
void ClientCommunicationHandler::run() {
// run thread
std::wstring clientMessage = d->clientSocket->read(2000);
@ -55,10 +52,10 @@ void ClientCommunicationHandler::run(){
TelldusCore::Message msg;
if(strReturn == L""){
if(strReturn == L"") {
msg.addArgument(intReturn);
}
else{
else {
msg.addArgument(strReturn);
}
msg.append(L"\n");
@ -69,13 +66,12 @@ void ClientCommunicationHandler::run(){
d->event->signal();
}
bool ClientCommunicationHandler::isDone(){
bool ClientCommunicationHandler::isDone() {
return d->done;
}
void ClientCommunicationHandler::parseMessage(const std::wstring &clientMessage, int *intReturn, std::wstring *wstringReturn){
void ClientCommunicationHandler::parseMessage(const std::wstring &clientMessage, int *intReturn, std::wstring *wstringReturn) {
(*intReturn) = 0;
(*wstringReturn) = L"";
std::wstring msg(clientMessage); //Copy
@ -127,8 +123,7 @@ void ClientCommunicationHandler::parseMessage(const std::wstring &clientMessage,
int deviceId = TelldusCore::Message::takeInt(&msg);
(*wstringReturn) = d->deviceManager->getDeviceStateValue(deviceId);
} else if(function == L"tdGetNumberOfDevices"){
} else if(function == L"tdGetNumberOfDevices") {
(*intReturn) = d->deviceManager->getNumberOfDevices();
} else if (function == L"tdGetDeviceId") {
@ -159,7 +154,7 @@ void ClientCommunicationHandler::parseMessage(const std::wstring &clientMessage,
int oldMethods = d->deviceManager->getDeviceMethods(deviceId);
(*intReturn) = d->deviceManager->setDeviceProtocol(deviceId, protocol);
sendDeviceSignal(deviceId, TELLSTICK_DEVICE_CHANGED, TELLSTICK_CHANGE_PROTOCOL);
if(oldMethods != d->deviceManager->getDeviceMethods(deviceId)){
if(oldMethods != d->deviceManager->getDeviceMethods(deviceId)) {
sendDeviceSignal(deviceId, TELLSTICK_DEVICE_CHANGED, TELLSTICK_CHANGE_METHOD);
}
@ -173,7 +168,7 @@ void ClientCommunicationHandler::parseMessage(const std::wstring &clientMessage,
int oldMethods = d->deviceManager->getDeviceMethods(deviceId);
(*intReturn) = d->deviceManager->setDeviceModel(deviceId, model);
sendDeviceSignal(deviceId, TELLSTICK_DEVICE_CHANGED, TELLSTICK_CHANGE_MODEL);
if(oldMethods != d->deviceManager->getDeviceMethods(deviceId)){
if(oldMethods != d->deviceManager->getDeviceMethods(deviceId)) {
sendDeviceSignal(deviceId, TELLSTICK_DEVICE_CHANGED, TELLSTICK_CHANGE_METHOD);
}
@ -189,20 +184,20 @@ void ClientCommunicationHandler::parseMessage(const std::wstring &clientMessage,
std::wstring value = TelldusCore::Message::takeString(&msg);
int oldMethods = d->deviceManager->getDeviceMethods(deviceId);
(*intReturn) = d->deviceManager->setDeviceParameter(deviceId, name, value);
if(oldMethods != d->deviceManager->getDeviceMethods(deviceId)){
if(oldMethods != d->deviceManager->getDeviceMethods(deviceId)) {
sendDeviceSignal(deviceId, TELLSTICK_DEVICE_CHANGED, TELLSTICK_CHANGE_METHOD);
}
} else if (function == L"tdAddDevice") {
(*intReturn) = d->deviceManager->addDevice();
if((*intReturn) >= 0){
if((*intReturn) >= 0) {
sendDeviceSignal((*intReturn), TELLSTICK_DEVICE_ADDED, 0);
}
} else if (function == L"tdRemoveDevice") {
int deviceId = TelldusCore::Message::takeInt(&msg);
(*intReturn) = d->deviceManager->removeDevice(deviceId);
if((*intReturn) == TELLSTICK_SUCCESS){
if((*intReturn) == TELLSTICK_SUCCESS) {
sendDeviceSignal(deviceId, TELLSTICK_DEVICE_REMOVED, 0);
}
@ -261,8 +256,7 @@ void ClientCommunicationHandler::parseMessage(const std::wstring &clientMessage,
}
}
void ClientCommunicationHandler::sendDeviceSignal(int deviceId, int eventDeviceChanges, int eventChangeType){
void ClientCommunicationHandler::sendDeviceSignal(int deviceId, int eventDeviceChanges, int eventChangeType) {
EventUpdateData *eventData = new EventUpdateData();
eventData->messageType = L"TDDeviceChangeEvent";
eventData->deviceId = deviceId;

View file

@ -14,8 +14,7 @@
#include "service/DeviceManager.h"
#include "service/ControllerManager.h"
class ClientCommunicationHandler : public TelldusCore::Thread
{
class ClientCommunicationHandler : public TelldusCore::Thread {
public:
ClientCommunicationHandler();
ClientCommunicationHandler(

View file

@ -25,8 +25,7 @@ public:
bool running;
};
ConnectionListener::ConnectionListener(const std::wstring &name, TelldusCore::EventRef waitEvent)
{
ConnectionListener::ConnectionListener(const std::wstring &name, TelldusCore::EventRef waitEvent) {
d = new PrivateData;
d->waitEvent = waitEvent;
@ -43,7 +42,7 @@ ConnectionListener::~ConnectionListener(void) {
delete d;
}
void ConnectionListener::run(){
void ConnectionListener::run() {
struct timeval tv = { 0, 0 };
//Timeout for select

View file

@ -17,7 +17,7 @@ public:
int id, firmwareVersion;
};
Controller::Controller(int id, TelldusCore::EventRef event, TelldusCore::EventRef updateEvent){
Controller::Controller(int id, TelldusCore::EventRef event, TelldusCore::EventRef updateEvent) {
d = new PrivateData;
d->event = event;
d->updateEvent = updateEvent;
@ -25,7 +25,7 @@ Controller::Controller(int id, TelldusCore::EventRef event, TelldusCore::EventRe
d->firmwareVersion = 0;
}
Controller::~Controller(){
Controller::~Controller() {
delete d;
}
@ -40,7 +40,7 @@ void Controller::decodePublishData(const std::string &data) const {
std::list<std::string> msgList = Protocol::decodeData(data);
for (std::list<std::string>::iterator msgIt = msgList.begin(); msgIt != msgList.end(); ++msgIt){
for (std::list<std::string>::iterator msgIt = msgList.begin(); msgIt != msgList.end(); ++msgIt) {
this->publishData(*msgIt);
}
}

View file

@ -36,7 +36,7 @@ public:
TelldusCore::Mutex mutex;
};
ControllerManager::ControllerManager(TelldusCore::EventRef event, TelldusCore::EventRef updateEvent){
ControllerManager::ControllerManager(TelldusCore::EventRef event, TelldusCore::EventRef updateEvent) {
d = new PrivateData;
d->lastControllerId = 0;
d->event = event;
@ -171,8 +171,8 @@ void ControllerManager::loadControllers() {
bool isNew = false;
if (!controllerId) {
controllerId = d->settings.addNode(Settings::Controller);
if(controllerId < 0){
//TODO: How to handle this?
if(controllerId < 0) {
// TODO: How to handle this?
continue;
}
isNew = true;
@ -212,8 +212,7 @@ void ControllerManager::loadStoredControllers() {
}
}
void ControllerManager::queryControllerStatus(){
void ControllerManager::queryControllerStatus() {
std::list<TellStick *> tellStickControllers;
{
@ -233,18 +232,18 @@ void ControllerManager::queryControllerStatus(){
std::string noop = "N+";
for(std::list<TellStick *>::iterator it = tellStickControllers.begin(); it != tellStickControllers.end(); ++it) {
int success = (*it)->send(noop);
if(success == TELLSTICK_ERROR_BROKEN_PIPE){
if(success == TELLSTICK_ERROR_BROKEN_PIPE) {
Log::warning("TellStick query: Error in communication with TellStick, resetting USB");
resetController(*it);
}
if(success == TELLSTICK_ERROR_BROKEN_PIPE || success == TELLSTICK_ERROR_NOT_FOUND){
if(success == TELLSTICK_ERROR_BROKEN_PIPE || success == TELLSTICK_ERROR_NOT_FOUND) {
reloadControllers = true;
}
}
if(!tellStickControllers.size() || reloadControllers){
//no tellstick at all found, or controller was reset
Log::debug("TellStick query: Rescanning USB ports"); //only log as debug, since this will happen all the time if no TellStick is connected
if(!tellStickControllers.size() || reloadControllers) {
// no tellstick at all found, or controller was reset
Log::debug("TellStick query: Rescanning USB ports"); // only log as debug, since this will happen all the time if no TellStick is connected
loadControllers();
}
}

View file

@ -47,7 +47,7 @@ ControllerMessage::ControllerMessage(const std::string &message) {
}
}
ControllerMessage::~ControllerMessage(){
ControllerMessage::~ControllerMessage() {
delete d;
}

View file

@ -23,8 +23,7 @@ public:
};
Device::Device(int id)
:Mutex()
{
:Mutex() {
d = new PrivateData;
d->protocol = 0;
d->preferredControllerId = 0;
@ -40,8 +39,7 @@ Device::~Device(void) {
* Get-/Set-methods
*/
int Device::getLastSentCommand(int methodsSupported){
int Device::getLastSentCommand(int methodsSupported) {
int lastSentCommand = Device::maskUnsupportedMethods(d->state, methodsSupported);
if (lastSentCommand == TELLSTICK_BELL) {
@ -63,32 +61,32 @@ int Device::getMethods() const {
return 0;
}
void Device::setLastSentCommand(int command, std::wstring value){
void Device::setLastSentCommand(int command, std::wstring value) {
d->state = command;
d->stateValue = value;
}
std::wstring Device::getModel(){
std::wstring Device::getModel() {
return d->model;
}
void Device::setModel(const std::wstring &model){
if(d->protocol){
void Device::setModel(const std::wstring &model) {
if(d->protocol) {
delete(d->protocol);
d->protocol = 0;
}
d->model = model;
}
std::wstring Device::getName(){
std::wstring Device::getName() {
return d->name;
}
void Device::setName(const std::wstring &name){
void Device::setName(const std::wstring &name) {
d->name = name;
}
std::wstring Device::getParameter(const std::wstring &key){
std::wstring Device::getParameter(const std::wstring &key) {
ParameterMap::iterator it = d->parameterList.find(key);
if (it == d->parameterList.end()) {
return L"";
@ -100,18 +98,18 @@ std::list<std::string> Device::getParametersForProtocol() const {
return Protocol::getParametersForProtocol(getProtocolName());
}
void Device::setParameter(const std::wstring &key, const std::wstring &value){
void Device::setParameter(const std::wstring &key, const std::wstring &value) {
d->parameterList[key] = value;
if(d->protocol){
if(d->protocol) {
d->protocol->setParameters(d->parameterList);
}
}
int Device::getPreferredControllerId(){
int Device::getPreferredControllerId() {
return d->preferredControllerId;
}
void Device::setPreferredControllerId(int controllerId){
void Device::setPreferredControllerId(int controllerId) {
d->preferredControllerId = controllerId;
}
@ -119,23 +117,23 @@ std::wstring Device::getProtocolName() const {
return d->protocolName;
}
void Device::setProtocolName(const std::wstring &protocolName){
if(d->protocol){
void Device::setProtocolName(const std::wstring &protocolName) {
if(d->protocol) {
delete(d->protocol);
d->protocol = 0;
}
d->protocolName = protocolName;
}
std::wstring Device::getStateValue(){
std::wstring Device::getStateValue() {
return d->stateValue;
}
int Device::getType(){
if(d->protocolName == L"group"){
int Device::getType() {
if(d->protocolName == L"group") {
return TELLSTICK_TYPE_GROUP;
}
else if(d->protocolName == L"scene"){
else if(d->protocolName == L"scene") {
return TELLSTICK_TYPE_SCENE;
}
return TELLSTICK_TYPE_DEVICE;
@ -199,7 +197,7 @@ Protocol* Device::retrieveProtocol() const {
}
d->protocol = Protocol::getProtocolInstance(d->protocolName);
if(d->protocol){
if(d->protocol) {
d->protocol->setModel(d->model);
d->protocol->setParameters(d->parameterList);
return d->protocol;

View file

@ -13,8 +13,7 @@
#include <string>
#include <list>
class Device : public TelldusCore::Mutex
{
class Device : public TelldusCore::Mutex {
public:
explicit Device(int id);
~Device(void);

View file

@ -30,7 +30,7 @@ public:
TelldusCore::EventRef deviceUpdateEvent;
};
DeviceManager::DeviceManager(ControllerManager *controllerManager, TelldusCore::EventRef deviceUpdateEvent){
DeviceManager::DeviceManager(ControllerManager *controllerManager, TelldusCore::EventRef deviceUpdateEvent) {
d = new PrivateData;
d->controllerManager = controllerManager;
d->deviceUpdateEvent = deviceUpdateEvent;
@ -52,7 +52,7 @@ DeviceManager::~DeviceManager(void) {
delete d;
}
void DeviceManager::fillDevices(){
void DeviceManager::fillDevices() {
int numberOfDevices = d->set.getNumberOfNodes(Settings::Device);
TelldusCore::MutexLocker deviceListLocker(&d->lock);
@ -74,7 +74,7 @@ void DeviceManager::fillDevices(){
}
}
int DeviceManager::getDeviceLastSentCommand(int deviceId, int methodsSupported){
int DeviceManager::getDeviceLastSentCommand(int deviceId, int methodsSupported) {
TelldusCore::MutexLocker deviceListLocker(&d->lock);
if (!d->devices.size()) {
return TELLSTICK_ERROR_DEVICE_NOT_FOUND;
@ -87,8 +87,7 @@ int DeviceManager::getDeviceLastSentCommand(int deviceId, int methodsSupported){
return TELLSTICK_ERROR_DEVICE_NOT_FOUND;
}
int DeviceManager::setDeviceLastSentCommand(int deviceId, int command, const std::wstring &value)
{
int DeviceManager::setDeviceLastSentCommand(int deviceId, int command, const std::wstring &value) {
TelldusCore::MutexLocker deviceListLocker(&d->lock);
if (!d->devices.size()) {
return TELLSTICK_ERROR_DEVICE_NOT_FOUND;
@ -99,13 +98,13 @@ int DeviceManager::setDeviceLastSentCommand(int deviceId, int command, const std
d->set.setDeviceState(deviceId, command,value);
it->second->setLastSentCommand(command, value);
}
else{
else {
return TELLSTICK_ERROR_DEVICE_NOT_FOUND;
}
return TELLSTICK_SUCCESS;
}
std::wstring DeviceManager::getDeviceStateValue(int deviceId){
std::wstring DeviceManager::getDeviceStateValue(int deviceId) {
TelldusCore::MutexLocker deviceListLocker(&d->lock);
if (!d->devices.size()) {
return L"UNKNOWN";
@ -127,7 +126,7 @@ int DeviceManager::getDeviceMethods(int deviceId) {
return DeviceManager::getDeviceMethods(deviceId, duplicateDeviceIds);
}
int DeviceManager::getDeviceMethods(int deviceId, std::set<int> &duplicateDeviceIds){
int DeviceManager::getDeviceMethods(int deviceId, std::set<int> &duplicateDeviceIds) {
int type = 0;
int methods = 0;
std::wstring deviceIds;
@ -152,29 +151,28 @@ int DeviceManager::getDeviceMethods(int deviceId, std::set<int> &duplicateDevice
}
}
}
if(type == 0){
if(type == 0) {
return 0;
}
if(type == TELLSTICK_TYPE_GROUP){
//get all methods that some device in the groups supports
if(type == TELLSTICK_TYPE_GROUP) {
// get all methods that some device in the groups supports
std::wstring deviceIdBuffer;
std::wstringstream devicesstream(deviceIds);
methods = 0;
duplicateDeviceIds.insert(deviceId);
while(std::getline(devicesstream, deviceIdBuffer, L',')){
while(std::getline(devicesstream, deviceIdBuffer, L',')) {
int deviceIdInGroup = TelldusCore::wideToInteger(deviceIdBuffer);
if(duplicateDeviceIds.count(deviceIdInGroup) == 1){
//action for device already executed, or will execute, do nothing to avoid infinite loop
if(duplicateDeviceIds.count(deviceIdInGroup) == 1) {
// action for device already executed, or will execute, do nothing to avoid infinite loop
continue;
}
duplicateDeviceIds.insert(deviceIdInGroup);
int deviceMethods = getDeviceMethods(deviceIdInGroup, duplicateDeviceIds);
if(deviceMethods > 0){
if(deviceMethods > 0) {
methods |= deviceMethods;
}
}
@ -182,8 +180,7 @@ int DeviceManager::getDeviceMethods(int deviceId, std::set<int> &duplicateDevice
return methods;
}
std::wstring DeviceManager::getDeviceModel(int deviceId){
std::wstring DeviceManager::getDeviceModel(int deviceId) {
TelldusCore::MutexLocker deviceListLocker(&d->lock);
if (!d->devices.size()) {
return L"UNKNOWN";
@ -196,8 +193,7 @@ std::wstring DeviceManager::getDeviceModel(int deviceId){
return L"UNKNOWN";
}
int DeviceManager::setDeviceModel(int deviceId, const std::wstring &model)
{
int DeviceManager::setDeviceModel(int deviceId, const std::wstring &model) {
TelldusCore::MutexLocker deviceListLocker(&d->lock);
if (!d->devices.size()) {
return TELLSTICK_ERROR_DEVICE_NOT_FOUND;
@ -211,15 +207,14 @@ int DeviceManager::setDeviceModel(int deviceId, const std::wstring &model)
}
it->second->setModel(model);
}
else{
else {
return TELLSTICK_ERROR_DEVICE_NOT_FOUND;
}
return TELLSTICK_SUCCESS;
}
std::wstring DeviceManager::getDeviceName(int deviceId){
std::wstring DeviceManager::getDeviceName(int deviceId) {
TelldusCore::MutexLocker deviceListLocker(&d->lock);
if (!d->devices.size()) {
return L"UNKNOWN";
@ -232,8 +227,7 @@ std::wstring DeviceManager::getDeviceName(int deviceId){
return L"UNKNOWN";
}
int DeviceManager::setDeviceName(int deviceId, const std::wstring &name){
int DeviceManager::setDeviceName(int deviceId, const std::wstring &name) {
TelldusCore::MutexLocker deviceListLocker(&d->lock);
if (!d->devices.size()) {
return TELLSTICK_ERROR_DEVICE_NOT_FOUND;
@ -247,32 +241,30 @@ int DeviceManager::setDeviceName(int deviceId, const std::wstring &name){
}
it->second->setName(name);
}
else{
else {
return TELLSTICK_ERROR_DEVICE_NOT_FOUND;
}
return TELLSTICK_SUCCESS;
}
std::wstring DeviceManager::getDeviceParameter(int deviceId, const std::wstring &name, const std::wstring &defaultValue){
std::wstring DeviceManager::getDeviceParameter(int deviceId, const std::wstring &name, const std::wstring &defaultValue) {
TelldusCore::MutexLocker deviceListLocker(&d->lock);
if (!d->devices.size()) {
return defaultValue;
}
DeviceMap::iterator it = d->devices.find(deviceId);
if (it != d->devices.end()){
if (it != d->devices.end()) {
TelldusCore::MutexLocker deviceLocker(it->second);
std::wstring returnString = it->second->getParameter(name);
if(returnString != L""){
if(returnString != L"") {
return returnString;
}
}
return defaultValue;
}
int DeviceManager::setDeviceParameter(int deviceId, const std::wstring &name, const std::wstring &value)
{
int DeviceManager::setDeviceParameter(int deviceId, const std::wstring &name, const std::wstring &value) {
TelldusCore::MutexLocker deviceListLocker(&d->lock);
if (!d->devices.size()) {
return TELLSTICK_ERROR_DEVICE_NOT_FOUND;
@ -286,15 +278,14 @@ int DeviceManager::setDeviceParameter(int deviceId, const std::wstring &name, co
}
it->second->setParameter(name, value);
}
else{
else {
return TELLSTICK_ERROR_DEVICE_NOT_FOUND;
}
return TELLSTICK_SUCCESS;
}
std::wstring DeviceManager::getDeviceProtocol(int deviceId){
std::wstring DeviceManager::getDeviceProtocol(int deviceId) {
TelldusCore::MutexLocker deviceListLocker(&d->lock);
if (!d->devices.size()) {
return L"UNKNOWN";
@ -307,8 +298,7 @@ std::wstring DeviceManager::getDeviceProtocol(int deviceId){
return L"UNKNOWN";
}
int DeviceManager::setDeviceProtocol(int deviceId, const std::wstring &protocol)
{
int DeviceManager::setDeviceProtocol(int deviceId, const std::wstring &protocol) {
TelldusCore::MutexLocker deviceListLocker(&d->lock);
if (!d->devices.size()) {
return TELLSTICK_ERROR_DEVICE_NOT_FOUND;
@ -322,28 +312,27 @@ int DeviceManager::setDeviceProtocol(int deviceId, const std::wstring &protocol)
}
it->second->setProtocolName(protocol);
}
else{
else {
return TELLSTICK_ERROR_DEVICE_NOT_FOUND;
}
return TELLSTICK_SUCCESS;
}
int DeviceManager::getNumberOfDevices(){
int DeviceManager::getNumberOfDevices() {
TelldusCore::MutexLocker deviceListLocker(&d->lock);
return (int)d->devices.size();
}
int DeviceManager::addDevice(){
int DeviceManager::addDevice() {
int id = d->set.addNode(Settings::Device);
if(id < 0){
if(id < 0) {
return id;
}
TelldusCore::MutexLocker deviceListLocker(&d->lock);
d->devices[id] = new Device(id);
if(!d->devices[id]){
if(!d->devices[id]) {
return TELLSTICK_ERROR_DEVICE_NOT_FOUND;
}
return id;
@ -353,8 +342,7 @@ int DeviceManager::getDeviceId(int deviceIndex) {
return d->set.getNodeId(Settings::Device, deviceIndex);
}
int DeviceManager::getDeviceType(int deviceId){
int DeviceManager::getDeviceType(int deviceId) {
TelldusCore::MutexLocker deviceListLocker(&d->lock);
if (!d->devices.size()) {
return TELLSTICK_ERROR_DEVICE_NOT_FOUND;
@ -367,8 +355,7 @@ int DeviceManager::getDeviceType(int deviceId){
return TELLSTICK_ERROR_DEVICE_NOT_FOUND;
}
int DeviceManager::getPreferredControllerId(int deviceId){
int DeviceManager::getPreferredControllerId(int deviceId) {
TelldusCore::MutexLocker deviceListLocker(&d->lock);
if (!d->devices.size()) {
@ -382,15 +369,15 @@ int DeviceManager::getPreferredControllerId(int deviceId){
return TELLSTICK_ERROR_DEVICE_NOT_FOUND;
}
void DeviceManager::connectTellStickController(int vid, int pid, const std::string &serial){
void DeviceManager::connectTellStickController(int vid, int pid, const std::string &serial) {
d->controllerManager->deviceInsertedOrRemoved(vid, pid, serial, true);
}
void DeviceManager::disconnectTellStickController(int vid, int pid, const std::string &serial){
void DeviceManager::disconnectTellStickController(int vid, int pid, const std::string &serial) {
d->controllerManager->deviceInsertedOrRemoved(vid, pid, serial, false);
}
int DeviceManager::doAction(int deviceId, int action, unsigned char data){
int DeviceManager::doAction(int deviceId, int action, unsigned char data) {
Device *device = 0;
//On the stack and will be released if we have a device lock.
std::auto_ptr<TelldusCore::MutexLocker> deviceLocker(0);
@ -412,7 +399,7 @@ int DeviceManager::doAction(int deviceId, int action, unsigned char data){
int retval = TELLSTICK_ERROR_UNKNOWN;
if(device->getType() == TELLSTICK_TYPE_GROUP || device->getType() == TELLSTICK_TYPE_SCENE){
if(device->getType() == TELLSTICK_TYPE_GROUP || device->getType() == TELLSTICK_TYPE_SCENE) {
std::wstring devices = device->getParameter(L"devices");
deviceLocker = std::auto_ptr<TelldusCore::MutexLocker>(0);
std::set<int> *duplicateDeviceIds = new std::set<int>;
@ -436,26 +423,26 @@ int DeviceManager::doAction(int deviceId, int action, unsigned char data){
device = it->second;
} //devicelist unlocked
}
else{
else {
Controller *controller = d->controllerManager->getBestControllerById(device->getPreferredControllerId());
if(!controller){
if(!controller) {
Log::warning("Trying to execute action, but no controller found. Rescanning USB ports");
//no controller found, scan for one, and retry once
d->controllerManager->loadControllers();
controller = d->controllerManager->getBestControllerById(device->getPreferredControllerId());
}
if(controller){
if(controller) {
retval = device->doAction(action, data, controller);
if(retval == TELLSTICK_ERROR_BROKEN_PIPE){
if(retval == TELLSTICK_ERROR_BROKEN_PIPE) {
Log::warning("Error in communication with TellStick when executing action. Resetting USB");
d->controllerManager->resetController(controller);
}
if(retval == TELLSTICK_ERROR_BROKEN_PIPE || retval == TELLSTICK_ERROR_NOT_FOUND){
if(retval == TELLSTICK_ERROR_BROKEN_PIPE || retval == TELLSTICK_ERROR_NOT_FOUND) {
Log::warning("Rescanning USB ports");
d->controllerManager->loadControllers();
controller = d->controllerManager->getBestControllerById(device->getPreferredControllerId());
if(!controller){
if(!controller) {
Log::error("No contoller (TellStick) found, even after reset. Giving up.");
return TELLSTICK_ERROR_NOT_FOUND;
}
@ -477,19 +464,18 @@ int DeviceManager::doAction(int deviceId, int action, unsigned char data){
return retval;
}
int DeviceManager::doGroupAction(const std::wstring devices, const int action, const unsigned char data, const int type, const int groupDeviceId, std::set<int> *duplicateDeviceIds){
int DeviceManager::doGroupAction(const std::wstring devices, const int action, const unsigned char data, const int type, const int groupDeviceId, std::set<int> *duplicateDeviceIds) {
int retval = TELLSTICK_ERROR_METHOD_NOT_SUPPORTED;
std::wstring singledevice;
std::wstringstream devicesstream(devices);
duplicateDeviceIds->insert(groupDeviceId);
while(std::getline(devicesstream, singledevice, L',')){
while(std::getline(devicesstream, singledevice, L',')) {
int deviceId = TelldusCore::wideToInteger(singledevice);
if(duplicateDeviceIds->count(deviceId) == 1){
//action for device already executed, or will execute, do nothing to avoid infinite loop
if(duplicateDeviceIds->count(deviceId) == 1) {
// action for device already executed, or will execute, do nothing to avoid infinite loop
continue;
}
@ -497,20 +483,20 @@ int DeviceManager::doGroupAction(const std::wstring devices, const int action, c
int deviceReturnValue = TELLSTICK_SUCCESS;
if(type == TELLSTICK_TYPE_SCENE && (action == TELLSTICK_TURNON || action == TELLSTICK_EXECUTE)){
if(type == TELLSTICK_TYPE_SCENE && (action == TELLSTICK_TURNON || action == TELLSTICK_EXECUTE)) {
deviceReturnValue = executeScene(singledevice, groupDeviceId);
}
else if(type == TELLSTICK_TYPE_GROUP){
if(deviceId != 0){
else if(type == TELLSTICK_TYPE_GROUP) {
if(deviceId != 0) {
int childType = DeviceManager::getDeviceType(deviceId);
if(childType == TELLSTICK_TYPE_DEVICE){
if(childType == TELLSTICK_TYPE_DEVICE) {
deviceReturnValue = doAction(deviceId, action, data);
}
else if(childType == TELLSTICK_TYPE_SCENE){
deviceReturnValue = doGroupAction(DeviceManager::getDeviceParameter(deviceId, L"devices", L""), action, data, childType, deviceId, duplicateDeviceIds); //TODO make scenes infinite loops-safe
else if(childType == TELLSTICK_TYPE_SCENE) {
deviceReturnValue = doGroupAction(DeviceManager::getDeviceParameter(deviceId, L"devices", L""), action, data, childType, deviceId, duplicateDeviceIds); // TODO make scenes infinite loops-safe
}
else{
//group (in group)
else {
// group (in group)
deviceReturnValue = doGroupAction(DeviceManager::getDeviceParameter(deviceId, L"devices", L""), action, data, childType, deviceId, duplicateDeviceIds);
if(deviceReturnValue == TELLSTICK_SUCCESS) {
@ -522,15 +508,15 @@ int DeviceManager::doGroupAction(const std::wstring devices, const int action, c
}
}
}
else{
deviceReturnValue = TELLSTICK_ERROR_DEVICE_NOT_FOUND; //Probably incorrectly formatted parameter
else {
deviceReturnValue = TELLSTICK_ERROR_DEVICE_NOT_FOUND; // Probably incorrectly formatted parameter
}
}
if(deviceReturnValue != TELLSTICK_ERROR_METHOD_NOT_SUPPORTED){
//if error(s), return the last error, but still try to continue the action with the other devices
//if the error is a method not supported we igore is since there might be others supporting it
//If no devices support the method the default value will be returned (method not supported)
if(deviceReturnValue != TELLSTICK_ERROR_METHOD_NOT_SUPPORTED) {
// if error(s), return the last error, but still try to continue the action with the other devices
// if the error is a method not supported we igore is since there might be others supporting it
// If no devices support the method the default value will be returned (method not supported)
retval = deviceReturnValue;
}
@ -538,45 +524,43 @@ int DeviceManager::doGroupAction(const std::wstring devices, const int action, c
return retval;
}
int DeviceManager::executeScene(std::wstring singledevice, int groupDeviceId){
int DeviceManager::executeScene(std::wstring singledevice, int groupDeviceId) {
std::wstringstream devicestream(singledevice);
const int deviceParameterLength = 3;
std::wstring deviceParts[deviceParameterLength] = {L"", L"", L""};
std::wstring devicePart = L"";
int i = 0;
while(std::getline(devicestream, devicePart, L':') && i < deviceParameterLength){
while(std::getline(devicestream, devicePart, L':') && i < deviceParameterLength) {
deviceParts[i] = devicePart;
i++;
}
if(deviceParts[0] == L"" || deviceParts[1] == L""){
return TELLSTICK_ERROR_UNKNOWN; //malformed or missing parameter
if(deviceParts[0] == L"" || deviceParts[1] == L"") {
return TELLSTICK_ERROR_UNKNOWN; // malformed or missing parameter
}
int deviceId = TelldusCore::wideToInteger(deviceParts[0]);
if(deviceId == groupDeviceId){
return TELLSTICK_ERROR_UNKNOWN; //the scene itself has been added to its devices, avoid infinite loop
if(deviceId == groupDeviceId) {
return TELLSTICK_ERROR_UNKNOWN; // the scene itself has been added to its devices, avoid infinite loop
}
int method = Device::methodId(TelldusCore::wideToString(deviceParts[1])); //support methodparts both in the form of integers (e.g. TELLSTICK_TURNON) or text (e.g. "turnon")
if(method == 0){
int method = Device::methodId(TelldusCore::wideToString(deviceParts[1])); // support methodparts both in the form of integers (e.g. TELLSTICK_TURNON) or text (e.g. "turnon")
if(method == 0) {
method = TelldusCore::wideToInteger(deviceParts[1]);
}
unsigned char devicedata = 0;
if(deviceParts[2] != L""){
if(deviceParts[2] != L"") {
devicedata = TelldusCore::wideToInteger(deviceParts[2]);
}
if(deviceId > 0 && method > 0){ //check for format error in parameter "devices"
if(deviceId > 0 && method > 0) { // check for format error in parameter "devices"
return doAction(deviceId, method, devicedata);
}
return TELLSTICK_ERROR_UNKNOWN;
}
int DeviceManager::removeDevice(int deviceId){
int DeviceManager::removeDevice(int deviceId) {
Device *device = 0;
{
int ret = d->set.removeNode(Settings::Device, deviceId); //remove from register/settings
@ -593,7 +577,7 @@ int DeviceManager::removeDevice(int deviceId){
device = it->second;
d->devices.erase(it); //remove from list, keep reference
}
else{
else {
return TELLSTICK_ERROR_DEVICE_NOT_FOUND;
}
}
@ -679,14 +663,14 @@ void DeviceManager::handleControllerMessage(const ControllerEventData &eventData
std::list<std::string> parameters = it->second->getParametersForProtocol();
bool thisDevice = true;
for (std::list<std::string>::iterator paramIt = parameters.begin(); paramIt != parameters.end(); ++paramIt){
if(!TelldusCore::comparei(it->second->getParameter(TelldusCore::charToWstring((*paramIt).c_str())), TelldusCore::charToWstring(msg.getParameter(*paramIt).c_str()))){
for (std::list<std::string>::iterator paramIt = parameters.begin(); paramIt != parameters.end(); ++paramIt) {
if(!TelldusCore::comparei(it->second->getParameter(TelldusCore::charToWstring((*paramIt).c_str())), TelldusCore::charToWstring(msg.getParameter(*paramIt).c_str()))) {
thisDevice = false;
break;
}
}
if(!thisDevice){
if(!thisDevice) {
continue;
}
@ -744,26 +728,25 @@ void DeviceManager::setSensorValueAndSignal( const std::string &dataType, int da
d->deviceUpdateEvent->signal(eventData);
}
int DeviceManager::sendRawCommand(const std::wstring &command, int reserved){
int DeviceManager::sendRawCommand(const std::wstring &command, int reserved) {
Controller *controller = d->controllerManager->getBestControllerById(-1);
if(!controller){
//no controller found, scan for one, and retry once
if(!controller) {
// no controller found, scan for one, and retry once
d->controllerManager->loadControllers();
controller = d->controllerManager->getBestControllerById(-1);
}
int retval = TELLSTICK_ERROR_UNKNOWN;
if(controller){
if(controller) {
retval = controller->send(TelldusCore::wideToString(command));
if(retval == TELLSTICK_ERROR_BROKEN_PIPE){
if(retval == TELLSTICK_ERROR_BROKEN_PIPE) {
d->controllerManager->resetController(controller);
}
if(retval == TELLSTICK_ERROR_BROKEN_PIPE || retval == TELLSTICK_ERROR_NOT_FOUND){
if(retval == TELLSTICK_ERROR_BROKEN_PIPE || retval == TELLSTICK_ERROR_NOT_FOUND) {
d->controllerManager->loadControllers();
controller = d->controllerManager->getBestControllerById(-1);
if(!controller){
if(!controller) {
return TELLSTICK_ERROR_NOT_FOUND;
}
retval = controller->send(TelldusCore::wideToString(command)); //retry one more time

View file

@ -16,8 +16,7 @@
class Sensor;
class DeviceManager
{
class DeviceManager {
public:
DeviceManager(ControllerManager *controllerManager, TelldusCore::EventRef deviceUpdateEvent);
~DeviceManager(void);

View file

@ -25,8 +25,7 @@ public:
};
EventUpdateManager::EventUpdateManager()
:Thread()
{
:Thread() {
d = new PrivateData;
d->stopEvent = d->eventHandler.addEvent();
d->updateEvent = d->eventHandler.addEvent();
@ -46,63 +45,60 @@ EventUpdateManager::~EventUpdateManager(void) {
delete d;
}
TelldusCore::EventRef EventUpdateManager::retrieveUpdateEvent(){
TelldusCore::EventRef EventUpdateManager::retrieveUpdateEvent() {
return d->updateEvent;
}
void EventUpdateManager::run(){
while(!d->stopEvent->isSignaled()){
void EventUpdateManager::run() {
while(!d->stopEvent->isSignaled()) {
if (!d->eventHandler.waitForAny()) {
continue;
}
if(d->clientConnectEvent->isSignaled()){
//new client added
if(d->clientConnectEvent->isSignaled()) {
// new client added
TelldusCore::EventDataRef eventData = d->clientConnectEvent->takeSignal();
ConnectionListenerEventData *data = reinterpret_cast<ConnectionListenerEventData*>(eventData.get());
if(data){
if(data) {
d->clients.push_back(data->socket);
}
}
else if(d->updateEvent->isSignaled()){
//device event, signal all clients
else if(d->updateEvent->isSignaled()) {
// device event, signal all clients
TelldusCore::EventDataRef eventData = d->updateEvent->takeSignal();
EventUpdateData *data = reinterpret_cast<EventUpdateData*>(eventData.get());
if(data){
if(data) {
sendMessageToClients(data);
}
}
}
}
void EventUpdateManager::sendMessageToClients(EventUpdateData *data){
void EventUpdateManager::sendMessageToClients(EventUpdateData *data) {
int connected = 0;
for(SocketList::iterator it = d->clients.begin(); it != d->clients.end();){
if((*it)->isConnected()){
for(SocketList::iterator it = d->clients.begin(); it != d->clients.end();) {
if((*it)->isConnected()) {
connected++;
TelldusCore::Message msg;
if(data->messageType == L"TDDeviceEvent"){
if(data->messageType == L"TDDeviceEvent") {
msg.addArgument("TDDeviceEvent");
msg.addArgument(data->deviceId);
msg.addArgument(data->eventState);
msg.addArgument(data->eventValue); //string
}
else if(data->messageType == L"TDDeviceChangeEvent"){
else if(data->messageType == L"TDDeviceChangeEvent") {
msg.addArgument("TDDeviceChangeEvent");
msg.addArgument(data->deviceId);
msg.addArgument(data->eventDeviceChanges);
msg.addArgument(data->eventChangeType);
}
else if(data->messageType == L"TDRawDeviceEvent"){
else if(data->messageType == L"TDRawDeviceEvent") {
msg.addArgument("TDRawDeviceEvent");
msg.addArgument(data->eventValue); //string
msg.addArgument(data->controllerId);
}
else if(data->messageType == L"TDSensorEvent"){
else if(data->messageType == L"TDSensorEvent") {
msg.addArgument("TDSensorEvent");
msg.addArgument(data->protocol);
msg.addArgument(data->model);
@ -123,8 +119,8 @@ void EventUpdateManager::sendMessageToClients(EventUpdateData *data){
it++;
}
else{
//connection is dead, remove it
else {
// connection is dead, remove it
delete *it;
it = d->clients.erase(it);
}

View file

@ -29,8 +29,7 @@ public:
int timestamp;
};
class EventUpdateManager : public TelldusCore::Thread
{
class EventUpdateManager : public TelldusCore::Thread {
public:
EventUpdateManager(void);
~EventUpdateManager(void);

View file

@ -31,8 +31,7 @@ public:
Log *Log::PrivateData::instance = 0;
Log::Log()
:d(new PrivateData)
{
:d(new PrivateData) {
#if defined(_LINUX)
setlogmask(LOG_UPTO(LOG_INFO));
openlog("telldusd", LOG_CONS, LOG_USER);

View file

@ -37,8 +37,7 @@ public:
std::wstring model;
};
Protocol::Protocol(){
Protocol::Protocol() {
d = new PrivateData;
}
@ -57,11 +56,11 @@ std::wstring Protocol::model() const {
return strModel;
}
void Protocol::setModel(const std::wstring &model){
void Protocol::setModel(const std::wstring &model) {
d->model = model;
}
void Protocol::setParameters(ParameterMap &parameterList){
void Protocol::setParameters(ParameterMap &parameterList) {
d->parameterList = parameterList;
}
@ -96,9 +95,8 @@ bool Protocol::checkBit(int data, int bitno) {
}
Protocol *Protocol::getProtocolInstance(const std::wstring &protocolname){
if(TelldusCore::comparei(protocolname, L"arctech")){
Protocol *Protocol::getProtocolInstance(const std::wstring &protocolname) {
if(TelldusCore::comparei(protocolname, L"arctech")) {
return new ProtocolNexa();
} else if (TelldusCore::comparei(protocolname, L"brateck")) {
@ -153,7 +151,7 @@ Protocol *Protocol::getProtocolInstance(const std::wstring &protocolname){
std::list<std::string> Protocol::getParametersForProtocol(const std::wstring &protocolName) {
std::list<std::string> parameters;
if(TelldusCore::comparei(protocolName, L"arctech")){
if(TelldusCore::comparei(protocolName, L"arctech")) {
parameters.push_back("house");
parameters.push_back("unit");

View file

@ -16,8 +16,7 @@ typedef std::map<std::wstring, std::wstring> ParameterMap;
class Controller;
class Protocol
{
class Protocol {
public:
Protocol();
virtual ~Protocol(void);

View file

@ -10,8 +10,7 @@
#include <string>
#include "service/Protocol.h"
class ProtocolBrateck : public Protocol
{
class ProtocolBrateck : public Protocol {
public:
int methods() const;
virtual std::string getStringForMethod(int method, unsigned char data, Controller *controller);

View file

@ -94,8 +94,7 @@ unsigned int ProtocolEverflourish::calculateChecksum(unsigned int x) {
return res;
}
std::string ProtocolEverflourish::decodeData(ControllerMessage &dataMsg)
{
std::string ProtocolEverflourish::decodeData(ControllerMessage &dataMsg) {
std::string data = dataMsg.getParameter("data");
unsigned int allData;
unsigned int house = 0;
@ -113,20 +112,20 @@ std::string ProtocolEverflourish::decodeData(ControllerMessage &dataMsg)
method = allData & 0xF;
if(house < 0 || house > 16383 || unit < 1 || unit > 4){
//not everflourish
if(house < 0 || house > 16383 || unit < 1 || unit > 4) {
// not everflourish
return "";
}
std::stringstream retString;
retString << "class:command;protocol:everflourish;model:selflearning;house:" << house << ";unit:" << unit << ";method:";
if(method == 0){
if(method == 0) {
retString << "turnoff;";
}
else if(method == 15){
else if(method == 15) {
retString << "turnon;";
}
else if(method == 10){
else if(method == 10) {
retString << "learn;";
}
else {

View file

@ -11,8 +11,7 @@
#include "service/Protocol.h"
#include "service/ControllerMessage.h"
class ProtocolEverflourish : public Protocol
{
class ProtocolEverflourish : public Protocol {
public:
int methods() const;
virtual std::string getStringForMethod(int method, unsigned char data, Controller *controller);

View file

@ -10,8 +10,7 @@
#include <sstream>
#include <iomanip>
std::string ProtocolFineoffset::decodeData(ControllerMessage &dataMsg)
{
std::string ProtocolFineoffset::decodeData(ControllerMessage &dataMsg) {
std::string data = dataMsg.getParameter("data");
if (data.length() < 8) {
return "";

View file

@ -11,8 +11,7 @@
#include "service/Protocol.h"
#include "service/ControllerMessage.h"
class ProtocolFineoffset : public Protocol
{
class ProtocolFineoffset : public Protocol {
public:
static std::string decodeData(ControllerMessage &dataMsg);
};

View file

@ -10,8 +10,7 @@
#include <string>
#include "service/Protocol.h"
class ProtocolFuhaote : public Protocol
{
class ProtocolFuhaote : public Protocol {
public:
int methods() const;
virtual std::string getStringForMethod(int method, unsigned char data, Controller *controller);

View file

@ -10,8 +10,7 @@
#include <string>
#include "service/Protocol.h"
class ProtocolHasta : public Protocol
{
class ProtocolHasta : public Protocol {
public:
int methods() const;
virtual std::string getStringForMethod(int method, unsigned char data, Controller *controller);

View file

@ -10,8 +10,7 @@
#include <string>
#include "service/Protocol.h"
class ProtocolIkea : public Protocol
{
class ProtocolIkea : public Protocol {
public:
int methods() const;
virtual std::string getStringForMethod(int method, unsigned char data, Controller *controller);

View file

@ -10,8 +10,7 @@
#include <sstream>
#include <iomanip>
std::string ProtocolMandolyn::decodeData(ControllerMessage &dataMsg)
{
std::string ProtocolMandolyn::decodeData(ControllerMessage &dataMsg) {
std::string data = dataMsg.getParameter("data");
uint32_t value = (uint32_t)TelldusCore::hexTo64l(data);

View file

@ -11,8 +11,7 @@
#include "service/Protocol.h"
#include "service/ControllerMessage.h"
class ProtocolMandolyn : public Protocol
{
class ProtocolMandolyn : public Protocol {
public:
static std::string decodeData(ControllerMessage &dataMsg);
};

View file

@ -163,23 +163,22 @@ std::string ProtocolNexa::getStringSelflearningForCode(int intHouse, int intCode
return strMessage;
}
std::string ProtocolNexa::decodeData(ControllerMessage& dataMsg)
{
std::string ProtocolNexa::decodeData(ControllerMessage& dataMsg) {
unsigned long allData = 0;
sscanf(dataMsg.getParameter("data").c_str(), "%lx", &allData);
if(TelldusCore::comparei(dataMsg.model(), L"selflearning")){
//selflearning
if(TelldusCore::comparei(dataMsg.model(), L"selflearning")) {
// selflearning
return decodeDataSelfLearning(allData);
}
else{
//codeswitch
else {
// codeswitch
return decodeDataCodeSwitch(allData);
}
}
std::string ProtocolNexa::decodeDataSelfLearning(long allData){
std::string ProtocolNexa::decodeDataSelfLearning(long allData) {
unsigned int house = 0;
unsigned int unit = 0;
unsigned int group = 0;
@ -197,17 +196,17 @@ std::string ProtocolNexa::decodeDataSelfLearning(long allData){
unit = allData & 0xF;
unit++;
if(house < 1 || house > 67108863 || unit < 1 || unit > 16){
//not arctech selflearning
if(house < 1 || house > 67108863 || unit < 1 || unit > 16) {
// not arctech selflearning
return "";
}
std::stringstream retString;
retString << "class:command;protocol:arctech;model:selflearning;house:" << house << ";unit:" << unit << ";group:" << group << ";method:";
if(method == 1){
if(method == 1) {
retString << "turnon;";
}
else if(method == 0){
else if(method == 0) {
retString << "turnoff;";
}
else {
@ -218,8 +217,7 @@ std::string ProtocolNexa::decodeDataSelfLearning(long allData){
return retString.str();
}
std::string ProtocolNexa::decodeDataCodeSwitch(long allData){
std::string ProtocolNexa::decodeDataCodeSwitch(long allData) {
unsigned int house = 0;
unsigned int unit = 0;
unsigned int method = 0;
@ -233,33 +231,33 @@ std::string ProtocolNexa::decodeDataCodeSwitch(long allData){
house = allData & 0xF;
if(house < 0 || house > 16 || unit < 1 || unit > 16){
//not arctech codeswitch
if(house < 0 || house > 16 || unit < 1 || unit > 16) {
// not arctech codeswitch
return "";
}
house = house + 'A'; //house from A to P
if(method != 6 && lastArctecCodeSwitchWasTurnOff == 1){
if(method != 6 && lastArctecCodeSwitchWasTurnOff == 1) {
lastArctecCodeSwitchWasTurnOff = 0;
return ""; //probably a stray turnon or bell (perhaps: only certain time interval since last, check that it's the same house/unit... Will lose
//one turnon/bell, but it's better than the alternative...
}
if(method == 6){
if(method == 6) {
lastArctecCodeSwitchWasTurnOff = 1;
}
std::stringstream retString;
retString << "class:command;protocol:arctech;model:codeswitch;house:" << char(house);
if(method == 6){
if(method == 6) {
retString << ";unit:" << unit << ";method:turnoff;";
}
else if(method == 14){
else if(method == 14) {
retString << ";unit:" << unit << ";method:turnon;";
}
else if(method == 15){
else if(method == 15) {
retString << ";method:bell;";
}
else {

View file

@ -10,8 +10,7 @@
#include <sstream>
#include <iomanip>
std::string ProtocolOregon::decodeData(ControllerMessage &dataMsg)
{
std::string ProtocolOregon::decodeData(ControllerMessage &dataMsg) {
std::string data = dataMsg.getParameter("data");
std::wstring model = dataMsg.model();

View file

@ -11,8 +11,7 @@
#include "service/Protocol.h"
#include "service/ControllerMessage.h"
class ProtocolOregon : public Protocol
{
class ProtocolOregon : public Protocol {
public:
static std::string decodeData(ControllerMessage &dataMsg);

View file

@ -10,8 +10,7 @@
#include <string>
#include "service/Protocol.h"
class ProtocolRisingSun : public Protocol
{
class ProtocolRisingSun : public Protocol {
public:
int methods() const;
virtual std::string getStringForMethod(int method, unsigned char data, Controller *controller);

View file

@ -41,8 +41,7 @@ std::string ProtocolSartano::getStringForCode(const std::wstring &strCode, int m
}
std::string ProtocolSartano::decodeData(ControllerMessage &dataMsg)
{
std::string ProtocolSartano::decodeData(ControllerMessage &dataMsg) {
std::string data = dataMsg.getParameter("data");
signed int allDataIn;
signed int allData = 0;
@ -54,9 +53,9 @@ std::string ProtocolSartano::decodeData(ControllerMessage &dataMsg)
sscanf(data.c_str(), "%X", &allDataIn);
unsigned long mask = (1<<11);
for(int i=0;i<12;++i){
for(int i=0;i<12;++i) {
allData >>= 1;
if((allDataIn & mask) == 0){
if((allDataIn & mask) == 0) {
allData |= (1<<11);
}
mask >>= 1;
@ -70,39 +69,39 @@ std::string ProtocolSartano::decodeData(ControllerMessage &dataMsg)
method2 = allData & 0x1;
if(method1 == 0 && method2 == 1){
method = 0; //off
if(method1 == 0 && method2 == 1) {
method = 0; // off
}
else if(method1 == 1 && method2 == 0){
method = 1; //on
else if(method1 == 1 && method2 == 0) {
method = 1; // on
}
else{
else {
return "";
}
if(code < 0 || code > 1023){
//not sartano
if(code < 0 || code > 1023) {
// not sartano
return "";
}
std::stringstream retString;
retString << "class:command;protocol:sartano;model:codeswitch;code:";
mask = (1<<9);
for(int i=0;i<10;i++){
if((code & mask) != 0){
for(int i=0;i<10;i++) {
if((code & mask) != 0) {
retString << 1;
}
else{
else {
retString << 0;
}
mask >>= 1;
}
retString << ";method:";
if(method == 0){
if(method == 0) {
retString << "turnoff;";
}
else{
else {
retString << "turnon;";
}

View file

@ -11,8 +11,7 @@
#include "service/Protocol.h"
#include "service/ControllerMessage.h"
class ProtocolSartano : public Protocol
{
class ProtocolSartano : public Protocol {
public:
int methods() const;
virtual std::string getStringForMethod(int method, unsigned char data, Controller *controller);

View file

@ -10,8 +10,7 @@
#include <string>
#include "service/Protocol.h"
class ProtocolSilvanChip : public Protocol
{
class ProtocolSilvanChip : public Protocol {
public:
int methods() const;
virtual std::string getStringForMethod(int method, unsigned char data, Controller *controller);

View file

@ -10,8 +10,7 @@
#include <string>
#include "service/Protocol.h"
class ProtocolUpm : public Protocol
{
class ProtocolUpm : public Protocol {
public:
int methods() const;
virtual std::string getStringForMethod(int method, unsigned char data, Controller *controller);

View file

@ -22,8 +22,7 @@ std::string ProtocolWaveman::getOffCode() const {
return "$k$k$k$k$k$k$k$k$k+";
}
std::string ProtocolWaveman::decodeData(ControllerMessage& dataMsg)
{
std::string ProtocolWaveman::decodeData(ControllerMessage& dataMsg) {
unsigned long allData = 0;
unsigned int house = 0;
unsigned int unit = 0;
@ -40,30 +39,30 @@ std::string ProtocolWaveman::decodeData(ControllerMessage& dataMsg)
house = allData & 0xF;
if(house < 0 || house > 16 || unit < 1 || unit > 16){
//not waveman
if(house < 0 || house > 16 || unit < 1 || unit > 16) {
// not waveman
return "";
}
house = house + 'A'; //house from A to P
if(method != 6 && lastArctecCodeSwitchWasTurnOff == 1){
if(method != 6 && lastArctecCodeSwitchWasTurnOff == 1) {
lastArctecCodeSwitchWasTurnOff = 0;
return ""; //probably a stray turnon or bell (perhaps: only certain time interval since last, check that it's the same house/unit... Will lose
//one turnon/bell, but it's better than the alternative...
}
if(method == 6){
if(method == 6) {
lastArctecCodeSwitchWasTurnOff = 1;
}
std::stringstream retString;
retString << "class:command;protocol:waveman;model:codeswitch;house:" << char(house);
if(method == 0){
if(method == 0) {
retString << ";unit:" << unit << ";method:turnoff;";
}
else if(method == 14){
} else if(method == 14) {
retString << ";unit:" << unit << ";method:turnon;";
}
else {

View file

@ -171,7 +171,7 @@ std::string ProtocolX10::decodeData(ControllerMessage& dataMsg) {
retString << "house:" << (char)('A' + intHouse);
retString << ";unit:" << unit+1;
retString << ";method:";
if(method == 0){
if(method == 0) {
retString << "turnon;";
} else {
retString << "turnoff;";

View file

@ -11,8 +11,7 @@
#include "service/Protocol.h"
#include "service/ControllerMessage.h"
class ProtocolX10 : public Protocol
{
class ProtocolX10 : public Protocol {
public:
int methods() const;
virtual std::string getStringForMethod(int method, unsigned char data, Controller *controller);

View file

@ -10,8 +10,7 @@
#include <string>
#include "service/ProtocolSartano.h"
class ProtocolYidong : public ProtocolSartano
{
class ProtocolYidong : public ProtocolSartano {
public:
virtual std::string getStringForMethod(int method, unsigned char data, Controller *controller);
};

View file

@ -18,8 +18,7 @@ public:
};
Sensor::Sensor(const std::wstring &protocol, const std::wstring &model, int id)
:Mutex()
{
:Mutex() {
d = new PrivateData;
d->protocol = protocol;
d->model = model;

View file

@ -10,8 +10,7 @@
#include "common/Mutex.h"
#include <string>
class Sensor : public TelldusCore::Mutex
{
class Sensor : public TelldusCore::Mutex {
public:
Sensor(const std::wstring &protocol, const std::wstring &model, int id);
~Sensor();

View file

@ -20,7 +20,7 @@ std::wstring Settings::getName(Node type, int intNodeId) const {
/*
* Set the name of the device
*/
int Settings::setName(Node type, int intDeviceId, const std::wstring &strNewName){
int Settings::setName(Node type, int intDeviceId, const std::wstring &strNewName) {
TelldusCore::MutexLocker locker(&mutex);
return setStringSetting(type, intDeviceId, L"name", strNewName, false);
}
@ -36,7 +36,7 @@ std::wstring Settings::getProtocol(int intDeviceId) const {
/*
* Set the device vendor
*/
int Settings::setProtocol(int intDeviceId, const std::wstring &strVendor){
int Settings::setProtocol(int intDeviceId, const std::wstring &strVendor) {
TelldusCore::MutexLocker locker(&mutex);
return setStringSetting(Device, intDeviceId, L"protocol", strVendor, false);
}
@ -52,7 +52,7 @@ std::wstring Settings::getModel(int intDeviceId) const {
/*
* Set the device model
*/
int Settings::setModel(int intDeviceId, const std::wstring &strModel){
int Settings::setModel(int intDeviceId, const std::wstring &strModel) {
TelldusCore::MutexLocker locker(&mutex);
return setStringSetting(Device, intDeviceId, L"model", strModel, false);
}
@ -60,7 +60,7 @@ int Settings::setModel(int intDeviceId, const std::wstring &strModel){
/*
* Set device argument
*/
int Settings::setDeviceParameter(int intDeviceId, const std::wstring &strName, const std::wstring &strValue){
int Settings::setDeviceParameter(int intDeviceId, const std::wstring &strName, const std::wstring &strValue) {
TelldusCore::MutexLocker locker(&mutex);
return setStringSetting(Device, intDeviceId, strName, strValue, true);
}
@ -76,7 +76,7 @@ std::wstring Settings::getDeviceParameter(int intDeviceId, const std::wstring &s
/*
* Set preferred controller id
*/
int Settings::setPreferredControllerId(int intDeviceId, int value){
int Settings::setPreferredControllerId(int intDeviceId, int value) {
TelldusCore::MutexLocker locker(&mutex);
return setIntSetting(Device, intDeviceId, L"controller", value, false);
}

View file

@ -32,8 +32,7 @@ const char* VAR_CONFIG_FILE = VAR_CONFIG_PATH "/telldus-core.conf";
/*
* Constructor
*/
Settings::Settings(void)
{
Settings::Settings(void) {
TelldusCore::MutexLocker locker(&mutex);
d = new PrivateData;
readConfig(&d->cfg);
@ -43,8 +42,7 @@ Settings::Settings(void)
/*
* Destructor
*/
Settings::~Settings(void)
{
Settings::~Settings(void) {
TelldusCore::MutexLocker locker(&mutex);
if (d->cfg > 0) {
cfg_free(d->cfg);
@ -100,7 +98,7 @@ int Settings::getNodeId(Node type, int intDeviceIndex) const {
/*
* Add a new node
*/
int Settings::addNode(Node type){
int Settings::addNode(Node type) {
TelldusCore::MutexLocker locker(&mutex);
int intNodeId = getNextNodeId(type);
@ -148,7 +146,7 @@ int Settings::getNextNodeId(Node type) const {
/*
* Remove a device
*/
int Settings::removeNode(Node type, int intNodeId){
int Settings::removeNode(Node type, int intNodeId) {
TelldusCore::MutexLocker locker(&mutex);
FILE *fp = fopen(CONFIG_FILE, "w");
if (!fp) {
@ -199,7 +197,7 @@ bool Settings::setDeviceState( int intDeviceId, int intDeviceState, const std::w
cfg_setstr(cfg_device, "stateValue", TelldusCore::wideToString(strDeviceStateValue).c_str());
FILE *fp = fopen(VAR_CONFIG_FILE, "w");
if(fp == 0){
if(fp == 0) {
return false;
}
cfg_print(d->var_cfg, fp);

View file

@ -40,8 +40,7 @@ public:
};
TellStick::TellStick(int controllerId, TelldusCore::EventRef event, TelldusCore::EventRef updateEvent, const TellStickDescriptor &td )
:Controller(controllerId, event, updateEvent)
{
:Controller(controllerId, event, updateEvent) {
d = new PrivateData;
d->open = false;
d->vid = td.vid;
@ -140,10 +139,10 @@ void TellStick::processData( const std::string &data ) {
}
}
int TellStick::reset(){
int TellStick::reset() {
int success = ftdi_usb_reset( &d->ftHandle );
if(success < 0){
return TELLSTICK_ERROR_UNKNOWN; //-1 = FTDI reset failed, -2 = USB device unavailable
if(success < 0) {
return TELLSTICK_ERROR_UNKNOWN; // -1 = FTDI reset failed, -2 = USB device unavailable
}
return TELLSTICK_SUCCESS;
}
@ -209,18 +208,18 @@ int TellStick::send( const std::string &strMessage ) {
delete[] tempMessage;
if(!c){
if(!c) {
Log::debug("Broken pipe on send");
return TELLSTICK_ERROR_BROKEN_PIPE;
}
if(strMessage.compare("N+") == 0 && ((pid() == 0x0C31 && firmwareVersion() < 5) || (pid() == 0x0C30 && firmwareVersion() < 6))){
//these firmware versions doesn't implement ack to noop, just check that the noop can be sent correctly
if(strMessage.compare("N+") == 0 && ((pid() == 0x0C31 && firmwareVersion() < 5) || (pid() == 0x0C30 && firmwareVersion() < 6))) {
// these firmware versions doesn't implement ack to noop, just check that the noop can be sent correctly
return TELLSTICK_SUCCESS;
}
if(d->ignoreControllerConfirmation){
//allow TellStick to finish its air-sending
if(d->ignoreControllerConfirmation) {
// allow TellStick to finish its air-sending
msleep(1000);
return TELLSTICK_SUCCESS;
}

View file

@ -25,8 +25,7 @@ public:
TelldusCore::EventRef stopEvent, controllerChangeEvent;
};
TelldusMain::TelldusMain(void)
{
TelldusMain::TelldusMain(void) {
d = new PrivateData;
d->stopEvent = d->eventHandler.addEvent();
d->controllerChangeEvent = d->eventHandler.addEvent();
@ -121,8 +120,8 @@ void TelldusMain::start(void) {
if (handlerEvent->isSignaled()) {
handlerEvent->popSignal();
for ( std::list<ClientCommunicationHandler *>::iterator it = clientCommunicationHandlerList.begin(); it != clientCommunicationHandlerList.end(); ){
if ((*it)->isDone()){
for ( std::list<ClientCommunicationHandler *>::iterator it = clientCommunicationHandlerList.begin(); it != clientCommunicationHandlerList.end(); ) {
if ((*it)->isDone()) {
delete *it;
it = clientCommunicationHandlerList.erase(it);
@ -143,6 +142,6 @@ void TelldusMain::start(void) {
supervisor.stop();
}
void TelldusMain::stop(void){
void TelldusMain::stop(void) {
d->stopEvent->signal();
}

View file

@ -7,8 +7,7 @@
#ifndef TELLDUS_CORE_SERVICE_TELLDUSMAIN_H_
#define TELLDUS_CORE_SERVICE_TELLDUSMAIN_H_
class TelldusMain
{
class TelldusMain {
public:
TelldusMain(void);
~TelldusMain(void);

View file

@ -28,8 +28,7 @@ public:
};
Timer::Timer(TelldusCore::EventRef event)
:TelldusCore::Thread(), d(new PrivateData)
{
:TelldusCore::Thread(), d(new PrivateData) {
d->event = event;
#ifdef _WINDOWS
d->cond = CreateEventW(NULL, false, false, NULL);