Documentation ¶
Index ¶
- Constants
- Variables
- func DebuggingEnabled() bool
- func EnableMQTTDebugLog(use_syslog bool)
- func GetStack() string
- func IsSubpath(basepath, maybeSubpath string) bool
- func MaybeInitProfiling(readyCh <-chan struct{})
- func SetDebugLogger(logger *log.Logger, keep bool)
- func SetDebuggingEnabled(enable bool)
- func Truename(filePath string) (string, error)
- func UseSyslog()
- func Visit(visitor interface{}, thing interface{}, prefix string, args ...interface{})
- type ContentTracker
- type Control
- type DeferredList
- type DeviceBase
- type DeviceModel
- type DeviceObserver
- type DirWatcher
- type DirWatcherClient
- type Driver
- func (drv *Driver) AcceptsExternalDevices() bool
- func (drv *Driver) AutoPoll() bool
- func (drv *Driver) CallSync(thunk func())
- func (drv *Driver) HandleMessageSync(thunk func())
- func (drv *Driver) OnError(dev DeviceModel, controlName, value string)
- func (drv *Driver) OnNewControl(dev LocalDeviceModel, control Control) string
- func (drv *Driver) OnNewDevice(dev DeviceModel)
- func (drv *Driver) OnValue(dev DeviceModel, controlName, value string)
- func (drv *Driver) Poll()
- func (drv *Driver) PollInterval() time.Duration
- func (drv *Driver) RemoveDevice(dev DeviceModel)
- func (drv *Driver) SetAcceptsExternalDevices(accepts bool)
- func (drv *Driver) SetAutoPoll(autoPoll bool)
- func (drv *Driver) SetPollInterval(pollInterval time.Duration)
- func (drv *Driver) Start() error
- func (drv *Driver) Stop()
- func (drv *Driver) WhenReady(thunk func())
- type ExtendedModel
- type ExternalDeviceModel
- type LocalDeviceModel
- type MQTTClient
- type MQTTMessage
- type MQTTMessageHandler
- type MQTTRPCServer
- type MQTTSubscriptionMap
- type Model
- type ModelBase
- type ModelObserver
- type PahoMQTTClient
- func (client *PahoMQTTClient) Publish(message MQTTMessage)
- func (client *PahoMQTTClient) Start()
- func (client *PahoMQTTClient) Stop()
- func (client *PahoMQTTClient) Subscribe(callback MQTTMessageHandler, topics ...string)
- func (client *PahoMQTTClient) Unsubscribe(topics ...string)
- func (client *PahoMQTTClient) WaitForReady() <-chan struct{}
- type RPCError
- type RTimer
- type RealRTimer
- type RealTicker
- type RealTimer
- type Timer
- type Writability
Constants ¶
const ( RELOAD_DELAY = 1000 * time.Millisecond DIRWATCHER_OP_LIST_CAPACITY = 128 DIRWATCHER_OP_CHANGE = dirWatcherOpType(iota) DIRWATCHER_OP_REMOVE )
const ( EVENT_QUEUE_LEN = 100 DEFAULT_POLL_INTERVAL = 5 * time.Second CONTROL_LIST_CAPACITY = 32 DefaultWritability Writability = iota ForceReadOnly ForceWritable )
const ( DISCONNECT_WAIT_MS = 100 TOKEN_QUEUE_LEN = 512 )
const ( RPC_MESSAGE_QUEUE_LEN = 32 RPC_APP_PREFIX = "/rpc/v1/" RPC_RESERVED_CODE_MIN = -32700 RPC_RESERVED_CODE_MAX = -32000 )
const DEFERRED_CAPACITY = 256
Variables ¶
Functions ¶
func DebuggingEnabled ¶
func DebuggingEnabled() bool
func EnableMQTTDebugLog ¶
func EnableMQTTDebugLog(use_syslog bool)
func IsSubpath ¶
IsSubpath returns true if maybeSubpath is a subpath of basepath. It uses filepath to be compatible with os-dependent paths.
func MaybeInitProfiling ¶
func MaybeInitProfiling(readyCh <-chan struct{})
func SetDebugLogger ¶
func SetDebuggingEnabled ¶
func SetDebuggingEnabled(enable bool)
Types ¶
type ContentTracker ¶
func NewContentTracker ¶
func NewContentTracker() *ContentTracker
type Control ¶
type Control struct { Name string Title string Type string Value string Units string Writability Writability HasMax bool Max float64 Forget bool Order int }
type DeferredList ¶
func NewDeferredList ¶
func NewDeferredList(executor func(func())) *DeferredList
func (*DeferredList) MaybeDefer ¶
func (dl *DeferredList) MaybeDefer(thunk func())
func (*DeferredList) Ready ¶
func (dl *DeferredList) Ready()
type DeviceBase ¶
type DeviceBase struct { DevName string DevTitle string Observer DeviceObserver }
func (*DeviceBase) Name ¶
func (dev *DeviceBase) Name() string
func (*DeviceBase) Observe ¶
func (dev *DeviceBase) Observe(observer DeviceObserver)
func (*DeviceBase) SetTitle ¶
func (dev *DeviceBase) SetTitle(title string)
func (*DeviceBase) Title ¶
func (dev *DeviceBase) Title() string
type DeviceModel ¶
type DeviceModel interface { Name() string Title() string Observe(observer DeviceObserver) // AcceptValue accepts the specified control value sent via an MQTT value topic // (not .../on). For local devices, that can be a retained value, for external // devices, the current control value AcceptValue(name, value string) }
type DeviceObserver ¶
type DeviceObserver interface { OnNewControl(dev LocalDeviceModel, control Control) string OnValue(dev DeviceModel, name, value string) OnError(dev DeviceModel, name, value string) }
type DirWatcher ¶
type DirWatcher struct {
// contains filtered or unexported fields
}
func NewDirWatcher ¶
func NewDirWatcher(pattern string, client DirWatcherClient) *DirWatcher
func (*DirWatcher) Load ¶
func (dw *DirWatcher) Load(filePath string) error
func (*DirWatcher) SetDelay ¶
func (dw *DirWatcher) SetDelay(delay time.Duration)
func (*DirWatcher) Stop ¶
func (dw *DirWatcher) Stop()
type DirWatcherClient ¶
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
Driver transfers data between Model with MQTTClient
func NewDriver ¶
func NewDriver(model Model, client MQTTClient) (drv *Driver)
func (*Driver) AcceptsExternalDevices ¶
func (*Driver) HandleMessageSync ¶
func (drv *Driver) HandleMessageSync(thunk func())
func (*Driver) OnError ¶
func (drv *Driver) OnError(dev DeviceModel, controlName, value string)
func (*Driver) OnNewControl ¶
func (drv *Driver) OnNewControl(dev LocalDeviceModel, control Control) string
func (*Driver) OnNewDevice ¶
func (drv *Driver) OnNewDevice(dev DeviceModel)
func (*Driver) OnValue ¶
func (drv *Driver) OnValue(dev DeviceModel, controlName, value string)
func (*Driver) PollInterval ¶
func (*Driver) RemoveDevice ¶
func (drv *Driver) RemoveDevice(dev DeviceModel)
func (*Driver) SetAcceptsExternalDevices ¶
func (*Driver) SetAutoPoll ¶
func (*Driver) SetPollInterval ¶
type ExtendedModel ¶
type ExtendedModel interface { Model AddExternalDevice(name string) (ExternalDeviceModel, error) }
ExtendedModel is a Model that supports external devices
type ExternalDeviceModel ¶
type ExternalDeviceModel interface { DeviceModel SetTitle(title string) AcceptControlType(name, controlType string) AcceptControlRange(name string, max float64) }
type LocalDeviceModel ¶
type LocalDeviceModel interface { DeviceModel // AcceptOnValue accepts the specified control value sent via an MQTT .../on topic // for the target device and returns true if the value should be automatically // echoed back AcceptOnValue(name, value string) bool IsVirtual() bool }
type MQTTClient ¶
type MQTTClient interface { WaitForReady() <-chan struct{} Start() Stop() Publish(message MQTTMessage) Subscribe(callback MQTTMessageHandler, topics ...string) Unsubscribe(topics ...string) }
type MQTTMessageHandler ¶
type MQTTMessageHandler func(message MQTTMessage)
type MQTTRPCServer ¶
func NewMQTTRPCServer ¶
func NewMQTTRPCServer(appName string, mqttClient MQTTClient) (server *MQTTRPCServer)
func (*MQTTRPCServer) Register ¶
func (server *MQTTRPCServer) Register(rcvr interface{}) error
Register publishes in the server the set of methods of the receiver value that satisfy the following conditions:
- exported method
- two arguments, both of exported type
- the second argument is a pointer
- one return value, of type error
It returns an error if the receiver is not an exported type or has no suitable methods. It also logs the error using package log. The client accesses each method using a string of the form "Type.Method", where Type is the receiver's concrete type.
func (*MQTTRPCServer) RegisterName ¶
func (server *MQTTRPCServer) RegisterName(name string, rcvr interface{}) error
RegisterName is like Register but uses the provided name for the type instead of the receiver's concrete type.
func (*MQTTRPCServer) Start ¶
func (server *MQTTRPCServer) Start()
func (*MQTTRPCServer) Stop ¶
func (server *MQTTRPCServer) Stop()
type MQTTSubscriptionMap ¶
type MQTTSubscriptionMap map[string][]MQTTMessageHandler
type Model ¶
type Model interface { Start() error Stop() Observe(observer ModelObserver) Poll() }
type ModelBase ¶
type ModelBase struct {
Observer ModelObserver
}
func (*ModelBase) Observe ¶
func (model *ModelBase) Observe(observer ModelObserver)
type ModelObserver ¶
type ModelObserver interface { CallSync(thunk func()) WhenReady(thunk func()) RemoveDevice(dev DeviceModel) OnNewDevice(dev DeviceModel) }
type PahoMQTTClient ¶
type PahoMQTTClient struct {
// contains filtered or unexported fields
}
func NewPahoMQTTClient ¶
func NewPahoMQTTClient(server, clientID string, waitForRetained bool) (client *PahoMQTTClient)
func (*PahoMQTTClient) Publish ¶
func (client *PahoMQTTClient) Publish(message MQTTMessage)
func (*PahoMQTTClient) Start ¶
func (client *PahoMQTTClient) Start()
func (*PahoMQTTClient) Stop ¶
func (client *PahoMQTTClient) Stop()
func (*PahoMQTTClient) Subscribe ¶
func (client *PahoMQTTClient) Subscribe(callback MQTTMessageHandler, topics ...string)
func (*PahoMQTTClient) Unsubscribe ¶
func (client *PahoMQTTClient) Unsubscribe(topics ...string)
func (*PahoMQTTClient) WaitForReady ¶
func (client *PahoMQTTClient) WaitForReady() <-chan struct{}
type RTimer ¶
type RTimer interface { // embed generic Timer here Timer // Reset changes the timer to expire after new duration d Reset(d time.Duration) }
RTimer is reusable Timer with Reset method
type RealRTimer ¶
type RealRTimer struct {
RealTimer
}
RealRTimer incapsulates a real time.Timer with Reset() method
func NewRealRTimer ¶
func NewRealRTimer(d time.Duration) *RealRTimer
func (*RealRTimer) Reset ¶
func (timer *RealRTimer) Reset(d time.Duration)
Reset resets an existing timer or creates a new one with given duration
type RealTicker ¶
type RealTicker struct {
// contains filtered or unexported fields
}
RealTicker incapsulates a real time.Ticker
func NewRealTicker ¶
func NewRealTicker(d time.Duration) *RealTicker
func (*RealTicker) GetChannel ¶
func (ticker *RealTicker) GetChannel() <-chan time.Time
func (*RealTicker) Stop ¶
func (ticker *RealTicker) Stop()
type RealTimer ¶
type RealTimer struct {
// contains filtered or unexported fields
}
RealTimer incapsulates a real time.Ticker
func NewRealTimer ¶
func (*RealTimer) GetChannel ¶
type Timer ¶
type Timer interface { // GetChannel retrieves a channel that signals timer expiration GetChannel() <-chan time.Time // Stop stops the timer Stop() }
Timer is fakeable timer interface
type Writability ¶
type Writability int