minor re-arrangement; prepare disconnect() function

This commit is contained in:
Helmut Merz 2023-07-26 14:56:54 +02:00
parent cd8982ada0
commit 10386651a4

View file

@ -17,21 +17,21 @@ func create(act lib.Action) bool {
//spec := act.Spec()
msg := act.Message()
cctx := createCell(ctx)
connect(ctx, cctx, msg)
connect(cctx, msg.Sender().Cell(), msg)
pattern := config.Pattern(msg.Domain(), "data", msg.Class(), msg.Item()).String()
connect(ctx, cctx, pattern)
connect(cctx, msg.Sender().Cell(), pattern)
return true
}
func createCell(ctx lib.Context) lib.Context {
cfg := DefaultConfig("")
cctx := ctx.ChildContext(cfg)
cctx := ctx.ChildContext(cfg) // .WithState(...)
cfg.Starter()(cctx)
return cctx
}
func connect(src, tgt lib.Context, msg lib.Message) {
func connect(src, tgt lib.Context, pattern string) {
cfg := src.Config()
pattern := config.Pattern(msg.Domain(), "data", msg.Class(), msg.Item()).String()
for _, act := range cfg.Actions() {
if act.Pattern().String() == pattern {
for _, spec := range act.Specs() {
@ -43,6 +43,17 @@ func connect(src, tgt lib.Context, msg lib.Message) {
cfg.AddAction(pattern, action.Base(handle).AddReceiver(tgt))
}
func disconnect(src, tgt lib.Context) { //, pattern string) {
cfg := src.Config()
for _, act := range cfg.Actions() {
//if act.Pattern().String() == pattern {
for _, spec := range act.Specs() {
//spec.RemoveReceiver(tgt)
}
//}
}
}
func handle(act lib.Action) bool {
// here comes the real stuff
return action.Forward(act)