cell creation basically working
This commit is contained in:
parent
c2eab31527
commit
5a7cbba536
6 changed files with 41 additions and 3 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue