Load the Controllers on startup

This commit is contained in:
Micke Prag 2010-10-13 09:51:31 +00:00
parent 027b29af93
commit 93d59e8175

View file

@ -1,5 +1,6 @@
#include "ControllerManager.h"
#include "Controller.h"
#include "TellStick.h"
#include <map>
@ -14,6 +15,7 @@ public:
ControllerManager::ControllerManager(){
d = new PrivateData;
d->lastControllerId = 0;
this->loadControllers();
}
ControllerManager::~ControllerManager(void) {
@ -24,5 +26,27 @@ ControllerManager::~ControllerManager(void) {
}
void ControllerManager::loadControllers() {
//TODO: Do something
while(1) {
TellStick *controller = TellStick::findFirstDevice();
if (!controller) {
break; //All TellStick loaded
}
//Make sure this isn't already loaded
bool found = false;
for(ControllerMap::iterator it = d->controllers.begin(); it != d->controllers.end(); ++it) {
TellStick *tellstick = reinterpret_cast<TellStick *>(it->second);
if (!tellstick) { //No TellStick controller
continue;
}
if (tellstick->serial().compare(controller->serial()) == 0) { //Found a duplicate
found = true;
break;
}
}
if (found) {
break;
}
d->lastControllerId--;
d->controllers[d->lastControllerId] = controller;
}
}