gohook/extern.go
Cauê Felchar f0ddfd620c Made the library Asyncronous (#2)
* Part 1 of supporting async events

made the dispatch process send events via json through a channel (the c kind), made another function that receives it and sends it trough another channel (the go kind)

todo: remove usage of function-local data trough channel
todo:find error that is causing the c channel to fill up?

* Part 2 of making the lib async

 - New event struct mimiking C structs
 - changed c channel library to eb_chan
 - changed API to something more palatable

* General cleanup

* updated go.mod

oopsie

* Probably final touches

i swear this time

* Changed constants, keychar type and test function

now Keychar is a rune, so it can be used as a regular character.

* WIP adding better support for conversion between Scancodes and Keychars

added table, will add rest of support soon(tm)

* finished conversion table

* Satisfied stringer interface for easier debug and logging, returned old function

what the title says

* Satisfied stringer interface for easier debug and logging, returned old function

what the title says

* forgot to import unsafe
2019-02-19 10:31:25 -04:00

34 lines
559 B
Go

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