Add function ControllerManager::count()

This function also rescans the controllers to add new ones if none is
connected.
This commit is contained in:
Micke Prag 2012-11-02 13:34:34 +01:00
parent d0b1dbba0e
commit aa16302e1e
2 changed files with 26 additions and 0 deletions

View file

@ -57,6 +57,31 @@ ControllerManager::~ControllerManager() {
delete d; 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) { void ControllerManager::deviceInsertedOrRemoved(int vid, int pid, const std::string &serial, bool inserted) {
if (vid == 0x0 && pid == 0x0) { // All if (vid == 0x0 && pid == 0x0) { // All
if (inserted) { if (inserted) {

View file

@ -19,6 +19,7 @@ public:
void deviceInsertedOrRemoved(int vid, int pid, const std::string &serial, bool inserted); void deviceInsertedOrRemoved(int vid, int pid, const std::string &serial, bool inserted);
int count();
Controller *getBestControllerById(int id); Controller *getBestControllerById(int id);
void loadControllers(); void loadControllers();
void loadStoredControllers(); void loadStoredControllers();