@@ -323,6 +323,46 @@ AsyncBluetoothPairDeviceRequest::start()
323323 bool success= true ;
324324 const int controller_id= m_controllerView->getDeviceID ();
325325
326+ // Reset the pairing device state
327+ BluetoothPairDeviceState *state= reinterpret_cast <BluetoothPairDeviceState *>(m_internal_state);
328+ state->initialize (controller_id);
329+ state->bUsesAuthentication = m_controllerView->getUsesBluetoothAuthentication ();
330+ state->controller_serial_string = m_controllerView->getSerial ();
331+ state->controller_device_type = m_controllerView->getControllerDeviceType ();
332+
333+ // Make sure the controller we're working with is a USB connection
334+ if (success && m_controllerView->getIsOpen () && m_controllerView->getIsBluetooth ())
335+ {
336+ SERVER_LOG_ERROR (" AsyncBluetoothPairDeviceRequest" )
337+ << " Controller " << controller_id
338+ << " isn't an open USB device" ;
339+ success= false ;
340+ }
341+
342+ // Find the bluetooth address of the host adapter
343+ if (success)
344+ {
345+ success= AsyncBluetoothPairDeviceRequest__findBluetoothRadio (state);
346+ }
347+
348+ // Assign this host address on the controller.
349+ // NOTE: This needs to be done on the main thread since the controller view isn't thread safe.
350+ if (success)
351+ {
352+ success= AsyncBluetoothPairDeviceRequest__registerHostAddress (m_controllerView, state);
353+ }
354+
355+ // Kick off the worker thread to do the rest of the work
356+ if (success)
357+ {
358+
359+ }
360+
361+ if (success)
362+ {
363+ m_status = AsyncBluetoothRequest::running;
364+ }
365+
326366 if (!success)
327367 {
328368 m_status = AsyncBluetoothRequest::failed;
@@ -357,4 +397,40 @@ AsyncBluetoothPairDeviceRequest::getDescription()
357397 description << " [Pair] ID: " << m_controllerView->getDeviceID () << " Conn: " << m_connectionId;
358398
359399 return description.str ();
400+ }
401+
402+ // -- AsyncBluetoothPairDeviceRequest State Machine -----
403+ static bool
404+ AsyncBluetoothPairDeviceRequest__findBluetoothRadio (BluetoothPairDeviceState *state)
405+ {
406+ assert (state->isMainThread ());
407+ bool bSuccess= true ;
408+
409+ return bSuccess;
410+ }
411+
412+ static bool
413+ AsyncBluetoothPairDeviceRequest__registerHostAddress (
414+ ServerControllerViewPtr &controllerView,
415+ BluetoothPairDeviceState *state)
416+ {
417+ assert (state->isMainThread ());
418+ const int controller_id= controllerView->getDeviceID ();
419+ bool bSuccess= true ;
420+
421+ if (controllerView->setHostBluetoothAddress (state->host_address_string ))
422+ {
423+ SERVER_LOG_INFO (" AsyncBluetoothPairDeviceRequest" )
424+ << " Assigned host address " << state->host_address_string
425+ << " to controller id " << controller_id;
426+ }
427+ else
428+ {
429+ SERVER_LOG_ERROR (" AsyncBluetoothPairDeviceRequest" )
430+ << " Failed to set host address " << state->host_address_string
431+ << " on controller id " << controller_id;
432+ bSuccess= false ;
433+ }
434+
435+ return bSuccess;
360436}
0 commit comments