feedback by ashikase and rpetrich: _delegate (assign) @property, @optional methods, and correct super init

This commit is contained in:
matthias.ringwald 2010-02-20 15:22:56 +00:00
parent 7ae7581b45
commit 160f793aff
2 changed files with 15 additions and 10 deletions

View File

@ -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<BTstackManagerDelegate> delegate;
id<BTstackManagerDelegate> _delegate;
}
// shared instance
+(BTstackManager *) sharedInstance;
// BTstackManagerDelegate protocol implemented by application
-(void) setDelegate:(id<BTstackManagerDelegate>) 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<BTstackManagerDelegate> 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;

View File

@ -34,7 +34,7 @@
#import <btstack/btstack.h>
#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<BTstackManagerDelegate>) newDelegate {
delegate = newDelegate;
}
-(void) activate {
bt_open();
bt_send_cmd(&btstack_set_power_mode, HCI_POWER_ON );