本文整理汇总了Golang中github.com/KiiPlatform/gateway-agent/internal/common.EndnodeAddress类的典型用法代码示例。如果您正苦于以下问题:Golang EndnodeAddress类的具体用法?Golang EndnodeAddress怎么用?Golang EndnodeAddress使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EndnodeAddress类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: FindByEndnodeAddress
// FindByEndnodeAddress returns an item which matches with endnode address.
func (db *DB) FindByEndnodeAddress(a common.EndnodeAddress) (common.MapItem, error) {
n, ok := db.endnodeIndex[a.IDString()]
if !ok {
return common.MapItem{}, common.ErrUnknownEndnode
}
return db.items[n], nil
}
示例2: UpsertEndnode
// UpsertEndnode updates or inserts a end-node with data.
func (db *DB) UpsertEndnode(ea common.EndnodeAddress, data []byte) (common.MapItem, error) {
db.lock.Lock()
defer db.lock.Unlock()
// update data for a known end-node.
id := ea.IDString()
n, ok := db.endnodeIndex[id]
if ok {
db.items[n].States = data
db.dumpTable()
return db.items[n], nil
}
// check capacity.
n = len(db.items)
if n >= cap(db.items) {
return common.MapItem{}, common.ErrTooManyEndnode
}
// insert a new end-node and its data.
db.items = append(db.items, common.MapItem{
EndnodeAddress: &ea,
States: data,
})
db.endnodeIndex[id] = n
db.dumpTable()
return db.items[n], nil
}
示例3: RegisterEndnode
// RegisterEndnode registers cloud address for a end-node.
func (m *Mapper) RegisterEndnode(ea common.EndnodeAddress, ca common.CloudAddress) error {
item, err := m.Store.UpdateCloud(ea, ca)
if err != nil {
return err
}
m.Log.Printf("mapped: endnodeID=%s cloudID=%s\n", ea.IDString(), ca.IDString())
return m.Cloud.SendState(*item.CloudAddress, item.States)
}
示例4: FindByEndnodeAddress
// FindByEndnodeAddress returns an item which matches with endnode address.
func (m *DB) FindByEndnodeAddress(ea common.EndnodeAddress) (common.MapItem, error) {
var item common.MapItem
err := m.db.View(func(tx *bolt.Tx) (err error) {
item, err = m.getMapItem(tx, []byte(ea.IDString()))
return err
})
if err != nil {
return common.MapItem{}, err
}
return item, nil
}
示例5: UpdateThingProperties
// UpdateThingProperties updates thing properties of endnode to locale DB.
func (m *Mapper) UpdateThingProperties(a common.EndnodeAddress, d []byte) error {
item, err := m.Store.UpsertEndnodeProperties(a, d)
if err != nil {
return err
}
if item.CloudAddress == nil {
m.Log.Printf("pended: endnodeID=%s ThingProperties=%s\n",
a.IDString(), util.DataToString(d))
}
return nil
}
示例6: UpdateStatus
// UpdateStatus updates status of endnode and send it to cloud if need.
func (m *Mapper) UpdateStatus(a common.EndnodeAddress, d []byte) error {
item, err := m.Store.UpsertEndnode(a, d)
if err != nil {
return err
}
if item.CloudAddress == nil {
m.Log.Printf("pended: endnodeID=%s data=%s\n",
a.IDString(), util.DataToString(d))
return nil
}
return m.Cloud.SendState(*item.CloudAddress, item.States)
}
示例7: UpdateCloud
// UpdateCloud updates CloudAddress field of a end-node.
func (db *DB) UpdateCloud(ea common.EndnodeAddress, caddr common.CloudAddress) (common.MapItem, error) {
db.lock.Lock()
defer db.lock.Unlock()
n, ok := db.endnodeIndex[ea.IDString()]
if !ok {
return common.MapItem{}, common.ErrUnknownEndnode
}
db.items[n].CloudAddress = &caddr
db.cloudIndex[caddr.IDString()] = n
db.dumpTable()
return db.items[n], nil
}
示例8: testUpdateCloud
func testUpdateCloud(t *testing.T, s mapper.Store, ea common.EndnodeAddress, ca common.CloudAddress) common.MapItem {
m, err := s.UpdateCloud(ea, ca)
if err != nil {
t.Fatal("UpdateCloud failed:", err)
}
if m.EndnodeAddress == nil || m.EndnodeAddress.IDString() != ea.IDString() {
t.Fatalf("UpdateCloud modified EndnodeAddress: %#v", m.EndnodeAddress)
}
if m.CloudAddress == nil || m.CloudAddress.IDString() != ca.IDString() {
t.Fatalf("UpdateCloud returned unexpected CloudAddress: %#v",
m.CloudAddress)
}
return m
}
示例9: testUpsertEndnodeProperties
func testUpsertEndnodeProperties(t *testing.T, s mapper.Store, ea common.EndnodeAddress, d []byte) common.MapItem {
m, err := s.UpsertEndnodeProperties(ea, d)
if err != nil {
t.Fatal("UpsertEndnodeProperties failed:", err)
}
if m.EndnodeAddress == nil || m.EndnodeAddress.IDString() != ea.IDString() {
t.Fatalf("UpsertEndnode returns unexpected MapItem: %#v",
m.EndnodeAddress)
}
if !bytes.Equal(m.ThingProperties, d) {
t.Fatalf("UpsertEndnode store wrong data: %#v (expecetd:%#v)",
m.States, d)
}
return m
}
示例10: UpdateCloud
// UpdateCloud updates CloudAddress field of a end-node.
func (m *DB) UpdateCloud(ea common.EndnodeAddress, ca common.CloudAddress) (common.MapItem, error) {
var item common.MapItem
err := m.db.Update(func(tx *bolt.Tx) (err error) {
item, err = m.getMapItem(tx, []byte(ea.IDString()))
if err != nil {
return err
}
item.CloudAddress = &ca
return m.putMapItem(tx, item)
})
if err != nil {
return common.MapItem{}, err
}
return item, nil
}
示例11: UpdateEndnode
// UpdateEndnode update EndnodeAddress for existing endnode
func (db *DB) UpdateEndnode(newEA common.EndnodeAddress, caddr common.CloudAddress) (common.MapItem, error) {
db.lock.Lock()
defer db.lock.Unlock()
// retrieve mapItem by cloudAddress
item, err := db.FindByCloudAddress(caddr)
if err != nil {
return common.MapItem{}, err
}
n := db.cloudIndex[caddr.IDString()]
// update endnodeIndex
delete(db.endnodeIndex, item.EndnodeAddress.IDString())
db.endnodeIndex[newEA.IDString()] = n
// update mapitem
db.items[n].EndnodeAddress = &newEA
db.dumpTable()
return db.items[n], nil
}
示例12: UpsertEndnodeProperties
// UpsertEndnodeProperties updates or inserts a end-node with thing properties.
func (m *DB) UpsertEndnodeProperties(ea common.EndnodeAddress, data []byte) (common.MapItem, error) {
var item common.MapItem
err := m.db.Update(func(tx *bolt.Tx) (err error) {
item, err = m.getMapItem(tx, []byte(ea.IDString()))
if err != nil {
if err != common.ErrUnknownEndnode {
return err
}
item = common.MapItem{
EndnodeAddress: &ea,
}
}
item.ThingProperties = data
return m.putMapItem(tx, item)
})
if err != nil {
return common.MapItem{}, err
}
return item, nil
}