api

package
v0.0.0-...-ec45d75 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2014 License: BSD-2-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EXECUTE       = 0
	NO_EXECUTE    = 1
	DEFER_EXECUTE = 2
)
View Source
const (
	TRIGGER_INTERVAL uint8 = 0
	TRIGGER_THING          = 1
)
View Source
const (
	CONFIG_FILE = "hub-config.json"
)

Hub Configuration as loaded from <home>/hub-config.json

View Source
const (
	EVENT_SENSE = 0
)
View Source
const (
	SCHEDULE_TICKER_INTERVAL = 15 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AppDB

type AppDB interface {
	Put(string, interface{})
	Get(string) interface{}
	Delete(string)
	Purge()
}

type BaseCommunicationChannel

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

func NewBaseCommunicationChannel

func NewBaseCommunicationChannel() BaseCommunicationChannel

func (*BaseCommunicationChannel) AddProtocol

func (cc *BaseCommunicationChannel) AddProtocol(h ProtocolHandler)

func (BaseCommunicationChannel) GetConfiguration

func (cc BaseCommunicationChannel) GetConfiguration() ChannelConfiguration

func (BaseCommunicationChannel) GetProtocol

func (BaseCommunicationChannel) GetProtocols

func (cc BaseCommunicationChannel) GetProtocols() map[string]ProtocolHandler

func (BaseCommunicationChannel) IsEnabled

func (s BaseCommunicationChannel) IsEnabled() bool

func (*BaseCommunicationChannel) SetChannelConfiguration

func (cc *BaseCommunicationChannel) SetChannelConfiguration(c ChannelConfiguration)

func (*BaseCommunicationChannel) SetContainer

func (cc *BaseCommunicationChannel) SetContainer(c Container)

func (*BaseCommunicationChannel) SetEnvironment

func (cc *BaseCommunicationChannel) SetEnvironment(e Environment)

func (*BaseCommunicationChannel) SetFactory

func (cc *BaseCommunicationChannel) SetFactory(f Factory)

func (*BaseCommunicationChannel) SetThingManager

func (cc *BaseCommunicationChannel) SetThingManager(t ThingManager)

type BaseProtocolHandler

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

func (*BaseProtocolHandler) GetChannel

func (h *BaseProtocolHandler) GetChannel() CommunicationChannel

func (*BaseProtocolHandler) GetEnvironment

func (h *BaseProtocolHandler) GetEnvironment() Environment

func (*BaseProtocolHandler) GetFactory

func (h *BaseProtocolHandler) GetFactory() Factory

func (*BaseProtocolHandler) GetThingManager

func (h *BaseProtocolHandler) GetThingManager() ThingManager

func (*BaseProtocolHandler) SetChannel

func (h *BaseProtocolHandler) SetChannel(c CommunicationChannel)

func (*BaseProtocolHandler) SetEnvironment

func (h *BaseProtocolHandler) SetEnvironment(e Environment)

func (*BaseProtocolHandler) SetFactory

func (h *BaseProtocolHandler) SetFactory(f Factory)

func (*BaseProtocolHandler) SetThingManager

func (h *BaseProtocolHandler) SetThingManager(t ThingManager)

type ChannelConfiguration

type ChannelConfiguration struct {
	Type      string
	Enabled   bool
	Port      string
	Baud      uint32
	Protocols []string
}

type CommChannelManager

type CommChannelManager interface {
	GetChannelForProtocol(string) CommunicationChannel
	InitChannels([]ChannelConfiguration)
	Register(string, CommunicationChannel)

	ContainerAware
	SetFactory(Factory)
}

type CommunicationChannel

type CommunicationChannel interface {
	Start() error
	IsEnabled() bool
	GetName() string
	GetLabel() string
	AddProtocol(ProtocolHandler)
	GetProtocol(string) ProtocolHandler
	GetProtocols() map[string]ProtocolHandler
	Write(WriteRequest)

	SetChannelConfiguration(ChannelConfiguration)
	SetThingManager(ThingManager)
	SetFactory(Factory)
	SetEnvironment(Environment)
	ContainerAware
}

type Condition

type Condition interface {
	Evaluate(when *RuleWhen, facts *RuleFacts, rule *Rule) bool
}

type Configuration

type Configuration struct {
	Name       string
	NodeID     string
	Db         string
	MaxProcs   uint8
	ServerPort uint16
	Channels   []ChannelConfiguration
	Mail       MailConfig
}

type Consequence

type Consequence interface {
	Execute(config map[string]interface{}, container Container)
}

type Container

type Container interface {
	CommChannelManager() CommChannelManager
	RulesManager() RulesManager
	ThingManager() ThingManager
	Env() Environment
	ScheduleService() ScheduleService
	DataSource() DataSource
	Factory() Factory
	ProtocolHandlers() map[string]ProtocolHandler
	ProtocolHandler(string) ProtocolHandler

	Channels() map[string]CommunicationChannel
	Channel(string) CommunicationChannel
}

Container handles all the services used as well as any cross-dependencies

type ContainerAware

type ContainerAware interface {
	SetContainer(Container)
	ValidateWiring()
}

Interface contract for any services which needs to be supported by the Container

type DataSource

type DataSource interface {
	PutThing(*Thing) Thing

	GetThingCount() int
	GetThings() []Thing

	GetEventsCountForThing(*Thing) int
	GetEventsCount() int
	GetEvents(int) []Event

	GetThingEvents(int, string) []Event

	CreateAppDB(*Thing) AppDB

	SaveThing(Thing)
	DeleteThing(Thing)

	PutEvent(*Event)
	SaveState(*Thing, map[string]interface{})
	ContainerAware

	SetEnvironment(Environment)
}

DataSource for Things, States and Events

type Environment

type Environment interface {
	GetUptime() string
	GetConfig() Configuration
	GetHome() string
	IsStartedUp() bool
	ContainerAware
}

type Event

type Event struct {
	Uid       string
	Thing     string
	Service   string
	Ts        time.Time
	ShortText string
	LongText  string
	Event     int
	Data      interface{}
}

func NewEvent

func NewEvent() *Event

func (*Event) Ago

func (e *Event) Ago() string

type Factory

type Factory interface {
	CreateCondition(string) Condition
	CreateConsequence(string) Consequence
	CreateChannelHandler(ChannelConfiguration) CommunicationChannel
	CreateProtocolHandler(string) ProtocolHandler
	CreateThingAdapter(string) ThingAdapter
	ContainerAware
}

type MailConfig

type MailConfig struct {
	User string
	Pass string
	Host string
	Port uint16
}

Configuration for Mail when sending out email (e.g. rule triggers)

type ProtocolHandler

type ProtocolHandler interface {
	OnStart()
	OnStop()
	GetName() string
	GetLabel() string
	OnRead(data ReadRequest)
	Write(*Thing, WriteRequest)

	GetChannel() CommunicationChannel
	SetChannel(CommunicationChannel)

	SetThingManager(ThingManager)
	SetFactory(Factory)
	SetEnvironment(Environment)
}

type ReadRequest

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

func NewReadRequest

func NewReadRequest(payload interface{}) ReadRequest

func (*ReadRequest) Get

func (c *ReadRequest) Get(key string) interface{}

func (*ReadRequest) GetAsInt

func (c *ReadRequest) GetAsInt(key string) int

func (*ReadRequest) GetAsString

func (c *ReadRequest) GetAsString(key string) string

func (ReadRequest) GetPayload

func (c ReadRequest) GetPayload() interface{}

func (*ReadRequest) Put

func (c *ReadRequest) Put(key string, val interface{})

type Rule

type Rule struct {
	Id          string
	Path        string
	Name        string
	Description string
	Enabled     bool
	Priority    byte
	Async       bool
	Buffer      int
	LastRun     time.Time
	Targets     []string
	When        []RuleWhen
	Then        []RuleThen
}

type RuleFacts

type RuleFacts struct {
	Target  string
	Thing   *Thing
	Service *ThingService
}

type RuleThen

type RuleThen struct {
	Do     string
	Config map[string]interface{}
}

type RuleWhen

type RuleWhen struct {
	Target  string
	Service string
	Event   string
}

type RulesManager

type RulesManager interface {
	GetRule(string) Rule
	GetRules() map[string]Rule
	Trigger(triggerType uint8, facts *RuleFacts)
	RegisterRule(Rule)

	ContainerAware
	SetThingManager(ThingManager)
	SetFactory(Factory)
}

type ScheduleService

type ScheduleService interface {
	Start()
	Stop()
	ContainerAware

	SetRulesManager(RulesManager)
	SetThingManager(ThingManager)
}

Service for managing scheduled tasks, e.g. the Cycle for things

type State

type State map[string]interface{}

type Thing

type Thing struct {
	DatabaseId  bson.ObjectId                  `bson:"_id"`
	Id          string                         `bson:"uid"`
	Name        string                         `bson:"lbl"`
	Group       string                         `bson:"grp"`
	Class       string                         `bson:"c"`
	Type        string                         `bson:"tid"`
	Enabled     bool                           `bson:"en"`
	Description string                         `bson:"desc"`
	LogEvents   bool                           `bson:"logEvents"`
	Descriptor  ThingType                      `bson:",omitempty"`
	Attributes  map[string]ThingAttributeValue `bson:"attrs"`
	LastEvents  map[string]time.Time
	LastEvent   time.Time
	LastCycle   time.Time
	Data        map[string]interface{}  `bson:"data"`
	Content     string                  `bson:""`
	Services    map[string]ThingService `bson:"services"`
	State       State                   `bson:"state"`
}

Representing a thing

func NewThing

func NewThing() *Thing

func (Thing) GetAttributeValue

func (d Thing) GetAttributeValue(name string) ThingAttributeValue

func (Thing) GetAttributeValues

func (d Thing) GetAttributeValues(expr string) (attrs map[string]ThingAttributeValue)

func (Thing) GetDatabaseId

func (d Thing) GetDatabaseId() string

func (*Thing) GetId

func (d *Thing) GetId() string

func (*Thing) RenderWidget

func (d *Thing) RenderWidget() template.HTML

func (*Thing) SaveAttributeValue

func (d *Thing) SaveAttributeValue(name string, value interface{}) error

func (*Thing) UpdateLastCycle

func (d *Thing) UpdateLastCycle(t time.Time)

func (*Thing) UpdateLastEvent

func (d *Thing) UpdateLastEvent(t time.Time)

func (*Thing) UpdateService

func (d *Thing) UpdateService(s *ThingService)

type ThingAdapter

type ThingAdapter interface {
	Cycle(*Thing)
	OnRead(*Thing, *ThingService, ReadRequest, ProtocolHandler) State
	OnWrite(*Thing, string, WriteRequest, AppDB, ProtocolHandler)
	GetEventText(*Thing, *ThingService, State) (shortText string, longText string)
}

Thing adapter to support any sensing or actuation

type ThingAttribute

type ThingAttribute struct {
	Name     string      `json:"name"`
	Type     string      `json:"type"`
	Config   bool        `json:"config"`
	Required bool        `json:"required"`
	Default  interface{} `json:"default"`
}

Attributes for a given Thing

func (*ThingAttribute) IsStringType

func (d *ThingAttribute) IsStringType() bool

type ThingAttributeValue

type ThingAttributeValue struct {
	Name  string      `bson:"n"`
	Value interface{} `bson:"v"`
}

func NewThingAttributeValue

func NewThingAttributeValue(n string, v interface{}) ThingAttributeValue

type ThingData

type ThingData interface {
	GetData() map[string]interface{}
}

type ThingManager

type ThingManager interface {
	GetThing(string) (Thing, bool)
	SaveThing(Thing)
	GetThingType(string) (ThingType, error)
	GetThingTypes() map[string]ThingType
	RegisterThingType(ThingType)
	RegisterThing(Thing)
	GetThings() []Thing
	Handle(*Thing, *ThingService, State)
	CreateThing(*Thing)
	RemoveThing(Thing)
	GetProtocolHandlerForThing(*Thing) ProtocolHandler

	LoadThings()

	Cycle()
	Actuate(*Thing, string, map[string]interface{})

	ContainerAware
	SetRulesManager(RulesManager)
	SetFactory(Factory)
	SetDataSource(DataSource)
	SetCommChannelManager(CommChannelManager)
}

Service for handling Things

type ThingOperation

type ThingOperation struct {
	Name        string
	Description string
	// contains filtered or unexported fields
}

Operations/Actuables for a Thing

type ThingOperationConfiguration

type ThingOperationConfiguration struct {
}

Meta-attributes for a given operation

type ThingService

type ThingService struct {
	Name      string `json:"name"`
	Label     string `json:"lbl"`
	LastEvent time.Time
}

func (*ThingService) UpdateLastEvent

func (d *ThingService) UpdateLastEvent(t time.Time)

type ThingType

type ThingType struct {
	TypeId            string `json:"tid"`
	LogEvents         bool   `json:"logEvents"`
	Name              string
	Description       string
	Protocol          string
	Vendor            string
	Model             string
	EventUpdateBuffer int
	Path              string
	Group             string
	CycleTime         int
	Operations        []ThingOperation
	Services          []ThingService
	Attributes        []ThingAttribute `json:"attributes"`
}

Thing descriptors as defined in <home>/Things

func (*ThingType) GetService

func (d *ThingType) GetService(name string) *ThingService

type Things

type Things []Thing

Things

func (Things) Len

func (slice Things) Len() int

func (Things) Less

func (slice Things) Less(i, j int) bool

func (Things) Swap

func (slice Things) Swap(i, j int)

type WebAwareThing

type WebAwareThing interface {
	HandleRequest(w http.ResponseWriter, req *http.Request)
	HandleOperation(w http.ResponseWriter, req *http.Request)
}

Interface contract for any thing which is able to respond to http requests to /api/thing/{id}

type WriteRequest

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

func NewWriteRequest

func NewWriteRequest(payload interface{}) WriteRequest

func (*WriteRequest) Get

func (c *WriteRequest) Get(key string) interface{}

func (*WriteRequest) Put

func (c *WriteRequest) Put(key string, val interface{})

Jump to

Keyboard shortcuts

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