Commit Graph

34 Commits

Author SHA1 Message Date
Kevin O'Connor b8c91914b7 webhooks: Convert to Python3 string encoding
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2021-10-04 14:36:08 -04:00
Kevin O'Connor cf2e941aec webhooks: Add register_mux_endpoint() helper function
Add ability to register an endpoint that invokes a handler based on a
parameter in the request.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2021-08-22 11:10:19 -04:00
Eric Callahan c64ea474d7 webhooks: log client requests on shutdown
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2021-08-21 15:00:29 -04:00
Kevin O'Connor 69d9497df3 webhooks: Remove spaces from json messages sent on api server
Reduce the bandwidth slightly by removing unnecessary spaces in
messages.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2021-07-29 16:54:21 -04:00
Maël Kerbiriou 9278f56e36
webhooks: Fix use of deprecated Exception.message attribute (#3781)
Since Python 2.6, the BaseException.message attribute is deprecated (PEP-352[1])
in favor of e.args[0] or str(e). This commit replaces e.message with str(e).

[1] https://www.python.org/dev/peps/pep-0352/

Signed-off-by: Maël Kerbiriou <m431.kerbiriou@gmail.com>
2021-01-17 22:37:41 -05:00
Kevin O'Connor ea85d419de gcode: Move definition of CommandError and Coord from homing.py to gcode.py
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2021-01-08 12:07:45 -05:00
Kevin O'Connor 1af28d8a79 webhooks: Improve python3 compatibility
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2020-12-01 11:07:36 -05:00
Arksine 108b66efe9 webhooks: Add "register_remote_method" endpoint
This allows clients to register methods that can be called from Klipper.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2020-11-04 18:32:30 -05:00
Kevin O'Connor 08adecd226 homing: Prefer printer.command_error() instead of homing.CommandError()
Update callers to use the printer.command_error reference instead of
directly using homing.CommandError() when raising or catching errors.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2020-09-04 12:10:36 -04:00
Kevin O'Connor b6a25393d3 webhooks: Add client_info parameter to "info" webhook
Allow clients to send their version info to klipper and arrange for
that info to be logged.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2020-08-26 10:12:58 -04:00
Kevin O'Connor b2c78d71b0 gcode: Remove "action_" commands from get_status() calls
Rename printer.gcode.action_emergency_stop() to
action_emergency_stop(), printer.gcode.action_respond_info() to
action_respond_info(), and printer.gcode.action_respond_error() to
action_raise_error() in command templates.

This simplifies the get_status() interface, as returning callable
functions from that interface was confusing.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2020-08-20 21:03:22 -04:00
Kevin O'Connor fa83b1319c webhooks: Improve type checking of api requests
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2020-08-16 13:49:45 -04:00
Kevin O'Connor 7ec2ec30e3 webhooks: Convert to a json-rpc inspired message format
Convert to a new json message format.  Requests look like:

{"id":14, "method": "info", "params": {}}

and responses look like:

{"id": 14, "result": {}}

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2020-08-16 13:23:16 -04:00
Kevin O'Connor 2b0b30ccd5 webhooks: Remove call_remote_method()
Clients will now only receive messages that they've subscribed to.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2020-08-16 13:23:16 -04:00
Kevin O'Connor 1ae671f61f webhooks: Add klippy state to webhooks get_status() method
Clients can now subscribe to the webhooks get_status() info to
determine if the printer state changes.  It is no longer needed to
send a message to all clients on a shutdown transition.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2020-08-16 13:23:16 -04:00
Kevin O'Connor b0e3effb53 webhooks: Rework get_status() subscriptions
Implement a new subscription system for get_status() updates.
Subscriptions are per-client.  After an initial update, only changes
will be transmitted.  Responses are only transmitted to the client
that issued the subscription.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2020-08-16 13:23:05 -04:00
Kevin O'Connor 16a53e6918 webhooks: Require a subscription to receive gcode output
Add a new "gcode/subscribe_output" webhook endpoint to subscribe to
gcode output.  Only client connections that subscribe to the gcode
output will receive that output.

This also moves all the gcode webhooks from gcode.py to webhooks.py
and arranges for gcode.py to be initialized prior to webhooks.py.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2020-08-16 13:20:26 -04:00
Kevin O'Connor 568393c941 webhooks: Remove "method" parameter from webhook requests
Don't require or use the "method" parameter of requests.  This
simplifies the interface.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2020-08-16 13:20:25 -04:00
Kevin O'Connor 7289af6560 webhooks: Create StatusHandler class in add_early_printer_objects()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2020-08-16 13:20:25 -04:00
Kevin O'Connor b74a5c5217 webhooks: Remove register_static_path()
Use the "info" webhook to pass critical process information back to
the caller.  The remaining users of register_static_path() can get the
required information via get_status() calls.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2020-08-16 13:20:25 -04:00
Kevin O'Connor 0aad2437c5 webhooks: Specify server_address on klippy command-line
Don't default to "/tmp/klippy_uds" for the webhooks unix domain socket
filename.  Instead, require the filename to be specified on the
command-line (via a new "-a" parameter).

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2020-08-16 13:20:25 -04:00
Arksine 0c7faa978c webhooks: register gcode output handler and additional static paths
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2020-08-11 10:47:04 -04:00
Arksine bf221d5e26 webhooks: Implement a send buffer for socket writes
This prevents ClientConnection.send() from blocking, removing the possibility that callers become reentrant.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2020-08-11 10:47:04 -04:00
Arksine 4dcf494b97 webhooks: Implement unix domain socket server
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2020-08-11 10:47:04 -04:00
Arksine 27ef58642e webhooks: Implement StatusHandler class
This class provides endpoints that allow connected hosts to fetch the state of printer objects and subscribe to state "pushed" over the connection.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2020-08-06 14:30:48 -04:00
Arksine cde7e75139 webhooks: Add call_remote_method helper function
This may be used to execute formatted RPC calls.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2020-08-06 14:30:13 -04:00
Kevin O'Connor 795bd03b33 webhooks: Directly invoke printer.invoke_shutdown()
No need to indirectly shutdown via the gcode class - just call
printer.invoke_shutdown() directly.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2020-08-06 14:21:08 -04:00
Kevin O'Connor 4346d37c06 webhooks: Introduce add_early_printer_objects()
Create the initial gcode class via new module level
add_early_printer_objects() function.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
2020-08-06 14:21:08 -04:00
Arksine 180f44b876 webhooks: fix lambda wrapper around _process_request
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2020-07-13 18:39:15 -04:00
Arksine cd8f250e84 webooks: do not connect if debuginput is enabled
Changing this check from debugoutput to debuginput allows remote applications to perform tests against Klippy without an MCU connected.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2020-07-06 12:57:50 -04:00
Arksine bfbdc04c02 webhooks: process request handlers using a Reactor Callback
This prevents _process_data from blocking and becoming reentrant.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2020-07-06 12:57:50 -04:00
Arksine 014c06f8a2 klippy: return message category in get_state_message()
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2020-06-24 19:07:33 -04:00
Arksine 2d2c09a0a3 webhooks: protect command processing from re-entry
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2020-06-24 19:07:33 -04:00
Arksine 475f543790 webhooks: Initial implementation
The webhooks module provides a means for Klippy to register remote API endpoints.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
2020-06-24 19:07:33 -04:00