diff --git a/lib/action/action.go b/lib/action/action.go index 008d1c7..7191b3d 100644 --- a/lib/action/action.go +++ b/lib/action/action.go @@ -18,3 +18,43 @@ func (spec *baseSpec) Receivers() []string { func BaseSpec(hdlr lib.ActionHandler, rcvrs []string) *baseSpec { return &baseSpec{hdlr, rcvrs} } + +// action selection + +func Select(ctx lib.Context, msg lib.Message) []lib.Action { + var acts []lib.Action + // act := action{ctx, spec, msg} + // acts = append(acts, &act) + return acts +} + +// action + +type action struct { + ctx lib.Context + spec lib.ActionSpec + msg lib.Message +} + +func (act *action) Context() lib.Context { + return act.ctx +} + +func (act *action) Spec() lib.ActionSpec { + return act.spec +} + +func (act *action) Message() lib.Message { + return act.msg +} + +func (act *action) Handle() bool { + return act.spec.Handler()(act) +} + +// predefined action handlers + +func Forward(act lib.Action) bool { + // Send(ctx, addr. msg) + return true +} diff --git a/lib/core/core.go b/lib/core/core.go index d482494..eb8358b 100644 --- a/lib/core/core.go +++ b/lib/core/core.go @@ -4,6 +4,7 @@ import ( "fmt" "git.sr.ht/~cco/go-scopes/lib" + "git.sr.ht/~cco/go-scopes/lib/action" ) func Start(ctx lib.Context) { @@ -29,7 +30,12 @@ func Step(ctx lib.Context) (loop bool) { return } -func HandleMessage(ctx lib.Context, msg lib.Message) bool { - fmt.Println("HandleMessage", msg) - return true +func HandleMessage(ctx lib.Context, msg lib.Message) (loop bool) { + loop = true + fmt.Println("core.HandleMessage", msg) + for _, act := range action.Select(ctx, msg) { + //loop = act.Spec().Handler()(act) + loop = act.Handle() + } + return } diff --git a/lib/lib.go b/lib/lib.go index 93f0c46..98d55f1 100644 --- a/lib/lib.go +++ b/lib/lib.go @@ -60,6 +60,7 @@ type Action interface { Context() Context Spec() ActionSpec Message() Message + Handle() bool } type Proc = func(Context) diff --git a/tests/etc/etc.go b/tests/etc/etc.go index 12d07fb..b62704d 100644 --- a/tests/etc/etc.go +++ b/tests/etc/etc.go @@ -27,8 +27,7 @@ func Config() lib.Config { return &cfg } -// register action handlers from ..._test.go here: - +// register action handlers from ..._test.go here. var ( AH_Receiver lib.ActionHandler )