start adding events

This commit is contained in:
Gabriel mermelstein 2025-04-16 11:01:48 +03:00
parent c0431d53a6
commit 521ac4a3bf
No known key found for this signature in database
GPG Key ID: 82B8134785FEAE0D
6 changed files with 63 additions and 8 deletions

View File

@ -0,0 +1,6 @@
type JsonEvent* = ref object of RootObj # https://rfc.vac.dev/spec/36/#jsonsignal-type
eventType* {.requiresInit.}: string
method `$`*(jsonEvent: JsonEvent): string {.base.} =
discard
# All events should implement this

View File

@ -0,0 +1,14 @@
import std/json
import ./json_base_event, ../../src/[message]
type JsonMessageReadyEvent* = ref object of JsonEvent
messageId*: MessageID
proc new*(T: type JsonMessageReadyEvent, messageId: MessageID): T =
# Returns a MessageReady event as indicated in
# https://rfc.vac.dev/spec/36/#jsonmessageevent-type
return JsonMessageReadyEvent(eventType: "message_ready", messageId: messageId)
method `$`*(jsonMessageReady: JsonMessageReadyEvent): string =
$(%*jsonMessageReady)

View File

@ -0,0 +1,14 @@
import std/json
import ./json_base_event, ../../src/[message]
type JsonMessageSentEvent* = ref object of JsonEvent
messageId*: MessageID
proc new*(T: type JsonMessageSentEvent, messageId: MessageID): T =
# Returns a MessageSent event as indicated in
# https://rfc.vac.dev/spec/36/#jsonmessageevent-type
return JsonMessageSentEvent(eventType: "message_sent", messageId: messageId)
method `$`*(jsonMessageSent: JsonMessageSentEvent): string =
$(%*jsonMessageSent)

View File

@ -5,9 +5,7 @@
when defined(linux):
{.passl: "-Wl,-soname,libsds.so".}
import std/[locks, typetraits, tables, atomics] # Added tables
import chronos
import results
import std/[locks, typetraits, tables, atomics], chronos, chronicles
import
./sds_thread/sds_thread,
./alloc,
@ -15,7 +13,8 @@ import
./sds_thread/inter_thread_communication/sds_thread_request,
./sds_thread/inter_thread_communication/requests/
[sds_lifecycle_request, sds_message_request, sds_dependencies_request],
../src/[reliability, reliability_utils, message]
../src/[reliability, reliability_utils, message],
./events/[json_message_ready_event, json_message_sent_event]
################################################################################
### Wrapper around the reliability manager
@ -69,6 +68,16 @@ proc handleRequest(
return RET_OK
proc onMessageReady(ctx: ptr SdsContext): MessageReadyCallback =
return proc(messageId: MessageID) {.gcsafe.} =
callEventCallback(ctx, "onMessageReady"):
$JsonMessageReadyEvent.new(messageId)
proc onMessageSent(ctx: ptr SdsContext): MessageSentCallback =
return proc(messageId: MessageID) {.gcsafe.} =
callEventCallback(ctx, "onMessageSent"):
$JsonMessageSentEvent.new(messageId)
### End of not-exported components
################################################################################

View File

@ -251,10 +251,9 @@ proc markDependenciesMet*(
proc setCallbacks*(
rm: ReliabilityManager,
onMessageReady: proc(messageId: MessageID) {.gcsafe.},
onMessageSent: proc(messageId: MessageID) {.gcsafe.},
onMissingDependencies:
proc(messageId: MessageID, missingDeps: seq[MessageID]) {.gcsafe.},
onMessageReady: MessageReadyCallback,
onMessageSent: MessageSentCallback,
onMissingDependencies: MissingDependenciesCallback,
onPeriodicSync: PeriodicSyncCallback = nil,
) =
## Sets the callback functions for various events in the ReliabilityManager.

View File

@ -2,8 +2,21 @@ import std/[times, locks]
import ./[rolling_bloom_filter, message]
type
MessageReadyCallback* = proc(messageId: MessageID) {.gcsafe.}
MessageSentCallback* = proc(messageId: MessageID) {.gcsafe.}
MissingDependenciesCallback* =
proc(messageId: MessageID, missingDeps: seq[MessageID]) {.gcsafe.}
PeriodicSyncCallback* = proc() {.gcsafe, raises: [].}
AppCallbacks* = ref object
messageReadyCb*: MessageReadyCallback
messageSentCb*: MessageSentCallback
missingDependenciesCb*: MissingDependenciesCallback
periodicSyncCb*: PeriodicSyncCallback
ReliabilityConfig* = object
bloomFilterCapacity*: int
bloomFilterErrorRate*: float