feat: initial commit
This commit is contained in:
140
reach/client/operations.go
Normal file
140
reach/client/operations.go
Normal file
@ -0,0 +1,140 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"forge.cadoles.com/cadoles/go-emlid/reach/client/protocol"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Emit implements protocol.Operations.
|
||||
func (c *Client) Emit(ctx context.Context, mType string, message any) error {
|
||||
_, ops, err := c.getProtocol(ctx)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
if err := ops.Emit(ctx, mType, message); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Configuration implements protocol.Operations.
|
||||
func (c *Client) Configuration(ctx context.Context) (any, error) {
|
||||
_, ops, err := c.getProtocol(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
config, err := ops.Configuration(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// Version implements protocol.Operations.
|
||||
func (c *Client) Version(ctx context.Context) (string, bool, error) {
|
||||
_, ops, err := c.getProtocol(ctx)
|
||||
if err != nil {
|
||||
return "", false, errors.WithStack(err)
|
||||
}
|
||||
|
||||
version, stable, err := ops.Version(ctx)
|
||||
if err != nil {
|
||||
return "", false, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return version, stable, nil
|
||||
}
|
||||
|
||||
// Close implements protocol.Operations.
|
||||
func (c *Client) Close(ctx context.Context) error {
|
||||
_, ops, err := c.getProtocol(ctx)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
if err := ops.Close(ctx); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Connect implements protocol.Operations.
|
||||
func (c *Client) Connect(ctx context.Context) error {
|
||||
_, ops, err := c.getProtocol(ctx)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
if err := ops.Connect(ctx); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Alive implements protocol.Operations.
|
||||
func (c *Client) Alive(ctx context.Context) (bool, error) {
|
||||
_, ops, err := c.getProtocol(ctx)
|
||||
if err != nil {
|
||||
return false, errors.WithStack(err)
|
||||
}
|
||||
|
||||
alive, err := ops.Alive(ctx)
|
||||
if err != nil {
|
||||
return false, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return alive, nil
|
||||
}
|
||||
|
||||
// On implements protocol.Operations.
|
||||
func (c *Client) On(ctx context.Context, messageType string) (chan any, error) {
|
||||
_, ops, err := c.getProtocol(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
ch, err := ops.On(ctx, messageType)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
return ch, nil
|
||||
}
|
||||
|
||||
// SetBase implements protocol.Operations.
|
||||
func (c *Client) SetBase(ctx context.Context, funcs ...protocol.SetBaseOptionFunc) error {
|
||||
_, ops, err := c.getProtocol(ctx)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
if err := ops.SetBase(ctx, funcs...); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reboot implements protocol.Operations.
|
||||
func (c *Client) Reboot(ctx context.Context) error {
|
||||
_, ops, err := c.getProtocol(ctx)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
if err := ops.Reboot(ctx); err != nil {
|
||||
return errors.WithStack(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ protocol.Operations = &Client{}
|
Reference in New Issue
Block a user