<!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][16751] </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=16751">16751</a></dd>
<dt>Author</dt> <dd>sathieu</dd>
<dt>Date</dt> <dd>2010-02-24 05:58:15 -0600 (Wed, 24 Feb 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Skinny: Milestone 1 : device level (API)

skinny device *
skinny device &lt;device_name&gt;</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunksrcmodendpointsmod_skinnymod_skinnyc">freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.c</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunksrcmodendpointsmod_skinnymod_skinnyc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.c (16750 => 16751)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.c        2010-02-24 11:58:07 UTC (rev 16750)
+++ freeswitch/trunk/src/mod/endpoints/mod_skinny/mod_skinny.c        2010-02-24 11:58:15 UTC (rev 16751)
</span><span class="lines">@@ -113,7 +113,7 @@
</span><span class="cx">         char deviceName[16];
</span><span class="cx">         uint32_t userId;
</span><span class="cx">         uint32_t instance;
</span><del>-        uint32_t ip;
</del><ins>+        struct in_addr ip;
</ins><span class="cx">         uint32_t deviceType;
</span><span class="cx">         uint32_t maxStreams;
</span><span class="cx"> };
</span><span class="lines">@@ -156,13 +156,15 @@
</span><span class="cx">         char deviceName[16];
</span><span class="cx">         uint32_t userId;
</span><span class="cx">         uint32_t instance;
</span><del>-        uint32_t ip;
</del><ins>+        struct in_addr ip;
</ins><span class="cx">         uint32_t deviceType;
</span><span class="cx">         uint32_t maxStreams;
</span><span class="cx">         uint16_t port;
</span><span class="cx"> };
</span><span class="cx"> typedef struct skinny_device skinny_device_t;
</span><span class="cx"> 
</span><ins>+typedef switch_status_t (*skinny_command_t) (char **argv, int argc, switch_stream_handle_t *stream);
+
</ins><span class="cx"> /*****************************************************************************/
</span><span class="cx"> /* LISTENERS TYPES */
</span><span class="cx"> /*****************************************************************************/
</span><span class="lines">@@ -189,7 +191,7 @@
</span><span class="cx"> 
</span><span class="cx"> typedef struct listener listener_t;
</span><span class="cx"> 
</span><del>-typedef switch_status_t (*skinny_listener_callback_func_t) (listener_t *listener);
</del><ins>+typedef switch_status_t (*skinny_listener_callback_func_t) (listener_t *listener, void *pvt);
</ins><span class="cx"> 
</span><span class="cx"> static struct {
</span><span class="cx">         switch_socket_t *sock;
</span><span class="lines">@@ -218,7 +220,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> /* LISTENER FUNCTIONS */
</span><del>-static switch_status_t keepalive_listener(listener_t *listener);
</del><ins>+static switch_status_t keepalive_listener(listener_t *listener, void *pvt);
</ins><span class="cx"> 
</span><span class="cx"> /*****************************************************************************/
</span><span class="cx"> /* CHANNEL FUNCTIONS */
</span><span class="lines">@@ -735,7 +737,7 @@
</span><span class="cx">                         reply-&gt;data.reg_ack.secondaryKeepAlive = globals.keep_alive;
</span><span class="cx">                         /* TODO send CapabilitiesReqMessage (and parse the CapabilitiesResMessage) */
</span><span class="cx">                         /* TODO event */
</span><del>-                        keepalive_listener(listener);
</del><ins>+                        keepalive_listener(listener, NULL);
</ins><span class="cx">                         break;
</span><span class="cx">                 case PORT_MESSAGE:
</span><span class="cx">                         /* Nothing to do */
</span><span class="lines">@@ -744,7 +746,7 @@
</span><span class="cx">                         reply = switch_core_alloc(listener-&gt;pool, 12);
</span><span class="cx">                         reply-&gt;type = KEEP_ALIVE_ACK_MESSAGE;
</span><span class="cx">                         reply-&gt;length = 4;
</span><del>-                        keepalive_listener(listener);
</del><ins>+                        keepalive_listener(listener, NULL);
</ins><span class="cx">                         break;
</span><span class="cx">                 /* TODO */
</span><span class="cx">                 default:
</span><span class="lines">@@ -807,13 +809,13 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-static void walk_listeners(skinny_listener_callback_func_t callback)
</del><ins>+static void walk_listeners(skinny_listener_callback_func_t callback, void *pvt)
</ins><span class="cx"> {
</span><span class="cx">         listener_t *l;
</span><span class="cx"> 
</span><span class="cx">         switch_mutex_lock(globals.listener_mutex);
</span><span class="cx">         for (l = listen_list.listeners; l; l = l-&gt;next) {
</span><del>-                callback(l);
</del><ins>+                callback(l, pvt);
</ins><span class="cx">         }
</span><span class="cx">         switch_mutex_unlock(globals.listener_mutex);
</span><span class="cx"> 
</span><span class="lines">@@ -825,6 +827,47 @@
</span><span class="cx">         /* TODO */
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static listener_t *find_listener(char *device_name)
+{
+        listener_t *l, *r = NULL;
+        skinny_device_t *device;
+
+        switch_mutex_lock(globals.listener_mutex);
+        for (l = listen_list.listeners; l; l = l-&gt;next) {
+                if (l-&gt;device) {
+                        device = l-&gt;device;
+                        if(!strcasecmp(device-&gt;deviceName,device_name)) {
+                                if (switch_thread_rwlock_tryrdlock(l-&gt;rwlock) == SWITCH_STATUS_SUCCESS) {
+                                        r = l;
+                                }
+                                break;
+                        }
+                }
+        }
+        switch_mutex_unlock(globals.listener_mutex);
+        return r;
+}
+
+static switch_status_t dump_listener(listener_t *listener, void *pvt)
+{
+        switch_stream_handle_t *stream = (switch_stream_handle_t *) pvt;
+        const char *line = &quot;=================================================================================================&quot;;
+        skinny_device_t *device;
+        if(listener-&gt;device) {
+                device = listener-&gt;device;
+                stream-&gt;write_function(stream, &quot;%s\n&quot;, line);
+                stream-&gt;write_function(stream, &quot;DeviceName    \t%s\n&quot;, switch_str_nil(device-&gt;deviceName));
+                stream-&gt;write_function(stream, &quot;UserId        \t%d\n&quot;, device-&gt;userId);
+                stream-&gt;write_function(stream, &quot;Instance      \t%d\n&quot;, device-&gt;instance);
+                stream-&gt;write_function(stream, &quot;IP            \t%s\n&quot;, inet_ntoa(device-&gt;ip));
+                stream-&gt;write_function(stream, &quot;DeviceType    \t%d\n&quot;, device-&gt;deviceType);
+                stream-&gt;write_function(stream, &quot;MaxStreams    \t%d\n&quot;, device-&gt;maxStreams);
+                stream-&gt;write_function(stream, &quot;Port          \t%d\n&quot;, device-&gt;port);
+                stream-&gt;write_function(stream, &quot;%s\n&quot;, line);
+        }
+        return SWITCH_STATUS_SUCCESS;
+}
+
</ins><span class="cx"> static void close_socket(switch_socket_t **sock)
</span><span class="cx"> {
</span><span class="cx">         switch_mutex_lock(listen_list.sock_mutex);
</span><span class="lines">@@ -836,7 +879,7 @@
</span><span class="cx">         switch_mutex_unlock(listen_list.sock_mutex);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static switch_status_t kill_listener(listener_t *listener)
</del><ins>+static switch_status_t kill_listener(listener_t *listener, void *pvt)
</ins><span class="cx"> {
</span><span class="cx">         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, &quot;Killing listener.\n&quot;);
</span><span class="cx">         switch_clear_flag(listener, LFLAG_RUNNING);
</span><span class="lines">@@ -844,15 +887,15 @@
</span><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static switch_status_t kill_expired_listener(listener_t *listener)
</del><ins>+static switch_status_t kill_expired_listener(listener_t *listener, void *pvt)
</ins><span class="cx"> {
</span><span class="cx">         if(listener-&gt;expire_time &lt; switch_epoch_time_now(NULL)) {
</span><del>-                return kill_listener(listener);
</del><ins>+                return kill_listener(listener, pvt);
</ins><span class="cx">         }
</span><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static switch_status_t keepalive_listener(listener_t *listener)
</del><ins>+static switch_status_t keepalive_listener(listener_t *listener, void *pvt)
</ins><span class="cx"> {
</span><span class="cx">         switch_assert(listener);
</span><span class="cx">         
</span><span class="lines">@@ -895,7 +938,7 @@
</span><span class="cx"> 
</span><span class="cx">         switch_socket_opt_set(listener-&gt;sock, SWITCH_SO_NONBLOCK, TRUE);
</span><span class="cx">         switch_set_flag_locked(listener, LFLAG_RUNNING);
</span><del>-        keepalive_listener(listener);
</del><ins>+        keepalive_listener(listener, NULL);
</ins><span class="cx">         add_listener(listener);
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -1140,15 +1183,110 @@
</span><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static switch_status_t cmd_device(char **argv, int argc, switch_stream_handle_t *stream)
+{
+        listener_t *listener;
+        if (argc != 1) {
+                stream-&gt;write_function(stream, &quot;Invalid Args!\n&quot;);
+                return SWITCH_STATUS_SUCCESS;
+        }
+        
+        if (argv[0] &amp;&amp; !strcasecmp(argv[0], &quot;*&quot;)) {
+                walk_listeners(dump_listener, stream);
+        } else {
+                listener=find_listener(argv[0]);
+                if(listener) {
+                        dump_listener(listener, stream);
+                }
+        }
+        
+        return SWITCH_STATUS_SUCCESS;
+}
+
+SWITCH_STANDARD_API(skinny_function)
+{
+        char *argv[1024] = { 0 };
+        int argc = 0;
+        char *mycmd = NULL;
+        switch_status_t status = SWITCH_STATUS_SUCCESS;
+        skinny_command_t func = NULL;
+        const char *usage_string = &quot;USAGE:\n&quot;
+                &quot;--------------------------------------------------------------------------------\n&quot;
+                &quot;skinny help\n&quot;
+                &quot;skinny device *\n&quot;
+                &quot;skinny device &lt;device_name&gt;\n&quot;
+                &quot;--------------------------------------------------------------------------------\n&quot;;
+        if (session) {
+                return SWITCH_STATUS_FALSE;
+        }
+
+        if (zstr(cmd)) {
+                stream-&gt;write_function(stream, &quot;%s&quot;, usage_string);
+                goto done;
+        }
+
+        if (!(mycmd = strdup(cmd))) {
+                status = SWITCH_STATUS_MEMERR;
+                goto done;
+        }
+
+        if (!(argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) || !argv[0]) {
+                stream-&gt;write_function(stream, &quot;%s&quot;, usage_string);
+                goto done;
+        }
+
+        if (!strcasecmp(argv[0], &quot;device&quot;)) {
+                func = cmd_device;
+        } else if (!strcasecmp(argv[0], &quot;help&quot;)) {
+                stream-&gt;write_function(stream, &quot;%s&quot;, usage_string);
+                goto done;
+        }
+        
+        if (func) {
+                status = func(&amp;argv[1], argc - 1, stream);
+        } else {
+                stream-&gt;write_function(stream, &quot;Unknown Command [%s]\n&quot;, argv[0]);
+        }
+
+  done:
+        switch_safe_free(mycmd);
+        return status;
+}
+
</ins><span class="cx"> static void event_handler(switch_event_t *event)
</span><span class="cx"> {
</span><span class="cx">         if (event-&gt;event_id == SWITCH_EVENT_HEARTBEAT) {
</span><del>-                walk_listeners(kill_expired_listener);
</del><ins>+                walk_listeners(kill_expired_listener, NULL);
</ins><span class="cx">         }
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+static switch_status_t skinny_list_devices(const char *line, const char *cursor, switch_console_callback_match_t **matches)
+{
+        switch_console_callback_match_t *my_matches = NULL;
+        switch_status_t status = SWITCH_STATUS_FALSE;
+        listener_t *l;
+        skinny_device_t *device;
+
+        switch_mutex_lock(globals.listener_mutex);
+        for (l = listen_list.listeners; l; l = l-&gt;next) {
+                if(l-&gt;device) {
+                        device = l-&gt;device;
+                        switch_console_push_match(&amp;my_matches, device-&gt;deviceName);
+                }
+        }
+        switch_mutex_unlock(globals.listener_mutex);
+
+        if (my_matches) {
+                *matches = my_matches;
+                status = SWITCH_STATUS_SUCCESS;
+        }
+        
+        return status;
+}
+
</ins><span class="cx"> SWITCH_MODULE_LOAD_FUNCTION(mod_skinny_load)
</span><span class="cx"> {
</span><ins>+        switch_api_interface_t *api_interface;
</ins><span class="cx"> 
</span><span class="cx">         module_pool = pool;
</span><span class="cx"> 
</span><span class="lines">@@ -1174,6 +1312,12 @@
</span><span class="cx">         skinny_endpoint_interface-&gt;state_handler = &amp;skinny_state_handlers;
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+        SWITCH_ADD_API(api_interface, &quot;skinny&quot;, &quot;Skinny Controls&quot;, skinny_function, &quot;&lt;cmd&gt; &lt;args&gt;&quot;);
+        switch_console_set_complete(&quot;add skinny help&quot;);
+        switch_console_set_complete(&quot;add skinny device *&quot;);
+        switch_console_set_complete(&quot;add skinny device ::skinny::list_devices&quot;);
+
+        switch_console_add_complete_func(&quot;::skinny::list_devices&quot;, skinny_list_devices);
</ins><span class="cx">         /* indicate that the module should continue to be loaded */
</span><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span><span class="cx"> }
</span><span class="lines">@@ -1191,13 +1335,13 @@
</span><span class="cx"> 
</span><span class="cx">         running = 0;
</span><span class="cx"> 
</span><del>-        walk_listeners(kill_listener);
</del><ins>+        walk_listeners(kill_listener, NULL);
</ins><span class="cx"> 
</span><span class="cx">         close_socket(&amp;listen_list.sock);
</span><span class="cx"> 
</span><span class="cx">         while (globals.listener_threads) {
</span><span class="cx">                 switch_yield(100000);
</span><del>-                walk_listeners(kill_listener);
</del><ins>+                walk_listeners(kill_listener, NULL);
</ins><span class="cx">                 if (++sanity &gt;= 200) {
</span><span class="cx">                         break;
</span><span class="cx">                 }
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>