2019-02-19 22:31:25 +08:00
|
|
|
package hook
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
// #include "event/hook_async.h"
|
|
|
|
*/
|
|
|
|
import "C"
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"time"
|
2019-02-19 22:47:03 +08:00
|
|
|
|
|
|
|
"encoding/json"
|
2019-02-19 22:31:25 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
//export go_send
|
|
|
|
func go_send(s *C.char) {
|
|
|
|
str := []byte(C.GoString(s))
|
|
|
|
out := Event{}
|
2019-02-19 22:47:03 +08:00
|
|
|
|
2019-02-19 22:31:25 +08:00
|
|
|
err := json.Unmarshal(str, &out)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2019-02-19 22:47:03 +08:00
|
|
|
|
2019-02-19 22:31:25 +08:00
|
|
|
if out.Keychar != CharUndefined {
|
|
|
|
raw2key[out.Rawcode] = string([]rune{out.Keychar})
|
|
|
|
}
|
2019-02-19 22:47:03 +08:00
|
|
|
|
|
|
|
// todo bury this deep into the C lib so that the time is correct
|
|
|
|
out.When = time.Now() // at least it's consistent
|
2019-02-19 22:31:25 +08:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2019-02-19 22:47:03 +08:00
|
|
|
|
|
|
|
// todo: maybe make non-bloking
|
2019-02-19 22:31:25 +08:00
|
|
|
ev <- out
|
|
|
|
}
|