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

FreeSWITCH SVN gmaruzz at freeswitch.org
Fri Dec 26 04:36:18 PST 2008


Author: gmaruzz
Date: Fri Dec 26 07:36:18 2008
New Revision: 10942

Log:
skypiax: continuing multiline on windows, no more global HANDLEs

Modified:
   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/skypiax.h
==============================================================================
--- freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax.h	(original)
+++ freeswitch/branches/gmaruzz/src/mod/endpoints/mod_skypiax/skypiax.h	Fri Dec 26 07:36:18 2008
@@ -137,6 +137,10 @@
 struct AsteriskHandles {
   HWND win32_hInit_MainWindowHandle;
   HWND win32_hGlobal_SkypeAPIWindowHandle;
+HINSTANCE win32_hInit_ProcessHandle;
+char win32_acInit_WindowClassName[128];
+UINT win32_uiGlobal_MsgID_SkypeControlAPIAttach;
+UINT win32_uiGlobal_MsgID_SkypeControlAPIDiscover;
   switch_file_t *fdesc[2];
 };
 

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	Fri Dec 26 07:36:18 2008
@@ -16,15 +16,14 @@
 
 
 #ifdef WIN32
-HWND win32_hInit_MainWindowHandle;
-struct AsteriskHandles *win32_AsteriskHandlesSkype;
-HINSTANCE win32_hInit_ProcessHandle;
-char win32_acInit_WindowClassName[128];
-UINT win32_uiGlobal_MsgID_SkypeControlAPIAttach;
-UINT win32_uiGlobal_MsgID_SkypeControlAPIDiscover;
-HWND win32_hGlobal_SkypeAPIWindowHandle = NULL;
-DWORD win32_ulGlobal_PromptConsoleMode = 0;
-HANDLE volatile win32_hGlobal_PromptConsoleHandle = NULL;
+//HWND win32_hInit_MainWindowHandle;
+//HINSTANCE win32_hInit_ProcessHandle;
+//char win32_acInit_WindowClassName[128];
+//UINT win32_uiGlobal_MsgID_SkypeControlAPIAttach;
+//UINT win32_uiGlobal_MsgID_SkypeControlAPIDiscover;
+//HWND win32_hGlobal_SkypeAPIWindowHandle = NULL;
+//DWORD win32_ulGlobal_PromptConsoleMode = 0;
+//HANDLE volatile win32_hGlobal_PromptConsoleHandle = NULL;
 #else /* NOT WIN32 */
 #define SKYPE_X11_BUF_SIZE 512
 //Window skype_win = (Window) - 1;
@@ -502,67 +501,14 @@
 
 
 #ifdef WIN32
