go-waku/library/c/cgo_utils.go

38 lines
639 B
Go
Raw Normal View History

2023-08-10 13:30:38 +00:00
package main
/*
#include <stdlib.h>
#include <cgo_utils.h>
extern void _waku_execCB(WakuCallBack op, char* a, size_t b);
*/
import "C"
import "unsafe"
func execOkCB(onOkCb C.WakuCallBack, value string) C.int {
if onOkCb == nil {
return retMissingCallback
}
val := C.CString(value)
valLen := C.size_t(len(value))
C._waku_execCB(onOkCb, val, valLen)
2023-08-10 13:30:38 +00:00
C.free(unsafe.Pointer(val))
return retOk
}
func execErrCB(onErrCb C.WakuCallBack, err error) C.int {
if onErrCb == nil {
return retMissingCallback
}
if err != nil {
errMsg := err.Error()
execOkCB(onErrCb, errMsg) // reusing ok cb
return retErr
}
return retOk
}