Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSanimir Agovic2018-12-28 14:55:23 +0000
committerSanimir Agovic2018-12-28 14:55:42 +0000
commit6e6dc03e79785816bf0847a90f86936402639684 (patch)
tree2bc86c6f6ecc4986315f595e4a25a852088673a3
parent2385d4fa0d7634de8ade13d06060aad5043ed1ee (diff)
downloadorg.eclipse.tcf-6e6dc03e79785816bf0847a90f86936402639684.tar.gz
org.eclipse.tcf-6e6dc03e79785816bf0847a90f86936402639684.tar.xz
org.eclipse.tcf-6e6dc03e79785816bf0847a90f86936402639684.zip
TCF Python: initial implementation of a basic Reset service client
Usage: import tcf from tcf import protocol from tcf.util import sync from tcf.services import contextreset protocol.startEventQueue() c = tcf.connect("TCP:localhost:1534") cmds = sync.CommandControl(c) ctx = cmds.RunControl.getChildren(None).getE()[0] caps = cmds.ContextReset.getCapabilities(ctx).getE() print("Reset capabilities: {}".format(caps)) reset_type = caps[0][contextreset.CAPABILITY_TYPE] params = {contextreset.PARAM_SUSPEND : True} cmds.ContextReset.reset(ctx, reset_type, params).getE() Change-Id: I40e07e4c83e224b76d4c1a0df7d185ac374b68cd Signed-off-by: Sanimir Agovic <sanimir@subpath.org>
-rw-r--r--python/src/docs/rst/tcf/services/contextreset.rst5
-rw-r--r--python/src/tcf/services/contextreset.py128
-rw-r--r--python/src/tcf/services/remote/ContextReset.py58
3 files changed, 191 insertions, 0 deletions
diff --git a/python/src/docs/rst/tcf/services/contextreset.rst b/python/src/docs/rst/tcf/services/contextreset.rst
new file mode 100644
index 000000000..d5ca525ca
--- /dev/null
+++ b/python/src/docs/rst/tcf/services/contextreset.rst
@@ -0,0 +1,5 @@
+.. include:: /globals.rst
+
+ContextReset
+============
+.. automodule:: tcf.services.contextreset
diff --git a/python/src/tcf/services/contextreset.py b/python/src/tcf/services/contextreset.py
new file mode 100644
index 000000000..14cea9e82
--- /dev/null
+++ b/python/src/tcf/services/contextreset.py
@@ -0,0 +1,128 @@
+# *****************************************************************************
+# * Copyright (c) 2019.
+# * All rights reserved. This program and the accompanying materials
+# * are made available under the terms of the Eclipse Public License v1.0
+# * which accompanies this distribution, and is available at
+# * http://www.eclipse.org/legal/epl-v10.html
+# *****************************************************************************
+
+"""TCF ContextReset service interface.
+
+ContextReset Properties
+-----------------------
+Parameters
+^^^^^^^^^^
++------------------+--------------+-------------------------------------------+
+| Name | Type | Description |
++==================+==============+===========================================+
+| PARAM_SUSPEND | |bool| | If **true**, the context should be |
+| | | suspended after reset. |
++------------------+--------------+-------------------------------------------+
+
+Capabilities
+^^^^^^^^^^^^
++------------------------+--------------+-------------------------------------+
+| Name | Type | Description |
++========================+==============+=====================================+
+| CAPABILITY_TYPE | |str| | The name of the reset. |
++------------------------+--------------+-------------------------------------+
+| CAPABILITY_DESCRIPTION | |str| | Brief description of the reset |
++------------------------+--------------+-------------------------------------+
+| CAPABILITY_SUSPEND | |bool| | If **True**, context suspend is |
+| | | supported. |
++------------------------+--------------+-------------------------------------+
+
+Service Methods
+---------------
+.. autodata:: NAME
+.. autoclass:: ContextResetService
+
+reset
+^^^^^
+.. automethod:: ContextResetService.reset
+
+getCapabilities
+^^^^^^^^^^^^^^^
+.. automethod:: ContextResetService.getCapabilities
+
+Callback Classes
+----------------
+DoneReset
+^^^^^^^^^
+.. autoclass:: DoneReset
+ :members:
+
+DoneGetCapabilities
+^^^^^^^^^^^^^^^^^^^
+.. autoclass:: DoneGetCapabilities
+ :members:
+"""
+
+from .. import services
+
+NAME = "ContextReset"
+"""ContextReset service name."""
+
+CAPABILITY_TYPE = "Type"
+CAPABILITY_DESCRIPTION = "Description"
+
+# context reset parameters
+PARAM_SUSPEND = "Suspend"
+
+
+class ContextResetService(services.Service):
+ def getName(self):
+ """Get this service name.
+
+ :returns: The value of string :const:`NAME`
+ """
+ return NAME
+
+ def getCapabilities(self, context_id, done):
+ """Retrieve context reset service capabilities a given context-id.
+
+ :param context_id: a context ID, usually one returned by Run Control
+ or Memory services.
+ :param done: command result call back object.
+ :type done: :class:`DoneGetCapabilities`
+
+ :returns: pending command handle.
+ """
+ raise NotImplementedError("Abstract method")
+
+ def reset(self, context_id, type, params, done):
+ """Reset a specified context.
+
+ :param context_id: a context ID, usually one returned by Run Control.
+ :param type: the reset type.
+ :param params: parameteres to control the reset.
+ :param done: command result call back object.
+ :type done: :class:`DoneReset`
+
+ :returns: pending command handle.
+ """
+ raise NotImplementedError("Abstract method")
+
+
+class DoneGetCapabilities(object):
+ """Call back interface for 'getCapabilities' command."""
+ def doneGetCapabilities(self, token, error, capabilities):
+ """Called when capabilities retrieval is done.
+
+ :param token: command handle.
+ :param error: error object or None.
+ :param capabilities: array of capabilities, see `Capabilities`_ for
+ contents of each array element.
+ """
+ pass
+
+
+class DoneReset(object):
+ """Call back interface for 'reset' command."""
+ def doneReset(self, token, error):
+ """Called when reset is done.
+
+ :param token: command handle.
+ :param error: error object or None.
+ """
+ pass
diff --git a/python/src/tcf/services/remote/ContextReset.py b/python/src/tcf/services/remote/ContextReset.py
new file mode 100644
index 000000000..22afb1a06
--- /dev/null
+++ b/python/src/tcf/services/remote/ContextReset.py
@@ -0,0 +1,58 @@
+# *****************************************************************************
+# * Copyright (c) 2019.
+# * All rights reserved. This program and the accompanying materials
+# * are made available under the terms of the Eclipse Public License v1.0
+# * which accompanies this distribution, and is available at
+# * http://www.eclipse.org/legal/epl-v10.html
+# *****************************************************************************
+
+from .. import contextreset
+from ...channel.Command import Command
+
+
+class ContextResetProxy(contextreset.ContextResetService):
+
+ def __init__(self, channel):
+ self.channel = channel
+
+ def getCapabilities(self, context_id, done):
+ done = self._makeCallback(done)
+ service = self
+
+ class GetCapabilitiesCommand(Command):
+
+ def __init__(self):
+ super(GetCapabilitiesCommand, self).__init__(service.channel,
+ service,
+ "getCapabilities",
+ (context_id,))
+
+ def done(self, error, args):
+ arr = None
+ if not error:
+ assert len(args) == 2
+ error = self.toError(args[0])
+ arr = args[1]
+ done.doneGetCapabilities(self.token, arr, error)
+ return GetCapabilitiesCommand().token
+
+ def reset(self, context_id, type, params, done):
+ done = self._makeCallback(done)
+ service = self
+
+ class ResetCommand(Command):
+
+ def __init__(self):
+ super(ResetCommand, self).__init__(service.channel,
+ service,
+ reset",
+ (context_id, type,
+ params))
+
+ def done(self, error, args):
+ arr = None
+ if not error:
+ assert len(args) == 2
+ error = self.toError(args[0])
+ done.doneReset(self.token, error)
+ return DisassembleCommand().token

Back to the top