89 lines
1.8 KiB
Go
89 lines
1.8 KiB
Go
|
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{}
|