modules

package
v0.0.0-...-4ceac3e Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HiveModuleBase

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

HiveModuleBase implements the boilerplate of running a module. - define and store properties - manage message sinks - generate TD - send notifications for property changes and events

Call Init(moduleID,sink) after construction

func (*HiveModuleBase) ForwardNotification

func (m *HiveModuleBase) ForwardNotification(notif *msg.NotificationMessage)

ForwardNotification (output) passes notifications to the registered callback. If none is registered this does nothing. note that the handler is not the downstream sink but the upstream consumer.

func (*HiveModuleBase) ForwardRequest

func (m *HiveModuleBase) ForwardRequest(req *msg.RequestMessage, replyTo msg.ResponseHandler) (err error)

ForwardRequest (output) is a helper function to pass a request to the sink's HandleRequest method. If no sink os configured this returns an error

func (*HiveModuleBase) ForwardRequestWait

func (m *HiveModuleBase) ForwardRequestWait(req *msg.RequestMessage) (resp *msg.ResponseMessage, err error)

ForwardRequestWait is a helper function to pass a request to the sink and wait for a response. If no sink os configured this returns an error. If the response contains an error, that error is also returned.

func (*HiveModuleBase) GetModuleID

func (m *HiveModuleBase) GetModuleID() string

GetModuleID returns the module's Thing ID

func (*HiveModuleBase) GetSink

func (m *HiveModuleBase) GetSink() msg.RequestHandler

GetSink returns the module's request sink

func (*HiveModuleBase) GetTM

func (m *HiveModuleBase) GetTM() string

GetTM returns the module's TM describing its properties, actions and events. If supported, the TM can be obtained after a successful start. If no TM is available then this returns "". To convert the TM to a TD, use AddForms on the transport modules to include forms that describe interactions. This can be handled by the pipeline server or by the application itself.

func (*HiveModuleBase) HandleNotification

func (m *HiveModuleBase) HandleNotification(notif *msg.NotificationMessage)

HandleNotification receives an incoming notification from a producer.

The default behavior passes the notification to the registered hook an forwards it upstream to a register notification handler, if set.

Applications that use notifications should use SetNotificationHook to register its handler as it leaves the chain intact..

func (*HiveModuleBase) HandleRequest

func (m *HiveModuleBase) HandleRequest(req *msg.RequestMessage, replyTo msg.ResponseHandler) (err error)

HandleRequest handles request for this module.

This is just the default implementation. Applications can either set an appRequestHandler or a module can override HandleRequest to do its own thing.

If appRequestHandler is set, the request is passed to the application.

Modules that override HandleRequest should first handle the request itself and only hand it over to this base method when there is nothing for them to do.

If a custom request handler is set then this invokes that handler. Intended for use by applications (and tests) that implement a function as request handler.

ReadProperties is handled here as a convenience.

If the request is not for this module, it is forwarded to the sink. if defined. If the request is for this module and read property(ies), it is handled here.

If the request is unhandled it returns an error.

func (*HiveModuleBase) ReadAllProperties

func (m *HiveModuleBase) ReadAllProperties(req *msg.RequestMessage) (resp *msg.ResponseMessage, err error)

ReadAllProperties returns a response containing the map of all known property values

func (*HiveModuleBase) ReadChangedProperties

func (m *HiveModuleBase) ReadChangedProperties() (changes map[string]any)

ReadChangedProperties returns the changed properties and clear the tracked changes Intended to be used with sending a notification of changed properties. This returns nil if no properties have changed.

func (*HiveModuleBase) ReadMultipleProperties

func (m *HiveModuleBase) ReadMultipleProperties(req *msg.RequestMessage) (resp *msg.ResponseMessage, err error)

ReadMultipleProperties returns a response containing the map of requested property values If a requested property doesn't exist then it isn't included in the result. This should be considered an error but not reason enough to fail reading the other properties.

func (*HiveModuleBase) ReadProperty

func (m *HiveModuleBase) ReadProperty(req *msg.RequestMessage) (resp *msg.ResponseMessage, err error)

ReadProperty returns a response containing the requested property value This returns an error if the property doesn't exist.

func (*HiveModuleBase) SetModuleID

func (m *HiveModuleBase) SetModuleID(moduleID string)

Initialize the module base with a moduleID

This sets this module notification handler with the sink.

func (*HiveModuleBase) SetNotificationHook

func (m *HiveModuleBase) SetNotificationHook(hook msg.NotificationHandler)

Set the hook to invoke with received notifications

func (*HiveModuleBase) SetNotificationSink

func (m *HiveModuleBase) SetNotificationSink(consumer msg.NotificationHandler)

Set the handler that will receive notifications emitted by this module

func (*HiveModuleBase) SetRequestHook

func (m *HiveModuleBase) SetRequestHook(hook msg.RequestHandler)

Set the hook to invoke with received requests directed at this module Any other requests received by HandleRequest will be forwarded to the sink.

func (*HiveModuleBase) SetRequestSink

func (m *HiveModuleBase) SetRequestSink(sink msg.RequestHandler)

SetRequestSink sets the producer that will handle requests for this consumer and register this module as the receive of notifications from the module.

