deprecated carbon calls?
deprecated carbon calls?
- Subject: deprecated carbon calls?
- From: "Daniel Birns" <email@hidden>
- Date: Tue, 27 Mar 2007 16:20:02 -0700
I found this wonderfully useful posting in the maillist from Bubba
Giles, appended, which works and which we're basing our carbon
bluetooth app on.
However, the compiler says that virtually all the calls are deprecated. I can't find any information on this.
Also, the note appended seems to indicate the cocoa is more reliable.
One
possibility is that I write the bluetooth code in cocoa for
reliability. if so, how should I mix the two??? Can you have objects
in cocoa and some objects in carbon? Should I have 2 binaries that
communicate via sockets??? (Geez what a lot of work that would be).
I'd really prefer to stay in carbon, but I'm concerned about the deprecated messages.
Thanks.
From: Bubba Giles <email@hidden>
Date: Fri, 1 Dec 2006 14:25:36 -0800
well, there are a couple of issues here:
1.
we screwed up the C API for 10.4 for inquiries, and omitted the
extremely important Start/Stop methods. Without calling Start(), the
inquiry never actually gets off the ground. We fixed this problem in
10.4.3 or later. The obj-c API does not have this issue.
2. the
inquiry API doesn't cause an event source to get set up, so the runloop
will immediately exit. Calling IOBluetoothLocalDeviceAvailable()
will rectify that problem.
3. extra note - Bluetooth activity must be done on the main thread,
so make sure you don't take this code and go crazy with threads, or
things will break. Make sure you perform all Bluetooth calls back on
the main thread.
I've attached a sample project and source code that will do inquiries on 10.4.3 or later using the C API.
jason
=======================================================
#include <CoreFoundation/CoreFoundation.h>
#include <IOBluetooth/IOBluetoothUserLib.h>
//===========================================================================================================================
// DeviceNamePrinterFunction
//===========================================================================================================================
void DeviceNamePrinterFunction( const void *value, void *context )
{
IOBluetoothDeviceRef deviceRef = (IOBluetoothDeviceRef) value;
if( deviceRef )
{
CFShow( IOBluetoothDeviceGetNameOrAddress( deviceRef ) );
}
}
//===========================================================================================================================
// inquiryDeviceFound
//===========================================================================================================================
void inquiryDeviceFound(void *userRefCon,IOBluetoothDeviceInquiryRef inquiryRef, IOBluetoothDeviceRef deviceRef)
{
CFArrayRef resultsArray;
static int i = 0;
resultsArray = IOBluetoothDeviceInquiryGetFoundDevices( inquiryRef );
if( resultsArray )
{
printf( "=========== Results Set %d ===========\n", ++i );
CFArrayApplyFunction( resultsArray, CFRangeMake(0,
CFArrayGetCount( resultsArray) ), &DeviceNamePrinterFunction, NULL
);
printf( "\n" );
}
}
//===========================================================================================================================
// inquiryComplete
//===========================================================================================================================
void inquiryComplete( void * userRefCon,
IOBluetoothDeviceInquiryRef inquiryRef,
IOReturn error,
Boolean aborted )
{
printf( "inquiryComplete!\n" );
CFRunLoopStop( CFRunLoopGetCurrent() );
}
//===========================================================================================================================
// main
//===========================================================================================================================
int main (int argc, const char * argv[])
{
IOBluetoothDeviceInquiryRef theInquiry;
IOReturn error;
error = kIOReturnNoDevice;
require( IOBluetoothLocalDeviceAvailable(), exit );
theInquiry = IOBluetoothDeviceInquiryCreateWithCallbackRefCon(NULL);
require_action( theInquiry, exit, error = kIOReturnNoResources );
error = IOBluetoothDeviceInquirySetDeviceFoundCallback(theInquiry, inquiryDeviceFound);
require_noerr( error, exit );
error = IOBluetoothDeviceInquirySetCompleteCallback(theInquiry, inquiryComplete);
require_noerr( error, exit );
// not necessary to call this, but if you want to get some [raw] results fast, don't get names.
error = IOBluetoothDeviceInquirySetUpdateNewDeviceNames( theInquiry, false );
error = IOBluetoothDeviceInquiryStart(theInquiry);
require_noerr( error, exit );
CFRunLoopRun();
exit:
if( theInquiry )
{
IOBluetoothDeviceInquiryDelete( theInquiry );
}
return 0;
}
_______________________________________________
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