Problem with Bluetooth API
Problem with Bluetooth API
- Subject: Problem with Bluetooth API
- From: tiennou <email@hidden>
- Date: Wed, 6 Jun 2007 12:04:21 +0200
Hi !
I'm not really sure if this belongs more to bluetooth-dev than cocoa-
dev, but this is more of a cocoa question, so I post it here.
I'm trying to use RFCOMMChannel to ask for a phone it's model so I
know how to 'talk' to it.
I'm using a clustered plugin architecture, which is initialized by
the host application by passing the channel object, and I want my
plugin to ask for the phone id using this channel.
The problem I have (from what I can think) is that the Bluetooth
stuff uses the current runloop to handle communication, which means
the answer to my write arrives *after* the init completes (That's the
behavior I get right now) :
- I've tried putting [NSThread sleepUntilDate:...] but while this
stops my init, it also stops bluetooth (which I don't want).
- There might be some way to fiddle with the runLoop, telling it to
stop executing and handle bluetooth stuff, then come back here to
finish my init.
How can I do that ?
(I know I could resort to threads, but I've read the Bluetooth API
isn't thread-safe, and trying to "thread-safe" it it would break
IOBluetoothUI, which I'm also using, and that seems a little overkill
to me...)
Here is my plugin initialization (i'm writing in Mail, my code is
pretty debug-stuff actually) :
@interface MyPlugin {
IOBluetoothRFCOMMChannel *_channel;
NSString *_phoneName;
}
@end
- (id) initWithObject:(id)anObject {
IOReturn errorCode = kIOReturnSuccess;
if (![anObject isKindOfClass:[IOBluetoothRFCOMMChannel class]])
return nil;
_channel = anObject; // I'm not retaining, 'cause I don't know if I
will use it
[_channel setDelegate:self]; // I want my plugin to be notified of
channel stuff
[_channel writeSyncString:@"ATI\r"]; // Using Async here doesn't
change much, see below
[self doMagicStuff];// HERE something must be inserted, but what ?
if (![[self supportedPhoneList] containsObject:_phoneName])
return nil; // We don't support this phone.
self = [super init];
if (self) {
_channel = [_channel retain]; // Because now i want to keep it around
}
return self;
}
- (void) rfcommChannelData:(IOBluetoothRFCOMMChannel*)channel data:
(void*)dataPointer length:(size_t)dataLength
{
NSString *data = [[NSString stringWithCString:dataPointer
length:dataLength] stringByTrimmingCharactersInSet:[NSCharacterSet
whitespaceAndNewlineCharacterSet]];
NSLog(@"Plugin: Got data: %@", data);
_pluginName = data; // I want to access in initWithObject:
}
tiennou
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden