server

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exist

func Exist(name string) bool

Types

type Attribute

type Attribute struct {
	ID        int         `json:"id"`
	Attribute string      `json:"attribute"`
	Val       interface{} `json:"val"`
	ValType   string      `json:"val_type"`
	Min       *int        `json:"min,omitempty"`
	Max       *int        `json:"max,omitempty"`
}

type Device

type Device interface {
	Identity() string
	Info() DeviceInfo
	Setup() error
	Online() bool
	Update() error
	Close() error
	GetChannel() WatchChan
}

type DeviceInfo

type DeviceInfo struct {
	Identity     string
	Model        string
	Manufacturer string
}

type Instance

type Instance struct {
	Type       string      `json:"type"`
	InstanceId int         `json:"instance_id"`
	Attributes []Attribute `json:"attributes"`
}

type Manager

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

func NewManager

func NewManager() *Manager

func (*Manager) AddDevice

func (p *Manager) AddDevice(device Device) error

AddDevice 添加设备

func (*Manager) Devices

func (p *Manager) Devices() (ds []Device, err error)

func (*Manager) GetAttributes

func (p *Manager) GetAttributes(identity string) (s []Instance, err error)

func (*Manager) HealthCheck

func (p *Manager) HealthCheck(identity string) bool

func (*Manager) Init

func (p *Manager) Init()

func (*Manager) Notify

func (p *Manager) Notify(identity string, instanceID int, attr *utils.Attribute) attribute.NotifyFunc

func (*Manager) RemoveDevice

func (p *Manager) RemoveDevice(identity string) error

RemoveDevice 删除设备

func (*Manager) SetAttribute

func (p *Manager) SetAttribute(identity string, instanceID int, attr string, val interface{}) (err error)

func (*Manager) Subscribe

func (p *Manager) Subscribe(notify chan Notify)

func (*Manager) Unsubscribe

func (p *Manager) Unsubscribe(notify chan Notify)

func (*Manager) WatchNotify

func (p *Manager) WatchNotify(device Device)

type Notification

type Notification struct {
	Identity   string
	InstanceID int
	Attr       string
	Val        interface{}
}

type Notify

type Notify struct {
	Identity   string    `json:"identity"`
	InstanceID int       `json:"instance_id"`
	Attribute  Attribute `json:"attribute"`
}

type OptionFunc

type OptionFunc func(s *Server)

func WithConfigFile

func WithConfigFile(configFile string) OptionFunc

func WithStatic

func WithStatic(staticDir string) OptionFunc

type Server

type Server struct {
	Manager   *Manager
	Domain    string
	Router    *gin.Engine
	ApiRouter *gin.RouterGroup
	// contains filtered or unexported fields
}

func NewPluginServer

func NewPluginServer(domain string, opts ...OptionFunc) *Server

func (Server) Discover

func (p Server) Discover(request *proto.Empty, server proto.Plugin_DiscoverServer) error

func (Server) GetAttributes

func (p Server) GetAttributes(context context.Context, request *proto.GetAttributesReq) (resp *proto.GetAttributesResp, err error)

func (Server) HealthCheck

func (p Server) HealthCheck(context context.Context, req *proto.HealthCheckReq) (resp *proto.HealthCheckResp, err error)

func (*Server) Init

func (p *Server) Init()

func (Server) SetAttributes

func (p Server) SetAttributes(context context.Context, request *proto.SetAttributesReq) (resp *proto.SetAttributesResp, err error)

func (Server) StateChange

func (p Server) StateChange(request *proto.Empty, server proto.Plugin_StateChangeServer) error

type SetAttribute

type SetAttribute struct {
	InstanceID int         `json:"instance_id"`
	Attribute  string      `json:"attribute"`
	Val        interface{} `json:"val"`
}

type SetRequest

type SetRequest struct {
	Attributes []SetAttribute `json:"attributes"`
}

type WatchChan

type WatchChan chan Notification

Jump to

Keyboard shortcuts

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