[Freeswitch-branches] [commit] r10750 - freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax

FreeSWITCH SVN gmaruzz at freeswitch.org
Sat Dec 13 00:31:51 PST 2008


Author: gmaruzz
Date: Sat Dec 13 03:31:50 2008
New Revision: 10750

Log:
skypiax: cleaning, restructuring

Modified:
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax.h
   freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/mod_skypiax.c	Sat Dec 13 03:31:50 2008
@@ -20,6 +20,7 @@
   int fd;
   int calls;
   char hold_music[256];
+  skypiax_interface_t SKYPIAX_INTERFACES[SKYPIAX_MAX_INTERFACES];
   switch_mutex_t *mutex;
 } globals;
 
@@ -30,14 +31,11 @@
 switch_endpoint_interface_t *skypiax_endpoint_interface;
 switch_memory_pool_t *skypiax_module_pool = NULL;
 int running = 1;
-skypiax_interface_t SKYPIAX_INTERFACES[SKYPIAX_MAX_INTERFACES];
 switch_core_session_t *global_session = NULL;
 #ifdef WIN32
 HANDLE win32_hGlobal_ThreadShutdownEvent;
 HWND win32_hInit_MainWindowHandle;
 #endif /* WIN32 */
-switch_thread_t *skypiax_do_controldev_thread_thread;
-switch_thread_t *do_skype_thread_thread;
 /*************************************************/
 /*************************************************/
 /*************************************************/
@@ -509,7 +507,7 @@
     switch_core_session_add_stream(*new_session, NULL);
     if ((tech_pvt =
          (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) != 0) {
-      tech_pvt->p = &SKYPIAX_INTERFACES[2]; //FIXME
+      tech_pvt->p = &globals.SKYPIAX_INTERFACES[2]; //FIXME
       channel = switch_core_session_get_channel(*new_session);
       skypiax_tech_init(tech_pvt, *new_session, NULL);
     } else {
@@ -754,44 +752,54 @@
       if (name) {
         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "name=%s\n", name);
       }
+
+#ifndef WIN32
+  if (!XInitThreads()) {
+    ERRORA("Not initialized XInitThreads!\n", SKYPIAX_P_LOG);
+  } else {
+    DEBUGA_SKYPE("Initialized XInitThreads!\n", SKYPIAX_P_LOG);
+  }
+  switch_sleep(100);
+#endif /* WIN32 */
+
       if (interface_id && interface_id < SKYPIAX_MAX_INTERFACES) {
         struct skypiax_interface newconf;
         switch_threadattr_t *do_skype_thd_attr = NULL;
         switch_threadattr_t *skypiax_do_controldev_thread_thd_attr = NULL;
 
         memset(&newconf, '\0', sizeof(newconf));
-        SKYPIAX_INTERFACES[interface_id] = newconf;
+        globals.SKYPIAX_INTERFACES[interface_id] = newconf;
         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
                           "CONFIGURING interface_id=%d\n", interface_id);
-        switch_set_string(SKYPIAX_INTERFACES[interface_id].interface_id, id);
+        switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].interface_id, id);
         if (name) {
-          switch_set_string(SKYPIAX_INTERFACES[interface_id].name, name);
+          switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].name, name);
         } else {
-          switch_set_string(SKYPIAX_INTERFACES[interface_id].name, "N/A");
+          switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].name, "N/A");
         }
-        switch_set_string(SKYPIAX_INTERFACES[interface_id].X11_display, X11_display);
-        switch_set_string(SKYPIAX_INTERFACES[interface_id].context, context);
-        switch_set_string(SKYPIAX_INTERFACES[interface_id].dialplan, dialplan);
+        switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].X11_display, X11_display);
+        switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].context, context);
+        switch_set_string(globals.SKYPIAX_INTERFACES[interface_id].dialplan, dialplan);
         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
-                          "interface_id=%d SKYPIAX_INTERFACES[interface_id].X11_display=%s\n",
-                          interface_id, SKYPIAX_INTERFACES[interface_id].X11_display);
+                          "interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].X11_display=%s\n",
+                          interface_id, globals.SKYPIAX_INTERFACES[interface_id].X11_display);
         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
-                          "interface_id=%d SKYPIAX_INTERFACES[interface_id].name=%s\n",
-                          interface_id, SKYPIAX_INTERFACES[interface_id].name);
+                          "interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].name=%s\n",
+                          interface_id, globals.SKYPIAX_INTERFACES[interface_id].name);
         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
