state

package
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 10, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanStates

func CleanStates(in map[string]interface{}) (out map[string]interface{})

func GetTemplateParameterList

func GetTemplateParameterList(str string) (result []string, err error)
Example
templ := `
Hello {{name}}
You have just won {{value}} dollars!
{{#in_ca}}
Well, {{taxed_value}} dollars, after taxes.
{{/in_ca}}
`
fmt.Println(GetTemplateParameterList(templ))
Output:

[name value in_ca taxed_value] <nil>

func RenderTempl

func RenderTempl(templ string, parameter interface{}) (result string, err error)

Types

type ChangeRoutine

type ChangeRoutine struct {
	Id       string `json:"id" bson:"id"`
	Interval int64  `json:"interval" bson:"interval"`
	Code     string `json:"code" bson:"code"`
}

type ChangeRoutineIndexElement

type ChangeRoutineIndexElement struct {
	Id      string
	RefType string // "world" || "room" || "device"
	RefId   string
}

type ChangeRoutineResponse

type ChangeRoutineResponse struct {
	Id       string `json:"id"`
	RefType  string `json:"ref_type"` // "world" || "room" || "device"
	RefId    string `json:"ref_id"`
	Interval int64  `json:"interval"`
	Code     string `json:"code"`
}

type CreateChangeRoutineByTemplateRequest

type CreateChangeRoutineByTemplateRequest struct {
	RefType   string            `json:"ref_type"` // "world" || "room" || "device"
	RefId     string            `json:"ref_id"`
	TemplId   string            `json:"templ_id"`
	Interval  int64             `json:"interval"`
	Parameter map[string]string `json:"parameter"`
}

{ref_type:"workd|room|device", ref_id: "", templ_id: "", name: "", desc: "", parameter: {<<param_name>>: <<param_value>>}}

type CreateChangeRoutineRequest

type CreateChangeRoutineRequest struct {
	RefType  string `json:"ref_type"` // "world" || "room" || "device"
	RefId    string `json:"ref_id"`
	Interval int64  `json:"interval"`
	Code     string `json:"code"`
}

{ref_type:"workd|room|device", ref_id: "", interval: 0, code:""}

type CreateDeviceByTypeRequest

type CreateDeviceByTypeRequest struct {
	DeviceTypeId string `json:"device_type_id"`
	Room         string `json:"room"`
	Name         string `json:"name"`
}

type CreateDeviceRequest

type CreateDeviceRequest struct {
	Room        string                 `json:"room"`
	Name        string                 `json:"name"`
	States      map[string]interface{} `json:"states"`
	ExternalRef string                 `json:"external_ref"` //platform intern device id; 1:1
}

type CreateRoomRequest

type CreateRoomRequest struct {
	World  string                 `json:"world"`
	Name   string                 `json:"name"`
	States map[string]interface{} `json:"states"`
}

type CreateServiceRequest

type CreateServiceRequest struct {
	Device         string `json:"device"`
	Name           string `json:"name"`
	ExternalRef    string `json:"external_ref"` //platform intern service id, will be used to populate Service.Marshaller and as endpoint for the Connector
	SensorInterval int64  `json:"sensor_interval"`
	Code           string `json:"code"`
}

type CreateTemplateRequest

type CreateTemplateRequest struct {
	Name        string `json:"name"`
	Description string `json:"description"`
	Template    string `json:"template"`
}

type CreateWorldRequest

type CreateWorldRequest struct {
	Name   string                 `json:"name"`
	States map[string]interface{} `json:"states"`
}

type Device

type Device struct {
	Id             string                   `json:"id" bson:"id"`
	Name           string                   `json:"name" bson:"name"`
	ImageUrl       string                   `json:"image_url" bson:"image_url"`
	ExternalTypeId string                   `json:"external_type_id" bson:"external_type_id"`
	ExternalRef    string                   `json:"external_ref" bson:"external_ref"` //platform intern device id; 1:1
	States         map[string]interface{}   `json:"states" bson:"states"`
	ChangeRoutines map[string]ChangeRoutine `json:"change_routines" bson:"change_routines"`
	Services       map[string]Service       `json:"services" bson:"services"`
}

func (*Device) CleanStates

func (this *Device) CleanStates()

func (Device) ToMsg

func (this Device) ToMsg() (result DeviceMsg, err error)

type DeviceMsg

type DeviceMsg struct {
	Id             string                   `json:"id"`
	Name           string                   `json:"name"`
	ExternalTypeId string                   `json:"external_type_id"`
	ExternalRef    string                   `json:"external_ref"` //platform intern device id; 1:1
	States         map[string]interface{}   `json:"states"`
	ChangeRoutines map[string]ChangeRoutine `json:"change_routines"`
	Services       map[string]Service       `json:"services"`
}

