Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'python/src/tcf/services/remote/MemoryProxy.py')
-rw-r--r--python/src/tcf/services/remote/MemoryProxy.py123
1 files changed, 85 insertions, 38 deletions
diff --git a/python/src/tcf/services/remote/MemoryProxy.py b/python/src/tcf/services/remote/MemoryProxy.py
index 8cf9f302e..8d84d3746 100644
--- a/python/src/tcf/services/remote/MemoryProxy.py
+++ b/python/src/tcf/services/remote/MemoryProxy.py
@@ -1,5 +1,5 @@
# *****************************************************************************
-# * Copyright (c) 2011, 2012 Wind River Systems, Inc. and others.
+# * Copyright (c) 2011, 2013 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
@@ -9,21 +9,27 @@
# * Wind River Systems - initial API and implementation
# *****************************************************************************
-from tcf import errors, channel
-from tcf.services import memory
-from tcf.channel.Command import Command
+from .. import memory
+from ... import errors, channel
+from ...channel.Command import Command
+
class Range(object):
offs = 0
size = 0
stat = 0
msg = None
+
def __cmp__(self, o):
- if self.offs < o.offs: return -1
- if self.offs > o.offs: return +1
+ if self.offs < o.offs:
+ return -1
+ if self.offs > o.offs:
+ return +1
return 0
-class MemoryErrorReport(errors.ErrorReport, memory.MemoryError, memory.ErrorOffset):
+
+class MemoryErrorReport(errors.ErrorReport, memory.MemoryError,
+ memory.ErrorOffset):
def __init__(self, msg, attrs, addr, ranges):
super(MemoryErrorReport, self).__init__(msg, attrs)
if ranges is None:
@@ -40,14 +46,16 @@ class MemoryErrorReport(errors.ErrorReport, memory.MemoryError, memory.ErrorOffs
r.offs = y - addr
r.size = m.get(memory.ErrorOffset.RANGE_KEY_SIZE)
r.stat = m.get(memory.ErrorOffset.RANGE_KEY_STAT)
- r.msg = errors.toErrorString(m.get(memory.ErrorOffset.RANGE_KEY_MSG))
+ key = memory.ErrorOffset.RANGE_KEY_MSG
+ r.msg = errors.toErrorString(m.get(key))
assert r.offs >= 0
assert r.size >= 0
self.ranges.append(r)
self.ranges.sort()
def getMessage(self, offset):
- if self.ranges is None: return None
+ if self.ranges is None:
+ return None
l = 0
h = len(self.ranges) - 1
while l <= h:
@@ -62,7 +70,8 @@ class MemoryErrorReport(errors.ErrorReport, memory.MemoryError, memory.ErrorOffs
return None
def getStatus(self, offset):
- if self.ranges is None: return memory.ErrorOffset.BYTE_UNKNOWN
+ if self.ranges is None:
+ return memory.ErrorOffset.BYTE_UNKNOWN
l = 0
h = len(self.ranges) - 1
while l <= h:
@@ -84,12 +93,15 @@ class MemContext(memory.MemoryContext):
def fill(self, addr, word_size, value, size, mode, done):
service = self.service
- id = self.getID()
+ contextID = self.getID()
done = service._makeCallback(done)
+
class FillCommand(MemoryCommand):
def __init__(self):
- super(FillCommand, self).__init__(service,
- "fill", (id, addr, word_size, size, mode, value))
+ super(FillCommand, self).__init__(service, "fill",
+ (contextID, addr, word_size,
+ size, mode, value))
+
def done(self, error, args):
e = None
if error:
@@ -102,12 +114,15 @@ class MemContext(memory.MemoryContext):
def get(self, addr, word_size, buf, offs, size, mode, done):
service = self.service
- id = self.getID()
+ contextID = self.getID()
done = service._makeCallback(done)
+
class GetCommand(MemoryCommand):
def __init__(self):
- super(GetCommand, self).__init__(service,
- "get", (id, addr, word_size, size, mode))
+ super(GetCommand, self).__init__(service, "get",
+ (contextID, addr, word_size,
+ size, mode))
+
def done(self, error, args):
e = None
if error:
@@ -116,19 +131,24 @@ class MemContext(memory.MemoryContext):
assert len(args) == 3
byts = channel.toByteArray(args[0])
assert len(byts) <= size
- buf[offs:offs+len(byts)] = byts
+ buf[offs:offs + len(byts)] = byts
e = self.toMemoryError(addr, args[1], args[2])
done.doneMemory(self.token, e)
return GetCommand().token
def set(self, addr, word_size, buf, offs, size, mode, done):
service = self.service
- id = self.getID()
+ contextID = self.getID()
done = service._makeCallback(done)
+
class SetCommand(MemoryCommand):
def __init__(self):
- super(SetCommand, self).__init__(service,
- "set", (id, addr, word_size, size, mode, bytearray(buf[offs:offs+size])))
+ super(SetCommand, self).__init__(service, "set",
+ (contextID, addr, word_size,
+ size, mode,
+ bytearray(buf[offs:offs +
+ size])))
+
def done(self, error, args):
e = None
if error:
@@ -139,6 +159,7 @@ class MemContext(memory.MemoryContext):
done.doneMemory(self.token, e)
return SetCommand().token
+
class MemoryProxy(memory.MemoryService):
def __init__(self, channel):
self.channel = channel
@@ -147,24 +168,34 @@ class MemoryProxy(memory.MemoryService):
def getContext(self, context_id, done):
done = self._makeCallback(done)
service = self
+
class GetContextCommand(Command):
def __init__(self):
- super(GetContextCommand, self).__init__(service.channel, service, "getContext", (context_id,))
+ super(GetContextCommand, self).__init__(service.channel,
+ service, "getContext",
+ (context_id,))
+
def done(self, error, args):
ctx = None
if not error:
assert len(args) == 2
error = self.toError(args[0])
- if args[1]: ctx = MemContext(service, args[1])
+ if args[1]:
+ ctx = MemContext(service, args[1])
done.doneGetContext(self.token, error, ctx)
return GetContextCommand().token
def getChildren(self, parent_context_id, done):
done = self._makeCallback(done)
service = self
+
class GetChildrenCommand(Command):
def __init__(self):
- super(GetChildrenCommand, self).__init__(service.channel, service, "getChildren", (parent_context_id,))
+ super(GetChildrenCommand, self).__init__(service.channel,
+ service,
+ "getChildren",
+ (parent_context_id,))
+
def done(self, error, args):
contexts = None
if not error:
@@ -185,20 +216,26 @@ class MemoryProxy(memory.MemoryService):
del self.listeners[listener]
self.channel.removeEventListener(self, l)
+
class MemoryCommand(Command):
def __init__(self, service, cmd, args):
- super(MemoryCommand, self).__init__(service.channel, service, cmd, args)
+ super(MemoryCommand, self).__init__(service.channel, service, cmd,
+ args)
+
def toMemoryError(self, addr, data, ranges):
- if data is None: return None
+ if data is None:
+ return None
code = data.get(errors.ERROR_CODE)
cmd = self.getCommandString()
- if len(cmd) > 72: cmd = cmd[0:72] + "..."
- e = MemoryErrorReport(
- "TCF command exception:\nCommand: %s\nException: %s\nError code: %d" % (
- cmd, errors.toErrorString(data), code),
+ if len(cmd) > 72:
+ cmd = cmd[0:72] + "..."
+ e = MemoryErrorReport("TCF command exception:\nCommand: %s\n" +
+ "Exception: %s\nError code: %d" %
+ (cmd, errors.toErrorString(data), code),
data, addr, ranges)
caused_by = data.get(errors.ERROR_CAUSED_BY)
- if caused_by is not None: e.caused_by = self.toError(caused_by, False)
+ if caused_by is not None:
+ e.caused_by = self.toError(caused_by, False)
return e
@@ -206,37 +243,47 @@ class ChannelEventListener(channel.EventListener):
def __init__(self, service, listener):
self.service = service
self.listener = listener
+
def event(self, name, data):
try:
args = channel.fromJSONSequence(data)
if name == "contextAdded":
assert len(args) == 1
- self.listener.contextAdded(_toContextArray(self.service, args[0]))
+ self.listener.contextAdded(_toContextArray(self.service,
+ args[0]))
elif name == "contextChanged":
assert len(args) == 1
- self.listener.contextChanged(_toContextArray(self.service, args[0]))
+ self.listener.contextChanged(_toContextArray(self.service,
+ args[0]))
elif name == "contextRemoved":
assert len(args) == 1
self.listener.contextRemoved(args[0])
elif name == "memoryChanged":
assert len(args) == 2
- self.listener.memoryChanged(args[0], _toAddrArray(args[1]), _toSizeArray(args[1]))
+ self.listener.memoryChanged(args[0], _toAddrArray(args[1]),
+ _toSizeArray(args[1]))
else:
- raise IOError("Memory service: unknown event: " + name);
+ raise IOError("Memory service: unknown event: " + name)
except Exception as x:
self.service.channel.terminate(x)
def _toContextArray(svc, o):
- if o is None: return None
+ if o is None:
+ return None
ctx = []
- for m in o: ctx.append(MemContext(svc, m))
+ for m in o:
+ ctx.append(MemContext(svc, m))
return ctx
+
def _toSizeArray(o):
- if o is None: return None
+ if o is None:
+ return None
return map(lambda m: m.get("size", 0), o)
+
def _toAddrArray(o):
- if o is None: return None
+ if o is None:
+ return None
return map(lambda m: m.get("addr"), o)

Back to the top