-                          "interface_id=%d SKYPIAX_INTERFACES[interface_id].context=%s\n",
-                          interface_id, SKYPIAX_INTERFACES[interface_id].context);
+                          "interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].context=%s\n",
+                          interface_id, globals.SKYPIAX_INTERFACES[interface_id].context);
         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
-                          "interface_id=%d SKYPIAX_INTERFACES[interface_id].dialplan=%s\n",
-                          interface_id, SKYPIAX_INTERFACES[interface_id].dialplan);
+                          "interface_id=%d globals.SKYPIAX_INTERFACES[interface_id].dialplan=%s\n",
+                          interface_id, globals.SKYPIAX_INTERFACES[interface_id].dialplan);
         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO,
                           "STARTING interface_id=%d\n", interface_id);
 
         switch_threadattr_create(&do_skype_thd_attr, skypiax_module_pool);
         //switch_threadattr_detach_set(do_skype_thd_attr, 1);
         switch_threadattr_stacksize_set(do_skype_thd_attr, SWITCH_THREAD_STACKSIZE);
-        switch_thread_create(&do_skype_thread_thread, do_skype_thd_attr, do_skype_thread,
-                             &SKYPIAX_INTERFACES[interface_id], skypiax_module_pool);
+        switch_thread_create(&globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_skype_thread_thread, do_skype_thd_attr, do_skype_thread,
+                             &globals.SKYPIAX_INTERFACES[interface_id], skypiax_module_pool);
 
         switch_sleep(100000);
 
@@ -800,14 +808,14 @@
         //switch_threadattr_detach_set(skypiax_do_controldev_thread_thd_attr, 1);
         switch_threadattr_stacksize_set(skypiax_do_controldev_thread_thd_attr,
                                         SWITCH_THREAD_STACKSIZE);
-        switch_thread_create(&skypiax_do_controldev_thread_thread,
+        switch_thread_create(&globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_controldev_thread_thread,
                              skypiax_do_controldev_thread_thd_attr,
                              skypiax_do_controldev_thread,
-                             &SKYPIAX_INTERFACES[interface_id], skypiax_module_pool);
+                             &globals.SKYPIAX_INTERFACES[interface_id], skypiax_module_pool);
 
         switch_sleep(1000000);
 
-        skypiax_skypeaudio_init(&SKYPIAX_INTERFACES[interface_id]);
+        skypiax_skypeaudio_init(&globals.SKYPIAX_INTERFACES[interface_id]);
 
         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
                           "STARTED interface_id=%d\n", interface_id);
@@ -822,22 +830,22 @@
     }
 
     for (i = 0; i < SKYPIAX_MAX_INTERFACES; i++) {
-      if (strlen(SKYPIAX_INTERFACES[i].name)) {
+      if (strlen(globals.SKYPIAX_INTERFACES[i].name)) {
         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
-                          "i=%d SKYPIAX_INTERFACES[%d].interface_id=%s\n", i, i,
-                          SKYPIAX_INTERFACES[i].interface_id);
+                          "i=%d globals.SKYPIAX_INTERFACES[%d].interface_id=%s\n", i, i,
+                          globals.SKYPIAX_INTERFACES[i].interface_id);
         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
-                          "i=%d SKYPIAX_INTERFACES[%d].X11_display=%s\n", i, i,
-                          SKYPIAX_INTERFACES[i].X11_display);
+                          "i=%d globals.SKYPIAX_INTERFACES[%d].X11_display=%s\n", i, i,
+                          globals.SKYPIAX_INTERFACES[i].X11_display);
         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
-                          "i=%d SKYPIAX_INTERFACES[%d].name=%s\n", i, i,
-                          SKYPIAX_INTERFACES[i].name);
+                          "i=%d globals.SKYPIAX_INTERFACES[%d].name=%s\n", i, i,
+                          globals.SKYPIAX_INTERFACES[i].name);
         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
-                          "i=%d SKYPIAX_INTERFACES[%d].context=%s\n", i, i,
-                          SKYPIAX_INTERFACES[i].context);
+                          "i=%d globals.SKYPIAX_INTERFACES[%d].context=%s\n", i, i,
+                          globals.SKYPIAX_INTERFACES[i].context);
         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
-                          "i=%d SKYPIAX_INTERFACES[%d].dialplan=%s\n", i, i,
-                          SKYPIAX_INTERFACES[i].dialplan);
+                          "i=%d globals.SKYPIAX_INTERFACES[%d].dialplan=%s\n", i, i,
+                          globals.SKYPIAX_INTERFACES[i].dialplan);
       }
     }
   }
