Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
djthorpe committed Mar 16, 2021
1 parent 6310a21 commit 85a980d
Show file tree
Hide file tree
Showing 6 changed files with 600 additions and 2 deletions.
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/djthorpe/gopi/v3
go 1.13

require (
github.com/djthorpe/mutablehome v1.0.1
github.com/go-ocf/go-coap v0.0.0-20200511140640-db6048acfdd3
github.com/golang/protobuf v1.4.3
github.com/google/go-cmp v0.5.4 // indirect
Expand All @@ -23,7 +22,6 @@ require (
golang.org/x/text v0.3.4 // indirect
google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d // indirect
google.golang.org/grpc v1.34.0
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0 // indirect
google.golang.org/protobuf v1.25.0
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c // indirect
Expand Down
13 changes: 13 additions & 0 deletions pkg/input/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package input

import (
"reflect"

gopi "github.com/djthorpe/gopi/v3"
graph "github.com/djthorpe/gopi/v3/pkg/graph"
)

func init() {
// Register gopi.InputManager
graph.RegisterUnit(reflect.TypeOf(&Manager{}), reflect.TypeOf((*gopi.InputManager)(nil)))
}
56 changes: 56 additions & 0 deletions pkg/input/manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package input

import (
"sync"

gopi "github.com/djthorpe/gopi/v3"
)

////////////////////////////////////////////////////////////////////////////////
// TYPES

type Manager struct {
sync.RWMutex
gopi.Unit
gopi.Logger
gopi.FilePoll

devices map[uintptr]gopi.InputDevice
}

////////////////////////////////////////////////////////////////////////////////
// LIFECYCLE

func (this *Manager) New(gopi.Config) error {
this.Require(this.Logger, this.FilePoll)

// Create devices
this.devices = make(map[uintptr]gopi.InputDevice)

return nil
}

func (this *Manager) Dispose() error {
this.RWMutex.Lock()
defer this.RWMutex.Unlock()

// Free devices
var result error
this.devices = nil

return result
}

////////////////////////////////////////////////////////////////////////////////
// PUBLIC METHODS

func (this *Manager) Devices() []gopi.InputDevice {
return nil
}

func (this *Manager) RegisterDevice(gopi.InputDevice) error {
return gopi.ErrNotImplemented
}

////////////////////////////////////////////////////////////////////////////////
// PRIVATE METHODS
30 changes: 30 additions & 0 deletions pkg/input/manager_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// +build linux

package input_test

import (
"context"
"testing"

gopi "github.com/djthorpe/gopi/v3"
tool "github.com/djthorpe/gopi/v3/pkg/tool"

_ "github.com/djthorpe/gopi/v3/pkg/file"
)

type InputApp struct {
gopi.Unit
gopi.Logger
gopi.InputManager
}

func (this *InputApp) Run(ctx context.Context) error {
<-ctx.Done()
return ctx.Err()
}

func Test_InputManager_001(t *testing.T) {
tool.Test(t, nil, new(InputApp), func(app *InputApp) {
app.Require(app.Logger, app.InputManager)
})
}
Loading

0 comments on commit 85a980d

Please sign in to comment.