dt1t and counter and refactoring using embedded interfaces
This commit is contained in:
@ -1,10 +1,8 @@
|
||||
package pv
|
||||
|
||||
import (
|
||||
"log"
|
||||
"reflect"
|
||||
"time"
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"udi/config"
|
||||
"udi/handlers/handler"
|
||||
@ -12,10 +10,8 @@ import (
|
||||
)
|
||||
|
||||
|
||||
var idSeq int = 0
|
||||
|
||||
type PvHandler struct {
|
||||
id int
|
||||
handler.CommonHandler
|
||||
dbh *database.DatabaseHandle
|
||||
}
|
||||
|
||||
@ -40,18 +36,14 @@ type PvValue struct {
|
||||
}
|
||||
|
||||
|
||||
func NewPvHandler(config config.HandlerConfigT) handler.Handler {
|
||||
func New(id string, config config.HandlerConfigT) handler.Handler {
|
||||
t := &PvHandler {
|
||||
id: idSeq,
|
||||
}
|
||||
idSeq += 1
|
||||
t.Id = id
|
||||
t.dbh = database.NewDatabaseHandle()
|
||||
return t
|
||||
}
|
||||
|
||||
func (self *PvHandler) GetId() string {
|
||||
return fmt.Sprintf("PV%d", self.id)
|
||||
}
|
||||
|
||||
func (self *PvHandler) Handle(message handler.MessageT) {
|
||||
//log.Printf("Handler PV %d processing %s -> %s", self.id, message.Topic, message.Payload)
|
||||
@ -59,7 +51,7 @@ func (self *PvHandler) Handle(message handler.MessageT) {
|
||||
var pvValue PvValue
|
||||
err := json.Unmarshal([]byte(message.Payload), &pvValue)
|
||||
if err != nil {
|
||||
log.Printf("Unable to parse payload into pvValue struct, message %s -> %s is lost, error: %s", message.Topic, message.Payload, err)
|
||||
self.Lost("Unable to parse payload into pvValue struct", err, message)
|
||||
return
|
||||
}
|
||||
|
||||
@ -85,6 +77,7 @@ func (self *PvHandler) Handle(message handler.MessageT) {
|
||||
}
|
||||
|
||||
self.dbh.StoreMeasurement(&measurement)
|
||||
self.S()
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user