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

Freeswitch SVN gmaruzz at freeswitch.org
Fri Nov 7 11:41:06 PST 2008


Author: gmaruzz
Date: Thu Nov  6 10:14:17 2008
New Revision: 10270

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

Log:
skypiax: added a little X11 init

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	Thu Nov  6 10:14:17 2008
@@ -2205,6 +2205,9 @@
 
 #define MOD_SKYPIAX
 #ifdef MOD_SKYPIAX
+#include <X11/Xlib.h>
+#include <X11/Xlibint.h>
+#include <X11/Xatom.h>
 #include <switch.h>
 
 #define SKYPIAX_MAX_INTERFACES 64
@@ -2672,6 +2675,157 @@
 	/*.receive_message */ channel_receive_message,
 	/*.receive_event */ channel_receive_event
 };
+#define SKYPE_THREAD
+#ifdef SKYPE_THREAD
+void *do_skype_thread(void *data)
+{
+
+//  struct skypiax_pvt *p;
+ // struct AsteriskHandles *AsteriskHandlesAst;
+  //FIXME char buf[SKYPE_X11_BUF_SIZE];
+  Display *disp = NULL;
+  //FIXME Window root = -1;
+  //FIXME Window win = -1;
+
+  /*
+  p = data;
+
+  if (option_debug > 10) {
+    DEBUGA_PBX("ENTERING FUNC\n", SKYPIAX_P_LOG);
+  }
+  if (pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL)) {
+    ERRORA("Unable to set cancel type to deferred\n", SKYPIAX_P_LOG);
+    if (option_debug > 10) {
+      DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+    }
+    return NULL;
+  }
+
+  AsteriskHandlesAst = &p->AsteriskHandlesAst;
+*/
+  disp = XOpenDisplay(getenv("DISPLAY"));
+  if (!disp) {
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot open X Display, exiting skype thread\n");
+    return NULL;
+  } else {
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "X Display opened\n");
+  }
+
+  int xfd;
+  xfd = XConnectionNumber(disp);
+  fcntl(xfd, F_SETFD, FD_CLOEXEC);
+
+#ifdef NOTDEF
+  pthread_cleanup_push(skypiax_skype_clean_disp, &xfd);
+  DEBUGA_SKYPE("PUSH disp %d\n", SKYPIAX_P_LOG, xfd);
+
+  if (skypiax_skype_present(disp)) {
+    root = DefaultRootWindow(disp);
+    win =
+      XCreateSimpleWindow(disp, root, 0, 0, 1, 1, 0,
+                          BlackPixel(disp, DefaultScreen(disp)), BlackPixel(disp,
+                                                                            DefaultScreen
+                                                                            (disp)));
+
+    DEBUGA_SKYPE("skype_win=%d win=%d\n", SKYPIAX_P_LOG, (unsigned int) skype_win,
+                 (unsigned int) win);
+
+    AsteriskHandlesAst->skype_win = skype_win;
+    AsteriskHandlesAst->disp = disp;
+    AsteriskHandlesAst->win = win;
+
+    snprintf(buf, SKYPE_X11_BUF_SIZE, "NAME skypiax");
+
+    if (!skypiax_skype_send_message(AsteriskHandlesAst, buf)) {
+      ERRORA
+        ("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch Skypiax again\n",
+         SKYPIAX_P_LOG);
+      p->skype = 0;
+      p->skype_thread = AST_PTHREADT_NULL;
+      if (option_debug > 10) {
+        DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+      }
+      return NULL;
+    }
+
+    snprintf(buf, SKYPE_X11_BUF_SIZE, "PROTOCOL 6");
+    if (!skypiax_skype_send_message(AsteriskHandlesAst, buf)) {
+      ERRORA
+        ("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch Skypiax again\n",
+         SKYPIAX_P_LOG);
+      p->skype = 0;
+      p->skype_thread = AST_PTHREADT_NULL;
+      if (option_debug > 10) {
+        DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+      }
+      return NULL;
+    }
+
+    /* perform an events loop */
+    XEvent an_event;
+    char buf[21];               /*  can't be longer */
+    char buffer[17000];
+    char *b;
+    int i;
+
+    b = buffer;
+
+    while (1) {
+      pthread_testcancel();
+      XNextEvent(disp, &an_event);
+      switch (an_event.type) {
+      case ClientMessage:
+
+        if (an_event.xclient.format != 8)
+          break;
+
+        for (i = 0; i < 20 && an_event.xclient.data.b[i] != '\0'; ++i)
+          buf[i] = an_event.xclient.data.b[i];
+
+        buf[i] = '\0';
+
+        //NOTICA("ClientMessage buf:|||%s||| buffer:|||%s||| serial=%ld|||\r\n",SKYPIAX_P_LOG,buf, buffer,an_event.xclient.serial);
+        //NOTICA ("SKYPE read: |||%s|||%d\n", SKYPIAX_P_LOG, buf, strlen(buf));
+        //NOTICA ("SKYPE buffer: |||%s|||%d\n", SKYPIAX_P_LOG, buffer, strlen(buffer));
+
+        strcat(buffer, buf);
+
+        if (i < 20) {           /* last fragment */
+          write(AsteriskHandlesAst->fdesc[1], b, strlen(b) + 1);
+          //write(AsteriskHandlesAst->fdesc[1], "\0", 1);
+          DEBUGA_SKYPE("SKYPE pipewrite: |||%s|||len=%d serial=%ld\n", SKYPIAX_P_LOG, b,
+                       strlen(b) + 1, an_event.xclient.serial);
+          //usleep(1000);
+          memset(buffer, '\0', 17000);
+        }
+
+        break;
+      default:
+        break;
+      }
+    }
+  } else {
+    ERRORA
+      ("Skype is not running, maybe crashed. Please run/restart Skype and relaunch Skypiax\n",
+       SKYPIAX_P_LOG);
+    p->skype = 0;
+    p->skype_thread = AST_PTHREADT_NULL;
+    return NULL;
+  }
+  p->skype = 0;
+  p->skype_thread = AST_PTHREADT_NULL;
+  pthread_cleanup_pop(1);
+  if (option_debug > 10) {
+    DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
+  }
+#endif /* NOTDEF */
+  return NULL;
+
+}
+
+
+#endif /* SKYPE_THREAD */
+
 
 static switch_status_t load_config(void)
 {
@@ -2805,7 +2959,6 @@
 
 			if(span_id && span_id < SKYPIAX_MAX_INTERFACES ) {
 				struct skypiax_config newconf;
-				//skypax_config_t newconf;
 				memset(&newconf, '\0', sizeof(newconf));
 				SKYPIAX_CONFIGS[span_id]=newconf;
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "CONFIGURING span_id=%d\n", span_id);
@@ -2840,15 +2993,24 @@
 
 	switch_xml_free(xml);
 
+	do_skype_thread(NULL);
+
 	return SWITCH_STATUS_SUCCESS;
 }
 
