[Freeswitch-svn] [commit] r11133 - in freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax: . configs
FreeSWITCH SVN
gmaruzz at freeswitch.org
Mon Jan 12 01:59:36 PST 2009
Author: gmaruzz
Date: Mon Jan 12 03:59:35 2009
New Revision: 11133
Log:
skypiax: X11_errors_trap() X11_errors_untrap()
Modified:
freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/configs/skypiax_auth.c
freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax_protocol.c
Modified: freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/configs/skypiax_auth.c
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/configs/skypiax_auth.c (original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/configs/skypiax_auth.c Mon Jan 12 03:59:35 2009
@@ -13,6 +13,32 @@
int fdesc[2];
};
+XErrorHandler old_handler = 0;
+int xerror = 0;
+ char *dispname;
+
+int X11_errors_handler(Display * dpy, XErrorEvent * err)
+{
+ (void) dpy;
+
+ xerror = err->error_code;
+ printf("\n\nReceived error code %d from X Server on display '%s'\n\n", xerror, dispname);
+ return 0; /* ignore the error */
+}
+
+static void X11_errors_trap(void)
+{
+ xerror = 0;
+ old_handler = XSetErrorHandler(X11_errors_handler);
+}
+
+static int X11_errors_untrap(void)
+{
+ XSetErrorHandler(old_handler);
+ return (xerror != BadValue) && (xerror != BadWindow);
+}
+
+
int skypiax_skype_send_message(struct SkypiaxHandles *SkypiaxHandles,
const char *message_P)
{
@@ -20,6 +46,7 @@
Window w_P;
Display *disp;
Window handle_P;
+ int ok;
w_P = SkypiaxHandles->skype_win;
disp = SkypiaxHandles->disp;
@@ -31,6 +58,7 @@
unsigned int len = strlen(message_P);
XEvent e;
+
memset(&e, 0, sizeof(e));
e.xclient.type = ClientMessage;
e.xclient.message_type = atom1; /* leading message */
@@ -38,6 +66,7 @@
e.xclient.window = handle_P;
e.xclient.format = 8;
+ X11_errors_trap();
do {
unsigned int i;
for (i = 0; i < 20 && i + pos <= len; ++i)
@@ -49,6 +78,11 @@
} while (pos <= len);
XSync(disp, False);
+ ok = X11_errors_untrap();
+
+ if (!ok)
+ printf("Sending message failed with status %d\n", xerror);
+
return 1;
}
@@ -64,20 +98,22 @@
unsigned char *prop;
int status;
+ X11_errors_trap();
status =
XGetWindowProperty(SkypiaxHandles->disp, DefaultRootWindow(SkypiaxHandles->disp),
skype_inst, 0, 1, False, XA_WINDOW, &type_ret, &format_ret,
&nitems_ret, &bytes_after_ret, &prop);
+ X11_errors_untrap();
/* sanity check */
if (status != Success || format_ret != 32 || nitems_ret != 1) {
SkypiaxHandles->skype_win = (Window) - 1;
- printf("Skype instance not found\n");
+ printf("Skype instance not found on display '%s'\n", dispname);
return 0;
}
SkypiaxHandles->skype_win = *(const unsigned long *) prop & 0xffffffff;
- printf("Skype instance found with id #%d\n",
+ printf("Skype instance found on display '%s', with id #%d\n", dispname,
(unsigned int) SkypiaxHandles->skype_win);
return 1;
}
@@ -106,7 +142,6 @@
Display *disp = NULL;
Window root = -1;
Window win = -1;
- char *dispname;
if(argc==2)
dispname=argv[1];
@@ -137,13 +172,13 @@
snprintf(buf, 512, "NAME skypiax");
if (!skypiax_skype_send_message(&SkypiaxHandles, buf)) {
- printf ("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch Skypiax again\n");
+ printf ("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch skypiax_auth again\n");
return -1;
}
snprintf(buf, 512, "PROTOCOL 6");
if (!skypiax_skype_send_message(&SkypiaxHandles, buf)) {
- printf ("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch Skypiax again\n");
+ printf ("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch skypiax_auth again\n");
return -1;
}
@@ -186,8 +221,7 @@
}
}
} else {
-
- printf ("Sending message failed - probably Skype crashed. Please run/restart Skype manually and launch Skypiax again\n");
+ printf ("Skype client not found on display '%s'. Please run/restart Skype manually and launch skypiax_auth again\n\n\n", dispname);
return -1;
}
return 0;
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 Mon Jan 12 03:59:35 2009
@@ -5,6 +5,13 @@
extern switch_endpoint_interface_t *skypiax_endpoint_interface;
extern int running;
+/*************************************/
+#ifndef WIN32
+XErrorHandler old_handler = 0;
+int xerror = 0;
+#endif /* WIN32 */
+/*************************************/
+
static void *SWITCH_THREAD_FUNC skypiax_do_tcp_srv_thread(switch_thread_t * thread,
void *obj)
{
@@ -778,6 +785,31 @@
}
#else /* NOT WIN32 */
+
+int X11_errors_handler(Display * dpy, XErrorEvent * err)
+{
+ (void) dpy;
+ private_t *tech_pvt = NULL;
+
+ xerror = err->error_code;
+ ERRORA("Received error code %d from X Server\n\n", SKYPIAX_P_LOG, xerror);
+ return 0; /* ignore the error */
+}
+
+static void X11_errors_trap(void)
+{
+ xerror = 0;
+ old_handler = XSetErrorHandler(X11_errors_handler);
+}
+
+static int X11_errors_untrap(void)
+{
+ XSetErrorHandler(old_handler);
+ return (xerror != BadValue) && (xerror != BadWindow);
+}
+
+
+
int skypiax_skype_send_message(struct SkypiaxHandles *SkypiaxHandles,
const char *message_P)
{
@@ -785,6 +817,8 @@
Window w_P;
Display *disp;
Window handle_P;
+ int ok;
+ private_t *tech_pvt = NULL;
w_P = SkypiaxHandles->skype_win;
disp = SkypiaxHandles->disp;
@@ -803,6 +837,7 @@
e.xclient.window = handle_P;
e.xclient.format = 8;
+ X11_errors_trap();
//XLockDisplay(disp);
do {
unsigned int i;
@@ -815,6 +850,10 @@
} while (pos <= len);
XSync(disp, False);
+ ok = X11_errors_untrap();
+
+ if (!ok)
+ ERRORA("Sending message failed with status %d\n", SKYPIAX_P_LOG, xerror);
//XUnlockDisplay(disp);
return 1;
@@ -832,12 +871,14 @@
int status;
private_t *tech_pvt = NULL;
+ X11_errors_trap();
//XLockDisplay(disp);
status =
XGetWindowProperty(SkypiaxHandles->disp, DefaultRootWindow(SkypiaxHandles->disp),
skype_inst, 0, 1, False, XA_WINDOW, &type_ret, &format_ret,
&nitems_ret, &bytes_after_ret, &prop);
//XUnlockDisplay(disp);
+ X11_errors_untrap();
/* sanity check */
if (status != Success || format_ret != 32 || nitems_ret != 1) {
More information about the Freeswitch-svn
mailing list