The EOSManager and EOSCamera classes both have accompanying protocols; EOSManagerProtocol and EOSCameraProtocol. Delegate objects that conform to these protocols can be notified of camera related events. See the API reference for a full list of these events. The delegate objects can be set using the setDelegate methods.
Note that with EOSCamera, a session must be opened before the delegate can be set.
The following example shows how to automatically update a popup button with a list of the currently connected cameras. First, an NSPopupButton should be added to a window and connected to an IBOutlet in a header file (this example uses AppDelegate). The header file should look something like this:
#import <Cocoa/Cocoa.h> #import <EOSFramework/EOSFramework.h> @interface AppDelegate : NSObject <NSApplicationDelegate, EOSManagerProtocol, EOSCameraProtocol> @property (assign) IBOutlet NSWindow *window; @property (weak) IBOutlet NSPopUpButton *cameraListPopup; @end
The implementation file, shown below, initializes the framework and sets the EOSManager delegate. Whenever a camera is connected, a session is opened and the EOSCamera delegate is set. The popup button is updated each time a camera is connected or disconnected.
#import "AppDelegate.h"
@implementation AppDelegate
@synthesize cameraListPopup;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
EOSManager* manager = [EOSManager sharedManager];
if ([manager load:nil]){
//set the EOSManager delegate to self
[manager setDelegate:self];
}else{
NSLog(@"Could not load SDK");
}
}
- (void)applicationWillTerminate:(NSNotification *)notification{
EOSManager* manager = [EOSManager sharedManager];
if ([manager isLoaded]){
[manager terminate:nil];
}
}
//method that will be called whenever a camera is connected or disconnected
- (void)updateCameraList{
//empty the popup button
[cameraListPopup removeAllItems];
//get new camera list
NSArray* cameraList = [[EOSManager sharedManager] getCameras];
//loop though the cameras
for (EOSCamera* camera in cameraList){
//we can determine which camera is new by checking whether it has been opened
if (![camera isOpen]){
//open session
if ([camera openSession:nil]){
//set the EOSCamera delegate to self
[camera setDelegate:self];
}else{
NSLog(@"Could not open camera session");
}
}
//add camera description to the popup button
[cameraListPopup addItemWithTitle: [camera description]];
}
}
//EOSManagerProtocol method: called each time a camera is connected
- (void)cameraDidConnect{
[self updateCameraList];
}
//EOSCameraProtocol method: called when a camera is disconnected
- (void)cameraDidDisconnect:(EOSCamera*)camera{
[self updateCameraList];
}