Bluetooth Preview for Mac OS X v10.1.5: Anyone?
site_archiver@lists.apple.com Delivered-To: bluetooth-dev@lists.apple.com Thread-index: AcxIWb0s3yCh06gS+06KqzLFBSnczA== Thread-topic: Bluetooth Preview for Mac OS X v10.1.5: Anyone? User-agent: Microsoft-Entourage/12.29.0.110113 Please, could somebody send me a copy of the Apple Bluetooth Preview for Mac OS X v10.1.5? By the way, IOBluetoothDeviceOpenRFCOMMChannel is not available since v10.7 (Lion; Apple Bluetooth 2.5). Let's look around for a replacement: a) IOBluetoothDeviceOpenRFCOMMChannelSync does not work for me reliably, since v10.5. Although it opens the channel, it returns an error. Sometimes it works without error. Are there any examples using it successfully? Until now, I gave up on it. b) IOBluetoothDeviceOpenRFCOMMChannelAsync works. However, I would have to change too much of my code. Furthermore, it is deprecated. c) openRFCOMMChannelSync:withChannelID:delegate: works. However, it is Objective-C. If your environment does not support mixed source code, let us have a look how to call this as C code: 1. Create an Objective-C class for the delegate 2. Add methods to class required by protocol 3. Add protocol to class 4. Register class within runtime, get an instance 5. Register this instance as delegate within IOBluetooth This delegate receives the events of the RFCOMM channel. On the net, I did not find a example, how to do create such a delegate. Here is my working solution. It is pseudo-code because I used REALbasic: // 1. Create an Objective-C class = delegate className = "MyIOBluetoothRFCOMMChannelDelegate" superCls = objc_lookUpClass("NSObject") delegateCls = objc_allocateClassPair(superCls, className, 0) // 2. Add methods to delegate required by protocol succeeded = class_addMethod(delegateCls, sel_registerName("rfcommChannelData:data:length:"), AddressOf YourCallbackForIOBluetoothRFCommChannelEventData, "v@:^v^vL") succeeded = class_addMethod(delegateCls, sel_registerName("rfcommChannelOpenComplete:status:"), AddressOf YourCallbackForIOBluetoothRFCommChannelEventOpenComplete, "v@:^vL") succeeded = class_addMethod(delegateCls, sel_registerName("rfcommChannelClosed:"), AddressOf YourCallbackForIOBluetoothRFCommChannelEventClosed, "v@:^v") succeeded = class_addMethod(delegateCls, sel_registerName("rfcommChannelControlSignalsChanged:"), AddressOf YourCallbackForIOBluetoothRFCommChannelEventControlSignalsChanged, "v@:^v") succeeded = class_addMethod(delegateCls, sel_registerName("rfcommChannelFlowControlChanged:"), AddressOf YourCallbackForIOBluetoothRFCommChannelEventFlowControlChanged, "v@:^v") succeeded = class_addMethod(delegateCls, sel_registerName("rfcommChannelWriteComplete:refcon:status:"), AddressOf YourCallbackForIOBluetoothRFCommChannelEventWriteComplete, "v@:^v^vL") succeeded = class_addMethod(delegateCls, sel_registerName("rfcommChannelQueueSpaceAvailable:"), AddressOf YourCallbackForIOBluetoothRFCommChannelEventQueueSpaceAvailable, "v@:^v") // 3. Add protocol protocolName = "IOBluetoothRFCOMMChannelDelegate" protocolRef = objc_getProtocol(protocolName) succeeded = class_addProtocol(delegateCls, protocolRef) // 4. Register class within runtime, get an instance objc_registerClassPair(delegateCls) delegateInst = class_createInstance(delegateCls, 0) // 5. Register instance as delegate within IOBluetooth sel = sel_registerName("openRFCOMMChannelSync:withChannelID:delegate:") err = objc_msgSend(deviceRef, sel, channelRef, channelID, delegateInst) // since v10.6: release but do not retain the channelRef This pseudo code requires v10.5 and is 64-bit-code ready. In v10.4 and earlier, structs had to be used (and filled) instead of calling methods. Therefore, I use IOBluetoothDeviceOpenRFCOMMChannel for older Mac OS X releases. Because you cannot register the delegate (at least its class) within the Objective-C runtime several times, I use the Singleton design pattern. Further reading (first one is recommended, the rest is for reference): 1. Objective-C Runtime Reference, 2.0 2. Objective-C Runtime Programming Guide, Chapter 6, Type Encodings 3. The Objective-C Programming Language, Chapter 4, Protocols 4. Inspired by <http://www.declaresub.com/ideclare/Cocoa/6.html> If you find a bug, please, report that to me! I use this in a commercial app and in my public domain IOBluetooth library written for REAL Studio. _______________________________________________ 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... This email sent to site_archiver@lists.apple.com
participants (1)
-
Alexander Traud