Delegate methods for OBEXFileTransferServices do not work in separate thread
Delegate methods for OBEXFileTransferServices do not work in separate thread
- Subject: Delegate methods for OBEXFileTransferServices do not work in separate thread
- From: Thomas Winkler <email@hidden>
- Date: Mon, 18 Aug 2008 16:26:08 +0200
Hello List,
I'm pretty new to Objective-C, therefore I'm running into weird
problems all the time. Here's the most recent one: I want to use
OBEXFileTransferServices to send a file to a bluetooth device using
OBEX. My code worked well in a standard single threaded Cocoa
application but if I try to run it in a separate thread it seems that
the delegate methods that are called by OBEXFileTransferServices (e.g.
fileTransferServicesConnectionComplete) do not work anymore.
I also implemented a delegate method (sdpQueryComplete) which is
called after the SDP query is complete. This works!
So, the question is: Why does the SDP query complete delegate method
work but others like fileTransferServicesConnectionComplete don't?
Thomas
PS: I've pasted a simplified version of the code below. As you can see
my class extends NSThread. To run the thread, I create an instance of
the class and call [myOBEXSendThread start] (this only works on 10.5
as far as I know)
@interface OBEXSendThread : NSThread {
}
@end
@implementation OBEXSendThread
IOBluetoothDevice *device;
BluetoothDeviceAddress devAddress;
IOBluetoothSDPServiceRecord *record;
OBEXFileTransferServices *mTransferServices;
IOBluetoothOBEXSession *mOBEXSession;
BOOL sdpQueryIsComplete = false;
BOOL fileSuccessfullySent = false;
-(void)main {
//Convert the BT address string to BluetoothDeviceAddress
IOBluetoothNSStringToDeviceAddress(@"<a valid BT address>",
&devAddress);
//Get a reference to the device
device = [IOBluetoothDevice withAddress:&devAddress];
//Perform a SDP Query
[device performSDPQuery:self];
//Wait until the SDP query is completed or 30 sec timeout is reached
int i;
for(i=0;i<30 && sdpQueryIsComplete == false;i++) {
usleep(1000000);
}
// Get the service record of the service we want to use
record = [device getServiceRecordForUUID:[IOBluetoothSDPUUID
uuid16:kBluetoothSDPUUID16ServiceClassOBEXObjectPush]];
//NSLog usually outputs "OBEX Object Push", so the record seems to be
valid
NSLog([record getServiceName]);
// Use the record to form an OBEX Session object
mOBEXSession = [IOBluetoothOBEXSession withSDPServiceRecord: record];
[mOBEXSession retain];
// Send the OBEXSession off to FTS
mTransferServices = [OBEXFileTransferServices withOBEXSession:
mOBEXSession];
[mTransferServices retain];
[mTransferServices setDelegate:self];
//Calling this method should trigger the delegate methods sooner or
later
[mTransferServices connectToObjectPushService];
//Wait until the file has been successfully sent or timeout of 100
sec occurs.
int j;
for(j=0;j<100 && fileSuccessfullySent == false;j++) {
usleep(1000000);
//If i call [mTransferServices isBusy] the result is true
//If i call [mTransferServices isConnected] the result is false
//This is weird too, isn't it?
}
[innerPool release];
}
//---------------------
//Delegate method for performSDPQuery
//---------------------
- (void)sdpQueryComplete:(IOBluetoothDevice *)device status:
(IOReturn)status {
sdpQueryIsComplete = true;
}
//---------------------
//Delegate methods for bluetooth OBEX transfer services
//---------------------
- (void) fileTransferServicesAbortComplete:
(OBEXFileTransferServices*)inServices
error:(OBEXError)inError {
NSLog(@"fileTransferServicesAbortComplete has been called");
}
- (void) fileTransferServicesDisconnectionComplete:
(OBEXFileTransferServices*)inServices
error:(OBEXError)inError {
NSLog(@"fileTransferServicesDisconnectionComplete has been called");
}
- (void) fileTransferServicesConnectionComplete:
(OBEXFileTransferServices*)inServices
error:(OBEXError)inError {
NSLog(@"connection complete");
[inServices sendFile: @"/test.pdf"];
}
- (void) fileTransferServicesSendFileProgress:
(OBEXFileTransferServices*)inServices
transferProgress:(NSDictionary*)inProgressDescription {
NSLog(@"connection complete");
}
- (void) fileTransferServicesSendFileComplete:
(OBEXFileTransferServices*)inServices
error:(OBEXError)inError {
NSLog(@"file sent");
fileSuccessfullySent = true;
}
@end
_______________________________________________
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