mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-03 14:03:10 +00:00
Return the Codex version
This commit is contained in:
parent
1e07c25f1d
commit
23ffa5a1fb
@ -80,6 +80,10 @@ package main
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void cGoCodexVersion(void* codexCtx, void* resp) {
|
||||
CODEX_CALL(codex_version(codexCtx, (CodexCallback) callback, resp));
|
||||
}
|
||||
|
||||
static void cGoCodexStart(void* codexCtx, void* resp) {
|
||||
CODEX_CALL(codex_start(codexCtx, (CodexCallback) callback, resp));
|
||||
}
|
||||
@ -199,6 +203,19 @@ func CodexNew(config CodexConfig) (*CodexNode, error) {
|
||||
return nil, errors.New(errMsg)
|
||||
}
|
||||
|
||||
func (self *CodexNode) CodexVersion() (string, error) {
|
||||
var resp = C.allocResp()
|
||||
defer C.freeResp(resp)
|
||||
C.cGoCodexVersion(self.ctx, resp)
|
||||
|
||||
if C.getRet(resp) == C.RET_OK {
|
||||
return C.GoStringN(C.getMyCharPtr(resp), C.int(C.getMyCharLen(resp))), nil
|
||||
}
|
||||
|
||||
errMsg := "error CodexStart: " + C.GoStringN(C.getMyCharPtr(resp), C.int(C.getMyCharLen(resp)))
|
||||
return "", errors.New(errMsg)
|
||||
}
|
||||
|
||||
func (self *CodexNode) CodexStart() error {
|
||||
var resp = C.allocResp()
|
||||
defer C.freeResp(resp)
|
||||
@ -207,6 +224,7 @@ func (self *CodexNode) CodexStart() error {
|
||||
if C.getRet(resp) == C.RET_OK {
|
||||
return nil
|
||||
}
|
||||
|
||||
errMsg := "error CodexStart: " + C.GoStringN(C.getMyCharPtr(resp), C.int(C.getMyCharLen(resp)))
|
||||
return errors.New(errMsg)
|
||||
}
|
||||
@ -257,7 +275,7 @@ func main() {
|
||||
LogLevel: Info,
|
||||
}
|
||||
|
||||
log.Println("Starting Codex...")
|
||||
log.Println("Creating Codex...")
|
||||
|
||||
node, err := CodexNew(config)
|
||||
if err != nil {
|
||||
@ -267,6 +285,16 @@ func main() {
|
||||
|
||||
node.CodexSetEventCallback()
|
||||
|
||||
version, err := node.CodexVersion()
|
||||
if err != nil {
|
||||
fmt.Println("Error happened:", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
log.Println("Codex version:", version)
|
||||
|
||||
log.Println("Starting Codex...")
|
||||
|
||||
err = node.CodexStart()
|
||||
if err != nil {
|
||||
fmt.Println("Error happened:", err.Error())
|
||||
@ -288,6 +316,8 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
log.Println("Destroying the node...")
|
||||
|
||||
err = node.CodexDestroy()
|
||||
if err != nil {
|
||||
fmt.Println("Error happened:", err.Error())
|
||||
|
||||
@ -30,6 +30,11 @@ void* codex_new(
|
||||
CodexCallback callback,
|
||||
void* userData);
|
||||
|
||||
int codex_version(
|
||||
void* ctx,
|
||||
CodexCallback callback,
|
||||
void* userData);
|
||||
|
||||
int codex_start(void* ctx,
|
||||
CodexCallback callback,
|
||||
void* userData);
|
||||
|
||||
@ -32,6 +32,8 @@ import ./codex_thread_requests/codex_thread_request
|
||||
import ./codex_thread_requests/requests/node_lifecycle_request
|
||||
import ./ffi_types
|
||||
|
||||
from ../codex/conf import codexVersion
|
||||
|
||||
template checkLibcodexParams*(
|
||||
ctx: ptr CodexContext, callback: CodexCallback, userData: pointer
|
||||
) =
|
||||
@ -98,8 +100,22 @@ proc codex_new(
|
||||
|
||||
return ctx
|
||||
|
||||
proc codex_version(
|
||||
ctx: ptr CodexContext, callback: CodexCallback, userData: pointer
|
||||
): cint {.dynlib, exportc.} =
|
||||
initializeLibrary()
|
||||
checkLibcodexParams(ctx, callback, userData)
|
||||
callback(
|
||||
RET_OK,
|
||||
cast[ptr cchar]($conf.codexVersion),
|
||||
cast[csize_t](len($conf.codexVersion)),
|
||||
userData,
|
||||
)
|
||||
|
||||
return RET_OK
|
||||
|
||||
proc codex_destroy(
|
||||
ctx: ptr CodexContext, callback: COdexCallback, userData: pointer
|
||||
ctx: ptr CodexContext, callback: CodexCallback, userData: pointer
|
||||
): cint {.dynlib, exportc.} =
|
||||
initializeLibrary()
|
||||
checkLibcodexParams(ctx, callback, userData)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user