example

package
v0.0.0-...-b0e10ae Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2016 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LampMaxOutputInLumens       = 700
	LampMinOutputInLumens       = 0
	LampExpectedLifetimeInHours = 10000
)

Constant values for the example light specs. These are totally made up, and are exported for testing purposes.

Variables

View Source
var Log = logging.Log.New("pkg", "drivers/example")

Log is used to log messages for the example package. Logs are disabled by default; use sift/logging.SetLevel() to set log levels for all packages, or Log.SetHandler() to set a custom handler for this package (see: https://godoc.org/gopkg.in/inconshreveable/log15.v2)

Functions

This section is empty.

Types

type AdapterFactory

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

An AdapterFactory creates adapters

func NewFactory

func NewFactory(port uint16) *AdapterFactory

NewFactory properly instantiates a new AdapterFactory

func (*AdapterFactory) GetIPv4Description

func (f *AdapterFactory) GetIPv4Description() ipv4.ServiceDescription

GetIPv4Description returns a description of the example IPv4 service that can be used to identify example services on a network

func (*AdapterFactory) HandleIPv4

func (f *AdapterFactory) HandleIPv4(context *ipv4.ServiceContext) adapter.Adapter

HandleIPv4 spawns a new Adapter to handle a context

func (*AdapterFactory) Name

func (f *AdapterFactory) Name() string

Name returns the name of this adapter factory, "SIFT example"

type Component

type Component interface {
	GetType() string
}

A Component is an example server's representation of a functional unit

type Device

type Device struct {
	Components map[string]Component
}

A Device is an example server's representation of a physical unit

type Light

type Light struct {
	IsOn            bool  `json:"is_on,omitempty"`
	OutputInPercent uint8 `json:"output_in_percent,omitempty"`
}

A Light is an example server's representation of a light

func (Light) GetType

func (l Light) GetType() string

GetType returns the light's type

func (Light) MarshalJSON

func (l Light) MarshalJSON() ([]byte, error)

MarshalJSON uses the 'typed' version of the Light when marshalling to JSON

type Lock

type Lock struct {
	IsOpen bool `json:"is_open"`
}

A Lock is an example server's representation of a lock

func (Lock) GetType

func (l Lock) GetType() string

GetType returns the lock's type

func (Lock) MarshalJSON

func (l Lock) MarshalJSON() ([]byte, error)

MarshalJSON uses the 'typed' version of the Lock when marshalling to JSON

type Server

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

A Server runs the example service. It mimics a hub-like service that maintains a collection of different Devices. The server's data model is intentionally different from the standard SIFT data types to demonstrate how one might translate real-world services.

func NewServer

func NewServer(port uint16) *Server

NewServer properly instantiates a Server

func (*Server) Handlers

func (s *Server) Handlers(prefix string) *mux.Router

Handlers provides the set of HTTP route handlers which make up the example service API.

func (*Server) Serve

func (s *Server) Serve()

Serve begins running the server. If provided with a valid port, the Server will serve the example service over a local RESTful http API.

func (*Server) SetDevice

func (s *Server) SetDevice(id string, device Device)

SetDevice sets the server to report the given device with id "id"

func (*Server) Stop

func (s *Server) Stop()

Stop stops the Server

Jump to

Keyboard shortcuts

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