diff --git a/core/action/action.go b/core/action/action.go index ee2f0b2..7ec6fb7 100644 --- a/core/action/action.go +++ b/core/action/action.go @@ -21,6 +21,10 @@ func (spec *baseSpec) Receivers() []lib.Addressable { return spec.receivers } +func (spec *baseSpec) AddReceiver(rcv lib.Addressable) { + spec.receivers = append(spec.receivers, rcv) +} + func Base(hdlr lib.ActionHandler, rcvs ...string) *baseSpec { spec := baseSpec{handler: hdlr} for _, rcv := range rcvs { @@ -29,6 +33,10 @@ func Base(hdlr lib.ActionHandler, rcvs ...string) *baseSpec { return &spec } +func BaseA(hdlr lib.ActionHandler, rcvs ...lib.Addressable) *baseSpec { + return &baseSpec{hdlr, rcvs} +} + // action selection func Select(ctx lib.Context, msg lib.Message) []lib.Action { diff --git a/matrix/matrix.go b/matrix/matrix.go index a5628d1..e8edc8a 100644 --- a/matrix/matrix.go +++ b/matrix/matrix.go @@ -14,13 +14,11 @@ func DefaultConfig(name string) lib.Config { func create(act lib.Action) bool { ctx := act.Context() - spec := act.Spec() + //spec := act.Spec() msg := act.Message() cctx := createCell(ctx) - //nmsg := message.New("matrix", "connect").WithSender(cctx) - //msg.Sender().Cell().Send(nmsg) - connect(ctx, cctx, spec, msg) - connect(cctx, msg.Sender().Cell(), spec, msg) + connect(ctx, cctx, msg) + connect(cctx, msg.Sender().Cell(), msg) return true } @@ -31,5 +29,21 @@ func createCell(ctx lib.Context) lib.Context { return cctx } -func connect(src, tgt lib.Context, spec lib.ActionSpec, msg lib.Message) { +func connect(src, tgt lib.Context, msg lib.Message) { + cfg := src.Config() + pattern := "matrix|data" + for _, act := range cfg.Actions() { + if act.Pattern().String() == pattern { + for _, spec := range act.Specs() { + spec.AddReceiver(tgt) + return + } + } + } + cfg.AddAction(pattern, action.BaseA(handle, tgt)) +} + +func handle(act lib.Action) bool { + // here comes the real stuff + return action.Forward(act) } diff --git a/scopes.go b/scopes.go index ecca02e..ebf708d 100644 --- a/scopes.go +++ b/scopes.go @@ -83,6 +83,7 @@ type Action interface { type ActionSpec interface { Handler() ActionHandler Receivers() []Addressable + AddReceiver(Addressable) } // procedures and handlers