-
 SWITCH_MODULE_LOAD_FUNCTION(mod_skypiax_load)
 {
 
 	module_pool = pool;
 
+#ifndef _WINDOWS_ //FIXME
+  if (!XInitThreads())
+    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Not initialized XInitThreads!\n");
+  else
+    switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Initialized XInitThreads!\n");
+#endif /* _WINDOWS_ */
+
+
 	load_config();
 
 	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
@@ -2860,60 +3022,6 @@
 /*****************************************/
 #ifdef CICOPET
 {
-  int i;
-  struct ast_config *cfg;
-  struct skypiax_pvt *tmp;
-  struct skypiax_pvt *p = NULL;
-
-#ifndef __CYGWIN__
-  if (!XInitThreads())
-    ast_log(LOG_ERROR, "Not initialized XInitThreads!\n");
-#endif /* __CYGWIN__ */
-
-  /* load skypiax.conf config file */
-  cfg = ast_config_load(skypiax_config);
-  if (cfg != NULL) {
-    char *ctg = NULL;
-    int is_first_category = 1;
-    while ((ctg = ast_category_browse(cfg, ctg)) != NULL) {
-      /* create one interface for each category in skypiax.conf config file, first one set the defaults */
-      tmp = skypiax_mkif(cfg, ctg, is_first_category);
-      if (tmp) {
-        DEBUGA_PBX
-          ("Created channel Skypiax: skypiax.conf category '[%s]', channel name '%s'"
-           "\n", SKYPIAX_P_LOG, ctg, tmp->name);
-        /* add interface to skypiax_iflist */
-        tmp->next = skypiax_iflist;
-        skypiax_iflist = tmp;
-        /* next one will not be the first ;) */
-        if (is_first_category == 1) {
-          is_first_category = 0;
-          skypiax_console_active = tmp->name;
-        }
-      } else {
-        ERRORA("Unable to create channel Skypiax from skypiax.conf category '[%s]'\n",
-               SKYPIAX_P_LOG, ctg);
-        /* if error, unload config from memory and return */
-        ast_config_destroy(cfg);
-        ast_channel_unregister(&skypiax_tech);
-        if (option_debug > 10) {
-          DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
-        }
-        return -1;
-      }
-      /* do it for each category described in config */
-    }
-
-    /* we finished, unload config from memory */
-    ast_config_destroy(cfg);
-  } else {
-    ERRORA("Unable to load skypiax_config skypiax.conf\n", SKYPIAX_P_LOG);
-    ast_channel_unregister(&skypiax_tech);
-    if (option_debug > 10) {
-      DEBUGA_PBX("EXITING FUNC\n", SKYPIAX_P_LOG);
-    }
-    return -1;
-  }
 #ifndef ASTERISK_VERSION_1_6
   ast_cli_register_multiple(myclis, sizeof(myclis) / sizeof(struct ast_cli_entry));
 #endif /* ASTERISK_VERSION_1_6 */



More information about the Freeswitch-branches mailing list