diff options
author | Eion Robb <eion@robbmob.com> | 2007-12-01 03:07:39 +0300 |
---|---|---|
committer | Eion Robb <eion@robbmob.com> | 2007-12-01 03:07:39 +0300 |
commit | 50ab351f242df4413213d77f08ecdf869dd4a716 (patch) | |
tree | 336831e855e98fdfad3df3bb2a76a34f10f0f8f4 /skype_messaging_carbon.c | |
parent | e2e704523abca7f9085dce271baeef28acf5e4e5 (diff) |
Added debugging for tracking 'missing' messages
Diffstat (limited to 'skype_messaging_carbon.c')
-rw-r--r-- | skype_messaging_carbon.c | 418 |
1 files changed, 212 insertions, 206 deletions
diff --git a/skype_messaging_carbon.c b/skype_messaging_carbon.c index c1fcfea..ab289b9 100644 --- a/skype_messaging_carbon.c +++ b/skype_messaging_carbon.c @@ -1,206 +1,212 @@ -#include <Carbon/Carbon.h> -//#include <Skype/Skype.h> -#include <glib.h> -#include <CoreFoundation/CoreFoundation.h> - -#include "AutoreleasePoolInit.h" - -//change this to 0 if using an old version of the Skype.framework -#define SENDSKYPERETURNS 0 - -#include "skype_messaging_carbon2.c" - -static gboolean connected_to_skype = FALSE; - -void -SkypeNotificationReceived(CFStringRef input) -{ - char *output = NULL; - void *pool = initAutoreleasePool(); - int strlen = CFStringGetMaximumSizeForEncoding(CFStringGetLength(input), kCFStringEncodingUTF8); - - printf("Message received"); - output = (char *)CFStringGetCStringPtr(input, kCFStringEncodingUTF8); - if (!output) - { - output = NewPtr(strlen+1); - CFStringGetCString(input, output, strlen+1, kCFStringEncodingUTF8); - } - printf(" %s\n", output); - g_thread_create((GThreadFunc)skype_message_received, (void *)output, FALSE, NULL); - - destroyAutoreleasePool(pool); -} - -void -SkypeAttachResponse(unsigned int aAttachResponseCode) -{ - if (aAttachResponseCode) - { - printf("Skype attached successfully :)\n"); - connected_to_skype = TRUE; - } - else - { - printf("Skype couldn't connect :(\n"); - connected_to_skype = FALSE; - } -} - -void -SkypeBecameAvailable(CFPropertyListRef aNotification) -{ - printf("Skype became available\n"); - connected_to_skype = TRUE; -} - -void -SkypeBecameUnavailable(CFPropertyListRef aNotification) -{ - printf("Skype became unavailable\n"); - connected_to_skype = FALSE; - g_thread_create((GThreadFunc)skype_message_received, "CONNSTATUS LOGGEDOUT", FALSE, NULL); -} - -static struct SkypeDelegate skypeDelegate = { - CFSTR("Adium"), /* clientAppName */ - SkypeNotificationReceived, - SkypeAttachResponse, - SkypeBecameAvailable, - SkypeBecameUnavailable -}; - -/*static gboolean -skype_connect_thread(gpointer data) -{ - static gboolean started = FALSE; - if (started) - return FALSE; - started = TRUE; - - void *pool = initAutoreleasePool(); - - printf("Start inner event loop\n"); - while(true) - { - //RunApplicationEventLoop(); - RunCurrentEventLoop(1); - } - printf("End of event loop\n"); - started = FALSE; - - destroyAutoreleasePool(pool); - - //don't loop this thread - return FALSE; -}*/ - -static gpointer static_pool; - -static gboolean -skype_connect() -{ - gboolean is_skype_running = FALSE; - - static_pool = initAutoreleasePool(); - - is_skype_running = IsSkypeRunning(); - - printf("Is Skype running? '%s'\n", (is_skype_running?"Yes":"No")); - if (!is_skype_running) - return FALSE; - - SetSkypeDelegate(&skypeDelegate); - ConnectToSkype(); - - //g_thread_create((GThreadFunc)skype_connect_thread, NULL, FALSE, NULL); - while(connected_to_skype == FALSE) - { - RunCurrentEventLoop(1); - } - printf("Connected to skype\n"); - return TRUE; -} - -static void -skype_disconnect() -{ - //TODO: Use MPTerminateTask to kill the runloop - - connected_to_skype = FALSE; - DisconnectFromSkype(); - RemoveSkypeDelegate(); - RunCurrentEventLoop(1); - - destroyAutoreleasePool(static_pool); -} - -static void -send_message(char* message) -{ - CFStringRef messageString = CFStringCreateWithCString(NULL, message, kCFStringEncodingUTF8); - if (!connected_to_skype) - { - if (message[0] == '#') - { - int message_num; - char error_return[40]; - //And we're expecting a response - sscanf(message, "#%d ", &message_num); - sprintf(error_return, "#%d ERROR", message_num); - g_thread_create((GThreadFunc)skype_message_received, (void *)g_strdup(error_return), FALSE, NULL); - } - CFRelease(messageString); - return; - } - - gpointer pool = initAutoreleasePool(); - printf("Skype send message "); -#if SENDSKYPERETURNS - CFStringRef returnString = NULL; - returnString = SendSkypeCommand(messageString); - if (returnString) - SkypeNotificationReceived(returnString); -#else - SendSkypeCommand(messageString); -#endif - destroyAutoreleasePool(pool); - printf("%s\n", message); - CFRelease(messageString); -} - -static void -hide_skype() -{ - OSStatus status = noErr; - ProcessSerialNumber psn = {kNoProcess, kNoProcess}; - unsigned int procNameLength = 32; - unsigned char procName[procNameLength]; - unsigned int i = 0; - ProcessInfoRec info; - info.processInfoLength = sizeof(ProcessInfoRec); - info.processName = procName; - info.processAppSpec = NULL; - - while(status == noErr) - { - for(i = 0; i < procNameLength; i++) - procName[i] = '\0'; - - status = GetNextProcess(&psn); - if (status == noErr) - if (GetProcessInformation(&psn, &info) == noErr) - //for some reason first character is poisioned - if (strcmp((char *)&procName[1], "Skype") == 0) - { - ShowHideProcess(&psn, FALSE); - return; - } - } -} - -static gboolean -exec_skype() -{ - return g_spawn_command_line_async("/Applications/Skype.app/Contents/MacOS/Skype", NULL); -} +#include <Carbon/Carbon.h>
+//#include <Skype/Skype.h>
+#include <glib.h>
+#include <CoreFoundation/CoreFoundation.h>
+
+#include "AutoreleasePoolInit.h"
+
+//change this to 0 if using an old version of the Skype.framework
+#define SENDSKYPERETURNS 0
+
+#include "skype_messaging_carbon2.c"
+
+static gboolean connected_to_skype = FALSE;
+
+void
+SkypeNotificationReceived(CFStringRef input)
+{
+ char *output = NULL;
+ GError *error = NULL;
+ void *pool = initAutoreleasePool();
+ int strlen = CFStringGetMaximumSizeForEncoding(CFStringGetLength(input), kCFStringEncodingUTF8);
+
+ printf("Message received");
+ output = (char *)CFStringGetCStringPtr(input, kCFStringEncodingUTF8);
+ if (!output)
+ {
+ output = NewPtr(strlen+1);
+ CFStringGetCString(input, output, strlen+1, kCFStringEncodingUTF8);
+ }
+ printf(" %s\n", output);
+ g_thread_create((GThreadFunc)skype_message_received, (void *)output, FALSE, &error);
+ if (error)
+ {
+ printf("Could not create new thread!!! %s\n", error->message);
+ g_error_free(error);
+ }
+
+ destroyAutoreleasePool(pool);
+}
+
+void
+SkypeAttachResponse(unsigned int aAttachResponseCode)
+{
+ if (aAttachResponseCode)
+ {
+ printf("Skype attached successfully :)\n");
+ connected_to_skype = TRUE;
+ }
+ else
+ {
+ printf("Skype couldn't connect :(\n");
+ connected_to_skype = FALSE;
+ }
+}
+
+void
+SkypeBecameAvailable(CFPropertyListRef aNotification)
+{
+ printf("Skype became available\n");
+ connected_to_skype = TRUE;
+}
+
+void
+SkypeBecameUnavailable(CFPropertyListRef aNotification)
+{
+ printf("Skype became unavailable\n");
+ connected_to_skype = FALSE;
+ g_thread_create((GThreadFunc)skype_message_received, "CONNSTATUS LOGGEDOUT", FALSE, NULL);
+}
+
+static struct SkypeDelegate skypeDelegate = {
+ CFSTR("Adium"), /* clientAppName */
+ SkypeNotificationReceived,
+ SkypeAttachResponse,
+ SkypeBecameAvailable,
+ SkypeBecameUnavailable
+};
+
+/*static gboolean
+skype_connect_thread(gpointer data)
+{
+ static gboolean started = FALSE;
+ if (started)
+ return FALSE;
+ started = TRUE;
+
+ void *pool = initAutoreleasePool();
+
+ printf("Start inner event loop\n");
+ while(true)
+ {
+ //RunApplicationEventLoop();
+ RunCurrentEventLoop(1);
+ }
+ printf("End of event loop\n");
+ started = FALSE;
+
+ destroyAutoreleasePool(pool);
+
+ //don't loop this thread
+ return FALSE;
+}*/
+
+static gpointer static_pool;
+
+static gboolean
+skype_connect()
+{
+ gboolean is_skype_running = FALSE;
+
+ static_pool = initAutoreleasePool();
+
+ is_skype_running = IsSkypeRunning();
+
+ printf("Is Skype running? '%s'\n", (is_skype_running?"Yes":"No"));
+ if (!is_skype_running)
+ return FALSE;
+
+ SetSkypeDelegate(&skypeDelegate);
+ ConnectToSkype();
+
+ //g_thread_create((GThreadFunc)skype_connect_thread, NULL, FALSE, NULL);
+ while(connected_to_skype == FALSE)
+ {
+ RunCurrentEventLoop(1);
+ }
+ printf("Connected to skype\n");
+ return TRUE;
+}
+
+static void
+skype_disconnect()
+{
+ //TODO: Use MPTerminateTask to kill the runloop
+
+ connected_to_skype = FALSE;
+ DisconnectFromSkype();
+ RemoveSkypeDelegate();
+ RunCurrentEventLoop(1);
+
+ destroyAutoreleasePool(static_pool);
+}
+
+static void
+send_message(char* message)
+{
+ CFStringRef messageString = CFStringCreateWithCString(NULL, message, kCFStringEncodingUTF8);
+ if (!connected_to_skype)
+ {
+ if (message[0] == '#')
+ {
+ int message_num;
+ char error_return[40];
+ //And we're expecting a response
+ sscanf(message, "#%d ", &message_num);
+ sprintf(error_return, "#%d ERROR", message_num);
+ g_thread_create((GThreadFunc)skype_message_received, (void *)g_strdup(error_return), FALSE, NULL);
+ }
+ CFRelease(messageString);
+ return;
+ }
+
+ gpointer pool = initAutoreleasePool();
+ printf("Skype send message ");
+#if SENDSKYPERETURNS
+ CFStringRef returnString = NULL;
+ returnString = SendSkypeCommand(messageString);
+ if (returnString)
+ SkypeNotificationReceived(returnString);
+#else
+ SendSkypeCommand(messageString);
+#endif
+ destroyAutoreleasePool(pool);
+ printf("%s\n", message);
+ CFRelease(messageString);
+}
+
+static void
+hide_skype()
+{
+ OSStatus status = noErr;
+ ProcessSerialNumber psn = {kNoProcess, kNoProcess};
+ unsigned int procNameLength = 32;
+ unsigned char procName[procNameLength];
+ unsigned int i = 0;
+ ProcessInfoRec info;
+ info.processInfoLength = sizeof(ProcessInfoRec);
+ info.processName = procName;
+ info.processAppSpec = NULL;
+
+ while(status == noErr)
+ {
+ for(i = 0; i < procNameLength; i++)
+ procName[i] = '\0';
+
+ status = GetNextProcess(&psn);
+ if (status == noErr)
+ if (GetProcessInformation(&psn, &info) == noErr)
+ //for some reason first character is poisioned
+ if (strcmp((char *)&procName[1], "Skype") == 0)
+ {
+ ShowHideProcess(&psn, FALSE);
+ return;
+ }
+ }
+}
+
+static gboolean
+exec_skype()
+{
+ return g_spawn_command_line_async("/Applications/Skype.app/Contents/MacOS/Skype", NULL);
+}
|