Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
authoraleherbau2011-05-20 12:04:31 +0000
committeraleherbau2011-05-20 12:04:31 +0000
commit4db8bf13e9f4a3236a70d0d4c5dccad4fad009c1 (patch)
tree060c041435f4f35b2acb58d64d6939d906bce4be /python
parentb22e0e7f1f599d75743ca0d0ac42d0e35aae6f98 (diff)
downloadorg.eclipse.tcf-4db8bf13e9f4a3236a70d0d4c5dccad4fad009c1.tar.gz
org.eclipse.tcf-4db8bf13e9f4a3236a70d0d4c5dccad4fad009c1.tar.xz
org.eclipse.tcf-4db8bf13e9f4a3236a70d0d4c5dccad4fad009c1.zip
TCF Python: Implemented Diagnostics service proxy
Diffstat (limited to 'python')
-rw-r--r--python/src/tcf/services/diagnostics.py285
-rw-r--r--python/src/tcf/services/remote/DiagnosticsProxy.py174
2 files changed, 459 insertions, 0 deletions
diff --git a/python/src/tcf/services/diagnostics.py b/python/src/tcf/services/diagnostics.py
new file mode 100644
index 000000000..aee1ac04a
--- /dev/null
+++ b/python/src/tcf/services/diagnostics.py
@@ -0,0 +1,285 @@
+# *******************************************************************************
+# * Copyright (c) 2011 Wind River Systems, Inc. and others.
+# * 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
+# *
+# * Contributors:
+# * Wind River Systems - initial API and implementation
+# *******************************************************************************
+
+"""
+This is an optional service that can be implemented by a peer.
+If implemented, the service can be used for testing of the peer and
+communication channel functionality and reliability.
+"""
+
+from tcf import services
+
+NAME = "Diagnostics"
+
+class DiagnosticsService(services.Service):
+ def getName(self):
+ return NAME
+
+ def echo(self, s, done):
+ """
+ 'echo' command result returns same string that was given as command argument.
+ The command is used to test communication channel ability to transmit arbitrary strings in
+ both directions.
+ @param s - any string.
+ @param done - command result call back object.
+ @return - pending command handle.
+ """
+ return NotImplementedError("Abstract method")
+
+ def echoFP(self, n, done):
+ """
+ 'echoFP' command result returns same floating point number that was given as command argument.
+ The command is used to test communication channel ability to transmit arbitrary floating point numbers in
+ both directions.
+ @param n - any floating point number.
+ @param done - command result call back object.
+ @return - pending command handle.
+ """
+ return NotImplementedError("Abstract method")
+
+ def echoERR(self, error, done):
+ """
+ 'echoERR' command result returns same error report that was given as command argument.
+ The command is used to test remote agent ability to receive and transmit TCF error reports.
+ @param error - an error object.
+ @param done - command result call back object.
+ @return - pending command handle.
+ """
+ return NotImplementedError("Abstract method")
+
+ def getTestList(self, done):
+ """
+ Get list of test names that are implemented by the service.
+ Clients can request remote peer to run a test from the list.
+ When started, a test performs a predefined set actions.
+ Nature of test actions is uniquely identified by test name.
+ Exact description of test actions is a contract between client and remote peer,
+ and it is not part of Diagnostics service specifications.
+ Clients should not attempt to run a test if they don't recognize the test name.
+ @param done - command result call back object.
+ @return - pending command handle.
+ """
+ return NotImplementedError("Abstract method")
+
+ def runTest(self, name, done):
+ """
+ Run a test. When started, a test performs a predefined set actions.
+ Nature of test actions is uniquely identified by test name.
+ Running test usually has associated execution context ID.
+ Depending on the test, the ID can be used with services RunControl and/or Processes services to control
+ test execution, and to obtain test results.
+ @param name - test name
+ @param done - command result call back object.
+ @return - pending command handle.
+ """
+ return NotImplementedError("Abstract method")
+
+ def cancelTest(self, context_id, done):
+ """
+ Cancel execution of a test.
+ @param context_id - text execution context ID.
+ @param done - command result call back object.
+ @return - pending command handle.
+ """
+ return NotImplementedError("Abstract method")
+
+ def getSymbol(self, context_id, symbol_name, done):
+ """
+ Get information about a symbol in text execution context.
+ @param context_id
+ @param symbol_name
+ @param done
+ @return
+ """
+ return NotImplementedError("Abstract method")
+
+ def createTestStreams(self, inp_buf_size, out_buf_size, done):
+ """
+ Create a pair of virtual streams, @see IStreams service.
+ Remote ends of the streams are connected, so any data sent into 'inp' stream
+ will become for available for reading from 'out' stream.
+ The command is used for testing virtual streams.
+ @param inp_buf_size - buffer size in bytes of the input stream.
+ @param out_buf_size - buffer size in bytes of the output stream.
+ @param done - command result call back object.
+ @return - pending command handle.
+ """
+ return NotImplementedError("Abstract method")
+
+ def disposeTestStream(self, id, done):
+ """
+ Dispose a virtual stream that was created by 'createTestStreams' command.
+ @param id - the stream ID.
+ @param done - command result call back object.
+ @return - pending command handle.
+ """
+ return NotImplementedError("Abstract method")
+
+ def not_implemented_command(self, done):
+ """
+ Send a command that is not implemented by peer.
+ Used to test handling of 'N' messages by communication channel.
+ @param done - command result call back object.
+ @return - pending command handle.
+ """
+ return NotImplementedError("Abstract method")
+
+
+class DoneEcho(object):
+ """
+ Call back interface for 'echo' command.
+ """
+ def doneEcho(self, token, error, s):
+ """
+ Called when 'echo' command is done.
+ @param token - command handle.
+ @param error - error object or null.
+ @param s - same string as the command argument.
+ """
+ pass
+
+class DoneEchoFP(object):
+ """
+ Call back interface for 'echoFP' command.
+ """
+ def doneEchoFP(self, token, error, n):
+ """
+ Called when 'echoFP' command is done.
+ @param token - command handle.
+ @param error - error object or null.
+ @param n - same number as the command argument.
+ """
+ pass
+
+class DoneEchoERR(object):
+ """
+ Call back interface for 'echoERR' command.
+ """
+ def doneEchoERR(self, token, error, error_obj, error_msg):
+ """
+ Called when 'echoERR' command is done.
+ @param token - command handle.
+ @param error - communication error report or null.
+ @param error_obj - error object, should be equal to the command argument.
+ @param error_msg - error object converted to a human readable string.
+ """
+ pass
+
+class DoneGetTestList(object):
+ """
+ Call back interface for 'getTestList' command.
+ """
+ def doneGetTestList(self, token, error, list):
+ """
+ Called when 'getTestList' command is done.
+ @param token - command handle.
+ @param error - error object or null.
+ @param list - names of tests that are supported by the peer.
+ """
+ pass
+
+class DoneRunTest(object):
+ """
+ Call back interface for 'runTest' command.
+ """
+ def doneRunTest(self, token, error, context_id):
+ """
+ Called when 'runTest' command is done.
+ @param token - command handle.
+ @param error - error object or null.
+ @param context_id - test execution contest ID.
+ """
+ pass
+
+class DoneCancelTest(object):
+ """
+ Call back interface for 'cancelTest' command.
+ """
+ def doneCancelTest(self, token, error):
+ """
+ Called when 'cancelTest' command is done.
+ @param token - command handle.
+ @param error - error object or null.
+ """
+ pass
+
+class DoneGetSymbol(object):
+ """
+ Call back interface for 'getSymbol' command.
+ """
+ def doneGetSymbol(self, token, error, symbol):
+ """
+ Called when 'getSymbol' command is done.
+ @param token - command handle.
+ @param error - error object or null.
+ @param symbol
+ """
+ pass
+
+class Symbol(object):
+ """
+ Represents result value of 'getSymbol' command.
+ """
+ def __init__(self, props):
+ self._props = props or {}
+ def getSectionName(self):
+ return self._props.get("Section")
+ def getValue(self):
+ return self._props.get("Value")
+ def isUndef(self):
+ val = self._props.get("Storage")
+ return val == "UNDEF"
+ def isCommon(self):
+ val = self._props.get("Storage")
+ return val == "COMMON"
+ def isGlobal(self):
+ val = self._props.get("Storage")
+ return val == "GLOBAL"
+ def isLocal(self):
+ val = self._props.get("Storage")
+ return val == "LOCAL"
+ def isAbs(self):
+ return self._props.get("Abs", False)
+
+class DoneCreateTestStreams(object):
+ """
+ Call back interface for 'createTestStreams' command.
+ """
+ def doneCreateTestStreams(self, token, error, inp_id, out_id):
+ """
+ Called when 'createTestStreams' command is done.
+ @param token - command handle.
+ @param error - error object or null.
+ @param inp_id - the input stream ID.
+ @param out_id - the output stream ID.
+ """
+ pass
+
+class DoneDisposeTestStream(object):
+ """
+ Call back interface for 'disposeTestStream' command.
+ """
+ def doneDisposeTestStream(self, token, error):
+ """
+ Called when 'createTestStreams' command is done.
+ @param token - command handle.
+ @param error - error object or null.
+ """
+ pass
+
+class DoneNotImplementedCommand(object):
+ def doneNotImplementedCommand(self, token, error):
+ """
+ Called when 'not_implemented_command' command is done.
+ @param token - command handle.
+ @param error - error object.
+ """
+ pass
diff --git a/python/src/tcf/services/remote/DiagnosticsProxy.py b/python/src/tcf/services/remote/DiagnosticsProxy.py
new file mode 100644
index 000000000..24305a1ca
--- /dev/null
+++ b/python/src/tcf/services/remote/DiagnosticsProxy.py
@@ -0,0 +1,174 @@
+# *******************************************************************************
+# * Copyright (c) 2011 Wind River Systems, Inc. and others.
+# * 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
+# *
+# * Contributors:
+# * Wind River Systems - initial API and implementation
+# *******************************************************************************
+
+import time
+from tcf import errors
+from tcf.services import diagnostics
+from tcf.channel.Command import Command
+
+class DiagnosticsProxy(diagnostics.DiagnosticsService):
+ def __init__(self, channel):
+ self.channel = channel
+
+ def echo(self, s, done):
+ done = self._makeCallback(done)
+ service = self
+ class EchoCommand(Command):
+ def __init__(self):
+ super(EchoCommand, self).__init__(service.channel, service, "echo", (s,))
+ def done(self, error, args):
+ str = None
+ if not error:
+ assert len(args) == 1
+ str = args[0]
+ done.doneEcho(self.token, error, str)
+ return EchoCommand().token
+
+ def echoFP(self, n, done):
+ done = self._makeCallback(done)
+ service = self
+ class EchoFPCommand(Command):
+ def __init__(self):
+ super(EchoFPCommand, self).__init__(service.channel, service, "echoFP", (n,))
+ def done(self, error, args):
+ n = None
+ if not error:
+ assert len(args) == 1
+ n = args[0]
+ done.doneEchoFP(self.token, error, n)
+ return EchoFPCommand().token
+
+ def echoERR(self, err, done):
+ map = None
+ if isinstance(err, errors.ErrorReport):
+ map = err.getAttributes()
+ else:
+ map = {
+ errors.ERROR_TIME : int(time.time() * 1000),
+ errors.ERROR_CODE : errors.TCF_ERROR_OTHER,
+ errors.ERROR_FORMAT : err.message
+ }
+ done = self._makeCallback(done)
+ service = self
+ class EchoERRCommand(Command):
+ def __init__(self):
+ super(EchoERRCommand, self).__init__(service.channel, service, "echoERR", (map,))
+ def done(self, error, args):
+ err = None
+ str = None
+ if not error:
+ assert len(args) == 2
+ err = self.toError(args[0])
+ str = args[1]
+ done.doneEchoERR(self.token, error, err, str)
+ return EchoERRCommand().token
+
+ def getTestList(self, done):
+ done = self._makeCallback(done)
+ service = self
+ class GetTestListCommand(Command):
+ def __init__(self):
+ super(GetTestListCommand, self).__init__(service.channel, service, "getTestList", None)
+ def done(self, error, args):
+ arr = None
+ if not error:
+ assert len(args) == 2
+ error = self.toError(args[0])
+ arr = args[1]
+ done.doneGetTestList(self.token, error, arr)
+ return GetTestListCommand().token
+
+ def runTest(self, s, done):
+ done = self._makeCallback(done)
+ service = self
+ class RunTestCommand(Command):
+ def __init__(self):
+ super(RunTestCommand, self).__init__(service.channel, service, "runTest", (s,))
+ def done(self, error, args):
+ str = None
+ if not error:
+ assert len(args) == 2
+ error = self.toError(args[0])
+ str = args[1]
+ done.doneRunTest(self.token, error, str)
+ return RunTestCommand().token
+
+ def cancelTest(self, s, done):
+ done = self._makeCallback(done)
+ service = self
+ class CancelTestCommand(Command):
+ def __init__(self):
+ super(CancelTestCommand, self).__init__(service.channel, service, "cancelTest", (s,))
+ def done(self, error, args):
+ if not error:
+ assert len(args) == 1
+ error = self.toError(args[0])
+ done.doneCancelTest(self.token, error)
+ return CancelTestCommand().token
+
+ def getSymbol(self, context_id, symbol_name, done):
+ done = self._makeCallback(done)
+ service = self
+ class GetSymbolCommand(Command):
+ def __init__(self):
+ super(GetSymbolCommand, self).__init__(service.channel, service, "getSymbol", (context_id, symbol_name))
+ def done(self, error, args):
+ sym = None
+ if not error:
+ assert len(args) == 2
+ error = self.toError(args[0])
+ sym = _toSymbol(args[1])
+ done.doneGetSymbol(self.token, error, sym)
+ return GetSymbolCommand().token
+
+ def createTestStreams(self, inp_buf_size, out_buf_size, done):
+ done = self._makeCallback(done)
+ service = self
+ class CreateTestStreamsCommand(Command):
+ def __init__(self):
+ super(CreateTestStreamsCommand, self).__init__(service.channel, service, "createTestStreams", (inp_buf_size, out_buf_size))
+ def done(self, error, args):
+ inp_id = None
+ out_id = None
+ if not error:
+ assert len(args) == 3
+ error = self.toError(args[0])
+ inp_id = args[1]
+ out_id = args[2]
+ done.doneCreateTestStreams(self.token, error, inp_id, out_id)
+ return CreateTestStreamsCommand().token
+
+ def disposeTestStream(self, id, done):
+ done = self._makeCallback(done)
+ service = self
+ class DisposeTestStreamCommand(Command):
+ def __init__(self):
+ super(DisposeTestStreamCommand, self).__init__(service.channel, service, "disposeTestStream", (id,))
+ def done(self, error, args):
+ if not error:
+ assert len(args) == 1
+ error = self.toError(args[0])
+ done.doneDisposeTestStream(self.token, error)
+ return DisposeTestStreamCommand().token
+
+ def not_implemented_command(self, done):
+ done = self._makeCallback(done)
+ service = self
+ class NotImplementedCommand(Command):
+ def __init__(self):
+ super(NotImplementedCommand, self).__init__(service.channel, service, "not implemented command", None)
+ def done(self, error, args):
+ done.doneNotImplementedCommand(self.token, error)
+ return NotImplementedCommand().token
+
+def _toSymbol(o):
+ if o is None: return None
+ return diagnostics.Symbol(o)

Back to the top