Skip to content

Commit 2b24b07

Browse files
committed
Moved all Port definitions in a separate file
1 parent 7ab33de commit 2b24b07

File tree

3 files changed

+55
-37
lines changed

3 files changed

+55
-37
lines changed

client.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -96,31 +96,6 @@ func (msg discoveryMessage) String() string {
9696
return s
9797
}
9898

99-
// Equals returns true if the given port has the same address and protocol
100-
// of the current port.
101-
func (p *Port) Equals(o *Port) bool {
102-
return p.Address == o.Address && p.Protocol == o.Protocol
103-
}
104-
105-
func (p *Port) String() string {
106-
if p == nil {
107-
return "none"
108-
}
109-
return p.Address
110-
}
111-
112-
// Clone creates a copy of this Port
113-
func (p *Port) Clone() *Port {
114-
if p == nil {
115-
return nil
116-
}
117-
res := *p
118-
if p.Properties != nil {
119-
res.Properties = p.Properties.Clone()
120-
}
121-
return &res
122-
}
123-
12499
// Event is a pluggable discovery event
125100
type Event struct {
126101
Type string

discovery.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,8 @@ import (
3636
"strconv"
3737
"strings"
3838
"sync"
39-
40-
"github.com/arduino/go-properties-orderedmap"
4139
)
4240

43-
// Port is a descriptor for a board port
44-
type Port struct {
45-
Address string `json:"address"`
46-
AddressLabel string `json:"label,omitempty"`
47-
Protocol string `json:"protocol,omitempty"`
48-
ProtocolLabel string `json:"protocolLabel,omitempty"`
49-
Properties *properties.Map `json:"properties,omitempty"`
50-
HardwareID string `json:"hardwareId,omitempty"`
51-
}
52-
5341
// Discovery is an interface that represents the business logic that
5442
// a pluggable discovery must implement. The communication protocol
5543
// is completely hidden and it's handled by a DiscoveryServer.

port.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//
2+
// This file is part of pluggable-discovery-protocol-handler.
3+
//
4+
// Copyright 2024 ARDUINO SA (http://www.arduino.cc/)
5+
//
6+
// This software is released under the GNU General Public License version 3,
7+
// which covers the main part of arduino-cli.
8+
// The terms of this license can be found at:
9+
// https://www.gnu.org/licenses/gpl-3.0.en.html
10+
//
11+
// You can be released from the requirements of the above licenses by purchasing
12+
// a commercial license. Buying such a license is mandatory if you want to modify or
13+
// otherwise use the software for commercial activities involving the Arduino
14+
// software without disclosing the source code of your own applications. To purchase
15+
// a commercial license, send an email to license@arduino.cc.
16+
//
17+
18+
package discovery
19+
20+
import "github.com/arduino/go-properties-orderedmap"
21+
22+
// Port is a descriptor for a board port
23+
type Port struct {
24+
Address string `json:"address"`
25+
AddressLabel string `json:"label,omitempty"`
26+
Protocol string `json:"protocol,omitempty"`
27+
ProtocolLabel string `json:"protocolLabel,omitempty"`
28+
Properties *properties.Map `json:"properties,omitempty"`
29+
HardwareID string `json:"hardwareId,omitempty"`
30+
}
31+
32+
// Equals returns true if the given port has the same address and protocol
33+
// of the current port.
34+
func (p *Port) Equals(o *Port) bool {
35+
return p.Address == o.Address && p.Protocol == o.Protocol
36+
}
37+
38+
func (p *Port) String() string {
39+
if p == nil {
40+
return "none"
41+
}
42+
return p.Address
43+
}
44+
45+
// Clone creates a copy of this Port
46+
func (p *Port) Clone() *Port {
47+
if p == nil {
48+
return nil
49+
}
50+
res := *p
51+
if p.Properties != nil {
52+
res.Properties = p.Properties.Clone()
53+
}
54+
return &res
55+
}

0 commit comments

Comments
 (0)