Further fixes to slot assignment in xboxdrv daemon

This commit is contained in:
Ingo Ruhnke 2011-05-23 19:43:49 +02:00
parent be39c5db49
commit 19f66afb75
2 changed files with 43 additions and 76 deletions

View file

@ -480,9 +480,50 @@ void
XboxdrvDaemon::on_controller_activate()
{
log_tmp("on_controller_activate");
// check for inactive controller and free the slots
for(ControllerSlots::iterator i = m_controller_slots.begin(); i != m_controller_slots.end(); ++i)
{
// if a slot contains an inactive controller, disconnect it and save
// the controller for later when it might be active again
if ((*i)->get_controller() && !(*i)->get_controller()->is_active())
{
ControllerPtr controller = disconnect(*i);
m_inactive_controllers.push_back(controller);
}
}
cleanup_threads();
check_thread_status();
// check for activated controller and connect them to a slot
for(Controllers::iterator i = m_inactive_controllers.begin(); i != m_inactive_controllers.end(); ++i)
{
if (!*i)
{
log_error("NULL in m_inactive_controllers, shouldn't happen");
}
else
{
if ((*i)->is_active())
{
ControllerSlotPtr slot = find_free_slot((*i)->get_udev_device());
if (!slot)
{
log_info("couldn't find a free slot for activated controller");
}
else
{
connect(slot, *i);
// successfully connected the controller, so set it to NULL and cleanup later
*i = ControllerPtr();
}
}
}
}
// cleanup inactive controller
m_inactive_controllers.erase(std::remove(m_inactive_controllers.begin(), m_inactive_controllers.end(),
ControllerPtr()),
m_inactive_controllers.end());
}
std::string
@ -536,75 +577,4 @@ XboxdrvDaemon::on_sigint(int)
XboxdrvDaemon::current()->shutdown();
}
void
XboxdrvDaemon::cleanup_threads()
{
int count = 0;
for(ControllerSlots::iterator i = m_controller_slots.begin(); i != m_controller_slots.end(); ++i)
{
if ((*i)->is_connected())
{
count += 1;
on_disconnect(*i);
// disconnect slot and put the controller back into the inactive group
m_inactive_controllers.push_back((*i)->disconnect());
}
}
if (count > 0)
{
log_info("cleaned up " << count << " thread(s), free slots: " <<
get_free_slot_count() << "/" << m_controller_slots.size());
}
}
void
XboxdrvDaemon::check_thread_status()
{
// check for inactive controller and free the slots
for(ControllerSlots::iterator i = m_controller_slots.begin(); i != m_controller_slots.end(); ++i)
{
// if a slot contains an inactive controller, disconnect it and save
// the controller for later when it might be active again
if ((*i)->get_controller() && !(*i)->get_controller()->is_active())
{
ControllerPtr controller = disconnect(*i);
m_inactive_controllers.push_back(controller);
}
}
// check for activated controller and connect them to a slot
for(Controllers::iterator i = m_inactive_controllers.begin(); i != m_inactive_controllers.end(); ++i)
{
if (!*i)
{
log_error("NULL in m_inactive_controllers, shouldn't happen");
}
else
{
if ((*i)->is_active())
{
ControllerSlotPtr slot = find_free_slot((*i)->get_udev_device());
if (!slot)
{
log_info("couldn't find a free slot for activated controller");
}
else
{
connect(slot, *i);
// successfully connected the controller, so set it to NULL and cleanup later
*i = ControllerPtr();
}
}
}
}
// cleanup inactive controller
m_inactive_controllers.erase(std::remove(m_inactive_controllers.begin(), m_inactive_controllers.end(), ControllerPtr()),
m_inactive_controllers.end());
}
/* EOF */

View file

@ -84,9 +84,6 @@ private:
void on_controller_disconnect();
void on_controller_activate();
void check_thread_status();
void cleanup_threads();
private:
static gboolean on_controller_disconnect_wrap(gpointer data) {
static_cast<XboxdrvDaemon*>(data)->on_controller_disconnect();