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
|
return cfg.name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cfg *base) SetName(n string) {
|
||||||
|
cfg.name = n
|
||||||
|
}
|
||||||
|
|
||||||
func (cfg *base) Starter() lib.StartProc {
|
func (cfg *base) Starter() lib.StartProc {
|
||||||
return cfg.starter
|
return cfg.starter
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package context
|
||||||
|
|
||||||
import (
|
import (
|
||||||
stdlib_context "context"
|
stdlib_context "context"
|
||||||
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -24,6 +25,10 @@ func (ctx *context) Config() lib.Config {
|
||||||
return ctx.cfg
|
return ctx.cfg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ctx *context) Name() string {
|
||||||
|
return ctx.cfg.Name()
|
||||||
|
}
|
||||||
|
|
||||||
func (ctx *context) Parent() lib.Context {
|
func (ctx *context) Parent() lib.Context {
|
||||||
return ctx.parent
|
return ctx.parent
|
||||||
}
|
}
|
||||||
|
@ -34,8 +39,13 @@ func (ctx *context) Services() Services {
|
||||||
|
|
||||||
func (ctx *context) ChildContext(cfg lib.Config) Context {
|
func (ctx *context) ChildContext(cfg lib.Config) Context {
|
||||||
cctx := makeCtx(cfg, ctx)
|
cctx := makeCtx(cfg, ctx)
|
||||||
ctx.Services()[cfg.Name()] = cctx
|
|
||||||
ctx.children = append(ctx.children, 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
|
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
|
// implement interface context.Context from standard library
|
||||||
|
|
||||||
func (ctx *context) Deadline() (deadline time.Time, ok bool) {
|
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 {
|
if e == nil || ctx == nil {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
return e.Str("service", ctx.Config().Name())
|
return e.Str("service", ctx.Name())
|
||||||
}
|
}
|
||||||
|
|
||||||
func Debug(ctx lib.Context) *Evt {
|
func Debug(ctx lib.Context) *Evt {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package matrix
|
||||||
|
|
||||||
import (
|
import (
|
||||||
lib "git.sr.ht/~cco/go-scopes"
|
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"
|
||||||
"git.sr.ht/~cco/go-scopes/core/action"
|
"git.sr.ht/~cco/go-scopes/core/action"
|
||||||
)
|
)
|
||||||
|
@ -12,6 +13,16 @@ func Start(ctx lib.Context) {
|
||||||
core.Start(ctx)
|
core.Start(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type celLConfig struct {
|
||||||
|
*config.BaseCfg
|
||||||
|
}
|
||||||
|
|
||||||
func create(act lib.Action) bool {
|
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
|
return true
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ type ContextState interface{}
|
||||||
type Context interface {
|
type Context interface {
|
||||||
stdlib_context.Context
|
stdlib_context.Context
|
||||||
Config() Config
|
Config() Config
|
||||||
|
Name() string
|
||||||
Parent() Context
|
Parent() Context
|
||||||
Services() Services
|
Services() Services
|
||||||
ChildContext(Config) Context
|
ChildContext(Config) Context
|
||||||
|
@ -94,6 +95,7 @@ type ActionHandler = func(Action) bool
|
||||||
|
|
||||||
type Config interface {
|
type Config interface {
|
||||||
Name() string
|
Name() string
|
||||||
|
SetName(string)
|
||||||
Starter() StartProc
|
Starter() StartProc
|
||||||
Step() StepProc
|
Step() StepProc
|
||||||
MessageHandler() MessageHandler
|
MessageHandler() MessageHandler
|
||||||
|
@ -130,6 +132,7 @@ func HandleMsg(ctx Context, msg Message) bool {
|
||||||
|
|
||||||
func Send(ctx Context, addr Address, msg Message) {
|
func Send(ctx Context, addr Address, msg Message) {
|
||||||
if svc, ok := ctx.Services()[addr.Service()]; ok {
|
if svc, ok := ctx.Services()[addr.Service()]; ok {
|
||||||
|
// TODO: check Address for sid, iid
|
||||||
svc.Send(msg)
|
svc.Send(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ func TestMatrixApp(tb *tbase.T) {
|
||||||
t := testing.SetUpApp(tb, etc.ConfigMx())
|
t := testing.SetUpApp(tb, etc.ConfigMx())
|
||||||
t.Run("app-matrix", MxTest)
|
t.Run("app-matrix", MxTest)
|
||||||
t.TearDownApp("matrix")
|
t.TearDownApp("matrix")
|
||||||
t.AssertEqual(t.LogCheck(logfile, true), 6)
|
t.AssertEqual(t.LogCheck(logfile, true), 7)
|
||||||
}
|
}
|
||||||
|
|
||||||
func MxTest(t *testing.T) {
|
func MxTest(t *testing.T) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue