[Freeswitch-trunk] [commit] r13765 - freeswitch/trunk/scripts/contrib/jmesquita/mod_khomp

FreeSWITCH SVN jmesquita at freeswitch.org
Thu Jun 11 16:03:23 PDT 2009


Author: jmesquita
Date: Thu Jun 11 18:03:23 2009
New Revision: 13765

Log:
Added <khomp show links> api command

Modified:
   freeswitch/trunk/scripts/contrib/jmesquita/mod_khomp/Makefile
   freeswitch/trunk/scripts/contrib/jmesquita/mod_khomp/mod_khomp.cpp

Modified: freeswitch/trunk/scripts/contrib/jmesquita/mod_khomp/Makefile
==============================================================================
--- freeswitch/trunk/scripts/contrib/jmesquita/mod_khomp/Makefile	(original)
+++ freeswitch/trunk/scripts/contrib/jmesquita/mod_khomp/Makefile	Thu Jun 11 18:03:23 2009
@@ -1,5 +1,5 @@
 MODNAME=mod_khomp
-LOCAL_CFLAGS=-I./include -I./commons/include -lk3l -D_REENTRANT -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -DK3L_HOSTSYSTEM -DKHOMP_COMMONS_WITH_CHANNEL -lboost_thread -lboost_regex
+LOCAL_CFLAGS=-I./include -I./commons/include -lk3l -D_REENTRANT -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -DK3L_HOSTSYSTEM -DKHOMP_COMMONS_WITH_CHANNEL
 
 LOCAL_OBJS= ./commons/k3lapi.o
 

Modified: freeswitch/trunk/scripts/contrib/jmesquita/mod_khomp/mod_khomp.cpp
==============================================================================
--- freeswitch/trunk/scripts/contrib/jmesquita/mod_khomp/mod_khomp.cpp	(original)
+++ freeswitch/trunk/scripts/contrib/jmesquita/mod_khomp/mod_khomp.cpp	Thu Jun 11 18:03:23 2009
@@ -30,7 +30,7 @@
  *
  */
 
-#define KHOMP_SYNTAX "khomp [show]"
+#define KHOMP_SYNTAX "khomp show [info|links]"
 
 /* Our includes */
 #include "k3lapi.hpp"
@@ -38,6 +38,7 @@
 extern "C"
 {
     #include <switch.h>
+    #include "k3l.h"
 }
 
 SWITCH_MODULE_LOAD_FUNCTION(mod_khomp_load);
@@ -125,6 +126,7 @@
 
 /* My function prototypes */
 static void printBoardsInfo(switch_stream_handle_t*);
+static const char* linkStatus(unsigned int device, unsigned int link);
 
 
 
@@ -493,7 +495,7 @@
 
 static switch_status_t load_config(void)
 {
-	char *cf = "khomp.conf";
+	const char *cf = "khomp.conf";
 	switch_xml_t cfg, xml, settings, param;
 
 	memset(&globals, 0, sizeof(globals));
@@ -620,10 +622,8 @@
 }
 
 /* 
-   khomp API
-   Only displays board information right now
+   khomp API definition
 */
-
 SWITCH_STANDARD_API(khomp)
 {
    	char *argv[10] = { 0 };
@@ -640,13 +640,34 @@
 		return SWITCH_STATUS_FALSE;
 	}
 
-	if ((argc = switch_separate_string(myarg, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) != 1) {
+	if ((argc = switch_separate_string(myarg, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) < 1) {
 		stream->write_function(stream, "USAGE: %s\n", KHOMP_SYNTAX);
 		goto done;
 	}
 
-	if (argv[0] && !strncasecmp(argv[0], "show", 6)) {
-        printBoardsInfo(stream);
+    /* Below show ... */
+	if (argv[0] && !strncasecmp(argv[0], "show", 4)) {
+        /* Show the API summary and information */
+        if (argv[1] && !strncasecmp(argv[1], "info", 4)) {
+            printBoardsInfo(stream);
+        }
+        /* Show all the links and their status */
+        if (argv[1] && !strncasecmp(argv[1], "links", 5)) {
+            for(int device=0 ; device < k3l->device_count() ; device++)
+            {
+                stream->write_function(stream, "___________________________________________\n");
+                stream->write_function(stream, "|--------------Khomp Links----------------|\n");
+                stream->write_function(stream, "|----Board----|----Link----|----Status----|\n");
+                for(int link=0 ; link < k3l->link_count(device) ; link++)
+                {
+                    stream->write_function(stream, "|%13d|%12d|%s|\n"
+                                            , device
+                                            , link
+                                            , linkStatus(device, link));
+                }
+            }
+            stream->write_function(stream, "-------------------------------------------\n");
+        }
 
 	} else {
 		stream->write_function(stream, "USAGE: %s\n", KHOMP_SYNTAX);
@@ -658,6 +679,64 @@
 
 }
 
+/* Helper functions */
+static const char * linkStatus(unsigned int device, unsigned int link)
+{
+
+    K3L_LINK_CONFIG & config = k3l->link_config(device, link);
+    K3L_LINK_STATUS   status;
+    
+    KLibraryStatus ret = (KLibraryStatus) k3lGetDeviceStatus (device, link + ksoLink, &status, sizeof(status));
+
+    if (ret == ksSuccess)
+    {
+        switch (config.Signaling)
+        {
+            case ksigInactive:
+                return "[ksigInactive]";
+
+            case ksigAnalog:
+                return "[ksigAnalog]";
+
+            case ksigSIP:
+                return "[ksigSIP]";
+
+            case ksigOpenCAS:
+            case ksigOpenR2:
+            case ksigR2Digital:
+            case ksigUserR2Digital:
+            case ksigOpenCCS:
+            case ksigPRI_EndPoint:
+            case ksigPRI_Network:
+            case ksigPRI_Passive:
+            case ksigLineSide:
+            case ksigCAS_EL7:
+            case ksigAnalogTerminal:
+                if (kesOk == status.E1)
+                {
+                    return "kesOk";
+                }
+                else
+                {
+                    if (kesSignalLost & status.E1)         return "SignalLost";
+                    if (kesNetworkAlarm & status.E1)       return "NetworkAlarm";
+                    if (kesFrameSyncLost & status.E1)      return "FrameSyncLost";
+                    if (kesMultiframeSyncLost & status.E1) return "MultiframeSyncLost";
+                    if (kesRemoteAlarm & status.E1)        return "RemoteAlarm";
+                    if (kesHighErrorRate & status.E1)      return "HighErrorRate";
+                    if (kesUnknownAlarm & status.E1)       return "UnknownAlarm";
+                    if (kesE1Error & status.E1)            return "E1Error";
+
+                }
+            default:
+                return "NotImplementedBoard";
+        }
+    }
+
+    return "<unknown>";
+}
+
+
 static void printBoardsInfo(switch_stream_handle_t* stream) {
 
     K3L_API_CONFIG apiCfg;
@@ -759,6 +838,7 @@
 
     stream->write_function(stream, " ------------------------------------------------------------------\n");
 }
+/* End of helper functions */
 
 
 /* For Emacs:



More information about the Freeswitch-trunk mailing list