Delegate methods for OBEXFileTransferServices do not work in separate thread
site_archiver@lists.apple.com Delivered-To: bluetooth-dev@lists.apple.com Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:from:to :content-type:content-transfer-encoding:mime-version:subject:date :x-mailer; bh=DtD7cEdfY5AV6/QNzo6hjgImrxcSZnCo9Ytfj8cj3rs=; b=uZ5oqAvBZMpZejxS/5sCVBRFNFyYXfIcAhvPtgWrfLGGGo0tYr+SfPcAVPhlCulF22 7K/Xv0FYpVOjDLs/TXl9gfxKRmEsNuv0fc3jUn2AKR9Z2lP+bTcwJ2B70Ylnd5eA8HuT DwZiecsyJQpKR+SApSXVlVoqy8/MH6uIfMPlc= Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:from:to:content-type:content-transfer-encoding :mime-version:subject:date:x-mailer; b=TvnI1z4DALsS5JS5HI86IxzhjjbBbuBNFvmdO1d/5KBCyZiuiuBfoYPIKB80Hnbc2a gFGNRw/rs4kEF3kGa1272xN6u3W1nO3wJCRRrXvS6EWmXSn8L20UYva39SWbpDriJTBc ZYna2Wi7iY7RRi1i7s3x8EhUgI9oMmXE1jevQ= Hello List, Thomas @interface OBEXSendThread : NSThread { } @end @implementation OBEXSendThread IOBluetoothDevice *device; BluetoothDeviceAddress devAddress; IOBluetoothSDPServiceRecord *record; OBEXFileTransferServices *mTransferServices; IOBluetoothOBEXSession *mOBEXSession; BOOL sdpQueryIsComplete = false; BOOL fileSuccessfullySent = false; } [innerPool release]; } @end _______________________________________________ Do not post admin requests to the list. They will be ignored. Bluetooth-dev mailing list (Bluetooth-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/bluetooth-dev/site_archiver%40lists.a... 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? 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) -(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? //--------------------- //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; } This email sent to site_archiver@lists.apple.com
participants (1)
-
Thomas Winkler