From 842e02191a8db7aa83229263e828ba05208d38f9 Mon Sep 17 00:00:00 2001 From: Malte Bauch <malte.bauch@stud.h-da.de> Date: Thu, 11 Feb 2021 14:21:18 +0100 Subject: [PATCH] added NewDevice() for Device --- nucleus/cli-handling.go | 18 ++++-------------- nucleus/device.go | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/nucleus/cli-handling.go b/nucleus/cli-handling.go index a1172fdbc..10e4842c0 100644 --- a/nucleus/cli-handling.go +++ b/nucleus/cli-handling.go @@ -222,19 +222,9 @@ func (s *server) AddDevice(ctx context.Context, in *pb.AddDeviceRequest) (*pb.Ad } transport.SetConfig(cfg) - newDevice := Device{ - SBI: sbi, - Config: DeviceConfig{ - Uuid: uuid.New(), - Address: in.Device.Address, - Username: in.Device.Username, - Password: in.Device.Password, - }, - Transport: transport, - } - newDevice.GoStruct = sbi.Schema().Root - devicesMap := pnd.GetDevices() - devicesMap[newDevice.Config.Uuid] = &newDevice + newDevice := NewDevice(sbi, in.Device.Address, in.Device.Username, + in.Device.Password, transport) + pnd.AddDevice(newDevice) return &pb.AddDeviceReply{Message: "Added new Device: " + newDevice.Config.Uuid.String()}, err } @@ -254,7 +244,7 @@ func (s *server) HandleDeviceGetRequest(ctx context.Context, in *pb.DeviceGetReq err := errors.New("Couldnt find PND: UUID is wrong") return &pb.DeviceGetReply{Message: err.Error()}, err } - device, exists := s.core.principalNetworkDomains[uuidPND].GetDevices()[uuidDevice] + device, exists := s.core.principalNetworkDomains[uuidPND].GetDevice(uuidDevice) if exists != true { err := errors.New("Couldnt find device: UUID is wrong") return &pb.DeviceGetReply{Message: err.Error()}, err diff --git a/nucleus/device.go b/nucleus/device.go index 86ea4a08b..d33e62b79 100644 --- a/nucleus/device.go +++ b/nucleus/device.go @@ -19,6 +19,21 @@ type Device struct { Transport Transport `json:"-"` } +func NewDevice(sbi SouthboundInterface, addr, username, password string, + transport Transport) *Device { + return &Device{ + GoStruct: sbi.Schema().Root, + SBI: sbi, + Config: DeviceConfig{ + Uuid: uuid.New(), + Address: addr, + Username: username, + Password: password, + }, + Transport: transport, + } +} + type DeviceConfig struct { Uuid uuid.UUID Address string -- GitLab