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, isUploadRequest bool, ...) (*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) GetObjectModel() (*machine.MachineModel, error)
- func (bcc *BaseCommandConnection) GetSerializedMachineModel() (json.RawMessage, error)
- func (bcc *BaseCommandConnection) GetSerializedObjectModel() (json.RawMessage, error)
- func (bcc *BaseCommandConnection) InstallPlugin(pluginFile string) error
- func (bcc *BaseCommandConnection) LockMachineModel() error
- func (bcc *BaseCommandConnection) LockObjectModel() error
- func (bcc *BaseCommandConnection) PatchObjectModel(key, value string) 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) SetObjectModel(path, value string) (bool, error)
- func (bcc *BaseCommandConnection) SetPluginData(plugin, key, value string) error
- func (bcc *BaseCommandConnection) SetUpdateStatus(updating bool) error
- func (bcc *BaseCommandConnection) StartPlugin(plugin string) error
- func (bcc *BaseCommandConnection) StopPlugin(plugin string) error
- func (bcc *BaseCommandConnection) SyncMachineModel() error
- func (bcc *BaseCommandConnection) SyncObjectModel() error
- func (bcc *BaseCommandConnection) UninstallPlugin(plugin string) error
- func (bcc *BaseCommandConnection) UnlockMachineModel() error
- func (bcc *BaseCommandConnection) UnlockObjectModel() error
- func (bcc *BaseCommandConnection) WriteMessage(message messages.Message, outputMessage, logMessage bool) error
- func (bcc *BaseCommandConnection) WriteTextMessage(mType messages.MessageType, message string, outputMessage, logMessage bool) 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, channels []types.CodeChannel, ...) 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 = "/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, isUploadRequest bool, 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 Deprecated: Use GetObjectModel instead
func (*BaseCommandConnection) GetObjectModel ¶ added in v3.2.0
func (bcc *BaseCommandConnection) GetObjectModel() (*machine.MachineModel, error)
GetObjectModel 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 Deprecated: Use GetSerializedObjectModel instead
func (*BaseCommandConnection) GetSerializedObjectModel ¶ added in v3.2.0
func (bcc *BaseCommandConnection) GetSerializedObjectModel() (json.RawMessage, error)
GetSerializedObjectModel fetches the object model as UTF-8 JSON
func (*BaseCommandConnection) InstallPlugin ¶ added in v3.2.0
func (bcc *BaseCommandConnection) InstallPlugin(pluginFile string) error
InstallPlugin to install or upgrade a plugin. pluginFile is the absolute file path to the plugin ZIP bundle
func (*BaseCommandConnection) LockMachineModel ¶
func (bcc *BaseCommandConnection) LockMachineModel() error
LockMachineModel locks the machine model for read/write Access It is MANDATORY to call UnlockObjectModel when write access has finished Deprecated: Use LockObjectModel instead
func (*BaseCommandConnection) LockObjectModel ¶ added in v3.2.0
func (bcc *BaseCommandConnection) LockObjectModel() error
LockObjectModel locks the machine model for read/write Access It is MANDATORY to call UnlockObjectModel when write access has finished
func (*BaseCommandConnection) PatchObjectModel ¶ added in v3.2.0
func (bcc *BaseCommandConnection) PatchObjectModel(key, value string) error
PatchObjectModel will apply a full patch to the object model. Use with care!
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. Deprecated: Use SetObjectModel instead
func (*BaseCommandConnection) SetObjectModel ¶ added in v3.2.0
func (bcc *BaseCommandConnection) SetObjectModel(path, value string) (bool, error)
SetObjectModel sets a given property to a certain value. Make sure to lock the object model before calling this.
func (*BaseCommandConnection) SetPluginData ¶ added in v3.2.0
func (bcc *BaseCommandConnection) SetPluginData(plugin, key, value string) error
SetPluginData sets custom plugin data in the object model plugin is the name of the plugin and is optional. Leave empty if not needed
func (*BaseCommandConnection) SetUpdateStatus ¶ added in v3.2.0
func (bcc *BaseCommandConnection) SetUpdateStatus(updating bool) error
SetUpdateStatus overrides the current machin status if a software update is in progress. The object model may not be locked when this is called.
func (*BaseCommandConnection) StartPlugin ¶ added in v3.2.0
func (bcc *BaseCommandConnection) StartPlugin(plugin string) error
StartPlugin starts a plugin
func (*BaseCommandConnection) StopPlugin ¶ added in v3.2.0
func (bcc *BaseCommandConnection) StopPlugin(plugin string) error
StopPlugin stops a plugin
func (*BaseCommandConnection) SyncMachineModel ¶
func (bcc *BaseCommandConnection) SyncMachineModel() error
SyncMachineModel waits for the full machine model to be updated from RepRapFirmware Deprecated: Use SyncObjectModel instead
func (*BaseCommandConnection) SyncObjectModel ¶ added in v3.2.0
func (bcc *BaseCommandConnection) SyncObjectModel() error
SyncObjectModel waits for the full object model to be updated from RepRapFirmware
func (*BaseCommandConnection) UninstallPlugin ¶ added in v3.2.0
func (bcc *BaseCommandConnection) UninstallPlugin(plugin string) error
UninstallPlugin uninstalls a plugin
func (*BaseCommandConnection) UnlockMachineModel ¶
func (bcc *BaseCommandConnection) UnlockMachineModel() error
UnlockMachineModel unlocks the machine model Deprecated: Use UnlockObjectModel instead
func (*BaseCommandConnection) UnlockObjectModel ¶ added in v3.2.0
func (bcc *BaseCommandConnection) UnlockObjectModel() error
UnlockObjectModel unlocks the object model
func (*BaseCommandConnection) WriteMessage ¶ added in v3.2.0
func (bcc *BaseCommandConnection) WriteMessage(message messages.Message, outputMessage, logMessage bool) error
Write an arbitrary generic message from an existing messages.Message instance
func (*BaseCommandConnection) WriteTextMessage ¶ added in v3.2.0
func (bcc *BaseCommandConnection) WriteTextMessage(mType messages.MessageType, message string, outputMessage, logMessage bool) error
Write an arbitrary generic message
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 Channels []types.CodeChannel Filters []string PriorityCodes bool }
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, channels []types.CodeChannel, filters []string, priorityCodes bool, socketPath string) error
Connect sends a InterceptInitMessage to the control server mode is the initmessages.InterceptionMode channels is an optional list of input channels to intercept codes from (empty list = all) filters to filter specific codes (see initmessages.InterceptInitMessage for details) priorityCodes to enable codes with CodeFlags.IsPrioritized
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 is the deprecated delimited filter expression Filter string // Filters is a list of filter expressions Filters []string }
SubscribeConnection is used to subscribe for object model updates
func (*SubscribeConnection) Connect ¶
func (sc *SubscribeConnection) Connect(mode initmessages.SubscriptionMode, filters []string, 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. |