-#if 1
-/*******************************************************/
-int CALLBACK EnumWindowsProc(HWND hwnd, LPARAM param)
-{	DWORD pID;
-	DWORD TpID;
-	struct skypiax_interface *p = NULL;
-
-	TpID = GetWindowThreadProcessId(hwnd, &pID);
-
-	if (TpID == (DWORD)param)
-	{
-		NOTICA("HWND=%p\n", SKYPIAX_P_LOG, hwnd);
-		win32_hGlobal_SkypeAPIWindowHandle = hwnd;
-		return 0;
-	}else{
-		DEBUGA_SKYPE("HWND=%p\n", SKYPIAX_P_LOG, hwnd);
-		return 1;
-	}
-} 
-
-int LaunchSkype(void)
-{
-	PROCESS_INFORMATION pi;
-	STARTUPINFO si = {0};
-	struct skypiax_interface *p = NULL;
-	int ret=1;
-	int times=0;
+int LaunchSkype(struct skypiax_interface *p)
+{
 	LPTSTR pszMessage;
 	DWORD dwLastError; 
 
 
-	ZeroMemory( &si, sizeof(si) );
-	si.cb = sizeof(si);
-	ZeroMemory( &pi, sizeof(pi) );
-
-
-	//ShellExecute(NULL, "open", "C:\\Program Files\\Skype\\Phone\\Skype.exe", "/secondary /username:skypiax1 /password:ciapalo", ".", SW_SHOWNORMAL);
-	//switch_sleep(1000000);
-	//ShellExecute(NULL, "open", "C:\\Program Files\\Skype\\Phone\\Skype.exe", "/secondary /username:skypiax2 /password:ciapalo", ".", SW_SHOWNORMAL);
-	//switch_sleep(1000000);
-	//ShellExecute(NULL, "open", "C:\\Program Files\\Skype\\Phone\\Skype.exe", "/secondary /username:skypiax3 /password:ciapalo", ".", SW_SHOWNORMAL);
-	//switch_sleep(1000000);
-	//ShellExecute(NULL, "open", "C:\\Program Files\\Skype\\Phone\\Skype.exe", "/secondary /username:skypiax4 /password:ciapalo", ".", SW_SHOWNORMAL);
-	//switch_sleep(1000000);
 	ShellExecute(NULL, "open", "C:\\Program Files\\Skype\\Phone\\Skype.exe", "/secondary /username:skypiax5 /password:ciapalo", ".", SW_SHOWNORMAL);
 
-#if 0
-
-	CreateProcess( "C:\\Program Files\\Skype\\Phone\\Skype.exe",
-			"/secondary /username:skypiax4 /password:xxx", // Command line.
-			NULL, // Process handle not inheritable.
-			NULL, // Thread handle not inheritable.
-			FALSE, // Set handle inheritance to FALSE.
-			NORMAL_PRIORITY_CLASS, // No creation flags.
-			NULL, // Use parent's environment block.
-			NULL, // Use parent's starting directory.
-			&si, // Pointer to STARTUPINFO structure.
-			&pi  // Pointer to PROCESS_INFORMATION structure.
-		     );
-#endif
-
 	dwLastError = GetLastError();
 
 	FormatMessage(
@@ -577,23 +523,9 @@
 
 	NOTICA("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA %s\n", SKYPIAX_P_LOG,pszMessage);
 	LocalFree(pszMessage);
-#if 0
-	switch_sleep(10000000);
-
-	while(ret){
-		ret = EnumWindows(&EnumWindowsProc, pi.dwThreadId);
-		switch_sleep(10000);
-		times++;
-		if (times == 1000)
-			break;
-	}
-	NOTICA("HWND=%p\n", SKYPIAX_P_LOG, win32_hGlobal_SkypeAPIWindowHandle);
-#endif
 	return 1;
 
 }
-/*******************************************************/
-#endif //NOTDEF
 
 
 enum {
@@ -657,11 +589,11 @@
     break;
   case WM_DESTROY:
     NOTICA("got DESTROY\n", SKYPIAX_P_LOG);
-    win32_hInit_MainWindowHandle = NULL;
+    p->AsteriskHandlesAst.win32_hInit_MainWindowHandle = NULL;
     PostQuitMessage(0);
     break;
   case WM_COPYDATA:
-    if (win32_hGlobal_SkypeAPIWindowHandle == (HWND) uiParam) {
+    if (p->AsteriskHandlesAst.win32_hGlobal_SkypeAPIWindowHandle == (HWND) uiParam) {
       unsigned int howmany;
       char msg_from_skype[2048];
 
@@ -672,20 +604,21 @@
               sizeof(msg_from_skype) - 2);
 
       howmany = strlen(msg_from_skype) + 1;
-      switch_file_write(win32_AsteriskHandlesSkype->fdesc[1], msg_from_skype, &howmany);
+      switch_file_write(p->AsteriskHandlesAst.fdesc[1], msg_from_skype, &howmany);
       NOTICA("From Skype API: %s\n", SKYPIAX_P_LOG, (const char *) poCopyData->lpData);
       lReturnCode = 1;
     }
     break;
   default:
-    if (uiMessage == win32_uiGlobal_MsgID_SkypeControlAPIAttach) {
+    if(p && p->AsteriskHandlesAst.win32_uiGlobal_MsgID_SkypeControlAPIAttach) {
+    if (uiMessage == p->AsteriskHandlesAst.win32_uiGlobal_MsgID_SkypeControlAPIAttach) {
       switch (ulParam) {
       case SKYPECONTROLAPI_ATTACH_SUCCESS:
         NOTICA("\n\n\tConnected to Skype API!\n", SKYPIAX_P_LOG);
-        win32_hGlobal_SkypeAPIWindowHandle = (HWND) uiParam;
+        p->AsteriskHandlesAst.win32_hGlobal_SkypeAPIWindowHandle = (HWND) uiParam;
         switch_sleep(5000);
-        win32_AsteriskHandlesSkype->win32_hGlobal_SkypeAPIWindowHandle =
-          win32_hGlobal_SkypeAPIWindowHandle;
+        p->AsteriskHandlesAst.win32_hGlobal_SkypeAPIWindowHandle =
+          p->AsteriskHandlesAst.win32_hGlobal_SkypeAPIWindowHandle;
         break;
       case SKYPECONTROLAPI_ATTACH_PENDING_AUTHORIZATION:
         WARNINGA
@@ -702,8 +635,8 @@
         DEBUGA_SKYPE("Skype API available\n", SKYPIAX_P_LOG);
 
         SendMessage
-            (HWND_BROADCAST, win32_uiGlobal_MsgID_SkypeControlAPIDiscover,
-             (WPARAM) win32_hInit_MainWindowHandle, 0);
+            (HWND_BROADCAST, p->AsteriskHandlesAst.win32_uiGlobal_MsgID_SkypeControlAPIDiscover,
+             (WPARAM) p->AsteriskHandlesAst.win32_hInit_MainWindowHandle, 0);
         break;
       default:
         WARNINGA("GOT AN UNKNOWN SKYPE WINDOWS MSG\n", SKYPIAX_P_LOG);
@@ -711,6 +644,7 @@
       lReturnCode = 1;
       break;
     }
+    }
     fIssueDefProc = 1;
     break;
   }
@@ -719,7 +653,7 @@
   return (lReturnCode);
 }
 
-int win32_Initialize_CreateWindowClass(void)
+int win32_Initialize_CreateWindowClass(struct skypiax_interface *p)
 {
   unsigned char *paucUUIDString;
   RPC_STATUS lUUIDResult;
@@ -728,26 +662,26 @@
 
   fReturnStatus = 0;
   lUUIDResult = UuidCreate(&oUUID);
-  win32_hInit_ProcessHandle =
+  p->AsteriskHandlesAst.win32_hInit_ProcessHandle =
     (HINSTANCE) OpenProcess(PROCESS_DUP_HANDLE, FALSE, GetCurrentProcessId());
-  if (win32_hInit_ProcessHandle != NULL
+  if (p->AsteriskHandlesAst.win32_hInit_ProcessHandle != NULL
       && (lUUIDResult == RPC_S_OK || lUUIDResult == RPC_S_UUID_LOCAL_ONLY)) {
     if (UuidToString(&oUUID, &paucUUIDString) == RPC_S_OK) {
       WNDCLASS oWindowClass;
 
-      strcpy(win32_acInit_WindowClassName, "Skype-API-Skypiax-");
-      strcat(win32_acInit_WindowClassName, (char *) paucUUIDString);
+      strcpy(p->AsteriskHandlesAst.win32_acInit_WindowClassName, "Skype-API-Skypiax-");
+      strcat(p->AsteriskHandlesAst.win32_acInit_WindowClassName, (char *) paucUUIDString);
 
       oWindowClass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
       oWindowClass.lpfnWndProc = (WNDPROC) & skypiax_skype_present;
       oWindowClass.cbClsExtra = 0;
       oWindowClass.cbWndExtra = 0;
-      oWindowClass.hInstance = win32_hInit_ProcessHandle;
+      oWindowClass.hInstance = p->AsteriskHandlesAst.win32_hInit_ProcessHandle;
       oWindowClass.hIcon = NULL;
       oWindowClass.hCursor = NULL;
       oWindowClass.hbrBackground = NULL;
       oWindowClass.lpszMenuName = NULL;
-      oWindowClass.lpszClassName = win32_acInit_WindowClassName;
+      oWindowClass.lpszClassName = p->AsteriskHandlesAst.win32_acInit_WindowClassName;
 
       if (RegisterClass(&oWindowClass) != 0)
         fReturnStatus = 1;
@@ -756,29 +690,29 @@
     }
   }
   if (fReturnStatus == 0)
-    CloseHandle(win32_hInit_ProcessHandle), win32_hInit_ProcessHandle = NULL;
+    CloseHandle(p->AsteriskHandlesAst.win32_hInit_ProcessHandle), p->AsteriskHandlesAst.win32_hInit_ProcessHandle = NULL;
   return (fReturnStatus);
 }
 
-void win32_DeInitialize_DestroyWindowClass(void)
+void win32_DeInitialize_DestroyWindowClass(struct skypiax_interface *p)
 {
-  UnregisterClass(win32_acInit_WindowClassName, win32_hInit_ProcessHandle);
-  CloseHandle(win32_hInit_ProcessHandle), win32_hInit_ProcessHandle = NULL;
+  UnregisterClass(p->AsteriskHandlesAst.win32_acInit_WindowClassName, p->AsteriskHandlesAst.win32_hInit_ProcessHandle);
+  CloseHandle(p->AsteriskHandlesAst.win32_hInit_ProcessHandle), p->AsteriskHandlesAst.win32_hInit_ProcessHandle = NULL;
 }
 
 int win32_Initialize_CreateMainWindow(struct skypiax_interface *p)
 {
-  win32_hInit_MainWindowHandle =
-    CreateWindowEx(WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, win32_acInit_WindowClassName, "",
+  p->AsteriskHandlesAst.win32_hInit_MainWindowHandle =
+    CreateWindowEx(WS_EX_APPWINDOW | WS_EX_WINDOWEDGE, p->AsteriskHandlesAst.win32_acInit_WindowClassName, "",
                    WS_BORDER | WS_SYSMENU | WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT,
-                   128, 128, NULL, 0, win32_hInit_ProcessHandle, p);
-  return (win32_hInit_MainWindowHandle != NULL ? 1 : 0);
+                   128, 128, NULL, 0, p->AsteriskHandlesAst.win32_hInit_ProcessHandle, p);
+  return (p->AsteriskHandlesAst.win32_hInit_MainWindowHandle != NULL ? 1 : 0);
 }
 
-void win32_DeInitialize_DestroyMainWindow(void)
+void win32_DeInitialize_DestroyMainWindow(struct skypiax_interface *p)
 {
-  if (win32_hInit_MainWindowHandle != NULL)
-    DestroyWindow(win32_hInit_MainWindowHandle), win32_hInit_MainWindowHandle = NULL;
+  if (p->AsteriskHandlesAst.win32_hInit_MainWindowHandle != NULL)
+    DestroyWindow(p->AsteriskHandlesAst.win32_hInit_MainWindowHandle), p->AsteriskHandlesAst.win32_hInit_MainWindowHandle = NULL;
 }
 
 DWORD win32_dwThreadId;
@@ -803,30 +737,29 @@
   switch_file_pipe_create(&p->AsteriskHandlesAst.fdesc[0], &p->AsteriskHandlesAst.fdesc[1], skypiax_module_pool);
   //switch_file_pipe_timeout_set(p->AsteriskHandlesAst.fdesc[0], 100);
 
-  win32_AsteriskHandlesSkype = &p->AsteriskHandlesAst;
 
-  win32_uiGlobal_MsgID_SkypeControlAPIAttach =
+  p->AsteriskHandlesAst.win32_uiGlobal_MsgID_SkypeControlAPIAttach =
     RegisterWindowMessage("SkypeControlAPIAttach");
-  win32_uiGlobal_MsgID_SkypeControlAPIDiscover =
+  p->AsteriskHandlesAst.win32_uiGlobal_MsgID_SkypeControlAPIDiscover =
     RegisterWindowMessage("SkypeControlAPIDiscover");
 
-  LaunchSkype();
+  LaunchSkype(p);
 	switch_sleep(1000000);
 
-  if (win32_uiGlobal_MsgID_SkypeControlAPIAttach != 0
-      && win32_uiGlobal_MsgID_SkypeControlAPIDiscover != 0) {
-    if (win32_Initialize_CreateWindowClass()) {
+  if (p->AsteriskHandlesAst.win32_uiGlobal_MsgID_SkypeControlAPIAttach != 0
+      && p->AsteriskHandlesAst.win32_uiGlobal_MsgID_SkypeControlAPIDiscover != 0) {
+    if (win32_Initialize_CreateWindowClass(p)) {
       if (win32_Initialize_CreateMainWindow(p)) {
 #if 1
         if (SendMessage
-            (HWND_BROADCAST, win32_uiGlobal_MsgID_SkypeControlAPIDiscover,
-             (WPARAM) win32_hInit_MainWindowHandle, 0) != 0) {
+            (HWND_BROADCAST, p->AsteriskHandlesAst.win32_uiGlobal_MsgID_SkypeControlAPIDiscover,
+             (WPARAM) p->AsteriskHandlesAst.win32_hInit_MainWindowHandle, 0) != 0) {
 #else
 
         if (1) {
 #endif
-          win32_AsteriskHandlesSkype->win32_hInit_MainWindowHandle =
-            win32_hInit_MainWindowHandle;
+          p->AsteriskHandlesAst.win32_hInit_MainWindowHandle =
+            p->AsteriskHandlesAst.win32_hInit_MainWindowHandle;
           while (1) {
             MSG oMessage;
             if (!running)
@@ -838,9 +771,9 @@
             }
           }
         }
-        win32_DeInitialize_DestroyMainWindow();
+        win32_DeInitialize_DestroyMainWindow(p);
       }
-      win32_DeInitialize_DestroyWindowClass();
+      win32_DeInitialize_DestroyWindowClass(p);
     }
   }
 



More information about the Freeswitch-branches mailing list