diff --git a/config/config.go b/config/config.go index 0adfd59..1b943b7 100644 --- a/config/config.go +++ b/config/config.go @@ -35,6 +35,10 @@ func (cfg *base) Name() string { return cfg.name } +func (cfg *base) SetName(n string) { + cfg.name = n +} + func (cfg *base) Starter() lib.StartProc { return cfg.starter } diff --git a/core/context/context.go b/core/context/context.go index d3660a6..c776e73 100644 --- a/core/context/context.go +++ b/core/context/context.go @@ -2,6 +2,7 @@ package context import ( stdlib_context "context" + "fmt" "sync" "time" @@ -24,6 +25,10 @@ func (ctx *context) Config() lib.Config { return ctx.cfg } +func (ctx *context) Name() string { + return ctx.cfg.Name() +} + func (ctx *context) Parent() lib.Context { return ctx.parent } @@ -34,8 +39,13 @@ func (ctx *context) Services() Services { func (ctx *context) ChildContext(cfg lib.Config) Context { cctx := makeCtx(cfg, ctx) - ctx.Services()[cfg.Name()] = cctx ctx.children = append(ctx.children, cctx) + name := cfg.Name() + if name == "" { + cfg.SetName(fmt.Sprintf("%s.%d", ctx.Name(), len(ctx.children))) + } else { + ctx.Services()[name] = cctx + } return cctx } @@ -76,6 +86,16 @@ func makeCtx(cfg lib.Config, parent Context) *context { } } +// interface Addressable + +func (ctx *context) Cell() Context { + return ctx +} + +func (ctx *context) Address() lib.Address { + return nil +} + // implement interface context.Context from standard library func (ctx *context) Deadline() (deadline time.Time, ok bool) { diff --git a/logging/event.go b/logging/event.go index aafa5c1..01907ed 100644 --- a/logging/event.go +++ b/logging/event.go @@ -13,7 +13,7 @@ func WithContext(ctx lib.Context, e *Evt) *Evt { if e == nil || ctx == nil { return e } - return e.Str("service", ctx.Config().Name()) + return e.Str("service", ctx.Name()) } func Debug(ctx lib.Context) *Evt { diff --git a/matrix/matrix.go b/matrix/matrix.go index 7ce41de..e344ec6 100644 --- a/matrix/matrix.go +++ b/matrix/matrix.go @@ -2,6 +2,7 @@ package matrix import ( lib "git.sr.ht/~cco/go-scopes" + "git.sr.ht/~cco/go-scopes/config" "git.sr.ht/~cco/go-scopes/core" "git.sr.ht/~cco/go-scopes/core/action" ) @@ -12,6 +13,16 @@ func Start(ctx lib.Context) { core.Start(ctx) } +type celLConfig struct { + *config.BaseCfg +} + func create(act lib.Action) bool { + ctx := act.Context() + //msg := act.Message() + //spec := act.ActionSpec() + cctx := ctx.ChildContext(config.Base("", core.Start)) + core.Start(cctx) + // msg.Sender().Cell().Send(message.New("matrix", "connect").WithSender(cctx)) return true } diff --git a/scopes.go b/scopes.go index 0a953ee..94d1d67 100644 --- a/scopes.go +++ b/scopes.go @@ -17,6 +17,7 @@ type ContextState interface{} type Context interface { stdlib_context.Context Config() Config + Name() string Parent() Context Services() Services ChildContext(Config) Context @@ -94,6 +95,7 @@ type ActionHandler = func(Action) bool type Config interface { Name() string + SetName(string) Starter() StartProc Step() StepProc MessageHandler() MessageHandler @@ -130,6 +132,7 @@ func HandleMsg(ctx Context, msg Message) bool { func Send(ctx Context, addr Address, msg Message) { if svc, ok := ctx.Services()[addr.Service()]; ok { + // TODO: check Address for sid, iid svc.Send(msg) } } diff --git a/tests/matrix_test.go b/tests/matrix_test.go index b2311a3..693fd8b 100644 --- a/tests/matrix_test.go +++ b/tests/matrix_test.go @@ -16,7 +16,7 @@ func TestMatrixApp(tb *tbase.T) { t := testing.SetUpApp(tb, etc.ConfigMx()) t.Run("app-matrix", MxTest) t.TearDownApp("matrix") - t.AssertEqual(t.LogCheck(logfile, true), 6) + t.AssertEqual(t.LogCheck(logfile, true), 7) } func MxTest(t *testing.T) {