mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-11-09 04:49:05 +00:00
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@17128 d0543943-73ff-0310-b7d9-9358b9ac24b2
59 lines
1.7 KiB
Perl
59 lines
1.7 KiB
Perl
# Copyright (c) 2010 Mathieu Parent <math.parent@gmail.com>.
|
|
# All rights reserved. This program is free software; you can redistribute it
|
|
# and/or modify it under the same terms as Perl itself.
|
|
|
|
package Net::Skinny::Message;
|
|
|
|
use strict;
|
|
use warnings;
|
|
|
|
use Net::Skinny::Protocol qw/:all/;
|
|
|
|
use Data::Dumper;
|
|
|
|
require Exporter;
|
|
our @ISA = qw(Exporter);
|
|
our @EXPORT = qw(send);
|
|
|
|
sub new {
|
|
my $class = shift;
|
|
my $self = {};
|
|
bless $self, $class;
|
|
$self->{'socket'} = shift;
|
|
$self->{'type'} = shift;
|
|
%{$self->{'data'}} = @_;
|
|
return $ self;
|
|
}
|
|
|
|
sub send {
|
|
my $self = shift;
|
|
my $struct = Net::Skinny::Protocol::skinny_message_struct($self->{'type'});
|
|
my $raw = '';
|
|
my $parsed_count = 0;
|
|
for my $info ( @$struct) {
|
|
last if !defined($self->{'data'}{@$info[1]});
|
|
if(@$info[0] eq 'char') {
|
|
$raw .= pack("a".@$info[2], $self->{'data'}{@$info[1]});
|
|
} elsif(@$info[0] eq 'uint32_t') {
|
|
$raw .= pack("V".@$info[2], $self->{'data'}{@$info[1]});
|
|
} elsif(@$info[0] eq 'uint16_t') {
|
|
$raw .= pack("n".@$info[2], $self->{'data'}{@$info[1]});
|
|
} elsif(@$info[0] eq 'struct in_addr') {
|
|
$raw .= pack("V".@$info[2], $self->{'data'}{@$info[1]});
|
|
} elsif(@$info[0] eq 'struct station_capabilities') {
|
|
$raw .= $self->{'data'}{@$info[1]};
|
|
} else {
|
|
printf "Unknown type: %s\n", @$info[0];
|
|
return;
|
|
}
|
|
$parsed_count++;
|
|
}
|
|
if($parsed_count != scalar(keys %{$self->{'data'}})) {
|
|
printf "Incomplete message: %d out of %d\n", $parsed_count, scalar(keys %{$self->{'data'}});
|
|
return;
|
|
}
|
|
$self->{'socket'}->send_data($self->{'type'}, $raw);
|
|
}
|
|
|
|
1;
|