chlab

package
v0.0.0-...-cb7d559 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2020 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetNetAddress

func GetNetAddress() (string, error)

func GetSubscribeTopic

func GetSubscribeTopic(topic string) string

func LoadModuleInfo

func LoadModuleInfo(filename string) *model.Module

func MatchTopicPattern

func MatchTopicPattern(pattern, path string) (*map[string]string, bool)

Types

type App

type App interface {
	Module
}

App implementors should provide an implementation of this interface.

The methods of this interface are used by the RPC framework to learn about the app and also to configure the app with a callback that the app can use to emit events that comply with the app service specification (http://schema.ninjablocks.com/service/app)

Implementors can inherit default implementations of these methods by including an anonymous struct member of type support.AppSupport.

type Channel

type Channel interface {
	GetProtocol() string
	SetEventHandler(func(event string, payload ...interface{}) error)
}

Channel implementors should provide an implementation of this interface for each channel a device exports.

FIXME: consider adding a ChannelSupport object

type Connection

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

Connection Holds the connection to the Ninja MQTT bus, and provides all the methods needed to communicate with the other modules in Sphere.

func Connect

func Connect(clientID string) (*Connection, error)

Connect Builds a new ninja connection to the MQTT broker, using the given client ID

func (*Connection) ExportApp

func (c *Connection) ExportApp(app App) error

ExportApp Exports an app using the 'app' protocol, and announces it

func (*Connection) ExportChannel

func (c *Connection) ExportChannel(device Device, channel Channel, id string) error

ExportChannel Exports a device using the given protocol, and announces it

func (*Connection) ExportChannelWithModel

func (c *Connection) ExportChannelWithModel(service interface{}, deviceTopic string, model *model.Channel) (*rpc.ExportedService, error)

func (*Connection) ExportChannelWithSupported

func (c *Connection) ExportChannelWithSupported(device Device, channel Channel, id string, supportedMethods *[]string, supportedEvents *[]string) error

ExportChannelWithSupported is the same as ExportChannel, but any methods provided must actually be exported by the channel, or an error is returned

func (*Connection) ExportDevice

func (c *Connection) ExportDevice(device Device) error

ExportDevice Exports a device using the 'device' protocol, and announces it

func (*Connection) ExportDriver

func (c *Connection) ExportDriver(driver Driver) error

ExportDriver Exports a driver using the 'driver' protocol, and announces it

func (*Connection) ExportService

func (c *Connection) ExportService(service interface{}, topic string, announcement *model.ServiceAnnouncement) (*rpc.ExportedService, error)

ExportService Exports an RPC service, and announces it over TOPIC/event/announce

func (*Connection) GetMqttClient

func (c *Connection) GetMqttClient() bus.Bus

GetMqttClient will be removed in a later version. All communication should happen via methods on Connection

func (*Connection) GetServiceClient

func (c *Connection) GetServiceClient(serviceTopic string) *ServiceClient

GetServiceClient returns an RPC client for the given service.

func (*Connection) GetServiceClientFromAnnouncement

func (c *Connection) GetServiceClientFromAnnouncement(announcement model.ServiceAnnouncement) *ServiceClient

GetServiceClientWithSupported returns an RPC client for the given service.

func (*Connection) MustExportService

func (c *Connection) MustExportService(service interface{}, topic string, announcement *model.ServiceAnnouncement) *rpc.ExportedService

MustExportService Exports an RPC service, and announces it over TOPIC/event/announce. Must not cause an error or will panic.

func (*Connection) PublishRaw

func (c *Connection) PublishRaw(topic string, payload ...interface{}) error

PublishRaw sends a simple message

func (*Connection) PublishRawSingleValue

func (c *Connection) PublishRawSingleValue(topic string, payload interface{}) error

PublishRawSingleValue sends a simple message with a single json payload

func (*Connection) SendNotification

func (c *Connection) SendNotification(topic string, params ...interface{}) error

SendNotification Sends a simple json-rpc notification to a topic

func (*Connection) Subscribe

func (c *Connection) Subscribe(topic string, callback interface{}) (*bus.Subscription, error)

Subscribe allows you to subscribe to an MQTT topic. Topics can contain variables of the form ":myvar" which will be returned in the values map in the callback.

The provided callback must be a function of 0, 1 or 2 parameters which returns "true" if it wants to receive more messages.

The first parameter must either of type *json.RawMessage or else a pointer to a go struct type to which the expected event payload can be successfully unmarshalled.

The second parameter should be of type map[string]string and will contain one value for each place holder specified in the topic string.

func (*Connection) SubscribeRaw

func (c *Connection) SubscribeRaw(topic string, callback interface{}) (*bus.Subscription, error)

type Device

type Device interface {
	GetDriver() Driver
	GetDeviceInfo() *model.Device
	SetEventHandler(func(event string, payload interface{}) error)
}

Device implementors should provide an implementation of this interface for each device a driver discovers.

FIXME: consider adding a DeviceSupport object

type Driver

type Driver interface {
	Module
}

Driver implementors should provide an implementation of this interface.

The methods of this interface are used by the RPC framework to learn about the driver and also to configure the driver with a callback that the driver can use to emit events that comply with the driver service specification (http://schema.ninjablocks.com/service/driver)

Implementors can inherit default implementations of these methods by including an anonymous struct member of type support.DriverSupport.

type LogControl

type LogControl interface {
	// Sets the current log level for the driver process, specified as a string.
	//
	// This method is intended to called remotely in cases where it is necessary
	// to adjust the logging levels in order to acquire additional diagnostic information
	// from the driver
	//
	// Available logging levels are as per http://godoc.org/github.com/juju/loggo#Level
	SetLogLevel(level string) error
}

A default implementation of this method is provided by support.DriverSupport.

type Module

type Module interface {
	GetModuleInfo() *model.Module
	SetEventHandler(func(event string, payload interface{}) error)
}

Driver implementors should provide an implementation of this interface.

The methods of this interface are used by the RPC framework to learn about the driver and also to configure the driver with a callback that the driver can use to emit events that comply with the driver service specification (http://schema.ninjablocks.com/service/driver)

Implementors can inherit default implementations of these methods by including an anonymous struct member of type support.DriverSupport.

type ServiceClient

type ServiceClient struct {
	Topic            string
	SupportedEvents  []string
	SupportedMethods []string
	// contains filtered or unexported fields
}

func (*ServiceClient) Call

func (c *ServiceClient) Call(method string, args interface{}, reply interface{}, timeout time.Duration) error

func (*ServiceClient) OnEvent

func (c *ServiceClient) OnEvent(event string, callback interface{}) (*bus.Subscription, error)

OnEvent builds a simple subscriber which supports pulling apart the topic

	err := sm.conn.GetServiceClient("$device/:deviceid/channel/:channelid")
                    .OnEvent("state", func(params *YourEventType, topicKeys map[string]string) bool {
 	..
	    return true
	})

YourEventType must either be *json.RawMessage or a pointer to go type to which the raw JSON message can successfully be unmarshalled.

There is one entry in the topicKeys map for each parameter marker in the topic string used to obtain the ServiceClient.

Both the params and topicKeys parameters can be omitted. If the topicKeys parameter is required, the params parameter must also be specified.

Jump to

Keyboard shortcuts

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