Asterisk.framework Mac OS-X Cocoa API for Asterisk PBX

©2005-2007 Sven Slezak <sunny at mezzo.net>
Version: 1.2(May 17. 2007)

download


Objective-C example code

AsteriskTest.m
#import <Asterisk/Asterisk.h>
#import "AsteriskController.h"

int main( int inArgC, const char* inArgV[] ) 
{
  NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

  NS_DURING
  {
    Asterisk *asterisk = [[[Asterisk alloc] initWithHost:@"192.168.0.1"] retain];
    [asterisk setDelegate:[[AsteriskController alloc] init]];
    [asterisk connectTimeout:2.0];
    if([asterisk connect]) {
      if([asterisk Login:@"admin" secret:@"secret" withEvents:YES]) {
        [[NSTimer scheduledTimerWithTimeInterval:3.0 target:asterisk selector:@selector(Ping) userInfo:nil repeats:YES] fire];
        NSDictionary *commands = [asterisk Action:@"Mailboxcount" 
                                   withParameters:[NSDictionary dictionaryWithObjectsAndKeys:@"1234", @"Mailbox", nil]];
        NSLog(@"commands: %@", [commands description]);
        // [asterisk Logoff];
      }

      [[NSRunLoop currentRunLoop] run];
    }
  }
  NS_HANDLER
  NSLog( @"Unhandled exception: %@",localException );

  NS_ENDHANDLER
      
  [pool release];
  return 0;
}
AsteriskController.m
#import "AsteriskController.h"

@implementation AsteriskController

- (void)asteriskConnected:(Asterisk *)asterisk {
  NSLog(@"*** connected.");
}
- (void)asteriskDisconnected:(Asterisk *)asterisk {
  NSLog(@"*** disconnected.");
}
- (void)asteriskLoggedIn:(Asterisk *)asterisk {
  NSLog(@"*** logged in.");
}
- (void)asteriskTimeout:(Asterisk *)asterisk {
  NSLog(@"*** timeout.");
}
- (void)asteriskEventReceived:(Asterisk *)asterisk event:(NSDictionary *)event {
  NSLog(@"*** event:\n%@", [event description]);  
}

@end
AsteriskController.h
#import <Foundation/Foundation.h>
#import <Asterisk/Asterisk.h>

@interface AsteriskController : NSObject {
}

@end
	 \ | /
	- :-) -
	 / | \