func (*DeviceMsg) CleanStates

func (this *DeviceMsg) CleanStates()

func (DeviceMsg) ToModel

func (this DeviceMsg) ToModel() (result Device, err error)

type DeviceResponse

type DeviceResponse struct {
	World  string    `json:"world"`
	Room   string    `json:"room"`
	Device DeviceMsg `json:"device"`
}

type Graph

type Graph struct {
	Id     string  `json:"id" bson:"id"`
	Name   string  `json:"name" bson:"name"`
	Values []Point `json:"values" bson:"values"`
}

type MongoPersistence

type MongoPersistence struct {
	// contains filtered or unexported fields
}

func NewMongoPersistence

func NewMongoPersistence(config config.Config) (result MongoPersistence, err error)

func (*MongoPersistence) Close

func (this *MongoPersistence) Close()

func (MongoPersistence) DeleteGraph

func (this MongoPersistence) DeleteGraph(id string) (err error)

func (MongoPersistence) DeleteTemplate

func (this MongoPersistence) DeleteTemplate(id string) (err error)

func (MongoPersistence) DeleteWorld

func (this MongoPersistence) DeleteWorld(id string) (err error)

func (MongoPersistence) GetTemplate

func (this MongoPersistence) GetTemplate(id string) (templ RoutineTemplate, err error)

func (MongoPersistence) GetTemplates

func (this MongoPersistence) GetTemplates() (templ []RoutineTemplate, err error)

func (MongoPersistence) LoadGraphs

func (this MongoPersistence) LoadGraphs() (result map[string]*Graph, err error)

func (MongoPersistence) LoadWorlds

func (this MongoPersistence) LoadWorlds() (result map[string]*World, err error)

func (MongoPersistence) PersistGraph

func (this MongoPersistence) PersistGraph(graph Graph) (err error)

func (MongoPersistence) PersistTemplate

func (this MongoPersistence) PersistTemplate(templ RoutineTemplate) (err error)

func (MongoPersistence) PersistWorld

func (this MongoPersistence) PersistWorld(world World) (err error)

type PersistenceInterface

type PersistenceInterface interface {
	PersistWorld(world World) (err error)
	PersistGraph(graph Graph) (err error)
	PersistTemplate(templ RoutineTemplate) error
	LoadWorlds() (map[string]*World, error)
	LoadGraphs() (map[string]*Graph, error)
	GetTemplate(id string) (templ RoutineTemplate, err error)
	GetTemplates() (templ []RoutineTemplate, err error)
	DeleteWorld(id string) error
	DeleteGraph(id string) error
	DeleteTemplate(id string) error
}

type Point

type Point struct {
	X float64 `json:"x" bson:"x"`
	Y float64 `json:"y" bson:"y"`
}

type Room

type Room struct {
	Id             string                   `json:"id" bson:"id"`
	Name           string                   `json:"name" bson:"name"`
	States         map[string]interface{}   `json:"states" bson:"states"`
	Devices        map[string]*Device       `json:"devices" bson:"devices"`
	ChangeRoutines map[string]ChangeRoutine `json:"change_routines" bson:"change_routines"`
}

func (*Room) CleanStates

func (this *Room) CleanStates()

func (Room) ToMsg

func (this Room) ToMsg() (result RoomMsg, err error)

type RoomMsg

type RoomMsg struct {
	Id             string                   `json:"id"`
	Name           string                   `json:"name"`
	States         map[string]interface{}   `json:"states"`
	Devices        map[string]DeviceMsg     `json:"devices"`
	ChangeRoutines map[string]ChangeRoutine `json:"change_routines"`
}

func (*RoomMsg) CleanStates

func (this *RoomMsg) CleanStates()

func (RoomMsg) ToModel

func (this RoomMsg) ToModel() (result Room, err error)

type RoomResponse

type RoomResponse struct {
	World string  `json:"world"`
	Room  RoomMsg `json:"room"`
}

type RoutineTemplate

type RoutineTemplate struct {
	Id          string   `json:"id" bson:"id"`
	Name        string   `json:"name" bson:"name"`
	Description string   `json:"description" bson:"description"`
	Template    string   `json:"template" bson:"template"`
	Parameter   []string `json:"parameter" bson:"parameter"`
}

type Service

type Service struct {
	Id             string `json:"id" bson:"id"`
	Name           string `json:"name" bson:"name"`
	ExternalRef    string `json:"external_ref" bson:"external_ref"` //platform intern service id, will be used to populate Service.Marshaller and as endpoint for the Connector
	SensorInterval int64  `json:"sensor_interval" bson:"sensor_interval"`
	Code           string `json:"code"`
}

