<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[Freeswitch-trunk][17124] </title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<div id="header">FreeSWITCH Subversion</div>
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://fisheye.freeswitch.org/changelog/FreeSWITCH?cs=17124">17124</a></dd>
<dt>Author</dt> <dd>sathieu</dd>
<dt>Date</dt> <dd>2010-03-27 17:43:18 -0500 (Sat, 27 Mar 2010)</dd>
</dl>
<h3>Log Message</h3>
<pre>Skinny: split the test into perl lib + bin</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunksrcmodendpointsmod_skinnytestskinnypl">freeswitch/trunk/src/mod/endpoints/mod_skinny/test-skinny.pl</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li>freeswitch/trunk/src/mod/endpoints/mod_skinny/Net/</li>
<li>freeswitch/trunk/src/mod/endpoints/mod_skinny/Net/Skinny/</li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_skinnyNetSkinnyMessagepm">freeswitch/trunk/src/mod/endpoints/mod_skinny/Net/Skinny/Message.pm</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_skinnyNetSkinnyProtocolpm">freeswitch/trunk/src/mod/endpoints/mod_skinny/Net/Skinny/Protocol.pm</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_skinnyNetSkinnypm">freeswitch/trunk/src/mod/endpoints/mod_skinny/Net/Skinny.pm</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunksrcmodendpointsmod_skinnyNetSkinnyMessagepm"></a>
<div class="addfile"><h4>Added: freeswitch/trunk/src/mod/endpoints/mod_skinny/Net/Skinny/Message.pm (0 => 17124)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_skinny/Net/Skinny/Message.pm         (rev 0)
+++ freeswitch/trunk/src/mod/endpoints/mod_skinny/Net/Skinny/Message.pm        2010-03-27 22:43:18 UTC (rev 17124)
</span><span class="lines">@@ -0,0 +1,10 @@
</span><ins>+# 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;
+
+
</ins></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_skinnyNetSkinnyProtocolpm"></a>
<div class="addfile"><h4>Added: freeswitch/trunk/src/mod/endpoints/mod_skinny/Net/Skinny/Protocol.pm (0 => 17124)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_skinny/Net/Skinny/Protocol.pm         (rev 0)
+++ freeswitch/trunk/src/mod/endpoints/mod_skinny/Net/Skinny/Protocol.pm        2010-03-27 22:43:18 UTC (rev 17124)
</span><span class="lines">@@ -0,0 +1,64 @@
</span><ins>+# 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::Protocol;
+
+use strict;
+no strict "refs";
+use warnings;
+use Carp;
+
+require Exporter;
+our @ISA = qw(Exporter);
+our @EXPORT = qw(skinny_message_type2str);
+
+my %const;
+my %sub;
+my $skinny_protocol_h = 'src/mod/endpoints/mod_skinny/skinny_protocol.h';
+
+sub import {
+ shift;
+ my $callpkg = caller(0);
+ _find(@_);
+ my $oops;
+ my $all = grep /:all/, @_;
+ foreach my $sym ($all ? keys %sub : @_) {
+ if (my $sub = $sub{$sym}) {
+ *{$callpkg . "::$sym"} = $sub;
+ }
+ else {
+ ++$oops;
+ carp(qq["$sym" is not exported by the Net::Skinny::Protocol module]);
+ }
+ }
+ croak("Can't continue after import errors") if $oops;
+}
+
+sub _find {
+ my $fh;
+ unless (open($fh, $skinny_protocol_h)) {
+ print STDERR "Can't open $skinny_protocol_h: $!\n";
+ return;
+ }
+ while(<$fh>) {
+ if( /^#define\s+([\w_]+)\s+(0x[0-9a-f]+)\s*$/i) {
+ my ($name, $value) = ($1,hex($2));
+ $sub{$name} = sub () { $value };
+ $const{$name} = $value;
+ }
+ }
+ @sub{@_};
+}
+
+sub skinny_message_type2str {
+ my $message_type = shift;
+
+ keys %const;
+ while (my ($key, $value) = each %const) {
+ if($value == $message_type) {
+ return $key;
+ }
+ }
+ return "UnknownMessage";
+}
</ins></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_skinnyNetSkinnypm"></a>
<div class="addfile"><h4>Added: freeswitch/trunk/src/mod/endpoints/mod_skinny/Net/Skinny.pm (0 => 17124)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_skinny/Net/Skinny.pm         (rev 0)
+++ freeswitch/trunk/src/mod/endpoints/mod_skinny/Net/Skinny.pm        2010-03-27 22:43:18 UTC (rev 17124)
</span><span class="lines">@@ -0,0 +1,68 @@
</span><ins>+# 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;
+
+use strict;
+use warnings;
+use IO::Socket;
+use Net::Skinny::Protocol qw/:all/;
+
+our(@ISA);
+@ISA = qw(IO::Socket::INET);
+
+sub new {
+ shift->SUPER::new(PeerPort => 2000, @_);
+}
+
+sub send_message
+{
+ my $self = shift;
+        my $type = shift;
+        my $data = shift;
+        my $len = length($data)+4;
+        printf "Sending message (length=%d, type=%s (%X))", $len, Net::Skinny::Protocol::skinny_message_type2str($type), $type;
+        $self->send(
+                pack("VVV", $len, 0, $type).
+                $data);
+        printf ".\n";
+}
+
+sub receive_message
+{
+ my $self = shift;
+        my $buf;
+        $self->recv($buf, 4);
+        my $len = unpack("V", $buf);
+        printf "Receiving message (length=%d,", $len;
+        if($len < 4) {
+                printf "type=?).\n";
+                printf "Problem! Length is < 4.\n";
+                exit 1;
+        }
+        $self->recv($buf, 4); #reserved
+        $self->recv($buf, 4); #type
+        my $type = unpack("V", $buf);
+        printf "type=%s (%X))", Net::Skinny::Protocol::skinny_message_type2str($type), $type;
+        if($len > 4) {
+                $self->recv($buf, $len-4);
+        }
+        printf ".\n";
+}
+
+sub sleep
+{
+ my $self = shift;
+        my $t = shift;
+        
+        printf "Sleeping %d seconds", $t;
+        while(--$t){
+                sleep(1);
+                printf "." if $t % 10;
+                printf "_" unless $t % 10;
+        }
+        printf ".\n";
+}
+
+1;
</ins></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_skinnytestskinnypl"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_skinny/test-skinny.pl (17123 => 17124)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_skinny/test-skinny.pl        2010-03-27 22:37:48 UTC (rev 17123)
+++ freeswitch/trunk/src/mod/endpoints/mod_skinny/test-skinny.pl        2010-03-27 22:43:18 UTC (rev 17124)
</span><span class="lines">@@ -1,9 +1,20 @@
</span><span class="cx"> #!/usr/bin/perl
</span><span class="cx">
</span><ins>+# 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.
+
+BEGIN {
+ push @INC, 'src/mod/endpoints/mod_skinny';
+}
+
</ins><span class="cx"> use strict;
</span><span class="cx"> use warnings;
</span><del>-use IO::Socket;
</del><span class="cx">
</span><ins>+use Data::Dumper;
+use Net::Skinny;
+use Net::Skinny::Protocol qw/:all/;
+
</ins><span class="cx"> #Config
</span><span class="cx"> my $skinny_server = '127.0.0.1';
</span><span class="cx"> my $device_name = "SEP001120AABBCC";
</span><span class="lines">@@ -11,69 +22,17 @@
</span><span class="cx"> #======
</span><span class="cx"> $| = 1;
</span><span class="cx">
</span><del>-my $socket;
-
-sub skinny_connect
-{
-        $socket = IO::Socket::INET->new(
</del><ins>+my $socket = Net::Skinny->new(
</ins><span class="cx">                 PeerAddr => $skinny_server,
</span><span class="cx">                 PeerPort => 2000,
</span><span class="cx">                 );
</span><del>-}
</del><span class="cx">
</span><del>-sub skinny_send
-{
-        my $type = shift;
-        my $data = shift;
-        my $len = length($data)+4;
-        printf "Sending message (length=%d, type=%X)", $len, $type;
-        $socket->send(
-                pack("VVV", $len, 0, $type).
-                $data);
-        printf ".\n";
</del><ins>+if(!$socket) {
+ print "Unable to connect to server\n";
+ exit 1;
</ins><span class="cx"> }
</span><del>-
-sub skinny_recv
-{
-        my $buf;
-        $socket->recv($buf, 4);
-        my $len = unpack("V", $buf);
-        printf "Receiving message (length=%d,", $len;
-        if($len < 4) {
-                printf "type=?).\n";
-                printf "Problem! Length is < 4.\n";
-                exit 1;
-        }
-        $socket->recv($buf, 4); #reserved
-        $socket->recv($buf, 4); #type
-        my $type = unpack("V", $buf);
-        printf "type=%X)", $type;
-        if($len > 4) {
-                $socket->recv($buf, $len-4);
-        }
-        printf ".\n";
-}
-
-sub skinny_sleep
-{
-        my $t = shift;
-        
-        printf "Sleeping %d seconds", $t;
-        while(--$t){
-                sleep(1);
-                printf "." if $t % 10;
-                printf "_" unless $t % 10;
-        }
-        printf ".\n";
-}
-
</del><span class="cx"> # =============================================================================
</span><del>-#
-# =============================================================================
-skinny_connect();
-
-# =============================================================================
-skinny_send(0x0001, # Register
</del><ins>+$socket->send_message(REGISTER_MESSAGE, # Register
</ins><span class="cx">         pack("a16VVVVV",
</span><span class="cx">                 $device_name,
</span><span class="cx">                 0, # userId;
</span><span class="lines">@@ -82,48 +41,41 @@
</span><span class="cx">                 7, # deviceType;
</span><span class="cx">                 0, # maxStreams;
</span><span class="cx">         ));
</span><del>-skinny_recv(); # RegisterAck
</del><ins>+$socket->receive_message(); # RegisterAck
</ins><span class="cx">
</span><del>-skinny_send(0x0002, # Port
</del><ins>+$socket->send_message(0x0002, # Port
</ins><span class="cx">         pack("n", 2000
</span><span class="cx">         ));
</span><span class="cx">
</span><del>-skinny_send(0x002b, # HeadSetStatus
</del><ins>+$socket->send_message(HEADSET_STATUS_MESSAGE,
</ins><span class="cx">         pack("V",
</span><span class="cx">                 2, # Off
</span><span class="cx">         ));
</span><span class="cx">
</span><del>-skinny_recv(); # CapabilitiesReq
-skinny_send(0x0010, # CapabilitiesRes
</del><ins>+$socket->receive_message(); # CapabilitiesReq
+$socket->send_message(CAPABILITIES_RES_MESSAGE,
</ins><span class="cx">         pack("V"."Vva10"."Vva10",
</span><span class="cx">                 2, # count
</span><span class="cx">                 2, 8, "", # codec, frames, res
</span><span class="cx">                 4, 16, "", # codec, frames, res
</span><span class="cx">         ));
</span><span class="cx">
</span><del>-skinny_send(0x000e, # ButtonTemplateReqMessage
-        "");
-skinny_recv(); # ButtonTemplateMessage
</del><ins>+$socket->send_message(BUTTON_TEMPLATE_REQ_MESSAGE, "");
+$socket->receive_message(); # ButtonTemplateMessage
</ins><span class="cx">
</span><del>-skinny_send(0x0028, # SoftKeyTemplateReq
-        "");
-skinny_recv(); # SoftKeyTemplateRes
</del><ins>+$socket->send_message(SOFT_KEY_TEMPLATE_REQ_MESSAGE, "");
+$socket->receive_message(); # SoftKeyTemplateRes
</ins><span class="cx">
</span><del>-skinny_send(0x0025, # SoftKeySetReq
-        "");
-skinny_recv(); # SoftKeySetRes
</del><ins>+$socket->send_message(SOFT_KEY_SET_REQ_MESSAGE,        "");
+$socket->receive_message(); # SoftKeySetRes
</ins><span class="cx">
</span><del>-skinny_send(0x000B, # LineStatReq
-        pack("V", 1));
-skinny_recv(); # LineStat
</del><ins>+$socket->send_message(LINE_STAT_REQ_MESSAGE, pack("V", 1));
+$socket->receive_message(); # LineStat
</ins><span class="cx">
</span><del>-skinny_send(0x002D, # RegisterAvailableLines
-        pack("V", 2
-        ));
</del><ins>+$socket->send_message(REGISTER_AVAILABLE_LINES_MESSAGE, pack("V", 2));
</ins><span class="cx">
</span><span class="cx"> while(1) {
</span><del>-        skinny_sleep(20);
-        skinny_send(0x0000, # keepalive
-                "");
-        skinny_recv(); # keepaliveack
</del><ins>+        $socket->sleep(20);
+        $socket->send_message(KEEP_ALIVE_MESSAGE, "");
+        $socket->receive_message(); # keepaliveack
</ins><span class="cx"> }
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>
</body>
</html>