replace Endpoint interface with a real Endpoint struct.
This commit is contained in:
@@ -92,7 +92,7 @@ func (d *Device) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *Device) OpenEndpoint(cfgNum, ifNum, setNum, epNum uint8) (Endpoint, error) {
|
||||
func (d *Device) OpenEndpoint(cfgNum, ifNum, setNum, epNum uint8) (*Endpoint, error) {
|
||||
var cfg *ConfigInfo
|
||||
for _, c := range d.Configs {
|
||||
if c.Config == cfgNum {
|
||||
|
@@ -20,14 +20,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Endpoint interface {
|
||||
Read(b []byte) (int, error)
|
||||
Write(b []byte) (int, error)
|
||||
Interface() InterfaceSetup
|
||||
Info() EndpointInfo
|
||||
}
|
||||
|
||||
type endpoint struct {
|
||||
type Endpoint struct {
|
||||
h *libusbDevHandle
|
||||
|
||||
InterfaceSetup
|
||||
@@ -37,7 +30,7 @@ type endpoint struct {
|
||||
writeTimeout time.Duration
|
||||
}
|
||||
|
||||
func (e *endpoint) Read(buf []byte) (int, error) {
|
||||
func (e *Endpoint) Read(buf []byte) (int, error) {
|
||||
if EndpointDirection(e.Address)&ENDPOINT_DIR_MASK != ENDPOINT_DIR_IN {
|
||||
return 0, fmt.Errorf("usb: read: not an IN endpoint")
|
||||
}
|
||||
@@ -45,7 +38,7 @@ func (e *endpoint) Read(buf []byte) (int, error) {
|
||||
return e.transfer(buf, e.readTimeout)
|
||||
}
|
||||
|
||||
func (e *endpoint) Write(buf []byte) (int, error) {
|
||||
func (e *Endpoint) Write(buf []byte) (int, error) {
|
||||
if EndpointDirection(e.Address)&ENDPOINT_DIR_MASK != ENDPOINT_DIR_OUT {
|
||||
return 0, fmt.Errorf("usb: write: not an OUT endpoint")
|
||||
}
|
||||
@@ -53,10 +46,10 @@ func (e *endpoint) Write(buf []byte) (int, error) {
|
||||
return e.transfer(buf, e.writeTimeout)
|
||||
}
|
||||
|
||||
func (e *endpoint) Interface() InterfaceSetup { return e.InterfaceSetup }
|
||||
func (e *endpoint) Info() EndpointInfo { return e.EndpointInfo }
|
||||
func (e *Endpoint) Interface() InterfaceSetup { return e.InterfaceSetup }
|
||||
func (e *Endpoint) Info() EndpointInfo { return e.EndpointInfo }
|
||||
|
||||
func (e *endpoint) transfer(buf []byte, timeout time.Duration) (int, error) {
|
||||
func (e *Endpoint) transfer(buf []byte, timeout time.Duration) (int, error) {
|
||||
if len(buf) == 0 {
|
||||
return 0, nil
|
||||
}
|
||||
@@ -78,8 +71,8 @@ func (e *endpoint) transfer(buf []byte, timeout time.Duration) (int, error) {
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func newEndpoint(h *libusbDevHandle, s InterfaceSetup, e EndpointInfo, rt, wt time.Duration) *endpoint {
|
||||
return &endpoint{
|
||||
func newEndpoint(h *libusbDevHandle, s InterfaceSetup, e EndpointInfo, rt, wt time.Duration) *Endpoint {
|
||||
return &Endpoint{
|
||||
InterfaceSetup: s,
|
||||
EndpointInfo: e,
|
||||
h: h,
|
||||
|
@@ -73,7 +73,7 @@ func TestEndpoint(t *testing.T) {
|
||||
fakeT.status = tc.status
|
||||
close(fakeT.done)
|
||||
}()
|
||||
opv := op.Func.Interface().(func(*endpoint, []byte) (int, error))
|
||||
opv := op.Func.Interface().(func(*Endpoint, []byte) (int, error))
|
||||
got, err := opv(ep, tc.buf)
|
||||
if (err != nil) != tc.wantErr {
|
||||
t.Errorf("%s: bulkInEP.Read(): got err: %v, err != nil is %v, want %v", tc.desc, err, err != nil, tc.wantErr)
|
||||
@@ -88,7 +88,7 @@ func TestEndpoint(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEndpointWrongDirection(t *testing.T) {
|
||||
ep := &endpoint{
|
||||
ep := &Endpoint{
|
||||
InterfaceSetup: testBulkInSetup,
|
||||
EndpointInfo: testBulkInEP,
|
||||
}
|
||||
@@ -96,7 +96,7 @@ func TestEndpointWrongDirection(t *testing.T) {
|
||||
if err == nil {
|
||||
t.Error("bulkInEP.Write(): got nil error, want non-nil")
|
||||
}
|
||||
ep = &endpoint{
|
||||
ep = &Endpoint{
|
||||
InterfaceSetup: testIsoOutSetup,
|
||||
EndpointInfo: testIsoOutEP,
|
||||
}
|
||||
|
Reference in New Issue
Block a user