69 lines
2.3 KiB
Go
69 lines
2.3 KiB
Go
package dinet
|
|
|
|
import (
|
|
"errors"
|
|
"io"
|
|
"time"
|
|
|
|
"src.dualinventive.com/go/dinet/rpc"
|
|
"src.dualinventive.com/go/lib/dilog"
|
|
)
|
|
|
|
// ErrInvalidTransportType is returned when the callback Transport returns an invalid transport type
|
|
var ErrInvalidTransportType = errors.New("invalid transport type")
|
|
|
|
// VersionCallback is a callback function which returns all device version numbers
|
|
type VersionCallback func() (rpc.VersionMap, rpc.ErrorCode)
|
|
|
|
// ConfigSetCallback is a callback type for config:set operations
|
|
type ConfigSetCallback func(rpc.ConfigParam) rpc.ErrorCode
|
|
|
|
// ConfigResetCallback is a callback type for config:reset operations
|
|
type ConfigResetCallback func() rpc.ErrorCode
|
|
|
|
type deviceConfig struct {
|
|
c rpc.Config
|
|
get RPCCallback
|
|
set ConfigSetCallback
|
|
reset ConfigResetCallback
|
|
}
|
|
|
|
// Device is the most basic dinet device
|
|
type Device interface {
|
|
io.Closer
|
|
UID() string
|
|
}
|
|
|
|
// DeviceInfo contains information about the device. This is used for the ChildDevice
|
|
type DeviceInfo interface {
|
|
Device
|
|
Versions() (rpc.VersionMap, rpc.ErrorCode)
|
|
TimeoutDuration() time.Duration
|
|
Transport() (interface{}, rpc.ErrorCode)
|
|
Type() rpc.DeviceType
|
|
}
|
|
|
|
// ParentDevice is a dinet devices that can contains children
|
|
type ParentDevice interface {
|
|
Device
|
|
// RegisterUID is called when the child device wants to register his UID on the connection. No administration
|
|
// is allowed
|
|
RegisterUID(uid string) error
|
|
// UnregisterUID is called when the child device wants to unregister his UID on the connection. No
|
|
// administration is allowed
|
|
UnregisterUID(uid string) error
|
|
// RegisterDevice is called when the child device wants to register. You can change your administration and
|
|
// call RegisterUID after your administration
|
|
RegisterDevice(device Device) error
|
|
// UnregisterDevice is called when the child device wants to unregister. You can change your administration
|
|
// and call UnregisterUID after your administration
|
|
UnregisterDevice(uid string) error
|
|
// Router returns the router which the child can use to subscribe to events
|
|
Router() *Router
|
|
// Logger returns a logger which the child can use to log data. It is the childs responsibility to rewrite the
|
|
// device:uid and device:type fields
|
|
Logger() dilog.Logger
|
|
// Search searches the uid in the children
|
|
Search(uid string) (Device, error)
|
|
}
|