Add function ControllerManager::count()
This function also rescans the controllers to add new ones if none is connected.
This commit is contained in:
parent
d0b1dbba0e
commit
aa16302e1e
2 changed files with 26 additions and 0 deletions
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue