From: Andrew Ruthven Date: Wed, 24 Sep 2008 03:42:31 +0000 (+1200) Subject: A start at adding an Asterisk plugin. X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1c7b6c9b68a2c4bf54a70c412a4e6d245c9404ba;p=picture-display.git A start at adding an Asterisk plugin. --- diff --git a/lib/Display/Plugins/Asterisk.pm b/lib/Display/Plugins/Asterisk.pm new file mode 100644 index 0000000..8d077c4 --- /dev/null +++ b/lib/Display/Plugins/Asterisk.pm @@ -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; diff --git a/picture.pl b/picture.pl index 4963e8f..eb86f14 100755 --- a/picture.pl +++ b/picture.pl @@ -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; });