add new parameter hasChild and set with connection id
This commit is contained in:
25
dbm/set.go
25
dbm/set.go
@@ -1,10 +1,12 @@
|
||||
package dbm
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
json_dataModels "github.com/tecamino/tecamino-json_data/models"
|
||||
)
|
||||
|
||||
func (d *DBMHandler) Set(req *json_dataModels.Request) {
|
||||
func (d *DBMHandler) Set(req *json_dataModels.Request, id string) {
|
||||
if req == nil {
|
||||
return
|
||||
} else if len(req.Set) == 0 {
|
||||
@@ -13,9 +15,28 @@ func (d *DBMHandler) Set(req *json_dataModels.Request) {
|
||||
d.RLock()
|
||||
defer d.RUnlock()
|
||||
|
||||
resp := json_dataModels.NewResponse()
|
||||
resp.Id = req.Id
|
||||
|
||||
for _, set := range req.Set {
|
||||
for _, dp := range d.DBM.QueryDatapoints(1, set.Uuid, set.Path) {
|
||||
dps := d.DBM.QueryDatapoints(1, set.Uuid, set.Path)
|
||||
if len(dps) == 0 {
|
||||
resp.SetError()
|
||||
if resp.Message == "" {
|
||||
resp.SetMessage(fmt.Sprintf("datapoint %s not found", set.Path))
|
||||
}
|
||||
continue
|
||||
}
|
||||
for _, dp := range dps {
|
||||
dp.UpdateValue(d.Conns, set.Value)
|
||||
resp.AddSet(json_dataModels.Set{
|
||||
Uuid: dp.Uuid,
|
||||
Path: dp.Path,
|
||||
Value: dp.Value,
|
||||
})
|
||||
}
|
||||
}
|
||||
if err := d.Conns.SendResponse(id, resp); err != nil {
|
||||
d.Log.Error("get.Set", err.Error())
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user