Browse Source

сохранение данных об узлах в домене

kpmy 10 years ago
parent
commit
f084c12e33
3 changed files with 31 additions and 11 deletions
  1. 17 10
      cp/adr.go
  2. 1 1
      fw.go
  3. 13 0
      rt2/context/ctx.go

+ 17 - 10
cp/adr.go

@@ -18,28 +18,35 @@ func (i ID) String() string {
 	}
 }
 
-func Init() {
+type Digest interface{}
+
+type dig struct {
+	fake int
+	this int
+	list map[ID]int
+}
+
+func Init() Digest {
 	var (
-		fake int        = 0
-		this int        = 0
-		list map[ID]int = make(map[ID]int)
+		d *dig = &dig{list: make(map[ID]int)}
 	)
 	Next = func(id int) ID {
 		if id >= 0 {
-			this++
-			list[ID(this)] = id
-			return ID(this)
+			d.this++
+			d.list[ID(d.this)] = id
+			return ID(d.this)
 		} else {
 			return ID(id)
 		}
 	}
 	Some = func() int {
-		fake--
-		return fake
+		d.fake--
+		return d.fake
 	}
 	getId = func(id ID) int {
-		return list[id]
+		return d.list[id]
 	}
+	return d
 }
 
 var Next func(id int) ID

+ 1 - 1
fw.go

@@ -37,11 +37,11 @@ func main() {
 		name = "Start2"
 		utils.Debug(false)
 	}
-	cp.Init()
 	global := &stdDomain{god: true}
 	global.global = global
 	modList := rtm.New()
 	global.Attach(context.MOD, modList)
+	global.Attach(context.DIGEST, context.Data(cp.Init()))
 	heap = scope.New(context.HEAP)
 	global.Attach(context.HEAP, heap)
 	t0 := time.Now()

+ 13 - 0
rt2/context/ctx.go

@@ -7,6 +7,7 @@ const (
 	UNIVERSE = "fw/rt2/ctx"
 	HEAP     = "fw/rt2/scope,heap"
 	MT       = "fw/rt2/table,flow"
+	DIGEST   = "fw/cp"
 )
 
 type Factory interface {
@@ -25,3 +26,15 @@ type ContextAware interface {
 	Domain() Domain
 	Handle(msg interface{})
 }
+
+type data struct {
+	inner interface{}
+}
+
+func (d *data) Init(x Domain)          {}
+func (d *data) Domain() Domain         { return nil }
+func (d *data) Handle(msg interface{}) {}
+
+func Data(x interface{}) ContextAware {
+	return &data{inner: x}
+}