From ee854f44ccaf698c2f8f8f1b077229fa8b549a00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 4 Mar 2019 17:29:00 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=20Make=20some=20protocol=20flags=20dy?= =?UTF-8?q?namic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Less risk of forgetting to adjust them on some randomg state change. Fixes issues with pausing/resuming/finishing. --- src/octoprint/comm/job/__init__.py | 6 +++++ .../comm/protocol/reprap/__init__.py | 26 +++++++------------ 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/octoprint/comm/job/__init__.py b/src/octoprint/comm/job/__init__.py index 04fe48dc0..aa11d9d1b 100644 --- a/src/octoprint/comm/job/__init__.py +++ b/src/octoprint/comm/job/__init__.py @@ -34,6 +34,10 @@ class LastResult(object): class Printjob(with_metaclass(ABCMeta, ProtocolListener, ListenerAware)): parallel = False + """Job runs parallel to regular communication.""" + + exclusive = False + """Job has exclusive claim to communication channel.""" def __init__(self, name=None, user=None, event_data=None): if event_data is None: @@ -378,6 +382,8 @@ class CopyJobMixin(object): class LocalGcodeStreamjob(LocalGcodeFilePrintjob, CopyJobMixin): + exclusive = True + @classmethod def from_job(cls, job, remote): if not isinstance(job, LocalGcodeFilePrintjob): diff --git a/src/octoprint/comm/protocol/reprap/__init__.py b/src/octoprint/comm/protocol/reprap/__init__.py index c1b0dc544..16c258de2 100644 --- a/src/octoprint/comm/protocol/reprap/__init__.py +++ b/src/octoprint/comm/protocol/reprap/__init__.py @@ -223,9 +223,15 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt long_running_command=False, # misc - only_from_job=False, - trigger_events=True, - expect_continous_comms=False, + only_from_job=BooleanCallbackValue(lambda: self.state in ProtocolState.PROCESSING_STATES + and self._job + and self._job.exclusive), + trigger_events=BooleanCallbackValue(lambda: not (self.state in ProtocolState.PROCESSING_STATES + and self._job + and self._job.exclusive)), + expect_continous_comms=BooleanCallbackValue(lambda: self.state in ProtocolState.PROCESSING_STATES + and self._job + and not self._job.parallel), ignore_ok=0, job_on_hold=BooleanCallbackValue(lambda: self.job_on_hold), @@ -349,17 +355,6 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt transport_args=transport_args, transport_kwargs=transport_kwargs) - def process(self, job, position=0, user=None, tags=None): - if isinstance(job, LocalGcodeStreamjob): - self._internal_flags["only_from_job"] = True - self._internal_flags["trigger_events"] = False - else: - self._internal_flags["only_from_job"] = False - self._internal_flags["trigger_events"] = True - self._internal_flags["expect_continous_comms"] = not job.parallel - - super(ReprapGcodeProtocol, self).process(job, position=position, user=user, tags=tags) - # cancel handling def _cancel_preparation_failed(self): @@ -789,9 +784,6 @@ class ReprapGcodeProtocol(Protocol, ThreeDPrinterProtocolMixin, MotorControlProt self._continue_sending() def _job_processed(self, job, *args, **kwargs): - self._internal_flags["expect_continous_comms"] = False - self._internal_flags["only_from_job"] = False - self._internal_flags["trigger_events"] = True self._job.unregister_listener(self) def _job_on_hold_cleared(self):