Re: Bluetooth Switched On - Notification/Callback
Re: Bluetooth Switched On - Notification/Callback
- Subject: Re: Bluetooth Switched On - Notification/Callback
- From: Ruotger Skupin <email@hidden>
- Date: Fri, 28 Apr 2006 10:25:13 +0200
Hi Alexander,
no, I didn't get an answer, so I opted for polling. This is Ok in my
case, because all I do is show the user if bluetooth is switched off.
I then tell him/her to switch it on.
Thanks for your solution, but that's a bit oversized for me.
Ruotger
P.S. the code (I poll timerAction every second):
- (void) timerAction:(id)sender
{
BluetoothDeviceAddress localBTAddress;
if (IOBluetoothLocalDeviceReadAddress (&localBTAddress, NULL,
NULL, NULL) == 0)
[_phoneDiagnosisData setIsBluetoothOff:NO];
else
[_phoneDiagnosisData setIsBluetoothOff:YES];
}
Am 12.04.2006 um 01:19 schrieb Alexander Traud:
is there a ... callback ... that tells me that bluetooth is switch
on/off
Short answer:
IOServiceAddInterestNotification of IOKitLib
service = instance of IOBluetoothHCIController
type = kIOGeneralInterest
In your callback filter for messages of type
kIOMessageDeviceWillPowerOff
for On > Off and kIOMessageDeviceHasPoweredOn for Off > On.
Long answer:
Have you received an answer on this? I noticed that this question
was not
answered on the mailing list previously:
Sorry for making it so short, however, I am not doing any C here so
my code
would not make sense to you. The above works for me in Mac OS X
v10.2.8 and
v10.3.9. Nevertheless, this seems to be broken in v10.4.6. There
you will
get kIOMessageDeviceWillPowerOff and kIOMessageDeviceHasPoweredOn
togeher
always - at least I get that for my D-Link DBT-120 with updated
firmware.
Perhaps the driver fails somewhere. In Mac OS X v10.4 you should
query the
normal IOBluetooth API for the actual status when you receive one
of the
above message types. Still much, much better than polling, isn't it?
How do you use IOServiceAddInterestNotification?
I recommend to have a look at the "Accessing Hardware From
Applications"
document from Apple. It covers in detail
IOServiceAddMatchingNotification of
IOKitLib which is quite similar to
IOServiceAddInterestNotification. You can
(and should because of v10.4) use IOServiceAddMatchingNotification
anyway to
get all IOBluetoothHCIController instances. For each found
IOBluetoothHCIController you request an
IOServiceAddInterestNotification
because in Mac OS X v10.4 it is possible to have several
IOBluetoothHCIControllers. Although only one is active a time, the
user is
able to change the selected one by inserting a new one or using the
Apple
Developer Tool "Bluetooth Explorer".
This way you even get notifications, when a user adds or removes the
Bluetooth (PC Card or USB) adapter.
Any comments? Works here for me.
@ Apple Bluetooth engineers:
- Why is this so wired in Mac OS X v10.4 - at least in v10.4.6?
- Why does not work kIOAppPowerStateInterest or
kIOPriorityPowerStateInterest as requested message types? The
latter does
not fire at Off > On and the first confuses the Bluetooth menu
state with
the On > Off transition. I do not understand this.
- What about a macro function for this within the IOBluetooth
headers...
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Bluetooth-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40ilink.de
This email sent to email@hidden
---
"Less code is better code" - Wil Shipley
Ruotger Skupin, Mac OS X Software Engineering
ilink Kommunikationssysteme GmbH
Münzstr. 13; 10178 Berlin - Germany
_______________________________________________
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