Documentation ¶
Index ¶
- Constants
- func ConnectControlEnvProxyServer(devId string, pool *DevicePool) (*grpc.ClientConn, error)
- func CreateHttpHandlers(pool *DevicePool, polledSet *PolledSet, config apiv1.InfraConfig, ...) *mux.Router
- func NewBadRequestError(msg string, e error) error
- func NewInternalError(msg string, e error) error
- func NewNotFoundError(msg string, e error) error
- func NewServiceUnavailableError(msg string, e error) error
- func PreRegister(c *JSONUnix, pool *DevicePool, msg *apiv1.PreRegisterMsg)
- func ReplyError(c JSONConn, msg string)
- func ReplyJSON(w http.ResponseWriter, obj interface{}, statusCode int) error
- func ReplyJSONErr(w http.ResponseWriter, err error) error
- func ReplyJSONOK(w http.ResponseWriter, obj interface{}) error
- func SetupControlEndpoint(pool *DevicePool, path string) (func() error, error)
- func SetupDeviceEndpoint(pool *DevicePool, config apiv1.InfraConfig, path string) (func() error, error)
- type AppError
- type Client
- type Device
- type DevicePool
- func (p *DevicePool) CancelPreRegistration(id string)
- func (p *DevicePool) DeviceIds() []string
- func (p *DevicePool) GetDevice(id string) *Device
- func (p *DevicePool) GetDeviceDescByGroupId(groupId string) []*apiv1.DeviceDescriptor
- func (p *DevicePool) GetDeviceDescList() []*apiv1.DeviceDescriptor
- func (p *DevicePool) GroupIds() []string
- func (p *DevicePool) PreRegister(Descriptor *apiv1.DeviceDescriptor, regCh chan bool) error
- func (p *DevicePool) Register(id string, conn *JSONUnix, port int, privateData interface{}) *Device
- func (p *DevicePool) Unregister(id string)
- type Group
- type JSONConn
- type JSONUnix
- type PolledClient
- type PolledSet
Constants ¶
const DEFAULT_GROUP_ID = "default"
Variables ¶
This section is empty.
Functions ¶
func ConnectControlEnvProxyServer ¶
func ConnectControlEnvProxyServer(devId string, pool *DevicePool) (*grpc.ClientConn, error)
Connect ControlEnvProxyServer
func CreateHttpHandlers ¶
func CreateHttpHandlers( pool *DevicePool, polledSet *PolledSet, config apiv1.InfraConfig, maybeIntercept func(string) *string) *mux.Router
Creates a router with handlers for the following endpoints: GET /infra_config GET /groups GET /devices GET /devices?groupId={groupId} GET /devices/{deviceId} GET /devices/{deviceId}/files/{path} GET /devices/{deviceId}/services GET /devices/{deviceId}/services/{serviceName} GET /devices/{deviceId}/services/{serviceName}/{methodName} POST /devices/{deviceId}/services/{serviceName}/{methodName} GET /devices/{deviceId}/services/{serviceName}/{typeName}/type GET /devices/{deviceId}/openwrt{path:/.*} POST /devices/{deviceId}/openwrt{path:/.*} GET /polled_connections GET /polled_connections/{connId}/messages POST /polled_connections/{connId}/:forward The maybeIntercept parameter is a function that accepts the requested device file and returns a path to a file to be returned instead or nil if the request should be allowed to proceed to the device.
func NewBadRequestError ¶
func NewInternalError ¶
func NewNotFoundError ¶
func PreRegister ¶
func PreRegister(c *JSONUnix, pool *DevicePool, msg *apiv1.PreRegisterMsg)
func ReplyJSON ¶
func ReplyJSON(w http.ResponseWriter, obj interface{}, statusCode int) error
Send a JSON http response to the client
func ReplyJSONErr ¶
func ReplyJSONErr(w http.ResponseWriter, err error) error
Send a JSON http response with error to the client
func ReplyJSONOK ¶
func ReplyJSONOK(w http.ResponseWriter, obj interface{}) error
Send a JSON http response with success status code to the client
func SetupControlEndpoint ¶
func SetupControlEndpoint(pool *DevicePool, path string) (func() error, error)
Sets up a unix socket for server control and returns a function that listens on the socket until an error occurrs.
func SetupDeviceEndpoint ¶
func SetupDeviceEndpoint(pool *DevicePool, config apiv1.InfraConfig, path string) (func() error, error)
Sets up a unix socket for devices to connect to and returns a function that listens on the socket until an error occurrs.
Types ¶
type AppError ¶
func (*AppError) JSONResponse ¶
type Client ¶
type Client interface { // Send a message to the device Send(msg interface{}) error // Provides an oportunity for the client to react to the device being disconnected OnDeviceDisconnected() }
type Device ¶
type Device struct { // Provided at pre-registration time Descriptor apiv1.DeviceDescriptor // Reverse proxy to the client files Proxy *httputil.ReverseProxy // contains filtered or unexported fields }
func (*Device) DisconnectClients ¶
func (d *Device) DisconnectClients()
Notify the clients that the device has disconnected
func (*Device) Unregister ¶
type DevicePool ¶
type DevicePool struct {
// contains filtered or unexported fields
}
Keeps track of the registered devices.
func NewDevicePool ¶
func NewDevicePool() *DevicePool
func (*DevicePool) CancelPreRegistration ¶
func (p *DevicePool) CancelPreRegistration(id string)
func (*DevicePool) DeviceIds ¶
func (p *DevicePool) DeviceIds() []string
List the registered devices' ids
func (*DevicePool) GetDevice ¶
func (p *DevicePool) GetDevice(id string) *Device
func (*DevicePool) GetDeviceDescByGroupId ¶
func (p *DevicePool) GetDeviceDescByGroupId(groupId string) []*apiv1.DeviceDescriptor
func (*DevicePool) GetDeviceDescList ¶
func (p *DevicePool) GetDeviceDescList() []*apiv1.DeviceDescriptor
func (*DevicePool) GroupIds ¶
func (p *DevicePool) GroupIds() []string
List the registered groups' ids
func (*DevicePool) PreRegister ¶
func (p *DevicePool) PreRegister(Descriptor *apiv1.DeviceDescriptor, regCh chan bool) error
PreRegister accepts a channel of boolean which it closes if the pre-registration is cancelled or sends the output of registering the device as a boolean.
func (*DevicePool) Register ¶
func (p *DevicePool) Register(id string, conn *JSONUnix, port int, privateData interface{}) *Device
Register a new device, returns false if a device with that id already exists
func (*DevicePool) Unregister ¶
func (p *DevicePool) Unregister(id string)
type JSONConn ¶
type JSONConn interface {
Send(val interface{}) error
}
Interface implemented by any connection capable of sending in JSON format
type JSONUnix ¶
type JSONUnix struct {
// contains filtered or unexported fields
}
A Unix socket connection (as returned by Accept) that can send and receive JSON objects. Only one thread should call Recv() at a time, Send and Close are thread safe
func NewJSONUnix ¶
type PolledClient ¶
type PolledClient struct {
// contains filtered or unexported fields
}
Implements the client interface using a polled connection
func (*PolledClient) ClientId ¶
func (c *PolledClient) ClientId() int
func (*PolledClient) GetMessages ¶
func (c *PolledClient) GetMessages(start int, count int) []interface{}
Gets count messages from the device, skipping the first start messages
func (*PolledClient) Id ¶
func (c *PolledClient) Id() string
func (*PolledClient) OnDeviceDisconnected ¶
func (c *PolledClient) OnDeviceDisconnected()
func (*PolledClient) ToDevice ¶
func (c *PolledClient) ToDevice(msg interface{}) error
Sends a message to the device
type PolledSet ¶
type PolledSet struct {
// contains filtered or unexported fields
}
Basically a map of polled clients by id.
func NewPolledSet ¶
func NewPolledSet() *PolledSet
func (*PolledSet) GetConnection ¶
func (s *PolledSet) GetConnection(id string) *PolledClient
func (*PolledSet) NewConnection ¶
func (s *PolledSet) NewConnection(d *Device) *PolledClient