]> git.etc.gen.nz Git - picture-display.git/commitdiff
A start at adding an Asterisk plugin.
authorAndrew Ruthven <puck@catalyst.net.nz>
Wed, 24 Sep 2008 03:42:31 +0000 (15:42 +1200)
committerAndrew Ruthven <puck@dirk.wgtn.cat-it.co.nz>
Wed, 24 Sep 2008 03:42:31 +0000 (15:42 +1200)
lib/Display/Plugins/Asterisk.pm [new file with mode: 0644]
picture.pl

diff --git a/lib/Display/Plugins/Asterisk.pm b/lib/Display/Plugins/Asterisk.pm
new file mode 100644 (file)
index 0000000..8d077c4
--- /dev/null
@@ -0,0 +1,93 @@
+package Display::Plugins::Asterisk;
+
+use base ("Display::Plugin");
+
+use strict;
+use Carp;
+
+use POE qw( Component::Client::Asterisk::Manager );
+use Data::Dumper;
+
+sub new {
+  my $proto = shift;
+  my $class = ref($proto) || $proto;
+
+  my $self = $class->SUPER::new(@_);
+
+  bless ($self, $class);
+
+  $self->{'kernel'}->state('asterisk_delayed_start', $self, 'delayed_start');
+
+  POE::Component::Client::Asterisk::Manager->new(
+    Alias => 'asterisk',
+    RemoteHost => $self->{config}{_config}{plugins}{Asterisk}{RemoteHost},
+    RemotePort => $self->{config}{_config}{plugins}{Asterisk}{RemotePort},
+    Username   => $self->{config}{_config}{plugins}{Asterisk}{Username},
+    Password   => $self->{config}{_config}{plugins}{Asterisk}{Password},
+
+    CallBacks => {
+      asterisk_ring  => {
+        'Event' => 'Newchannel',
+       'State' => 'Ring'
+      },
+      asterisk_ringing  => {
+        'Event' => 'Newstate',
+       'State' => 'Ringing',
+      },
+      asterisk_hangup => {
+        'Event' => 'Hangup'
+      },
+      asterisk_input => ':all',
+    },
+
+    inline_states => {
+      # When we're connected to Asterisk, post back to the main session for the rest of
+      # out states to be setup in asterisk_start.  This is to make sure the states are
+      # created in the correct session with a reference to $self.
+      _connected => sub { $self->{'kernel'}->post('display' => 'asterisk_delayed_start') },
+      asterisk_start => sub {
+        my ($kernel, $self) = @_[KERNEL, ARG0];
+
+        $kernel->state('asterisk_input',   $self, 'input');
+        $kernel->state('asterisk_ring',    $self, 'ring');
+        $kernel->state('asterisk_ringing', $self, 'ringing');
+        $kernel->state('asterisk_hangup',  $self, 'hangup');
+      },
+    },
+  );
+
+  return $self;
+}
+
+sub delayed_start {
+  my ($self) = shift;
+
+  $self->{'kernel'}->post('asterisk_client' => 'asterisk_start' => $self);
+}
+
+sub ring {
+  my ($self, $kernel, $session, $input) = @_[OBJECT, KERNEL, SESSION, ARG0];
+  
+  print STDERR "RING! $input->{Channel}\n";
+  print Dumper($input);
+}
+
+sub ringing {
+  my ($self, $kernel, $session, $input) = @_[OBJECT, KERNEL, SESSION, ARG0];
+
+  print STDERR "RING, RING! $input->{Channel}, $input->{'CallerID'} , $input->{'CallerIDName'}\n";
+  print Dumper($input);
+}
+
+sub input {
+  my ($self, $kernel, $input) = @_[OBJECT, KERNEL, ARG0];
+
+  print STDERR "Other input - $input->{Event}\n";
+  #print Dumper($input);
+}
+
+sub hangup {
+  my ($self, $kernel, $input) = @_[OBJECT, KERNEL, ARG0];
+}
+
+1;
index 4963e8f67995b2fa3889e049d65ef0542bb64a3e..eb86f14ba7c7b1fac8f7e6aca2fbe186667971af 100755 (executable)
@@ -32,6 +32,8 @@ $poe_kernel->run;
 sub start {
   my ( $kernel, $session ) = @_[ KERNEL, SESSION ];
 
+  $kernel->alias_set('display');
+
   my $stage = Clutter::Stage->get_default();
   $stage->set_color(Clutter::Color->parse('Black'));
   $stage->signal_connect('key-press-event' => sub { exit; });