btstack/CocoaTouch/include/BTstack/BTstackManager.h

165 lines
5.2 KiB
C
Raw Normal View History

/*
* 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.
*
*/
#pragma once
#import <Foundation/Foundation.h>
#import <stdint.h>
2010-02-19 22:05:24 +00:00
#import <btstack/btstack.h>
2010-02-21 16:06:16 +00:00
#define PREFS_REMOTE_NAME @"RemoteName"
#define PREFS_LINK_KEY @"LinkKey"
#define BTstackManagerID @"ch.ringwald.btstack"
2010-02-19 22:05:24 +00:00
@class BTDevice;
/*
* Information on devices is stored in a system-wide plist
* it is maintained by BTstackManager
2010-02-19 22:05:24 +00:00
* this includes the link keys
*/
// TODO enumerate BTstackError type
typedef int BTstackError;
typedef enum {
kDeactivated = 1,
kW4SysBTState,
kW4SysBTDisabled,
kW4Activated,
kActivated,
kW4Deactivated
} ManagerState;
typedef enum {
kInactive = 1,
kW4InquiryMode,
kInquiry,
kRemoteName,
} DiscoveryState;
@protocol BTstackManagerDelegate;
@protocol BTstackManagerListener;
@interface BTstackManager : NSObject {
@private
id<BTstackManagerDelegate> _delegate;
NSMutableDictionary *deviceInfo;
NSMutableArray *discoveredDevices;
NSMutableSet *listeners;
BOOL connectedToDaemon;
ManagerState state;
DiscoveryState discoveryState;
int discoveryDeviceIndex;
}
2010-02-19 22:05:24 +00:00
// shared instance
+(BTstackManager *) sharedInstance;
2010-02-19 22:05:24 +00:00
// listeners
-(void) addListener:(id<BTstackManagerListener>)listener;
-(void) removeListener:(id<BTstackManagerListener>)listener;
2010-02-19 22:05:24 +00:00
// Activation
-(BTstackError) activate;
-(BTstackError) deactivate;
-(BOOL) isActivating;
-(BOOL) isActive;
2010-02-19 22:05:24 +00:00
// Discovery
-(BTstackError) startDiscovery;
-(BTstackError) stopDiscovery;
-(int) numberOfDevicesFound;
-(BTDevice*) deviceAtIndex:(int)index;
// Connections
-(BTstackError) createL2CAPChannelAtAddress:(bd_addr_t) address withPSM:(uint16_t)psm authenticated:(BOOL)authentication;
-(BTstackError) closeL2CAPChannelWithID:(uint16_t) channelID;
-(BTstackError) sendL2CAPPacketForChannelID:(uint16_t)channelID;
2010-02-19 22:05:24 +00:00
-(BTstackError) createRFCOMMConnectionAtAddress:(bd_addr_t) address withChannel:(uint16_t)psm authenticated:(BOOL)authentication;
-(BTstackError) closeRFCOMMConnectionWithID:(uint16_t) connectionID;
-(BTstackError) sendRFCOMMPacketForChannelID:(uint16_t)connectionID;
// TODO add l2cap and rfcomm incoming commands
2010-02-21 16:06:16 +00:00
// store remote names and link keys
-(void)storeDeviceInfo;
@property (nonatomic, assign) id<BTstackManagerDelegate> delegate;
@end
2010-02-19 22:05:24 +00:00
@protocol BTstackManagerDelegate
@optional
// Activation callbacks
-(BOOL) disableSystemBluetooth; // default: YES
// Connection events
-(NSString*) 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;
@end
2010-02-19 22:05:24 +00:00
@protocol BTstackManagerListener
@optional
2010-02-19 22:05:24 +00:00
// Activation events
-(void) activated;
-(void) activationFailed:(BTstackError)error;
-(void) deactivated;
2010-02-19 22:05:24 +00:00
// Discovery events: general
-(void) deviceInfo:(BTDevice*)device;
-(void) discoveryStopped;
-(void) discoveryInquiry;
-(void) discoveryQueryRemoteName:(int)deviceIndex;
2010-02-19 22:05:24 +00:00
-(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;
-(void) l2capDataReceivedForChannelID:(uint16_t)channelID withData:(uint8_t *)packet ofLen:(uint16_t)size;
2010-02-19 22:05:24 +00:00
-(void) rfcommConnectionCreatedAtAddress:(bd_addr_t)addr forChannel:(uint16_t)channel asID:(uint16_t)connectionID;
-(void) rfcommConnectionCreateFailedAtAddress:(bd_addr_t)addr forChannel:(uint16_t)channel error:(BTstackError)error;
-(void) rfcommConnectionClosedForConnectionID:(uint16_t)connectionID;
-(void) rfcommDataReceivedForConnectionID:(uint16_t)connectionID withData:(uint8_t *)packet ofLen:(uint16_t)size;
2010-02-19 22:05:24 +00:00
// TODO add l2cap and rfcomm incoming events
@end