minor re-arrangement; prepare disconnect() function
This commit is contained in:
parent
cd8982ada0
commit
10386651a4
1 changed files with 16 additions and 5 deletions
|
@ -17,21 +17,21 @@ func create(act lib.Action) bool {
|
||||||
//spec := act.Spec()
|
//spec := act.Spec()
|
||||||
msg := act.Message()
|
msg := act.Message()
|
||||||
cctx := createCell(ctx)
|
cctx := createCell(ctx)
|
||||||
connect(ctx, cctx, msg)
|
pattern := config.Pattern(msg.Domain(), "data", msg.Class(), msg.Item()).String()
|
||||||
connect(cctx, msg.Sender().Cell(), msg)
|
connect(ctx, cctx, pattern)
|
||||||
|
connect(cctx, msg.Sender().Cell(), pattern)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func createCell(ctx lib.Context) lib.Context {
|
func createCell(ctx lib.Context) lib.Context {
|
||||||
cfg := DefaultConfig("")
|
cfg := DefaultConfig("")
|
||||||
cctx := ctx.ChildContext(cfg)
|
cctx := ctx.ChildContext(cfg) // .WithState(...)
|
||||||
cfg.Starter()(cctx)
|
cfg.Starter()(cctx)
|
||||||
return cctx
|
return cctx
|
||||||
}
|
}
|
||||||
|
|
||||||
func connect(src, tgt lib.Context, msg lib.Message) {
|
func connect(src, tgt lib.Context, pattern string) {
|
||||||
cfg := src.Config()
|
cfg := src.Config()
|
||||||
pattern := config.Pattern(msg.Domain(), "data", msg.Class(), msg.Item()).String()
|
|
||||||
for _, act := range cfg.Actions() {
|
for _, act := range cfg.Actions() {
|
||||||
if act.Pattern().String() == pattern {
|
if act.Pattern().String() == pattern {
|
||||||
for _, spec := range act.Specs() {
|
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))
|
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 {
|
func handle(act lib.Action) bool {
|
||||||
// here comes the real stuff
|
// here comes the real stuff
|
||||||
return action.Forward(act)
|
return action.Forward(act)
|
||||||
|
|
Loading…
Add table
Reference in a new issue