-
Notifications
You must be signed in to change notification settings - Fork 1
/
signals.go
44 lines (36 loc) · 1.1 KB
/
signals.go
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
package purple
/*
#include <libpurple/purple.h>
static gulong gopurple_signal_connect(char *signal) {
static int handle;
void *data = NULL;
void *instance = purple_connections_get_handle();
return purple_signal_connect(instance, signal, &handle, PURPLE_CALLBACK(NULL), data);
}
static gulong gopurple_signal_connect2(void *instance, char *signal, void *fn) {
static int handle;
void *data = NULL;
return purple_signal_connect(instance, signal, &handle, PURPLE_CALLBACK(fn), data);
}
*/
import "C"
import "unsafe"
import (
"log"
)
// 这个函数具有叠加效果,多次调用,则触发多次事件回调
func signalConnect(instance unsafe.Pointer, signal string, fn unsafe.Pointer) int {
r := C.gopurple_signal_connect2(instance, CCString(signal).Ptr, fn)
if r == 0 {
log.Println("error:", signal, r)
}
return int(r)
}
func SignalConnectConn(signal string, fn unsafe.Pointer) {
h := C.purple_connections_get_handle()
signalConnect(h, signal, fn)
}
func SignalConnectConv(signal string, fn unsafe.Pointer) {
h := C.purple_conversations_get_handle()
signalConnect(h, signal, fn)
}