Documentation
¶
Overview ¶
Package connection provides implementations for all connection types.
The zero value of each connection type is ready to initiate a connection and on success can be used for further interaction with DuetControlServer.
Index ¶
- Constants
- func CloseOnSignals(c Closer)
- type BaseCommandConnection
- func (bcc *BaseCommandConnection) AddHttpEndpoint(t httpendpoints.HttpEndpointType, ns, path string, backlog uint64) (*HttpEndpointUnixSocket, error)
- func (bcc *BaseCommandConnection) AddUserSession(access usersessions.AccessLevel, t usersessions.SessionType, origin string, ...) (int, error)
- func (bcc *BaseCommandConnection) Flush(channel types.CodeChannel) (bool, error)
- func (bcc *BaseCommandConnection) GetFileInfo(fileName string) (*job.ParsedFileInfo, error)
- func (bcc *BaseCommandConnection) GetMachineModel() (*machine.MachineModel, error)
- func (bcc *BaseCommandConnection) GetSerializedMachineModel() (json.RawMessage, error)
- func (bcc *BaseCommandConnection) LockMachineModel() error
- func (bcc *BaseCommandConnection) PerformCode(code *commands.Code) (*commands.CodeResult, error)
- func (bcc *BaseCommandConnection) PerformSimpleCode(code string, channel types.CodeChannel) (string, error)
- func (bcc *BaseCommandConnection) RemoveHttpEndpoint(t httpendpoints.HttpEndpointType, ns, path string) (bool, error)
- func (bcc *BaseCommandConnection) RemoveUserSession(id int) (bool, error)
- func (bcc *BaseCommandConnection) ResolvePath(path string) (string, error)
- func (bcc *BaseCommandConnection) SetMachineModel(path, value string) (bool, error)
- func (bcc *BaseCommandConnection) SyncMachineModel() error
- func (bcc *BaseCommandConnection) UnlockMachineModel() error
- type BaseConnection
- func (bc *BaseConnection) Close() error
- func (bc *BaseConnection) Connect(initMessage initmessages.ClientInitMessage, socketPath string) error
- func (bc *BaseConnection) PerformCommand(command commands.Command) (commands.Response, error)
- func (bc *BaseConnection) Receive(responseContainer interface{}) error
- func (bc *BaseConnection) ReceiveJSONString() (string, error)
- func (bc *BaseConnection) ReceiveJson() ([]byte, error)
- func (bc *BaseConnection) ReceiveResponse() (commands.Response, error)
- func (bc *BaseConnection) Send(data interface{}) error
- type Closer
- type CommandConnection
- type DecodeError
- type HttpEndpointConnection
- func (h *HttpEndpointConnection) Close() error
- func (h *HttpEndpointConnection) ReadRequest() (*commands.ReceivedHttpRequest, error)
- func (h *HttpEndpointConnection) Receive(responseContainer interface{}) error
- func (h *HttpEndpointConnection) ReceiveJson() (string, error)
- func (h *HttpEndpointConnection) Send(data interface{}) error
- func (h *HttpEndpointConnection) SendResponse(statusCode uint16, response string, t commands.HttpResponseType) error
- type HttpEndpointHandler
- type HttpEndpointUnixSocket
- type InterceptConnection
- func (ic *InterceptConnection) CancelCode() error
- func (ic *InterceptConnection) Connect(mode initmessages.InterceptionMode, socketPath string) error
- func (ic *InterceptConnection) IgnoreCode() error
- func (ic *InterceptConnection) ReceiveCode() (*commands.Code, error)
- func (ic *InterceptConnection) ResolveCode(mType messages.MessageType, content string) error
- type SubscribeConnection
Constants ¶
const ( // TaskCanceledException is the name of a remote exception to be checked for TaskCanceledException = "TaskCanceledException" // IncompatibleVersionException is the name of a remote exception to be checked for IncompatibleVersionException = "IncompatibleVersionException" // SocketDirectory is the default directory in which DSF-related UNIX sockets reside SocketDirectory = "/var/run/dsf" // SocketFile is the default UNIX socket file for DuetControlServer SocketFile = "dcs.sock" // FullSocketPath is the default fully-qualified path to the UNIX socket for DuetControlServer FullSocketPath = SocketDirectory + "/" + SocketFile )
const (
// DefaultBacklog for the Unix socket (currently unused)
DefaultBacklog = 4
)
Variables ¶
This section is empty.
Functions ¶
func CloseOnSignals ¶
func CloseOnSignals(c Closer)
CloseOnSignals will call Close on a connection if SIGINT or SIGTERM is encountered
Types ¶
type BaseCommandConnection ¶
type BaseCommandConnection struct {
BaseConnection
}
BaseCommandConnection for sending commands to the control server
func (*BaseCommandConnection) AddHttpEndpoint ¶
func (bcc *BaseCommandConnection) AddHttpEndpoint(t httpendpoints.HttpEndpointType, ns, path string, backlog uint64) (*HttpEndpointUnixSocket, error)
AddHttpEndpoint adds a new third-party HTTP endpoint in the format /machine/{ns}/{path}
func (*BaseCommandConnection) AddUserSession ¶
func (bcc *BaseCommandConnection) AddUserSession(access usersessions.AccessLevel, t usersessions.SessionType, origin string, originPort int) (int, error)
AddUserSession adds a new user session. Pass -1 as originPort to have it replaced by current PID.
func (*BaseCommandConnection) Flush ¶
func (bcc *BaseCommandConnection) Flush(channel types.CodeChannel) (bool, error)
Flush waits for all pending codes of the given channel to finish
func (*BaseCommandConnection) GetFileInfo ¶
func (bcc *BaseCommandConnection) GetFileInfo(fileName string) (*job.ParsedFileInfo, error)
GetFileInfo gets the parsed G-code file information
func (*BaseCommandConnection) GetMachineModel ¶
func (bcc *BaseCommandConnection) GetMachineModel() (*machine.MachineModel, error)
GetMachineModel retrieves the full object model of the machine. In subscription mode this is the first command that has to be called once a connection has been established
func (*BaseCommandConnection) GetSerializedMachineModel ¶
func (bcc *BaseCommandConnection) GetSerializedMachineModel() (json.RawMessage, error)
GetSerializedMachineModel fetches the machine model as UTF-8 JSON
func (*BaseCommandConnection) LockMachineModel ¶
func (bcc *BaseCommandConnection) LockMachineModel() error
LockMachineModel locks the machine model for read/write Access It is MANDATORY to call UnlockMachineModel when write access has finished
func (*BaseCommandConnection) PerformCode ¶
func (bcc *BaseCommandConnection) PerformCode(code *commands.Code) (*commands.CodeResult, error)
PerformCode executes an arbitrary pre-parsed code Note that even with an error being nil the returned *commands.CodeResult can also be nil, e.g. when sending Asynchronous commands that will only be queued and have no result yet.
func (*BaseCommandConnection) PerformSimpleCode ¶
func (bcc *BaseCommandConnection) PerformSimpleCode(code string, channel types.CodeChannel) (string, error)
PerformSimpleCode executes an arbitrary G/M/T-code in text form and returns the result as a string
func (*BaseCommandConnection) RemoveHttpEndpoint ¶
func (bcc *BaseCommandConnection) RemoveHttpEndpoint(t httpendpoints.HttpEndpointType, ns, path string) (bool, error)
RemoveHttpEndpoint removes an existing HTTP endpoint
func (*BaseCommandConnection) RemoveUserSession ¶
func (bcc *BaseCommandConnection) RemoveUserSession(id int) (bool, error)
RemoveUserSession removes an existing user session
func (*BaseCommandConnection) ResolvePath ¶
func (bcc *BaseCommandConnection) ResolvePath(path string) (string, error)
ResolvePath resolves a RepRapFirmware-style file path to a real file path
func (*BaseCommandConnection) SetMachineModel ¶
func (bcc *BaseCommandConnection) SetMachineModel(path, value string) (bool, error)
SetMachineModel sets a given property to a certain value. Make sure to lock the object model before calling this.
func (*BaseCommandConnection) SyncMachineModel ¶
func (bcc *BaseCommandConnection) SyncMachineModel() error
SyncMachineModel waits for the full machine model to be updated from RepRapFirmware
func (*BaseCommandConnection) UnlockMachineModel ¶
func (bcc *BaseCommandConnection) UnlockMachineModel() error
UnlockMachineModel unlocks the machine model
type BaseConnection ¶
type BaseConnection struct { Debug bool // contains filtered or unexported fields }
BaseConnection provides common functionalities for more concrete implementations
func (*BaseConnection) Close ¶
func (bc *BaseConnection) Close() error
Close the UNIX socket connection
func (*BaseConnection) Connect ¶
func (bc *BaseConnection) Connect(initMessage initmessages.ClientInitMessage, socketPath string) error
Connect establishes a connecton to the given UNIX socket file
func (*BaseConnection) PerformCommand ¶
PerformCommand performs an arbitrary command
func (*BaseConnection) Receive ¶
func (bc *BaseConnection) Receive(responseContainer interface{}) error
Receive a deserialized object
func (*BaseConnection) ReceiveJSONString ¶
func (bc *BaseConnection) ReceiveJSONString() (string, error)
ReceiveJSONString returns a server response as a JSON string
func (*BaseConnection) ReceiveJson ¶
func (bc *BaseConnection) ReceiveJson() ([]byte, error)
ReceiveJson returns a server response as a JSON []byteg
func (*BaseConnection) ReceiveResponse ¶
func (bc *BaseConnection) ReceiveResponse() (commands.Response, error)
ReceiveResponse receives a deserialized response from the server
func (*BaseConnection) Send ¶
func (bc *BaseConnection) Send(data interface{}) error
Send arbitrary data
type Closer ¶
type Closer interface { // Close the UNIX socket connection Close() error }
Closer is the interface implemented by all connections
type CommandConnection ¶
type CommandConnection struct {
BaseCommandConnection
}
CommandConnection used to send commands to the control server
func (*CommandConnection) Connect ¶
func (cc *CommandConnection) Connect(socketPath string) error
Connect sends a CommandInitMessage to the server
type DecodeError ¶
DecodeError is returned if a response from DCS could not be unmarshalled
func (*DecodeError) Error ¶
func (e *DecodeError) Error() string
func (*DecodeError) Unwrap ¶
func (e *DecodeError) Unwrap() error
type HttpEndpointConnection ¶
type HttpEndpointConnection struct {
// contains filtered or unexported fields
}
HttpEndpointConnection is dealing with requests received from a custom HTTP endpoint
func NewHttpEndpointConnection ¶
func NewHttpEndpointConnection(c net.Conn, isWebSocket bool) *HttpEndpointConnection
NewHttpEndpointConnection creates a new instance of HttpEndpointConnection
func (*HttpEndpointConnection) Close ¶
func (h *HttpEndpointConnection) Close() error
Close closes the underlying connection
func (*HttpEndpointConnection) ReadRequest ¶
func (h *HttpEndpointConnection) ReadRequest() (*commands.ReceivedHttpRequest, error)
ReadRequest reads information about the last HTTP request. A call to this method may fail
func (*HttpEndpointConnection) Receive ¶
func (h *HttpEndpointConnection) Receive(responseContainer interface{}) error
Receive a deserialized object
func (*HttpEndpointConnection) ReceiveJson ¶
func (h *HttpEndpointConnection) ReceiveJson() (string, error)
ReceiveJson returns a server response as a JSON string
func (*HttpEndpointConnection) Send ¶
func (h *HttpEndpointConnection) Send(data interface{}) error
Send arbitrary data
func (*HttpEndpointConnection) SendResponse ¶
func (h *HttpEndpointConnection) SendResponse(statusCode uint16, response string, t commands.HttpResponseType) error
SendResponse sends a simple HTTP response to the client and closes this connection unless it is a WebSocket
type HttpEndpointHandler ¶
type HttpEndpointHandler interface { // Handle the client request Handle(h *HttpEndpointUnixSocket, c *HttpEndpointConnection) }
HttpEndpointHandler defines the method that is called for connection handling
type HttpEndpointUnixSocket ¶
type HttpEndpointUnixSocket struct { // EndpointType of this HTTP endpoint EndpointType httpendpoints.HttpEndpointType // Namespace of this HTTO endpoint Namespace string // EndpointPath of this HTTP endpoint EndpointPath string // SocketPath to the UNIX socket file SocketPath string // Handler to handle individiual requests Handler HttpEndpointHandler // contains filtered or unexported fields }
HttpEndpointUnixSocket deals with custom HTTP endpoints
func NewHttpEndpointUnixSocket ¶
func NewHttpEndpointUnixSocket(t httpendpoints.HttpEndpointType, ns, path, socketPath string, backlog uint64) (*HttpEndpointUnixSocket, error)
NewHttpEndpointUnixSocket opens a new UNIX socket on the given file path
func (*HttpEndpointUnixSocket) Close ¶
func (h *HttpEndpointUnixSocket) Close() error
Close the socket connection and remove the corresponding socket file
type InterceptConnection ¶
type InterceptConnection struct { BaseCommandConnection Mode initmessages.InterceptionMode }
InterceptConnection to intercept G/M/T-codes from the control server
If this connection type is used to implement new G/M/T-codes, always call the commands.Flush command before further actions are started and make sure it returns true> before the code is further processed. This step is mandatory to guarantee that the new code is executed when all other codes have finished and not when a code is being fed for the internal G-code buffer. If the Flush command returns false, it is recommended to use CancelCode() to resolve the command. DCS follows the same pattern for internally processed codes, too. If a code from a macro file is intercepted, make sure to set the commands.CodeFlags.IsFromMacro flag if new codes are inserted, else they will be started when the macro file(s) have finished. This step is obsolete if a commands.SimpleCode is inserted.
func (*InterceptConnection) CancelCode ¶
func (ic *InterceptConnection) CancelCode() error
CancelCode instructs the control server to cancel the last received code
func (*InterceptConnection) Connect ¶
func (ic *InterceptConnection) Connect(mode initmessages.InterceptionMode, socketPath string) error
Connect sends a InterceptInitMessage to the control server
func (*InterceptConnection) IgnoreCode ¶
func (ic *InterceptConnection) IgnoreCode() error
IgnoreCode tells the control server that this connection is not interested in the last received Code so it can continue with handling it.
func (*InterceptConnection) ReceiveCode ¶
func (ic *InterceptConnection) ReceiveCode() (*commands.Code, error)
ReceiveCode waits for a code to be intercepted Any other error than io.EOF requires the client to respond by either CancelCode(), IgnoreCode() or ResolveCode() because DCS will otherwise block while waiting for the Interceptor's response.
func (*InterceptConnection) ResolveCode ¶
func (ic *InterceptConnection) ResolveCode(mType messages.MessageType, content string) error
ResolveCode instructs the control server to resolve the last received code with the given message details
type SubscribeConnection ¶
type SubscribeConnection struct { BaseConnection Mode initmessages.SubscriptionMode Filter string }
SubscribeConnection is used to subscribe for object model updates
func (*SubscribeConnection) Connect ¶
func (sc *SubscribeConnection) Connect(mode initmessages.SubscriptionMode, filter, socketPath string) error
Connect will send a SubscribeInitMessage to the control server
func (*SubscribeConnection) GetMachineModel ¶
func (sc *SubscribeConnection) GetMachineModel() (*machine.MachineModel, error)
GetMachineModel retrieves the full object model of the machine. In subscription mode this is the first command that has to be called once a connection has been established
func (*SubscribeConnection) GetMachineModelPatch ¶
func (sc *SubscribeConnection) GetMachineModelPatch() (string, error)
GetMachineModelPatch receives a (partial) machine model update as JSON UTF-8 string. If the subscription mode is set to Patch, new update patches of the object model need to be applied manually. This method is intended to receive such fragments.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package initmessages contains all init messages that can be used to initiate a certain type of connection with DuetControlServer.
|
Package initmessages contains all init messages that can be used to initiate a certain type of connection with DuetControlServer. |