@@ -62,7 +62,8 @@ ControllerSession::ControllerSession(
6262 // If we already missed it, run it ourselves.
6363 if (m_connection->is_ready ()){
6464 ControllerSession::post_connection_ready (
65- *m_connection, m_connection->supported_controllers ()
65+ *m_connection,
66+ m_connection->controller_mode_status ()
6667 );
6768 }
6869 }catch (...){
@@ -180,7 +181,8 @@ void ControllerSession::make_controller(){
180181 // If we already missed it, run it ourselves.
181182 if (ready){
182183 ControllerSession::post_connection_ready (
183- *m_connection, m_connection->supported_controllers ()
184+ *m_connection,
185+ m_connection->controller_mode_status ()
184186 );
185187 }
186188}
@@ -305,18 +307,21 @@ std::string ControllerSession::reset(){
305307// }
306308void ControllerSession::post_connection_ready (
307309 ControllerConnection& connection,
308- const std::map<ControllerType, std::set<ControllerFeature>>& controllers
310+ const ControllerModeStatus& mode_status
309311){
310- if (controllers.empty ()){
312+ const std::map<ControllerType, std::set<ControllerFeature>>& supported_controllers = mode_status.supported_controllers ;
313+ if (supported_controllers.empty ()){
311314 return ;
312315 }
313316
317+ ControllerType current_controller = mode_status.current_controller ;
318+
314319// cout << "sleeping" << endl;
315320// Sleep(10000);
316321
317322
318323 std::vector<ControllerType> available_controllers;
319- ControllerType selected_controller = ControllerType::None;
324+ // ControllerType selected_controller = ControllerType::None;
320325 bool ready;
321326 {
322327 std::lock_guard<std::mutex> lg (m_state_lock);
@@ -333,10 +338,10 @@ void ControllerSession::post_connection_ready(
333338
334339 // We only show the "none" option when there are multiple controllers
335340 // to choose from.
336- if (controllers .size () > 1 ){
341+ if (supported_controllers .size () > 1 ){
337342 available_controllers.emplace_back (ControllerType::None);
338343 }
339- for (const auto & item : controllers ){
344+ for (const auto & item : supported_controllers ){
340345 available_controllers.emplace_back (item.first );
341346 }
342347
@@ -345,30 +350,30 @@ void ControllerSession::post_connection_ready(
345350 m_available_controllers = available_controllers;
346351
347352
348- auto iter = controllers .begin ();
349- if (controllers .size () == 1 ){
353+ auto iter = supported_controllers .begin ();
354+ if (supported_controllers .size () == 1 ){
350355 // Only one controller available. Force the option to it.
351- selected_controller = iter->first ;
356+ current_controller = iter->first ;
352357 }else {
353358 // Keep the current controller only if it exists.
354- iter = controllers .find (m_option.m_controller_type );
355- if (iter != controllers .end ()){
356- selected_controller = m_option.m_controller_type ;
359+ iter = supported_controllers .find (m_option.m_controller_type );
360+ if (iter != supported_controllers .end ()){
361+ current_controller = m_option.m_controller_type ;
357362 }
358363 }
359364
360365 // Construct the controller.
361- if (selected_controller != ControllerType::None){
366+ if (current_controller != ControllerType::None){
362367 m_controller = m_descriptor->make_controller (
363368 m_logger,
364369 *m_connection,
365- selected_controller ,
370+ current_controller ,
366371 m_requirements
367372 );
368373 }
369374
370375 // Commit all changes.
371- m_option.m_controller_type = selected_controller ;
376+ m_option.m_controller_type = current_controller ;
372377 ready = m_controller && m_controller->is_ready ();
373378
374379 WriteSpinLock lg1 (m_message_lock);
@@ -377,7 +382,7 @@ void ControllerSession::post_connection_ready(
377382 }
378383 }
379384
380- signal_controller_changed (selected_controller , available_controllers);
385+ signal_controller_changed (current_controller , available_controllers);
381386 signal_ready_changed (ready);
382387 signal_status_text_changed (status_text ());
383388}
0 commit comments