hub

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2022 License: Apache-2.0 Imports: 45 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DeviceConnectionTimeout = 5 * time.Minute
)
View Source
const (
	SessionTimeout = 1 * time.Minute
)

Variables

View Source
var (
	DEVICE_CONNECTION_TIMEOUT = 30 * time.Second
	CONNECTION_TIMEOUT        = fmt.Errorf("connection timeout")
	ActionTimeout             = 20 * time.Second
)
View Source
var (
	UnknownSessionError = fmt.Errorf("unknown session")
)

Functions

func GetVersion

func GetVersion() string

func Logger

func Logger(logger logrus.FieldLogger) gin.HandlerFunc

func Recovery

func Recovery() gin.HandlerFunc

Recovery returns a middleware that recovers from any panics and writes a 500 if there was one.

func RecoveryWithWriter

func RecoveryWithWriter(out io.Writer) gin.HandlerFunc

RecoveryWithWriter returns a middleware for a given writer that recovers from any panics and writes a 500 if there was one.

func ZeroConfServer

func ZeroConfServer(ctx context.Context, name string, address string)

Types

type DeviceManager

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

func NewDeviceManager

func NewDeviceManager(logger *logrus.Logger, db *gorm.DB) *DeviceManager

func (*DeviceManager) AddHandler

func (dm *DeviceManager) AddHandler(manager device.Handler)

func (*DeviceManager) Devices

func (dm *DeviceManager) Devices() ([]device.Device, error)

func (*DeviceManager) FindDevice

func (dm *DeviceManager) FindDevice(params *app.Parameter) device.Device

func (*DeviceManager) GetDevice

func (dm *DeviceManager) GetDevice(id string) device.Device

func (*DeviceManager) ListDevices

func (dm *DeviceManager) ListDevices()

func (*DeviceManager) RegisterDevice

func (dm *DeviceManager) RegisterDevice(data device.RegisterData) (device.Device, error)

func (*DeviceManager) Run

func (dm *DeviceManager) Run(ctx context.Context) error

func (*DeviceManager) SendAction

func (dm *DeviceManager) SendAction(dev device.Device, act action.Interface) error

func (*DeviceManager) SocketListener

func (dm *DeviceManager) SocketListener() error

func (*DeviceManager) Start

func (dm *DeviceManager) Start(dev device.Device) error

func (*DeviceManager) Stop

func (dm *DeviceManager) Stop(dev device.Device) error

func (*DeviceManager) StopObserver

func (dm *DeviceManager) StopObserver()

type Recorder

type Recorder struct {
	Storage *SessionStorage
	Device  device.Device
}

func (*Recorder) Start

func (r *Recorder) Start() error

func (*Recorder) Stop

func (r *Recorder) Stop() error

type Service

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

func NewService

func NewService(logger *logrus.Logger, ip net.IP, devices manager.Devices, sessions manager.Sessions, cfg config.Service, sd storage.Device) *Service

func (*Service) AddEndpoint

func (s *Service) AddEndpoint(endpoint endpoints.ServiceEndpoint) error

func (*Service) RegisterHooks

func (s *Service) RegisterHooks(hooksCfgs []config.Hook)

func (*Service) RunMaster

func (s *Service) RunMaster() error

func (*Service) RunSlave

func (s *Service) RunSlave() error
func (g grpcSlave) DeviceList(srv action.RemoteDevice_DeviceListServer) error {
	logrus.Infof("DeviceList")
	ctx := srv.Context()
	for {
		select {
		case <-ctx.Done():
			return ctx.Err()
		default:
		}

		logrus.Infof("waiting for message")
		_, err := srv.Recv()
		if err == io.EOF {
			logrus.Infof("EOF")
			return nil
		}
		if err != nil {
			logrus.Errorf("stream error: %v", err)
			return err
		}

		var deviceList []*action.Device

		resp := action.DeviceResponse{
			Devices: deviceList,
		}

		logrus.Infof("Send Device List")

		if err := srv.Send(&resp); err != nil {
			return err
		}
	}

	return nil
}
func (g grpcSlave) DeviceInteraction(srv action.RemoteDevice_DeviceInteractionServer) error {
	logrus.Infof("DeviceInteraction")
	ctx := srv.Context()
	for {
		select {
		case <-ctx.Done():
			return ctx.Err()
		default:
		}

		_, err := srv.Recv()
		if err == io.EOF {
			return nil
		}
		if err != nil {
			return err
		}

		resp := action.InteractionResponse{}

		if err := srv.Send(&resp); err != nil {
			return err
		}
	}

	return nil
}
func (g grpcSlave) ActionExecute(srv action.RemoteDevice_ActionExecuteServer) error {
	logrus.Infof("ActionExecute")
	ctx := srv.Context()
	for {
		select {
		case <-ctx.Done():
			return ctx.Err()
		default:
		}

		_, err := srv.Recv()
		if err == io.EOF {
			return nil
		}
		if err != nil {
			return err
		}

		resp := action.Response{}

		if err := srv.Send(&resp); err != nil {
			return err
		}
	}

	return nil
}

