Documentation
¶
Overview ¶
Package axmdb provides a Go interface to the Axis Message Broker API, showcasing how to use cgo.Handle for callback user data.
Index ¶
- func NewMDBError(cErr *C.mdb_error_t) error
- type Box
- type Class
- type ColorInfo
- type ConsolidatedTrack
- type DoneCallback
- type ErrorCallback
- type Frame
- type Image
- type MDBConnection
- type MDBError
- type MDBProvider
- type MDBProviderError
- type MDBProviderErrorType
- type MDBSubscriber
- type MDBSubscriberConfig
- type Message
- type MessageCallback
- type MessageType
- type Observation
- type Operation
- type SceneDescription
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewMDBError ¶
func NewMDBError(cErr *C.mdb_error_t) error
NewMDBError creates a Go error from an MDBError pointer.
Types ¶
type Box ¶ added in v1.5.8
type Box struct {
Bottom float64 `json:"bottom"`
Left float64 `json:"left"`
Right float64 `json:"right"`
Top float64 `json:"top"`
}
Box represents bounding box coordinates.
type Class ¶ added in v1.5.8
type Class struct {
Type string `json:"type"`
Score float64 `json:"score"`
UpperClothingColors []ColorInfo `json:"upper_clothing_colors,omitempty"`
LowerClothingColors []ColorInfo `json:"lower_clothing_colors,omitempty"`
Colors []ColorInfo `json:"colors,omitempty"` // For consolidated tracks
}
Class represents class details in observations and tracks.
type ConsolidatedTrack ¶ added in v1.5.8
type ConsolidatedTrack struct {
Classes []Class `json:"classes"`
Duration float64 `json:"duration"`
EndTime time.Time `json:"end_time"`
ID string `json:"id"`
Image Image `json:"image"`
Observations []Observation `json:"observations"`
StartTime time.Time `json:"start_time"`
}
ConsolidatedTrack implements MessageType for `consolidated_track`.
func (ConsolidatedTrack) TransformMessage ¶ added in v1.5.8
func (ct ConsolidatedTrack) TransformMessage(jsonString string) (MessageType, error)
TransformMessage parses a JSON string into a ConsolidatedTrack.
type DoneCallback ¶
type DoneCallback func(err error)
DoneCallback defines the signature for a "done" callback, e.g. after asynchronously creating a subscriber, we get an optional error.
type ErrorCallback ¶
type ErrorCallback func(err error)
ErrorCallback defines the signature of the error callback function.
type Frame ¶ added in v1.5.8
type Frame struct {
Timestamp time.Time `json:"timestamp"`
Observations []Observation `json:"observations"`
Operations []Operation `json:"operations"`
}
Frame represents the frame structure for `analytics_scene_description`.
type Image ¶ added in v1.5.8
type Image struct {
BoundingBox Box `json:"bounding_box"`
Data string `json:"data"`
Timestamp time.Time `json:"timestamp,omitempty"` // Optional for consolidated tracks
}
Image represents image data with bounding box.
type MDBConnection ¶
type MDBConnection struct {
// contains filtered or unexported fields
}
MDBConnection wraps the mdb_connection_t type along with a cgo.Handle that references the Go callback (ErrorCallback).
func MDBConnectionCreate ¶
func MDBConnectionCreate(onErr ErrorCallback) (*MDBConnection, error)
MDBConnectionCreate creates a new MDB connection, storing the given onErr callback in a cgo.Handle.
func (*MDBConnection) Destroy ¶
func (conn *MDBConnection) Destroy()
Destroy cleans up the MDBConnection, calling the underlying C function. Also deletes the cgo.Handle if it hasn't already been destroyed.
type MDBError ¶
type MDBError struct {
// contains filtered or unexported fields
}
MDBError wraps the mdb_error_t type. Shown here for reference.
type MDBProvider ¶ added in v1.5.8
type MDBProvider[T MessageType] struct { Topic string Source string ErrorChan chan *MDBProviderError MessageChan chan T // contains filtered or unexported fields }
MDBProvider is a generic provider for messages of type T.
func NewMDBProvider ¶ added in v1.5.8
func NewMDBProvider[T MessageType](source string) (*MDBProvider[T], error)
NewMDBProvider creates a new MDBProvider.
func (*MDBProvider[T]) Connect ¶ added in v1.5.8
func (mdb *MDBProvider[T]) Connect()
Connect initializes the MDBProvider and processes JSON strings dynamically.
func (*MDBProvider[T]) Disconnect ¶ added in v1.5.8
func (mdb *MDBProvider[T]) Disconnect()
Disconnect cleans up resources.
type MDBProviderError ¶ added in v1.5.8
type MDBProviderError struct {
Err error
ErrType MDBProviderErrorType
}
type MDBProviderErrorType ¶ added in v1.5.8
type MDBProviderErrorType int
const ( MDBProviderErrorTypeConnection MDBProviderErrorType = iota MDBProviderErrorTypeSubscriberConfigCreate MDBProviderErrorTypeSubscriberCreate MDBProviderErrorTypeInvalidMessage MDBProviderErrorTypeParseMessage MDBProviderErrorTypeEmptyPayload MDBProviderErrorSubscribeDone MDBProviderErrorSubscribe )
type MDBSubscriber ¶
type MDBSubscriber struct {
// contains filtered or unexported fields
}
MDBSubscriber wraps the mdb_subscriber_t type.
func MDBSubscriberCreateAsync ¶
func MDBSubscriberCreateAsync( conn *MDBConnection, config *MDBSubscriberConfig, onDone DoneCallback, ) (*MDBSubscriber, error)
MDBSubscriberCreateAsync creates an async subscriber using the provided connection and subscriber config. The user can also pass a pointer to a completion callback (`onDoneFunc`) if needed.
func (*MDBSubscriber) Destroy ¶
func (subscriber *MDBSubscriber) Destroy()
Destroy cleans up the MDBSubscriber. It waits for the async creation callback to complete before freeing resources.
type MDBSubscriberConfig ¶
type MDBSubscriberConfig struct {
// contains filtered or unexported fields
}
MDBSubscriberConfig wraps the mdb_subscriber_config_t type along with a cgo.Handle for the Go message callback.
func MDBSubscriberConfigCreate ¶
func MDBSubscriberConfigCreate(topic string, source string, onMessage MessageCallback) (*MDBSubscriberConfig, error)
MDBSubscriberConfigCreate creates a subscriber configuration that uses a Go callback for messages, storing it in a cgo.Handle.
func (*MDBSubscriberConfig) Destroy ¶
func (config *MDBSubscriberConfig) Destroy()
Destroy cleans up the MDBSubscriberConfig, deleting its handle as well.
type Message ¶
type Message struct {
Timestamp time.Time // Timestamp of the message
Payload string // Payload data
}
Message represents a structured message received from the Message Broker.
type MessageCallback ¶
type MessageCallback func(msg *Message)
MessageCallback defines the signature for the callback handling messages.
type MessageType ¶ added in v1.5.8
type MessageType interface {
TransformMessage(jsonString string) (MessageType, error) // Converts a JSON string into a specific type
}
MessageType defines the interface for all message types.
type Observation ¶ added in v1.5.8
type Observation struct {
BoundingBox Box `json:"bounding_box"`
Timestamp time.Time `json:"timestamp,omitempty"` // For consolidated tracks
TrackID string `json:"track_id,omitempty"` // For scene description
Class *Class `json:"class,omitempty"` // Optional class information
Image *Image `json:"-"` // Optional image information
}
Observation represents observations in both formats.
type Operation ¶ added in v1.5.8
type Operation struct {
Type string `json:"type"`
ID string `json:"id,omitempty"`
From string `json:"from,omitempty"`
To string `json:"to,omitempty"`
}
Operation represents operations in `analytics_scene_description`.
type SceneDescription ¶ added in v1.5.8
type SceneDescription struct {
Frame Frame `json:"frame"`
}
SceneDescription implements MessageType for `analytics_scene_description`.
func (*SceneDescription) String ¶ added in v1.5.8
func (sd *SceneDescription) String() string
func (SceneDescription) TransformMessage ¶ added in v1.5.8
func (sd SceneDescription) TransformMessage(jsonString string) (MessageType, error)
TransformMessage parses a JSON string into a SceneDescription.