producer is the sink that will handle requests and send notifications

func (*HiveModuleBase) Start

func (m *HiveModuleBase) Start(yamlConfig string) error

func (*HiveModuleBase) Stop

func (m *HiveModuleBase) Stop()

func (*HiveModuleBase) UpdateProperty

func (m *HiveModuleBase) UpdateProperty(name string, val any)

UpdateProperty updates the given property value and sends a notification to subscribers. This tracks the changes to properties that can be retrieved with GetChangedProperties()

type IHiveModule

type IHiveModule interface {
	// GetModuleID returns module's ID.
	// For agents/devices this is the ThingID, for consumers this is the clientID.
	GetModuleID() string

	// GetTM returns the module's [W3C WoT Thing Model](https://www.w3.org/TR/wot-thing-description11/#thing-model)
	// in JSON, describing its properties, actions and events.
	//
	// The TM is converted to a TD using transport modules 'AddForms' which adds forms that describe
	// the interaction using the given transport. The TD is then published in a directory
	// service that is available to consumers. This is typically the responsibility of the pipeline
	// service. If the pipeline service is not used then this is up to the application startup logic.
	//
	// Only actual producers of information need to implement a TM. The TM can be obtained
	// after a successful start. If the module does not support a TM then this
	// returns an empty string.
	//
	// The HiveModuleBase implements a default method returning an empty TM.
	GetTM() string

	// HandleRequest - invoked by consumer to this producer.
	//  [producer] processes or forwards a request downstream to other producers.
	//
	// When the request is for this module then the module processes the request and
	// invokes replyTo with the response. ReplyTo is invoked asynchronously before
	// or after returning.
	//
	// When the request is not for this producer then it is forwarded:
	//
	// 1. Most modules forward the request to their sink which is the linked downstream producer.
	//    Flow: consumer -[sink]-> producer
	//
	// 2. If the module is a transport client: the request is transported to the server,
	//    and the server passes it to the producer that is registered as its sink.
	//    Flow: consumer -[sink]-> client -> server -[sink]-> producer
	//
	// 3. If the module is a transport server or server connection then the request is
	//    transported to the remote client. The client passes it to its registered sink.
	//    This sink should be a producer that can handle the request.
	//    (In this case the consumer is a process running on the server)
	//    Flow: consumer -[sink]-> server -> client -[sink]-> producer
	//
	//    Note this is the use-case where a device uses connection reversal to connect
	//         to a server, like a hub or gateway, to serve IoT data. The gateway acts
	//         as a consumer to the producer connected to the client.
	//
	//
	// A middleware module can intercept the response by forwarding the request downstream
	// while providing its own handler as the replyTo. This handler then forwards the response
	// to the original replyTo endpoint.
	//
	// This returns an error if the provided replyTo will not be able to receive a response.
	HandleRequest(request *msg.RequestMessage, replyTo msg.ResponseHandler) error

	// Handle the notification received from the producer.
	// The default behavior is to forward it upstream to the handler set with SetNotificationSink.
	HandleNotification(notif *msg.NotificationMessage)

	// Set the handler of notifications emitted by this module (acting as a producer)
	// Intended to create a chain of notifications from producer to consumer.
	//
	// This can be invoked before or after Start()
	SetNotificationSink(sink msg.NotificationHandler)

	// SetRequestSink sets the producer that will handle the requests emitted by this module.
	//
	// This can be invoked before or after Start() to allow for live rewiring of the
	// module chain.
	SetRequestSink(sink msg.RequestHandler)

	// Start readies the module for use.
	// Intended for modulues to initialize resources
	//  yamlConfig is an optional configuration or "" if not used
	Start(yamlConfig string) error

	// Stop halts module operation and releases resources.
	// Intended for modulues to free resources
	Stop()
}

The HiveOT module interface Anything that accepts requests can be a module, including clients and servers. This interface is the most basic module interface.

type ModuleEnv

type ModuleEnv struct {
	// Application home directory
	HomeDirectory string
	// Application storage directory
	StorageDirectory string
}

Module application environment

Directories

Path Synopsis
client
Package authn with the agent request handler for using service 'User' This builds a service consumer that send a service request.
Package authn with the agent request handler for using service 'User' This builds a service consumer that send a service request.
Package bucketstore is set of modules for data storage.
Package bucketstore is set of modules for data storage.
cmd command
module
package module with the directory module factory
package module with the directory module factory
stores/kvbtree
Package kvbtree
Package kvbtree
module/selfsigned
Package certs with managing certificates for testing
Package certs with managing certificates for testing
module
package module with the directory module factory
package module with the directory module factory
server
Package api with the WoT defined REST API
Package api with the WoT defined REST API
module
Package module with methods for storage, iteration and querying of thing values
Package module with methods for storage, iteration and querying of thing values
Package transports with http server and TLSClient apis
Package transports with http server and TLSClient apis
httpserver/client
Package tlsclient with a TLS client helper supporting certificate, JWT or Basic authentication
Package tlsclient with a TLS client helper supporting certificate, JWT or Basic authentication
wss

Jump to

Keyboard shortcuts

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