type Session

type Session struct {
	SessionID  string
	LastAccess time.Time
	Lock       *manager.DeviceLock

	Recorder         *Recorder
	DeviceProperties *device.Properties
	AppParameter     *app.Parameter
	XmlDocument      *xmlquery.Node
	Storage          manager.Storage
	// contains filtered or unexported fields
}

func (*Session) Close

func (s *Session) Close() error

func (*Session) DeviceDisconnected

func (s *Session) DeviceDisconnected()

func (*Session) GetActionTimeout

func (s *Session) GetActionTimeout() time.Time

func (*Session) GetAppParameter

func (s *Session) GetAppParameter() *app.Parameter

func (*Session) GetDevice

func (s *Session) GetDevice() device.Device

func (*Session) GetDeviceLock

func (s *Session) GetDeviceLock() *manager.DeviceLock

func (*Session) GetLastAccess

func (s *Session) GetLastAccess() time.Time

func (*Session) GetLogger

func (s *Session) GetLogger() *logrus.Entry

func (*Session) GetSessionID

func (s *Session) GetSessionID() string

func (*Session) GetStorage

func (s *Session) GetStorage() manager.Storage

func (*Session) HandleDisconnect

func (s *Session) HandleDisconnect()

func (*Session) SetActionTimeout

func (s *Session) SetActionTimeout(timeout time.Duration)

func (*Session) SetDeviceLock

func (s *Session) SetDeviceLock(lock *manager.DeviceLock)

func (*Session) SetLastAccess

func (s *Session) SetLastAccess(t time.Time)

func (*Session) WaitForConnection

func (s *Session) WaitForConnection() error

type SessionManager

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

func NewSessionManager

func NewSessionManager(logger *logrus.Logger, deviceManager *DeviceManager) *SessionManager

func (*SessionManager) AddSession

func (s *SessionManager) AddSession(session manager.Session)

func (*SessionManager) CreateNewSession

func (s *SessionManager) CreateNewSession(log *logrus.Entry, properties *device.Properties, appParameter *app.Parameter) manager.Session

func (*SessionManager) GetSession

func (s *SessionManager) GetSession(sessionID string) (manager.Session, error)

func (*SessionManager) GetSessionDetails

func (s *SessionManager) GetSessionDetails(sessionID string) manager.Session

func (*SessionManager) GetSessions

func (s *SessionManager) GetSessions() []manager.Session

func (*SessionManager) Run

func (s *SessionManager) Run(ctx context.Context)

func (*SessionManager) StopSession

func (s *SessionManager) StopSession(session manager.Session) error

type SessionStorage

type SessionStorage struct {
	Path      string
	SessionID string
	// contains filtered or unexported fields
}

func NewSessionStorage

func NewSessionStorage(Path, SessionID string) *SessionStorage

func (*SessionStorage) Close

func (s *SessionStorage) Close() error

func (*SessionStorage) GetPath

func (s *SessionStorage) GetPath() string

func (*SessionStorage) RemoteDeviceLog

func (s *SessionStorage) RemoteDeviceLog(line string)

func (*SessionStorage) StoreImage

func (s *SessionStorage) StoreImage(content []byte) (string, error)

func (*SessionStorage) StoreSceneGraph

func (s *SessionStorage) StoreSceneGraph(data []byte) (string, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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