Re: OBEX - getting a folder listing
Re: OBEX - getting a folder listing
- Subject: Re: OBEX - getting a folder listing
- From: Ralf Menssen <email@hidden>
- Date: Sun, 11 Mar 2007 23:48:48 +0100
Thomas Tempelmann schrieb:
I've just started trying out the bluetooth sample projects.
I played with "OBEXSample", which uses the OBEX File Transfer Profile (FTP).
While the Put command works (I connect to a second Mac), Get and SetPath
return errors. I can't figure out what's wrong there.
Reading the OBEX FTP docs I found that the connection should be created
using a particular UUID. The sample code does not seem to do this. I can't
figure out how to add this UUID. I can't find docs about this, either, at
least not using the plain C interfaces.
Has someone dealt with this before and has a working version that you can
send me, please?
Thomas
First of all I recommend to use Objective-C when working with Bluetooth.
Regarding the UUID, look into "BluetoothAssignedNumbers.h". You can
create the UUID like this:
IOBluetoothSDPUUIDRef ourUUID = IOBluetoothSDPUUIDCreateUUID16 ((UInt16)
kBluetoothSDPUUID16ServiceClassOBEXFileTransfer);
You can then get the channel id for a given device like this:
IOBluetoothDevice *btDevice; // comes from somewhere
BluetoothRFCOMMChannelID channelID;
dialupServiceRecord = [btDevice
getServiceRecordForUUID:(IOBluetoothSDPUUID *)ourUUID];
if (dialupServiceRecord)
{
IOReturn status = [dialupServiceRecord getRFCOMMChannelID:&channelID];
if (status == noErr)
{
// You got it in channelID!
}
}
Now you can open the Obex session:
IOBluetoothOBEXSession *mOBEXSession;
mOBEXSession = [IOBluetoothOBEXSession withDevice:btDevice
channelID:channelID];
[mOBEXSession retain]; // MUST BE DONE
and then the ObexFileTransferService
mFileTransferService = [OBEXFileTransferServices
withOBEXSession:mOBEXSession];
if( !mFileTransferService )
{
return -1;
}
[mFileTransferService setDelegate: self]; // register for the callbacks
[mFileTransferService retain];
Next is to open the connection:
status = [mFileTransferService connectToFTPService];
and now your software must release control to CFRunLoop so that the
callback function can be called when the connect was handled. So you
have to provide a function in your delegate:
- (void)
fileTransferServicesConnectionComplete:(OBEXFileTransferServices
*)inServices error:(OBEXError)inError
{
if(inError == kOBEXSuccess)
{
NSLog(@"it is connected!");
}
else
{
NSLog(@"Connection failed, I'm disappointed...");
}
}
Now you can ask for the content for the current directory (after
connection it is "/")
status = [mFileTransferService retrieveFolderListing];
Again release control to CFRunLoop and provide a callback function:
- (void)
fileTransferServicesRetrieveFolderListingComplete:(OBEXFileTransferServices*)inServices
error:(OBEXError)inError listing:(NSArray*)inListing
{
NSLog ([inListing description]; // Here is you directory
}
Ralf Menssen
_______________________________________________
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