type ServiceResponse

type ServiceResponse struct {
	World   string               `json:"world"`
	Room    string               `json:"room"`
	Device  string               `json:"device"`
	Service UpdateServiceRequest `json:"service"`
}

type StateRepo

type StateRepo struct {
	Worlds      map[string]*World
	Graphs      map[string]*Graph
	Persistence PersistenceInterface
	Connector   *platform_connector_lib.Connector
	Config      config.Config

	MosesProtocolId string
	StateLogger     connectionlog.Logger
	// contains filtered or unexported fields
}

func (*StateRepo) CreateChangeRoutine

func (this *StateRepo) CreateChangeRoutine(jwt jwt.Jwt, msg CreateChangeRoutineRequest) (result ChangeRoutineResponse, access bool, exists bool, err error)

func (*StateRepo) CreateChangeRoutineByTemplate

func (this *StateRepo) CreateChangeRoutineByTemplate(jwt jwt.Jwt, msg CreateChangeRoutineByTemplateRequest) (routine ChangeRoutineResponse, access bool, exists bool, err error)

func (*StateRepo) CreateDevice

func (this *StateRepo) CreateDevice(jwt jwt.Jwt, msg CreateDeviceRequest) (device DeviceResponse, access bool, worldAndExists bool, err error)

func (*StateRepo) CreateDeviceByType

func (this *StateRepo) CreateDeviceByType(jwt jwt.Jwt, msg CreateDeviceByTypeRequest) (result DeviceResponse, access bool, worldAndExists bool, err error)

func (*StateRepo) CreateProtocol

func (this *StateRepo) CreateProtocol(handler string, segments []model.ProtocolSegment) (protocol model.Protocol, err error)

func (*StateRepo) CreateRoom

func (this *StateRepo) CreateRoom(jwt jwt.Jwt, msg CreateRoomRequest) (room RoomResponse, access bool, worldExists bool, err error)

func (*StateRepo) CreateService

func (this *StateRepo) CreateService(jwt jwt.Jwt, msg CreateServiceRequest) (service ServiceResponse, access bool, worldAndExists bool, err error)

func (*StateRepo) CreateTemplate

func (this *StateRepo) CreateTemplate(jwt jwt.Jwt, request CreateTemplateRequest) (result RoutineTemplate, err error)

func (*StateRepo) CreateWorld

func (this *StateRepo) CreateWorld(jwt jwt.Jwt, msg CreateWorldRequest) (world WorldMsg, err error)

func (*StateRepo) DeleteChangeRoutine

func (this *StateRepo) DeleteChangeRoutine(jwt jwt.Jwt, id string) (routine ChangeRoutineResponse, access bool, exists bool, err error)

func (*StateRepo) DeleteDevice

func (this *StateRepo) DeleteDevice(jwt jwt.Jwt, id string) (device DeviceResponse, access bool, exists bool, err error)

func (*StateRepo) DeleteExternalDevice

func (this *StateRepo) DeleteExternalDevice(jwt jwt.Jwt, id string) (err error)

func (*StateRepo) DeleteRoom

func (this *StateRepo) DeleteRoom(jwt jwt.Jwt, id string) (room RoomResponse, access bool, exists bool, err error)

func (*StateRepo) DeleteService

func (this *StateRepo) DeleteService(jwt jwt.Jwt, id string) (service ServiceResponse, access bool, exists bool, err error)

func (*StateRepo) DeleteTemplate

func (this *StateRepo) DeleteTemplate(jwt jwt.Jwt, id string) (err error)

func (*StateRepo) DeleteWorld

func (this *StateRepo) DeleteWorld(jwt jwt.Jwt, id string) (access bool, exists bool, err error)

func (*StateRepo) DevDeleteWorld

func (this *StateRepo) DevDeleteWorld(id string) (err error)

func (*StateRepo) DevGetWorld

func (this *StateRepo) DevGetWorld(id string) (world WorldMsg, exist bool, err error)

func (*StateRepo) DevUpdateDevice

func (this *StateRepo) DevUpdateDevice(worldId string, roomId string, device DeviceMsg) (err error)

Update for HTTP-DEV-API Stops all change routines and redeploys new world with new room and device requests a mutex lock on the state repo

func (*StateRepo) DevUpdateRoom

func (this *StateRepo) DevUpdateRoom(worldId string, room RoomMsg) (err error)

Update for HTTP-DEV-API Stops all change routines and redeploys new world with new room requests a mutex lock on the state repo

func (*StateRepo) DevUpdateWorld

