go-emlid/reach/client/operations.go

89 lines
1.8 KiB
Go
Raw Normal View History

2024-07-30 14:28:39 +02:00
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, message any) error {
panic("unimplemented")
}
// 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
}
var _ protocol.Operations = &Client{}