1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
#include <Carbon/Carbon.h>
#include <Skype/Skype.h>
#include <glib.h>
#include <CoreFoundation/CoreFoundation.h>
#define SENDSKYPERETURNS 1
static gboolean connected_to_skype = FALSE;
void SkypeNotificationReceived(CFStringRef input)
{
printf("Message received\n");
char *output = CFStringGetCStringPtr(input, kCFStringEncodingUTF8);
if (!output)
{
output = NewPtr(CFStringGetLength(input)+1);
CFStringGetCString(input, output, CFStringGetLength(input)+1, kCFStringEncodingUTF8);
}
g_thread_create((GThreadFunc)skype_message_received, (void *)output, FALSE, NULL);
}
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;
}
static struct SkypeDelegate skypeDelegate = {
CFSTR("Adium"), /* clientAppName */
SkypeNotificationReceived,
SkypeAttachResponse,
SkypeBecameAvailable,
SkypeBecameUnavailable
};
static gboolean skype_connect_thread(gpointer data)
{
printf("Start inner event loop\n");
RunApplicationEventLoop();
printf("End of event loop\n");
return FALSE;
}
static gboolean skype_connect()
{
EventRef theEvent;
EventTargetRef theTarget;
EventRecord *eventRecord;
gboolean is_skype_running = FALSE;
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()
{
DisconnectFromSkype();
RemoveSkypeDelegate();
RunCurrentEventLoop(1);
}
static void send_message(char* message)
{
printf("Skype send message\n");
#if SENDSKYPERETURNS
CFStringRef returnString;
returnString = SendSkypeCommand(CFStringCreateWithCString(NULL, message, kCFStringEncodingUTF8));
if (returnString)
SkypeNotificationReceived(returnString);
#else
SendSkypeCommand(CFStringCreateWithCString(NULL, message, kCFStringEncodingUTF8));
#endif
}
|