Bluetooth and runloops in a dedicated thread.
Bluetooth and runloops in a dedicated thread.
- Subject: Bluetooth and runloops in a dedicated thread.
- From: David Giovannini <email@hidden>
- Date: Sun, 25 Apr 2010 23:08:24 -0500
Hello,
I have an old project that I am restarting, and under Snow Leopard it is broke. The problem didn't have a well documented solution in older OSes. I am hoping to get some guidance. I would like to have a dedicated thread for every IOBluetoothDevice/IOBluetoothRFCOMMChannel pair.
The runloop below exits immediately. IOBluetoothValidateHardware used to perform enough side-effect magic to keep the runloop running. What should startBlueToothThread look like?
// Construct object - (id) initWithBTDevice: (IOBluetoothDevice*)inDevice { self = [super init]; m_device = [inDevice retain]; m_worker = [[NSThread alloc]initWithTarget: self selector: @selector(startBlueToothThread:) object: nil]; [m_worker start]; }
// Create run loop - (void) startBlueToothThread: (id) arg { IOBluetoothValidateHardware( nil ); [[NSRunLoop currentRunLoop] run]; }
// Execute channel creation on bluetooth runloop // This never returns because the thread has exited long ago with the ill-run runloop - (void) setChannel: (int) channel { [self performSelector: @selector(connectOnChannelTask:) onThread: m_worker withObject: [NSNumber numberWithInt: channel] waitUntilDone:true]; }
// Execute channel creation - (void) connectOnChannelTask: (NSNumber*) channel { if (channel != 0) { IOBluetoothRFCOMMChannel* localRFCOMMChannel; [m_device openRFCOMMChannelAsync: &localRFCOMMChannel withChannelID: [channel intValue] delegate: self]; [localRFCOMMChannel setSerialParameters: 460800 dataBits: 8 parity: kBluetoothRFCOMMParityTypeNoParity stopBits: 1]; } else { [m_device closeConnection]; } }
I had read somewhere that invoking a Bluetooth function has the side effect of installing whatever the run loop needs to run and the bluetooth delegate selectors to work. And it did. Now the run loop exits immediately. What is the right thing to do
|
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Bluetooth-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden