nim-ffi/ffi/ffi_types.nim

40 lines
1.2 KiB
Nim
Raw Normal View History

2025-12-09 18:51:50 +01:00
import std/tables
2025-09-02 23:47:08 +02:00
import chronos
2025-08-09 22:56:44 +02:00
################################################################################
### Exported types
type FFICallBack* = proc(
callerRet: cint, msg: ptr cchar, len: csize_t, userData: pointer
) {.cdecl, gcsafe, raises: [].}
const RET_OK*: cint = 0
const RET_ERR*: cint = 1
const RET_MISSING_CALLBACK*: cint = 2
### End of exported types
################################################################################
################################################################################
### FFI utils
2025-09-02 23:47:08 +02:00
type FFIRequestProc* =
proc(request: pointer, reqHandler: pointer): Future[Result[string, string]] {.async.}
2025-08-09 22:56:44 +02:00
template foreignThreadGc*(body: untyped) =
when declared(setupForeignThreadGc):
setupForeignThreadGc()
body
when declared(tearDownForeignThreadGc):
tearDownForeignThreadGc()
## Registered requests table populated at compile time and never updated at run time.
## The key represents the request type name as cstring, e.g., "CreateNodeRequest".
## The value is a proc that handles the request asynchronously.
var registeredRequests*: Table[cstring, FFIRequestProc]
2025-12-09 18:51:50 +01:00
2025-08-09 22:56:44 +02:00
### End of FFI utils
################################################################################