<!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 &lt;math.parent@gmail.com&gt;.
+# 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 &lt;math.parent@gmail.com&gt;.
+# 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 &quot;refs&quot;;
+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 . &quot;::$sym&quot;} = $sub;
+        }
+        else {
+            ++$oops;
+            carp(qq[&quot;$sym&quot; is not exported by the Net::Skinny::Protocol module]);
+        }
+    }
+    croak(&quot;Can't continue after import errors&quot;) if $oops;
+}
+
+sub _find {
+    my $fh;
+    unless (open($fh, $skinny_protocol_h)) {
+        print STDERR &quot;Can't open $skinny_protocol_h: $!\n&quot;;
+        return;
+    }
+    while(&lt;$fh&gt;) {
+        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 &quot;UnknownMessage&quot;;
+}
</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 &lt;math.parent@gmail.com&gt;.
+# 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-&gt;SUPER::new(PeerPort =&gt; 2000, @_);
+}
+
+sub send_message
+{
+    my $self = shift;
+        my $type = shift;
+        my $data = shift;
+        my $len = length($data)+4;
+        printf &quot;Sending message (length=%d, type=%s (%X))&quot;, $len, Net::Skinny::Protocol::skinny_message_type2str($type), $type;
+        $self-&gt;send(
+                pack(&quot;VVV&quot;, $len, 0, $type).
+                $data);
+        printf &quot;.\n&quot;;
+}
+
+sub receive_message
+{
+    my $self = shift;
+        my $buf;
+        $self-&gt;recv($buf, 4);
+        my $len = unpack(&quot;V&quot;, $buf);
+        printf &quot;Receiving message (length=%d,&quot;, $len;
+        if($len &lt; 4) {
+                printf &quot;type=?).\n&quot;;
+                printf &quot;Problem! Length is &lt; 4.\n&quot;;
+                exit 1;
+        }
+        $self-&gt;recv($buf, 4); #reserved
+        $self-&gt;recv($buf, 4); #type
+        my $type = unpack(&quot;V&quot;, $buf);
+        printf &quot;type=%s (%X))&quot;, Net::Skinny::Protocol::skinny_message_type2str($type), $type;
+        if($len &gt; 4) {
+                $self-&gt;recv($buf, $len-4);
+        }
+        printf &quot;.\n&quot;;
+}
+
+sub sleep
+{
+    my $self = shift;
+        my $t = shift;
+        
+        printf &quot;Sleeping %d seconds&quot;, $t;
+        while(--$t){
+                sleep(1);
+                printf &quot;.&quot; if $t % 10;
+                printf &quot;_&quot; unless $t % 10;
+        }
+        printf &quot;.\n&quot;;
+}
+
+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 &lt;math.parent@gmail.com&gt;.
+# 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 = &quot;SEP001120AABBCC&quot;;
</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-&gt;new(
</del><ins>+my $socket = Net::Skinny-&gt;new(
</ins><span class="cx">                 PeerAddr =&gt; $skinny_server,
</span><span class="cx">                 PeerPort =&gt; 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 &quot;Sending message (length=%d, type=%X)&quot;, $len, $type;
-        $socket-&gt;send(
-                pack(&quot;VVV&quot;, $len, 0, $type).
-                $data);
-        printf &quot;.\n&quot;;
</del><ins>+if(!$socket) {
+    print &quot;Unable to connect to server\n&quot;;
+    exit 1;
</ins><span class="cx"> }
</span><del>-
-sub skinny_recv
-{
-        my $buf;
-        $socket-&gt;recv($buf, 4);
-        my $len = unpack(&quot;V&quot;, $buf);
-        printf &quot;Receiving message (length=%d,&quot;, $len;
-        if($len &lt; 4) {
-                printf &quot;type=?).\n&quot;;
-                printf &quot;Problem! Length is &lt; 4.\n&quot;;
-                exit 1;
-        }
-        $socket-&gt;recv($buf, 4); #reserved
-        $socket-&gt;recv($buf, 4); #type
-        my $type = unpack(&quot;V&quot;, $buf);
-        printf &quot;type=%X)&quot;, $type;
-        if($len &gt; 4) {
-                $socket-&gt;recv($buf, $len-4);
-        }
-        printf &quot;.\n&quot;;
-}
-
-sub skinny_sleep
-{
-        my $t = shift;
-        
-        printf &quot;Sleeping %d seconds&quot;, $t;
-        while(--$t){
-                sleep(1);
-                printf &quot;.&quot; if $t % 10;
-                printf &quot;_&quot; unless $t % 10;
-        }
-        printf &quot;.\n&quot;;
-}
-
</del><span class="cx"> # =============================================================================
</span><del>-# 
-# =============================================================================
-skinny_connect();
-
-# =============================================================================
-skinny_send(0x0001, # Register
</del><ins>+$socket-&gt;send_message(REGISTER_MESSAGE, # Register
</ins><span class="cx">         pack(&quot;a16VVVVV&quot;,
</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-&gt;receive_message(); # RegisterAck
</ins><span class="cx"> 
</span><del>-skinny_send(0x0002, # Port
</del><ins>+$socket-&gt;send_message(0x0002, # Port
</ins><span class="cx">         pack(&quot;n&quot;, 2000
</span><span class="cx">         ));
</span><span class="cx"> 
</span><del>-skinny_send(0x002b, # HeadSetStatus
</del><ins>+$socket-&gt;send_message(HEADSET_STATUS_MESSAGE,
</ins><span class="cx">         pack(&quot;V&quot;,
</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-&gt;receive_message(); # CapabilitiesReq
+$socket-&gt;send_message(CAPABILITIES_RES_MESSAGE,
</ins><span class="cx">         pack(&quot;V&quot;.&quot;Vva10&quot;.&quot;Vva10&quot;,
</span><span class="cx">                 2, # count
</span><span class="cx">                 2, 8, &quot;&quot;, # codec, frames, res
</span><span class="cx">                 4, 16, &quot;&quot;, # codec, frames, res
</span><span class="cx">         ));
</span><span class="cx"> 
</span><del>-skinny_send(0x000e, # ButtonTemplateReqMessage
-        &quot;&quot;);
-skinny_recv(); # ButtonTemplateMessage
</del><ins>+$socket-&gt;send_message(BUTTON_TEMPLATE_REQ_MESSAGE, &quot;&quot;);
+$socket-&gt;receive_message(); # ButtonTemplateMessage
</ins><span class="cx"> 
</span><del>-skinny_send(0x0028, # SoftKeyTemplateReq
-        &quot;&quot;);
-skinny_recv(); # SoftKeyTemplateRes
</del><ins>+$socket-&gt;send_message(SOFT_KEY_TEMPLATE_REQ_MESSAGE, &quot;&quot;);
+$socket-&gt;receive_message(); # SoftKeyTemplateRes
</ins><span class="cx"> 
</span><del>-skinny_send(0x0025, # SoftKeySetReq
-        &quot;&quot;);
-skinny_recv(); # SoftKeySetRes
</del><ins>+$socket-&gt;send_message(SOFT_KEY_SET_REQ_MESSAGE,        &quot;&quot;);
+$socket-&gt;receive_message(); # SoftKeySetRes
</ins><span class="cx"> 
</span><del>-skinny_send(0x000B, # LineStatReq
-        pack(&quot;V&quot;, 1));
-skinny_recv(); # LineStat
</del><ins>+$socket-&gt;send_message(LINE_STAT_REQ_MESSAGE, pack(&quot;V&quot;, 1));
+$socket-&gt;receive_message(); # LineStat
</ins><span class="cx"> 
</span><del>-skinny_send(0x002D, # RegisterAvailableLines
-        pack(&quot;V&quot;, 2
-        ));
</del><ins>+$socket-&gt;send_message(REGISTER_AVAILABLE_LINES_MESSAGE, pack(&quot;V&quot;, 2));
</ins><span class="cx"> 
</span><span class="cx"> while(1) {
</span><del>-        skinny_sleep(20);
-        skinny_send(0x0000, # keepalive
-                &quot;&quot;);
-        skinny_recv(); # keepaliveack
</del><ins>+        $socket-&gt;sleep(20);
+        $socket-&gt;send_message(KEEP_ALIVE_MESSAGE, &quot;&quot;);
+        $socket-&gt;receive_message(); # keepaliveack
</ins><span class="cx"> }
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>