mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-20 18:40:31 +00:00
added BTstackManager argument to all delegates
This commit is contained in:
parent
13939703e9
commit
71d9d7cecb
@ -60,6 +60,6 @@ typedef enum {
|
||||
|
||||
@protocol BTDiscoveryDelegate
|
||||
@optional
|
||||
-(BOOL)willSelectDeviceAtIndex:(int)deviceIndex; // returns NO to ignore selection
|
||||
-(void)statusCellSelected;
|
||||
-(BOOL) discoveryView:(BTDiscoveryViewController*)discoveryView willSelectDeviceAtIndex:(int)deviceIndex; // returns NO to ignore selection
|
||||
-(void) statusCellSelectedDiscoveryView:(BTDiscoveryViewController*)discoveryView;
|
||||
@end
|
||||
|
@ -142,16 +142,17 @@ typedef enum {
|
||||
@optional
|
||||
|
||||
// Activation callbacks
|
||||
-(BOOL) disableSystemBluetooth; // default: YES
|
||||
-(BOOL) disableSystemBluetoothBTstackManager:(BTstackManager*) manager; // default: YES
|
||||
|
||||
// Connection events
|
||||
-(NSString*) pinForAddress:(bd_addr_t)addr; // default: "0000"
|
||||
-(NSString*) btstackManager:(BTstackManager*) manager pinForAddress:(bd_addr_t)addr; // default: "0000"
|
||||
|
||||
// direct access
|
||||
-(void) handlePacketWithType:(uint8_t) packet_type
|
||||
forChannel:(uint16_t) channel
|
||||
andData:(uint8_t *)packet
|
||||
withLen:(uint16_t) size;
|
||||
-(void) btstackManager:(BTstackManager*) manager
|
||||
handlePacketWithType:(uint8_t) packet_type
|
||||
forChannel:(uint16_t) channel
|
||||
andData:(uint8_t *)packet
|
||||
withLen:(uint16_t) size;
|
||||
@end
|
||||
|
||||
|
||||
@ -159,17 +160,17 @@ typedef enum {
|
||||
@optional
|
||||
|
||||
// Activation events
|
||||
-(void) activated;
|
||||
-(void) activationFailed:(BTstackError)error;
|
||||
-(void) deactivated;
|
||||
-(void) activatedBTstackManager:(BTstackManager*) manager;
|
||||
-(void) btstackManager:(BTstackManager*)manager activationFailed:(BTstackError)error;
|
||||
-(void) deactivatedBTstackManager:(BTstackManager*) manager;
|
||||
|
||||
// Discovery events: general
|
||||
-(void) deviceInfo:(BTDevice*)device;
|
||||
-(void) discoveryStopped;
|
||||
-(void) discoveryInquiry;
|
||||
-(void) discoveryQueryRemoteName:(int)deviceIndex;
|
||||
|
||||
-(void) btstackManager:(BTstackManager*)manager deviceInfo:(BTDevice*)device;
|
||||
-(void) btstackManager:(BTstackManager*)manager discoveryQueryRemoteName:(int)deviceIndex;
|
||||
-(void) discoveryStoppedBTstackManager:(BTstackManager*) manager;
|
||||
-(void) discoveryInquiryBTstackManager:(BTstackManager*) manager;
|
||||
|
||||
// Connection
|
||||
-(void) l2capChannelCreatedAtAddress:(bd_addr_t)addr withPSM:(uint16_t)psm asID:(uint16_t)channelID;
|
||||
-(void) l2capChannelCreateFailedAtAddress:(bd_addr_t)addr withPSM:(uint16_t)psm error:(BTstackError)error;
|
||||
-(void) l2capChannelClosedForChannelID:(uint16_t)channelID;
|
||||
|
@ -130,26 +130,26 @@
|
||||
}
|
||||
|
||||
// BTstackManagerListenerDelegate
|
||||
-(void) activated{
|
||||
-(void) activatedBTstackManager:(BTstackManager*) manager{
|
||||
[self reload];
|
||||
}
|
||||
-(void) activationFailed:(BTstackError)error{
|
||||
-(void) btstackManager:(BTstackManager*)manager activationFailed:(BTstackError)error {
|
||||
[self reload];
|
||||
};
|
||||
-(void) discoveryInquiry {
|
||||
}
|
||||
-(void) discoveryInquiryBTstackManager:(BTstackManager*) manager {
|
||||
inquiryState = kInquiryActive;
|
||||
[self reload];
|
||||
}
|
||||
-(void) discoveryQueryRemoteName:(int)deviceIndex {
|
||||
-(void) btstackManager:(BTstackManager*)manager discoveryQueryRemoteName:(int)deviceIndex {
|
||||
inquiryState = kInquiryRemoteName;
|
||||
remoteNameIndex = deviceIndex;
|
||||
[self reload];
|
||||
}
|
||||
-(void) discoveryStopped {
|
||||
-(void) discoveryStoppedBTstackManager:(BTstackManager*) manager {
|
||||
inquiryState = kInquiryInactive;
|
||||
[self reload];
|
||||
}
|
||||
-(void) deviceInfo:(BTDevice*)device {
|
||||
-(void) btstackManager:(BTstackManager*)manager deviceInfo:(BTDevice*)device {
|
||||
[self reload];
|
||||
}
|
||||
|
||||
@ -316,12 +316,12 @@
|
||||
if (!_delegate) return nil;
|
||||
int index = [indexPath indexAtPosition:1];
|
||||
if (index >= [bt numberOfDevicesFound]){
|
||||
if ([_delegate respondsToSelector:@selector(statusCellSelected)]){
|
||||
[_delegate statusCellSelected];
|
||||
if ([_delegate respondsToSelector:@selector(statusCellSelectedDiscoveryView:)]){
|
||||
[_delegate statusCellSelectedDiscoveryView:self];
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
if ([_delegate respondsToSelector:@selector(willSelectDeviceAtIndex:)] && [_delegate willSelectDeviceAtIndex:index]){
|
||||
if ([_delegate respondsToSelector:@selector(discoveryView:willSelectDeviceAtIndex:)] && [_delegate discoveryView:self willSelectDeviceAtIndex:index]){
|
||||
return indexPath;
|
||||
}
|
||||
return nil;
|
||||
|
@ -127,50 +127,50 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
// send events
|
||||
-(void) sendActivated {
|
||||
for (NSObject<BTstackManagerListener>* listener in listeners) {
|
||||
if ([listener respondsToSelector:@selector(activated)]){
|
||||
[listener activated];
|
||||
if ([listener respondsToSelector:@selector(activatedBTstackManager:)]){
|
||||
[listener activatedBTstackManager:self];
|
||||
}
|
||||
}
|
||||
}
|
||||
-(void) sendActivationFailed:(BTstackError)error {
|
||||
for (NSObject<BTstackManagerListener>* listener in listeners) {
|
||||
if ([listener respondsToSelector:@selector(activationFailed:)]){
|
||||
[listener activationFailed:error];
|
||||
if ([listener respondsToSelector:@selector(btstackManager:activationFailed:)]){
|
||||
[listener btstackManager:self activationFailed:error];
|
||||
}
|
||||
}
|
||||
}
|
||||
-(void) sendDeactivated {
|
||||
for (NSObject<BTstackManagerListener>* listener in listeners) {
|
||||
if ([listener respondsToSelector:@selector(deactivated)]){
|
||||
[listener deactivated];
|
||||
if ([listener respondsToSelector:@selector(deactivatedBTstackManager:)]){
|
||||
[listener deactivatedBTstackManager:self];
|
||||
}
|
||||
}
|
||||
}
|
||||
-(void) sendDiscoveryStoppedEvent {
|
||||
for (NSObject<BTstackManagerListener>* listener in listeners) {
|
||||
if ([listener respondsToSelector:@selector(discoveryStopped)]){
|
||||
[listener discoveryStopped];
|
||||
if ([listener respondsToSelector:@selector(discoveryStoppedBTstackManager:)]){
|
||||
[listener discoveryStoppedBTstackManager:self];
|
||||
}
|
||||
}
|
||||
}
|
||||
-(void) sendDiscoveryInquiry{
|
||||
for (NSObject<BTstackManagerListener>* listener in listeners) {
|
||||
if ([listener respondsToSelector:@selector(discoveryInquiry)]){
|
||||
[listener discoveryInquiry];
|
||||
if ([listener respondsToSelector:@selector(discoveryInquiryBTstackManager:)]){
|
||||
[listener discoveryInquiryBTstackManager:self];
|
||||
}
|
||||
}
|
||||
}
|
||||
-(void) sendDiscoveryQueryRemoteName:(int)index {
|
||||
for (NSObject<BTstackManagerListener>* listener in listeners) {
|
||||
if ([listener respondsToSelector:@selector(discoveryQueryRemoteName:)]){
|
||||
[listener discoveryQueryRemoteName:index];
|
||||
if ([listener respondsToSelector:@selector(btstackManager:discoveryQueryRemoteName:)]){
|
||||
[listener btstackManager:self discoveryQueryRemoteName:index];
|
||||
}
|
||||
}
|
||||
}
|
||||
-(void) sendDeviceInfo:(BTDevice*) device{
|
||||
for (NSObject<BTstackManagerListener>* listener in listeners) {
|
||||
if ([listener respondsToSelector:@selector(deviceInfo:)]){
|
||||
[listener deviceInfo:device];
|
||||
if ([listener respondsToSelector:@selector(btstackManager:deviceInfo:)]){
|
||||
[listener btstackManager:self deviceInfo:device];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -277,8 +277,8 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
// system bt on - first time try to disable it
|
||||
if ( state == kW4SysBTState) {
|
||||
if (_delegate == nil
|
||||
|| ![_delegate respondsToSelector:@selector(disableSystemBluetooth)]
|
||||
|| [_delegate disableSystemBluetooth]){
|
||||
|| ![_delegate respondsToSelector:@selector(disableSystemBluetoothBTstackManager)]
|
||||
|| [_delegate disableSystemBluetoothBTstackManager]){
|
||||
state = kW4SysBTDisabled;
|
||||
bt_send_cmd(&btstack_set_system_bluetooth_enabled, 0);
|
||||
} else {
|
||||
@ -512,8 +512,8 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if ([_delegate respondsToSelector:@selector(handlePacketWithType:forChannel:andData:withLen:)]){
|
||||
[_delegate handlePacketWithType:packet_type forChannel:channel andData:packet withLen:size];
|
||||
if ([_delegate respondsToSelector:@selector(btstackManager:handlePacketWithType:forChannel:andData:withLen:)]){
|
||||
[_delegate btstackManager:self handlePacketWithType:packet_type forChannel:channel andData:packet withLen:size];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,33 @@
|
||||
//
|
||||
// TestBTstackManager.h
|
||||
//
|
||||
// Created by Matthias Ringwald on 19.02.10.
|
||||
//
|
||||
/*
|
||||
* Copyright (C) 2009 by Matthias Ringwald
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holders nor the names of
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
|
||||
* RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <BTstack/BTstackManager.h>
|
||||
|
@ -1,8 +1,33 @@
|
||||
//
|
||||
// TestBTstackManager.m
|
||||
//
|
||||
// Created by Matthias Ringwald on 19.02.10.
|
||||
//
|
||||
/*
|
||||
* Copyright (C) 2009 by Matthias Ringwald
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holders nor the names of
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
|
||||
* RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
||||
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#import "TestBTstackManager.h"
|
||||
#import <BTstack/BTDevice.h>
|
||||
@ -10,27 +35,27 @@
|
||||
|
||||
@implementation TestBTstackManager
|
||||
|
||||
-(void) activated{
|
||||
-(void) activatedBTstackManager:(BTstackManager*) manager {
|
||||
NSLog(@"activated!");
|
||||
// [bt startDiscovery];
|
||||
}
|
||||
-(void) activationFailed:(BTstackError)error{
|
||||
-(void) btstackManager:(BTstackManager*)manager activationFailed:(BTstackError)error {
|
||||
NSLog(@"activationFailed error 0x%02x!", error);
|
||||
};
|
||||
-(void) discoveryInquiry{
|
||||
-(void) discoveryInquiryBTstackManager:(BTstackManager*) manager {
|
||||
NSLog(@"discoveryInquiry!");
|
||||
[bt storeDeviceInfo];
|
||||
}
|
||||
-(void) discoveryStopped{
|
||||
-(void) discoveryStoppedBTstackManager:(BTstackManager*) manager {
|
||||
NSLog(@"discoveryStopped!");
|
||||
}
|
||||
-(void) discoveryQueryRemoteName:(int)deviceIndex{
|
||||
-(void) btstackManager:(BTstackManager*)manager discoveryQueryRemoteName:(int)deviceIndex {
|
||||
NSLog(@"discoveryQueryRemoteName %u/%u!", deviceIndex+1, [bt numberOfDevicesFound]);
|
||||
}
|
||||
-(void) deviceInfo:(BTDevice*)device {
|
||||
-(void) btstackManager:(BTstackManager*)manager deviceInfo:(BTDevice*)device;
|
||||
NSLog(@"Device Info: addr %@ name %@ COD 0x%06x", [device addressString], [device name], [device classOfDevice] );
|
||||
}
|
||||
- (BOOL)willSelectDeviceAtIndex:(int)deviceIndex {
|
||||
-(BOOL) discoveryView:(BTDiscoveryViewController*)discoveryView willSelectDeviceAtIndex:(int)deviceIndex {
|
||||
if (selectedDevice) return NO;
|
||||
selectedDevice = [bt deviceAtIndex:deviceIndex];
|
||||
BTDevice *device = selectedDevice;
|
||||
@ -38,7 +63,7 @@
|
||||
[bt stopDiscovery];
|
||||
return NO;
|
||||
}
|
||||
-(void)statusCellSelected{
|
||||
-(void) statusCellSelectedDiscoveryView:(BTDiscoveryViewController*)discoveryView {
|
||||
if (![bt isDiscoveryActive]) {
|
||||
selectedDevice = nil;
|
||||
[bt startDiscovery];
|
||||
|
5
TODO.txt
5
TODO.txt
@ -2,11 +2,16 @@
|
||||
|
||||
2009-11-08: Release 0.1
|
||||
|
||||
DONE:
|
||||
- BTstackManager activated/deactivated/discovery
|
||||
|
||||
NEXT:
|
||||
- BUG: bt_close crashes when used in CocoaTouch app
|
||||
- BUG: BTdaemon crashes on iPhone when CocoaTouch app is closed
|
||||
- Provide BTstackManager Objective-C class
|
||||
- move connection methods to BTdevice (get more object oriented)
|
||||
- initWithAddress:(bd_addr_t *)addr
|
||||
- setters private
|
||||
- implement l2cap code
|
||||
- implement rfcomm code
|
||||
- figure out how to receive iPhone System Power IONotifications (in BTdaemon) to detect, when phone gets locked
|
||||
|
Loading…
x
Reference in New Issue
Block a user