43 lines
990 B
Go
43 lines
990 B
Go
package daemon
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"src.dualinventive.com/go/devsim/simulator"
|
|
"src.dualinventive.com/go/devsim/storage"
|
|
"src.dualinventive.com/go/dinet/rpc"
|
|
"src.dualinventive.com/go/lib/kv"
|
|
)
|
|
|
|
// Storage for saving the state of the daemon
|
|
type Storage interface {
|
|
GetDeviceStorage(deviceUID string) simulator.Storage
|
|
GetNextDeviceUID() (string, error)
|
|
}
|
|
|
|
// RAMStorage for stor
|
|
type RAMStorage struct {
|
|
simUID uint64
|
|
}
|
|
|
|
// GetDeviceStorage creates a new in-ram storage for the simulator
|
|
func (r *RAMStorage) GetDeviceStorage(deviceUID string) simulator.Storage {
|
|
dStorage, err := storage.NewKV(deviceUID, kv.TypeRAM, "")
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
return dStorage
|
|
}
|
|
|
|
// GetNextDeviceUID generates unique device uids
|
|
func (r *RAMStorage) GetNextDeviceUID() (string, error) {
|
|
uid := fmt.Sprintf("FF%016x", r.simUID)
|
|
uid, err := rpc.GenerateDeviceUID(rpc.DeviceUIDPrefixSimulator, uid)
|
|
if err != nil {
|
|
return "", ErrCannotCreateDeviceUID
|
|
}
|
|
|
|
r.simUID++
|
|
return uid, nil
|
|
}
|