diff --git a/CocoaTouch/include/BTstack/BTstackManager.h b/CocoaTouch/include/BTstack/BTstackManager.h index 820676078..19e112468 100644 --- a/CocoaTouch/include/BTstack/BTstackManager.h +++ b/CocoaTouch/include/BTstack/BTstackManager.h @@ -38,7 +38,8 @@ @class BTDevice; /* - * Information on devices is stored in a system-wide plist and maintained by BTstackManager + * Information on devices is stored in a system-wide plist + * it is maintained by BTstackManager * this includes the link keys */ @@ -48,15 +49,12 @@ typedef int BTstackError; @protocol BTstackManagerDelegate; @interface BTstackManager : NSObject { - id delegate; + id _delegate; } // shared instance +(BTstackManager *) sharedInstance; -// BTstackManagerDelegate protocol implemented by application --(void) setDelegate:(id) delegate; - // Activation -(void) activate; -(void) deactivate; @@ -77,11 +75,16 @@ typedef int BTstackError; -(void) sendRFCOMMPacketForChannelID:(uint16_t)connectionID; // TODO add l2cap and rfcomm incoming commands + +@property (nonatomic, assign) id delegate; @end @protocol BTstackManagerDelegate +// Everything is optional but you should implement all methods of a group +@optional + // Activation events -(void) activated; -(void) activationFailed:(BTstackError)error; diff --git a/CocoaTouch/src/BTstackManager.m b/CocoaTouch/src/BTstackManager.m index 31d284434..a32fb554c 100644 --- a/CocoaTouch/src/BTstackManager.m +++ b/CocoaTouch/src/BTstackManager.m @@ -34,7 +34,7 @@ #import #import "../../RFCOMM/rfcomm.h" -static BTstackManager * btstackManager = NULL; +static BTstackManager * btstackManager = nil; @interface BTstackManager (privat) - (void) handlePacketWithType:(uint8_t) packet_type @@ -52,12 +52,18 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe @implementation BTstackManager +@synthesize delegate = _delegate; + -(BTstackManager *) init { + self = [super init]; + if (!self) return self; + // Cocoa compatible run loop run_loop_init(RUN_LOOP_COCOA); // our packet handler bt_register_packet_handler(packet_handler); + return self; } @@ -68,10 +74,6 @@ static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe return btstackManager; } --(void) setDelegate:(id) newDelegate { - delegate = newDelegate; -} - -(void) activate { bt_open(); bt_send_cmd(&btstack_set_power_mode, HCI_POWER_ON );