From aa16302e1e03730f85fba1699b9083ba9d26d00f Mon Sep 17 00:00:00 2001 From: Micke Prag Date: Fri, 2 Nov 2012 13:34:34 +0100 Subject: [PATCH] Add function ControllerManager::count() This function also rescans the controllers to add new ones if none is connected. --- telldus-core/service/ControllerManager.cpp | 25 ++++++++++++++++++++++ telldus-core/service/ControllerManager.h | 1 + 2 files changed, 26 insertions(+) diff --git a/telldus-core/service/ControllerManager.cpp b/telldus-core/service/ControllerManager.cpp index 0cc90a99..b02d65a5 100644 --- a/telldus-core/service/ControllerManager.cpp +++ b/telldus-core/service/ControllerManager.cpp @@ -57,6 +57,31 @@ ControllerManager::~ControllerManager() { delete d; } +int ControllerManager::count() { + unsigned int count = 0; + { + TelldusCore::MutexLocker locker(&d->mutex); + // Find all available controllers + for(ControllerMap::const_iterator it = d->controllers.begin(); it != d->controllers.end(); ++it) { + if (it->second.controller) { + ++count; + } + } + } + if (count == 0) { + this->loadControllers(); + // Try again + TelldusCore::MutexLocker locker(&d->mutex); + // Find all available controllers + for(ControllerMap::const_iterator it = d->controllers.begin(); it != d->controllers.end(); ++it) { + if (it->second.controller) { + ++count; + } + } + } + return count; +} + void ControllerManager::deviceInsertedOrRemoved(int vid, int pid, const std::string &serial, bool inserted) { if (vid == 0x0 && pid == 0x0) { // All if (inserted) { diff --git a/telldus-core/service/ControllerManager.h b/telldus-core/service/ControllerManager.h index f5e583b5..093caf2b 100644 --- a/telldus-core/service/ControllerManager.h +++ b/telldus-core/service/ControllerManager.h @@ -19,6 +19,7 @@ public: void deviceInsertedOrRemoved(int vid, int pid, const std::string &serial, bool inserted); + int count(); Controller *getBestControllerById(int id); void loadControllers(); void loadStoredControllers();