Skip to content

Commit

Permalink
simplification to meta AST to make augment possible and easier to nav…
Browse files Browse the repository at this point in the history
…igate
  • Loading branch information
dhubler committed Nov 19, 2017
1 parent 45f6786 commit edc9347
Show file tree
Hide file tree
Showing 115 changed files with 4,828 additions and 5,464 deletions.
3 changes: 3 additions & 0 deletions c2/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
// AssertEqual emits testing error if a and b are not equal. Returns true if
// equal
func AssertEqual(t *testing.T, a interface{}, b interface{}) bool {
t.Helper()
if !reflect.DeepEqual(a, b) {
err := errors.New(fmt.Sprintf("\nExpected:'%v'\n Actual:'%v'", a, b))
t.Error(err)
Expand All @@ -25,6 +26,7 @@ func AssertEqual(t *testing.T, a interface{}, b interface{}) bool {
// DiffBytes will compare two byte arrays and emit formatted difference
// useful in "Golden File Testing", return true if no differences
func DiffBytes(t *testing.T, a []byte, b []byte) bool {
t.Helper()
f, fErr := ioutil.TempFile(os.TempDir(), "tst")
if fErr != nil {
panic(fErr.Error())
Expand All @@ -39,6 +41,7 @@ func DiffBytes(t *testing.T, a []byte, b []byte) bool {
// Diff will compare byte array to file and emit formatted difference
// useful in "Golden File Testing", return true if no differences
func Diff(t *testing.T, a []byte, b string) bool {
t.Helper()
f, fErr := ioutil.TempFile(os.TempDir(), "tst")
if fErr != nil {
panic(fErr.Error())
Expand Down
2 changes: 1 addition & 1 deletion device/call_home_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func CallHomeNode(ch *CallHome) node.Node {
return &nodes.Extend{
Base: nodes.ReflectChild(&options),
OnField: func(p node.Node, r node.FieldRequest, hnd *node.ValueHandle) error {
switch r.Meta.GetIdent() {
switch r.Meta.Ident() {
case "registered":
hnd.Val = val.Bool(ch.Registered)
default:
Expand Down
5 changes: 2 additions & 3 deletions device/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ func (self *Local) UiSource() meta.StreamSource {
func (self *Local) Modules() map[string]*meta.Module {
mods := make(map[string]*meta.Module)
for _, b := range self.browsers {
m := b.Meta.(*meta.Module)
mods[m.GetIdent()] = m
mods[b.Meta.Ident()] = b.Meta
}
return mods
}
Expand All @@ -67,7 +66,7 @@ func (self *Local) Add(module string, n node.Node) error {
}

func (self *Local) AddBrowser(b *node.Browser) {
self.browsers[b.Meta.GetIdent()] = b
self.browsers[b.Meta.Ident()] = b
}

func (self *Local) ApplyStartupConfig(config io.Reader) error {
Expand Down
20 changes: 10 additions & 10 deletions device/map_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ type LocalLocationService map[string]string
func MapNode(mgr Map) node.Node {
return &nodes.Basic{
OnChild: func(r node.ChildRequest) (node.Node, error) {
switch r.Meta.GetIdent() {
switch r.Meta.Ident() {
case "device":
return deviceRecordListNode(mgr), nil
}
return nil, nil
},
OnNotify: func(r node.NotifyRequest) (node.NotifyCloser, error) {
switch r.Meta.GetIdent() {
switch r.Meta.Ident() {
case "update":
sub := mgr.OnUpdate(func(d Device, id string, c Change) {
n := deviceChangeNode(id, d, c)
Expand All @@ -41,10 +41,10 @@ func deviceChangeNode(id string, d Device, c Change) node.Node {
return &nodes.Extend{
Base: deviceNode(id, d),
OnField: func(p node.Node, r node.FieldRequest, hnd *node.ValueHandle) error {
switch r.Meta.GetIdent() {
switch r.Meta.Ident() {
case "change":
var err error
hnd.Val, err = node.NewValue(r.Meta.GetDataType(), int(c))
hnd.Val, err = node.NewValue(r.Meta.DataType(), int(c))
if err != nil {
return err
}
Expand Down Expand Up @@ -93,14 +93,14 @@ func deviceHndNode(hnd *DeviceHnd) node.Node {
func deviceNode(id string, d Device) node.Node {
return &nodes.Basic{
OnChild: func(r node.ChildRequest) (node.Node, error) {
switch r.Meta.GetIdent() {
switch r.Meta.Ident() {
case "module":
return deviceModuleList(d.Modules()), nil
}
return nil, nil
},
OnField: func(r node.FieldRequest, hnd *node.ValueHandle) error {
switch r.Meta.GetIdent() {
switch r.Meta.Ident() {
case "deviceId":
hnd.Val = val.String(id)
}
Expand All @@ -121,7 +121,7 @@ func deviceModuleList(mods map[string]*meta.Module) node.Node {
if v := index.NextKey(r.Row); v != node.NO_VALUE {
module := v.String()
if m = mods[module]; m != nil {
key = []val.Value{val.String(m.GetIdent())}
key = []val.Value{val.String(m.Ident())}
}
}
}
Expand All @@ -136,11 +136,11 @@ func deviceModuleList(mods map[string]*meta.Module) node.Node {
func deviceModuleNode(m *meta.Module) node.Node {
return &nodes.Basic{
OnField: func(r node.FieldRequest, hnd *node.ValueHandle) error {
switch r.Meta.GetIdent() {
switch r.Meta.Ident() {
case "name":
hnd.Val = val.String(m.GetIdent())
hnd.Val = val.String(m.Ident())
case "revision":
hnd.Val = val.String(m.Revision.GetIdent())
hnd.Val = val.String(m.Revision().Ident())
}
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion device/yang_lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func loadModuleNode(mods map[string]*meta.Module, resolver ResolveModule, hnd *M
if err != nil {
return err
}
mods[mod.GetIdent()] = mod
mods[mod.Ident()] = mod
return nil
},
}
Expand Down
14 changes: 7 additions & 7 deletions device/yang_lib_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type ModuleAddresser func(m *meta.Module) string
func LocalDeviceYangLibNode(addresser ModuleAddresser, d Device) node.Node {
return &nodes.Basic{
OnChild: func(r node.ChildRequest) (node.Node, error) {
switch r.Meta.GetIdent() {
switch r.Meta.Ident() {
case "modules-state":
return localYangLibModuleState(addresser, d), nil
}
Expand All @@ -31,7 +31,7 @@ func LocalDeviceYangLibNode(addresser ModuleAddresser, d Device) node.Node {
func localYangLibModuleState(addresser ModuleAddresser, d Device) node.Node {
return &nodes.Basic{
OnChild: func(r node.ChildRequest) (node.Node, error) {
switch r.Meta.GetIdent() {
switch r.Meta.Ident() {
case "module":
mods := d.Modules()
if len(mods) > 0 {
Expand Down Expand Up @@ -61,7 +61,7 @@ func YangLibModuleList(addresser ModuleAddresser, mods map[string]*meta.Module)
if v := index.NextKey(r.Row); v != node.NO_VALUE {
module := v.String()
if m = mods[module]; m != nil {
key = []val.Value{val.String(m.GetIdent())}
key = []val.Value{val.String(m.Ident())}
}
}
}
Expand All @@ -81,15 +81,15 @@ func yangLibModuleHandleNode(addresser ModuleAddresser, m *meta.Module) node.Nod
return nil, nil
},
OnField: func(r node.FieldRequest, hnd *node.ValueHandle) error {
switch r.Meta.GetIdent() {
switch r.Meta.Ident() {
case "name":
hnd.Val = val.String(m.GetIdent())
hnd.Val = val.String(m.Ident())
case "revision":
hnd.Val = val.String(m.Revision.GetIdent())
hnd.Val = val.String(m.Revision().Ident())
case "schema":
hnd.Val = val.String(addresser(m))
case "namespace":
hnd.Val = val.String(m.Namespace)
hnd.Val = val.String(m.Namespace())
case "feature":
case "conformance-type":
}
Expand Down
2 changes: 1 addition & 1 deletion device/yang_lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestYangLibNode(t *testing.T) {
"name" : "blue jay"
}]}`)
moduleNameAsAddress := func(m *meta.Module) string {
return m.GetIdent()
return m.Ident()
}
if err := d.Add("ietf-yang-library", device.LocalDeviceYangLibNode(moduleNameAsAddress, d)); err != nil {
t.Error(err)
Expand Down
6 changes: 3 additions & 3 deletions gateway/registrar_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import (
func RegistrarNode(registrar Registrar) node.Node {
return &nodes.Basic{
OnChild: func(r node.ChildRequest) (node.Node, error) {
switch r.Meta.GetIdent() {
switch r.Meta.Ident() {
case "registrations":
return registrationsNode(registrar), nil
}
return nil, nil
},
OnAction: func(r node.ActionRequest) (node.Node, error) {
switch r.Meta.GetIdent() {
switch r.Meta.Ident() {
case "register":
var reg Registration
if err := r.Input.InsertInto(regNode(&reg)).LastErr; err != nil {
Expand All @@ -36,7 +36,7 @@ func RegistrarNode(registrar Registrar) node.Node {
return nil, nil
},
OnNotify: func(r node.NotifyRequest) (node.NotifyCloser, error) {
switch r.Meta.GetIdent() {
switch r.Meta.Ident() {
case "update":
sub := registrar.OnRegister(func(reg Registration) {
r.Send(regNode(&reg))
Expand Down
134 changes: 0 additions & 134 deletions meta/clone.go

This file was deleted.

Loading

0 comments on commit edc9347

Please sign in to comment.