Documentation ¶
Overview ¶
Package sift - the Simple Interface of Functional Things.
SIFT makes it easy for developers to write code which understands and manipulates connected devices. A SIFT Server presents an authoritative, centralized repository of Devices (physical units) and their functional Components. SIFT Components are generically typed, meaning a developer can manipulate any number of Light Emitters or Media Players without understanding their specific implementations (e.g. Philips Hue / Google Chromecast) and their implementation details (such as wireless protocols and API specifics).
Example ¶
// start a new SIFT server serv, _ := sift.NewServer("") // "" indicates a random, temporary file go serv.Serve() defer func() { serv.StopAndWait(1 * time.Minute) }() // With no running adapters, the SIFT server should not report any connected components components, _ := serv.GetComponents(db.ExpandAll) fmt.Printf("len(components) == %v", len(components)) // "len(components) == 0" // Start an example service server running on localhost port 12345. This is // a demonstration server that you can control programatically for testing. exServ := example.NewServer(uint16(12345)) go exServ.Serve() defer exServ.Stop() <-time.After(500 * time.Millisecond) // Add a light to the example service. This code is specific to the example // server. In a real-world application, a light would be added when it is // plugged in and connected as defined by the manufacturer. light1 := example.Light{ IsOn: true, OutputInPercent: 100, } device1 := example.Device{ Components: map[string]example.Component{"light1": light1}, } exServ.SetDevice("device1", device1) // This should produce an update // Add an Adapter Factory to monitor the example service serv.AddAdapterFactory(example.NewFactory(12345)) components, _ = serv.GetComponents(db.ExpandAll) fmt.Printf("len(components) == %v", len(components)) // "len(components) == 1" fmt.Printf("components:") for id, component := range components { fmt.Printf(" component %v: %+v", id, component) }
Output:
Index ¶
- Constants
- Variables
- func SetLogLevel(lvlstr string)
- type Server
- func (s *Server) AddAdapterFactory(factory adapter.Factory) (string, error)
- func (s *Server) AddDefaults() error
- func (s *Server) EnactIntent(target types.ComponentID, intent types.Intent) error
- func (s *Server) Serve()
- func (s *Server) Stop()
- func (s *Server) StopAndWait(timeout time.Duration) error
Examples ¶
Constants ¶
const DefaultDBFilepath = "sift.db"
A suggested default database name.
Variables ¶
var Log = logging.Log.New("pkg", "sift")
Log is used to log messages for the sift 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 ¶
func SetLogLevel ¶
func SetLogLevel(lvlstr string)
SetLogLevel is a convenient wrapper to sift/logging.SetLevelStr() Use it to quickly set the log level for all loggers in this package. For more control over logging, manipulate logging.Log directly, as outlined by https://godoc.org/gopkg.in/inconshreveable/log15.v2#hdr-Library_Use (see also: github.com/inconshreveable/log15)
Types ¶
type Server ¶
type Server struct { // SiftDB provides direct access to the underlying sqlite database through // Jason Moiron's wonderful sqlx API (see: github.com/jmoiron/sqlx) *db.SiftDB auth.Authorizor // Provides login/authorize methods notif.Provider // Provides notification pub/sub methods notif.Receiver // Adds methods to post notifications // contains filtered or unexported fields }
Server maintains the state of SIFT objects and provides methods for listening to, retrieving, and manipulating them. You should always initialize Servers with a call to NewServer()
func NewServer ¶
NewServer constructs a new SIFT Server, using the SIFT database at the provided path (or creating a new one it does not exist). Be sure to start the Server with Serve()
func (*Server) AddAdapterFactory ¶
AddAdapterFactory adds an AdapterFactory to the Server. Once added, the Server will begin searching for services matching the AdapterFactory's description. If any are found, the Server will use the AdapterFactory to create an Adapter to handle the sevice.
func (*Server) AddDefaults ¶
AddDefaults adds default Adapter Factories to the SIFT server
func (*Server) EnactIntent ¶
EnactIntent attempts to fulfill an intent, usually to change the state of a particular Component. For a list of possible intents, see sift/types