-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflash++flavors.cpp
65 lines (54 loc) · 2.22 KB
/
flash++flavors.cpp
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
// Example of the functionality in <Flash++.h>
#include <pthread.h>
#include <Flash++.h>
static void *tryGetClipboardLocal(void *) {
using namespace AS3::local; // use Worker-local wrapper classes
try {
flash::desktop::Clipboard clip = flash::desktop::Clipboard::generalClipboard;
return (void *)internal::utf8_toString(clip);
} catch(var e) {
return (void *)internal::utf8_toString(e);
}
// unreachable
}
static void *tryGetClipboardUI(void *) {
using namespace AS3::ui; // use auto-delegating wrapper classes
try {
flash::desktop::Clipboard clip = flash::desktop::Clipboard::generalClipboard;
return (void *)internal::utf8_toString(clip);
} catch(var e) {
return (void *)internal::utf8_toString(e);
}
// unreachable
}
static void *tryGetClipboardLocalThunk(void *) {
return avm2_ui_thunk(tryGetClipboardLocal, NULL);
}
static void printAndFreeStatus(const char *context, void *result) {
printf("%s trying to get flash.desktop.Clipboard.generalClipboard: %s\n", context, (char *)result);
free(result);
}
int main() {
// try to get Clipboard in our thread -- should fail!
printAndFreeStatus("main (local)", tryGetClipboardLocal(NULL));
// try to get Clipboard in our thread using "AS3::ui" -- should succeed!
printAndFreeStatus("main (ui)", tryGetClipboardUI(NULL));
// try to get Clipboard in the ui Worker -- should succeed!
printAndFreeStatus("main via avm2_ui_thunk (local)", tryGetClipboardLocalThunk(NULL));
void *threadResult;
pthread_t thread;
// try to get Clipboard in a new pthread -- should fail!
pthread_create(&thread, NULL, tryGetClipboardLocal, NULL);
pthread_join(thread, &threadResult);
printAndFreeStatus("pthread (local)", threadResult);
// try to get Clipboard in a new pthread using "AS3::ui" -- should succeed!
pthread_create(&thread, NULL, tryGetClipboardUI, NULL);
pthread_join(thread, &threadResult);
printAndFreeStatus("pthread (ui)", threadResult);
// try to get Clipboard in a new pthread using "AS3::local" via avm2_ui_thunk -- should succeed!
pthread_create(&thread, NULL, tryGetClipboardLocalThunk, NULL);
pthread_join(thread, &threadResult);
printAndFreeStatus("pthread via avm2_ui_thunk (local)", threadResult);
puts("done!");
return 0;
}