From 108d4e1b47b9946a646f9721d6fb3aa8a3cac45e Mon Sep 17 00:00:00 2001 From: Arnaud Date: Fri, 12 Sep 2025 12:22:16 +0200 Subject: [PATCH] Add codex revision --- examples/golang/codex.go | 25 +++++++++++++++++++++++++ library/libcodex.h | 5 +++++ library/libcodex.nim | 14 ++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/examples/golang/codex.go b/examples/golang/codex.go index d39ef798..f997a2d8 100644 --- a/examples/golang/codex.go +++ b/examples/golang/codex.go @@ -84,6 +84,10 @@ package main CODEX_CALL(codex_version(codexCtx, (CodexCallback) callback, resp)); } + static void cGoCodexRevision(void* codexCtx, void* resp) { + CODEX_CALL(codex_revision(codexCtx, (CodexCallback) callback, resp)); + } + static void cGoCodexStart(void* codexCtx, void* resp) { CODEX_CALL(codex_start(codexCtx, (CodexCallback) callback, resp)); } @@ -216,6 +220,19 @@ func (self *CodexNode) CodexVersion() (string, error) { return "", errors.New(errMsg) } +func (self *CodexNode) CodexRevision() (string, error) { + var resp = C.allocResp() + defer C.freeResp(resp) + C.cGoCodexRevision(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) @@ -293,6 +310,14 @@ func main() { log.Println("Codex version:", version) + revision, err := node.CodexRevision() + if err != nil { + fmt.Println("Error happened:", err.Error()) + return + } + + log.Println("Codex revision:", revision) + log.Println("Starting Codex...") err = node.CodexStart() diff --git a/library/libcodex.h b/library/libcodex.h index fcc2e95a..b443ef37 100644 --- a/library/libcodex.h +++ b/library/libcodex.h @@ -35,6 +35,11 @@ int codex_version( CodexCallback callback, void* userData); +int codex_revision( + void* ctx, + CodexCallback callback, + void* userData); + int codex_start(void* ctx, CodexCallback callback, void* userData); diff --git a/library/libcodex.nim b/library/libcodex.nim index 254bef9f..46db932a 100644 --- a/library/libcodex.nim +++ b/library/libcodex.nim @@ -114,6 +114,20 @@ proc codex_version( return RET_OK +proc codex_revision( + ctx: ptr CodexContext, callback: CodexCallback, userData: pointer +): cint {.dynlib, exportc.} = + initializeLibrary() + checkLibcodexParams(ctx, callback, userData) + callback( + RET_OK, + cast[ptr cchar]($conf.codexRevision), + cast[csize_t](len($conf.codexRevision)), + userData, + ) + + return RET_OK + proc codex_destroy( ctx: ptr CodexContext, callback: CodexCallback, userData: pointer ): cint {.dynlib, exportc.} =