@@ -849,21 +857,12 @@
 
 SWITCH_MODULE_LOAD_FUNCTION(mod_skypiax_load)
 {
-  struct skypiax_interface *p = NULL;
+  struct skypiax_interface *p = NULL; //for logging
 
   skypiax_module_pool = pool;
 
   memset(&globals, '\0', sizeof(globals));
-  memset(SKYPIAX_INTERFACES, '\0', sizeof(SKYPIAX_INTERFACES));
-
-#ifndef WIN32
-  if (!XInitThreads()) {
-    ERRORA("Not initialized XInitThreads!\n", SKYPIAX_P_LOG);
-  } else {
-    DEBUGA_SKYPE("Initialized XInitThreads!\n", SKYPIAX_P_LOG);
-  }
-  switch_sleep(100);
-#endif /* _WINDOWS_ */
+  //memset(globals.SKYPIAX_INTERFACES, '\0', sizeof(globals.SKYPIAX_INTERFACES));
 
   load_config();
 
@@ -892,13 +891,20 @@
   struct skypiax_interface *p = NULL;
   switch_status_t status;
   unsigned int howmany = 8;
+int interface_id;
 
-  p = &SKYPIAX_INTERFACES[2];
+  //p = &globals.SKYPIAX_INTERFACES[2];
 
   running = 0;
 
+for(interface_id=0; interface_id < SKYPIAX_MAX_INTERFACES; interface_id++){
+  p = &globals.SKYPIAX_INTERFACES[interface_id];
+
+if(globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_controldev_thread_thread){
   switch_file_write(p->AsteriskHandlesAst.fdesc[1], "sciutati", &howmany);  // let's the controldev_thread die
+  }
 
+if(globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_skype_thread_thread){
 #ifdef WIN32
   if (SendMessage(win32_hInit_MainWindowHandle, WM_DESTROY, 0, 0) == FALSE) {   // let's the do_skype_thread die
     ERRORA("WHY FALSE HERE? %d\n", SKYPIAX_P_LOG, GetLastError());
@@ -917,12 +923,18 @@
   XSendEvent(p->AsteriskHandlesAst.disp, p->AsteriskHandlesAst.win, False, 0, &e);
   XSync(p->AsteriskHandlesAst.disp, False);
 #endif
+  }
   while (x) {
     x--;
     switch_yield(20000);
   }
-  switch_thread_join(&status, skypiax_do_controldev_thread_thread);
-  switch_thread_join(&status, do_skype_thread_thread);
+if(globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_controldev_thread_thread){
+  switch_thread_join(&status, globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_controldev_thread_thread);
+  }
+if(globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_skype_thread_thread){
+  switch_thread_join(&status, globals.SKYPIAX_INTERFACES[interface_id].skypiax_do_skype_thread_thread);
+  }
+  }
   return SWITCH_STATUS_SUCCESS;
 }
 

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax.h	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax.h	Sat Dec 13 03:31:50 2008
@@ -173,6 +173,8 @@
   switch_file_t *audioskypepipe[2];
   switch_thread_t *tcp_srv_thread;
   switch_thread_t *tcp_cli_thread;
+  switch_thread_t *skypiax_do_controldev_thread_thread;
+  switch_thread_t *skypiax_do_skype_thread_thread;
   short audiobuf[160];
   int audiobuf_is_loaded;
 

Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c	Sat Dec 13 03:31:50 2008
@@ -5,7 +5,6 @@
 extern switch_core_session_t *global_session;
 extern switch_endpoint_interface_t *skypiax_endpoint_interface;
 extern int running;
-extern skypiax_interface_t SKYPIAX_INTERFACES;
 #ifdef WIN32
 extern HWND win32_hInit_MainWindowHandle;
 #endif /* WIN32 */
@@ -575,7 +574,7 @@
   /*  destroy window class */
 
   struct skypiax_interface *p;
-  DWORD MsgWaitResult;
+  //DWORD MsgWaitResult;
   p = obj;
 
   switch_file_pipe_create_ex(&p->AsteriskHandlesAst.fdesc[0],
@@ -603,7 +602,7 @@
             if (!running)
               break;
             while (GetMessage(&oMessage, 0, 0, 0)) {
-              break;
+              //break;
               TranslateMessage(&oMessage);
               DispatchMessage(&oMessage);
             }



More information about the Freeswitch-branches mailing list