Hello list.

I'm new on this list.  I'm working with asterisk at a call center
company and recently started using asterisk perl to get better control.

I've been using Asterisk::AGI for a while, but just started using
Asterisk::Manager yesterday, and it seems quite in the rough.

I added a few comments, documentation and debugging-output (if you set
$astman->debug(1)).

Then, AMI sends a lot of messages, and I found that the answer to
sendcommand often was a completely different message.  I added ActionID
to all in sendcommand, and check that the correct response is returned. 
Other responses are sent to eventcallback.

Well, here's a diff, I hope it's useful.

/Fredrik   (fiddur on #asterisk)

42a43,44
> my $ACTIONID_SEQ = 1;
> 
64a67,76
> #######################################################################
> 
> =head2 user
> 
>   $astman->user('user')
> 
> Set user for manager connection.
> 
> =cut
> 
74a87,97
> 
> #######################################################################
> 
> =head2 secret
> 
>   $astman->secret('secret')
> 
> Set secret for manager connection.
> 
> =cut
> 
84a108,118
> 
> #######################################################################
> 
> =head2 host
> 
>   $astman->host('localhost')
> 
> Set host for manager connection.
> 
> =cut
> 
94a129,139
> 
> #######################################################################
> 
> =head2 port
> 
>   $astman->port(5038)
> 
> Set port for manager connection; defaults to 5038.
> 
> =cut
> 
104a150,162
> 
> #######################################################################
> 
> =head2 connected
> 
>   die "Not connected!" unless($astman->connected())
> 
> Checks if manager is connected.
> 
> Returns 1 if conencted, 0 if not.
> 
> =cut
> 
114a173,175
> 
> #######################################################################
> 
124a186,196
> 
> #######################################################################
> 
> =head2 debug
> 
>   $astman->debug(1)
> 
> Turns on or off debugging messages.
> 
> =cut
> 
134a207,209
> 
> #######################################################################
> 
144a220,222
> 
> #######################################################################
> 
168a247,258
> 
> #######################################################################
> 
> =head2 connect
> 
>   $astman->connect || die "Could not connect to ". $astman->host ."!\n";
> 
> Connects the manager to asterisk.  User, secret and host should be set
> before calling this.
> 
> =cut
> 
235a326,328
> 
> #######################################################################
> 
247a341,343
> 
> #######################################################################
> 
262,265c358,378
< #$want is how you want the data returned
< #$want = 0 (default) returns the results in a hash
< #$want = 1 returns the results in a large string
< #$want = 2 returns the results in an array
---
> 
> #########################################################################
> 
> =head2 sendcommand
> 
>   my %resp = $astman->sendcommand(  Action    => 'QueuePause',
>                                     Interface => 'SIP/1234',
>                                     Paused    => 'true',
>                                     $want
>                                  );
> 
> Sends a command to asterisk.
> 
>  $want is how you want the data returned
>    $want = 0 (default) returns the results in a hash
>    $want = 1 returns the results in a large string
>    $want = 2 returns the results in an array
> 
> 
> =cut
> 
272c385,393
<       
---
> 
>       my $actionid = $command{'ActionID'};
> 
>       unless( $actionid )
>       {
>               $actionid = $ACTIONID_SEQ++;
>               $command{'ActionID'} = $actionid;
>       }
> 
284a406,413
>       while( not grep(/ActionID: $actionid/, @resp ) )
>       {
>               # This is not our response; send it to eventhandler
>               $self->eventcallback( map { splitresult($_); } @resp );
> 
>               @resp = $self->read_response($conn);
>       }
> 
288c417,418
<               return map { splitresult($_) } @resp;
---
>               my %resp = map { splitresult($_) } @resp;
>               return %resp;
291a422,432
> 
> #######################################################################
> 
> =head2 setcallback
> 
>   $astman->setcallback('Join', \&join_eventhandler)
> 
> Set a callback for a specific event.
> 
> =cut
> 
299a441,443
> 
> #######################################################################
> 
306c450,455
<       return if (!$event);
---
>       unless($event) {
>               if ($self->debug) {
>                       print "Got non-event message.\n";
>               }
>               return;
>       }
312a462,463
>               print "Got unhandled event: ". $resp{Event} ."\n"
>                 if($self->debug);
318a470,472
> 
> #######################################################################
> 
326a481,483
> 
> #######################################################################
> 
335a493,495
> 
> #######################################################################
> 
354a515,517
> 
> #######################################################################
> 
363a527,539
> 
> #######################################################################
> 
> =head2 disconnect
> 
>   $astman->disconnect()
> 
> Disconnects the manager from asterisk.
> 
> Returns 1 if logoffed successfully.  Otherwise 0.
> 
> =cut
> 
371d546
< 
380a556,558
> 
> #######################################################################
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: asterisk-perl-unsubscr...@lists.gnuinter.net
For additional commands, e-mail: asterisk-perl-h...@lists.gnuinter.net

Reply via email to