func (this *StateRepo) DevUpdateWorld(worldMsg WorldMsg) (err error)

Update for HTTP-DEV-API Stops all change routines and redeploys new world requests a mutex lock on the state repo

func (*StateRepo) EnsureProtocol

func (this *StateRepo) EnsureProtocol(handler string, segments []model.ProtocolSegment) (protocolId string, err error)

func (*StateRepo) GenerateExternalDevice

func (this *StateRepo) GenerateExternalDevice(jwt jwt.Jwt, request CreateDeviceByTypeRequest) (device model.Device, err error)

func (*StateRepo) GetIotDeviceType

func (this *StateRepo) GetIotDeviceType(jwt jwt.Jwt, id string) (dt model.DeviceType, err error)

func (*StateRepo) GetIotDeviceTypes

func (this *StateRepo) GetIotDeviceTypes(jwt jwt.Jwt) (result []model.DeviceType, err error)

func (*StateRepo) GetIotDeviceTypesIds

func (this *StateRepo) GetIotDeviceTypesIds(jwt jwt.Jwt) (result []string, err error)

func (*StateRepo) GetMosesDeviceTypesIds

func (this *StateRepo) GetMosesDeviceTypesIds(jwt jwt.Jwt) (result []string, err error)

func (*StateRepo) GetProtocolList

func (this *StateRepo) GetProtocolList(handler string) (result []map[string]interface{}, err error)

func (*StateRepo) HandleCommand

func (this *StateRepo) HandleCommand(externalDeviceRef string, externalServiceRef string, cmdMsg interface{}, responder func(respMsg interface{}))

func (*StateRepo) Load

func (this *StateRepo) Load() (err error)

Stops all change routines if any are running and loads state repo from the database (no restart of change routines)

func (*StateRepo) PopulateServiceService

func (this *StateRepo) PopulateServiceService(jwt jwt.Jwt, serviceMsg UpdateServiceRequest) (service Service, err error)

func (*StateRepo) ReadChangeRoutine

func (this *StateRepo) ReadChangeRoutine(jwt jwt.Jwt, id string) (routine ChangeRoutineResponse, access bool, exists bool, err error)

func (*StateRepo) ReadDevice

func (this *StateRepo) ReadDevice(jwt jwt.Jwt, id string) (device DeviceResponse, access bool, exists bool, err error)

func (*StateRepo) ReadRoom

func (this *StateRepo) ReadRoom(jwt jwt.Jwt, id string) (room RoomResponse, access bool, exists bool, err error)

func (*StateRepo) ReadService

func (this *StateRepo) ReadService(jwt jwt.Jwt, id string) (service ServiceResponse, access bool, exists bool, err error)

func (*StateRepo) ReadTemplate

func (this *StateRepo) ReadTemplate(jwt jwt.Jwt, id string) (result RoutineTemplate, exists bool, err error)

func (*StateRepo) ReadTemplates

func (this *StateRepo) ReadTemplates(jwt jwt.Jwt) (result []RoutineTemplate, err error)

func (*StateRepo) ReadWorld

func (this *StateRepo) ReadWorld(jwt jwt.Jwt, id string) (world WorldMsg, access bool, exists bool, err error)

func (*StateRepo) ReadWorlds

func (this *StateRepo) ReadWorlds(jwt jwt.Jwt) (worlds []WorldMsg, err error)

func (*StateRepo) RunService

func (this *StateRepo) RunService(serviceId string, cmdMsg interface{}) (resp interface{}, err error)

func (*StateRepo) Start

func (this *StateRepo) Start()

starts change routines; will first call stop() to prevent overpopulation of change routines if error occurs, the state repo may be in a partially running state which can not be stopped with Stop() in this case a panic occurs

func (*StateRepo) StartDevice

func (this *StateRepo) StartDevice(world *World, room *Room, device *Device) (tickers []*time.Ticker, stops []chan bool, err error)

func (*StateRepo) StartRoom

func (this *StateRepo) StartRoom(world *World, room *Room) (tickers []*time.Ticker, stops []chan bool, err error)

func (*StateRepo) StartService

func (this *StateRepo) StartService(world *World, room *Room, device *Device, service Service) (tickers []*time.Ticker, stops []chan bool, err error)

func (*StateRepo) StartWorld

func (this *StateRepo) StartWorld(world *World) (tickers []*time.Ticker, stops []chan bool, err error)

func (*StateRepo) Stop

func (this *StateRepo) Stop() (err error)

stops all change routines; may be called repeatedly while already stopped ore not started

func (*StateRepo) UpdateChangeRoutine

