Asterisk-CoroManager
view release on metacpan or search on metacpan
lib/Asterisk/CoroManager.pm view on Meta::CPAN
##############################################################################
=head2 sendcommand
my $resp = $astman->sendcommand({
Action => 'QueuePause',
Interface => 'SIP/1234',
Paused => 'true',
},
{ Timeout => 2 });
Sends a command to asterisk.
If you are looking for a response, the command will wait for the
specific response from asterisk (identified with an ActionID).
Otherwise it returns immediately.
TODO: Implement timeout: Timeout is how long to wait for the response.
Defaults to 3 seconds.
Returns a hash or hash-ref on success (depending on wantarray), undef
on timeout.
=cut
sub sendcommand {
my( $astman, $command, $args ) = @_;
my $actionid = $command->{ActionID} || $ACTIONID_SEQ++;
lib/Asterisk/CoroManager.pm view on Meta::CPAN
eval { # Send command to Asterisk
$fh->send("$cstring$EOL");
} or $astman->check_connection;
if (defined wantarray) {
$astman->debug("Waiting for response of command here.");
$astman->trace(longmess());
$astman->trace("-------------------------------------");
$args ||= {};
my $timeout = $args->{Timeout} || DEFAULT_TIMEOUT;
my $response = new Coro::Channel;
$astman->{action_cb}{$actionid} = sub{ $response->put(@_) };
my $resp = $response->get; # Cede's until a response is gotten
return unless( $resp );
return wantarray ? %{$resp} : $resp;
# TODO: Timeout!
}
return;
}
##############################################################################
=head2 check_connection
lib/Asterisk/CoroManager.pm view on Meta::CPAN
Returns 1 if conencted, 0 if not.
=cut
sub connected {
my ($astman, $timeout) = @_;
return ($astman->{fh}->connected and
$astman->sendcommand({ Action => 'Ping' },
{ Timeout => $timeout || DEFAULT_TIMEOUT })
);
}
##############################################################################
##############################################################################
=head2 add_event_callback
$astman->add_event_callback('Join', \&update_queue_status)
( run in 0.239 second using v1.01-cache-2.11-cpan-4d50c553e7e )