func (this *StateRepo) UpdateChangeRoutine(jwt jwt.Jwt, msg UpdateChangeRoutineRequest) (routine ChangeRoutineResponse, access bool, exists bool, err error)

func (*StateRepo) UpdateChangeRoutineByTemplate

func (this *StateRepo) UpdateChangeRoutineByTemplate(jwt jwt.Jwt, msg UpdateChangeRoutineByTemplateRequest) (routine ChangeRoutineResponse, access bool, exists bool, err error)

func (*StateRepo) UpdateDevice

func (this *StateRepo) UpdateDevice(jwt jwt.Jwt, msg UpdateDeviceRequest) (device DeviceResponse, access bool, exists bool, err error)

func (*StateRepo) UpdateRoom

func (this *StateRepo) UpdateRoom(jwt jwt.Jwt, msg UpdateRoomRequest) (room RoomResponse, access bool, exists bool, err error)

func (*StateRepo) UpdateService

func (this *StateRepo) UpdateService(jwt jwt.Jwt, msg UpdateServiceRequest) (service ServiceResponse, access bool, exists bool, err error)

func (*StateRepo) UpdateTemplate

func (this *StateRepo) UpdateTemplate(jwt jwt.Jwt, request UpdateTemplateRequest) (result RoutineTemplate, exists bool, err error)

func (*StateRepo) UpdateWorld

func (this *StateRepo) UpdateWorld(jwt jwt.Jwt, msg UpdateWorldRequest) (world WorldMsg, access bool, exists bool, err error)

type UpdateChangeRoutineByTemplateRequest

type UpdateChangeRoutineByTemplateRequest struct {
	RoutineId string            `json:"routine_id""`
	TemplId   string            `json:"templ_id"`
	Interval  int64             `json:"interval"`
	Parameter map[string]string `json:"parameter"`
}

type UpdateChangeRoutineRequest

type UpdateChangeRoutineRequest struct {
	Id       string `json:"id"`
	Interval int64  `json:"interval"`
	Code     string `json:"code"`
}

type UpdateDeviceRequest

type UpdateDeviceRequest struct {
	Id             string                   `json:"id"`
	Name           string                   `json:"name"`
	States         map[string]interface{}   `json:"states"`
	ChangeRoutines map[string]ChangeRoutine `json:"change_routines"`
	Services       map[string]Service       `json:"services"`
	ExternalRef    string                   `json:"external_ref"` //platform intern device id; 1:1
}

type UpdateRoomRequest

type UpdateRoomRequest struct {
	Id             string                   `json:"id"`
	Name           string                   `json:"name"`
	States         map[string]interface{}   `json:"states"`
	ChangeRoutines map[string]ChangeRoutine `json:"change_routines"`
}

type UpdateServiceRequest

type UpdateServiceRequest struct {
	Id             string `json:"id"`
	Name           string `json:"name"`
	ExternalRef    string `json:"external_ref"` //platform intern service id
	SensorInterval int64  `json:"sensor_interval"`
	Code           string `json:"code"`
}

type UpdateTemplateRequest

type UpdateTemplateRequest struct {
	Id          string `json:"id"`
	Name        string `json:"name"`
	Description string `json:"description"`
	Template    string `json:"template"`
}

type UpdateWorldRequest

type UpdateWorldRequest struct {
	Id             string                   `json:"id"`
	Name           string                   `json:"name"`
	States         map[string]interface{}   `json:"states"`
	ChangeRoutines map[string]ChangeRoutine `json:"change_routines"`
}

type World

type World struct {
	Id             string                   `json:"id" bson:"id"`
	Owner          string                   `json:"-" bson:"owner"`
	Name           string                   `json:"name" bson:"name"`
	States         map[string]interface{}   `json:"states" bson:"states"`
	Rooms          map[string]*Room         `json:"rooms" bson:"rooms"`
	ChangeRoutines map[string]ChangeRoutine `json:"change_routines" bson:"change_routines"`
	// contains filtered or unexported fields
}

func (*World) CleanStates

func (this *World) CleanStates()

func (World) ToMsg

func (this World) ToMsg() (result WorldMsg, err error)

type WorldMsg

type WorldMsg struct {
	Id             string                   `json:"id"`
	Owner          string                   `json:"-"`
	Name           string                   `json:"name"`
	States         map[string]interface{}   `json:"states"`
	Rooms          map[string]RoomMsg       `json:"rooms"`
	ChangeRoutines map[string]ChangeRoutine `json:"change_routines"`
}

func (*WorldMsg) CleanStates

func (this *WorldMsg) CleanStates()

func (WorldMsg) ToModel

func (this WorldMsg) ToModel() (result World, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL