Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraleherbau2011-05-20 04:40:25 -0400
committeraleherbau2011-05-20 04:40:25 -0400
commit73735f051e804cbb706ff89be540f66a2f1fdbf8 (patch)
treed2f69bbbd9cc364733490e8a1014f79bac9d28a3
parent4b69abdaf927c94c4383e1771f3988af03d5d317 (diff)
downloadorg.eclipse.tcf-73735f051e804cbb706ff89be540f66a2f1fdbf8.tar.gz
org.eclipse.tcf-73735f051e804cbb706ff89be540f66a2f1fdbf8.tar.xz
org.eclipse.tcf-73735f051e804cbb706ff89be540f66a2f1fdbf8.zip
TCF Python: Implemented PathMap proxy service
-rw-r--r--python/src/tcf/services/pathmap.py153
-rw-r--r--python/src/tcf/services/remote/MemoryMapProxy.py6
-rw-r--r--python/src/tcf/services/remote/MemoryProxy.py15
-rw-r--r--python/src/tcf/services/remote/PathMapProxy.py56
-rw-r--r--python/src/tcf/tests/BasicTests.py74
-rw-r--r--python/todo.twiki4
6 files changed, 285 insertions, 23 deletions
diff --git a/python/src/tcf/services/pathmap.py b/python/src/tcf/services/pathmap.py
new file mode 100644
index 000000000..fd5cb3704
--- /dev/null
+++ b/python/src/tcf/services/pathmap.py
@@ -0,0 +1,153 @@
+# *******************************************************************************
+# * 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
+# *******************************************************************************
+
+"""
+PathMap service manages file path translation across systems.
+"""
+
+from tcf import services
+
+NAME = "PathMap"
+
+# Path mapping rule property names.
+# String, rule ID
+PROP_ID = "ID"
+
+# String, source, or compile-time file path
+PROP_SOURCE = "Source"
+
+# String, destination, or run-time file path
+PROP_DESTINATION = "Destination"
+
+# String
+PROP_HOST = "Host"
+
+# String, file access protocol, see PROTOCOL_*, default is regular file
+PROP_PROTOCOL = "Protocol"
+
+# PROP_PROTOCOL values.
+# Regular file access using system calls
+PROTOCOL_FILE = "file"
+
+# File should be accessed using File System service on host
+PROTOCOL_HOST = "host"
+
+# File should be accessed using File System service on target
+PROTOCOL_TARGET = "target"
+
+class PathMapRule(object):
+ """
+ PathMapRule represents a single file path mapping rule.
+ """
+ def __init__(self, props):
+ self._props = props or {}
+
+ def __str__(self):
+ return str(self._props)
+
+ def __json__(self):
+ return self._props
+
+ def getProperties(self):
+ """
+ Get rule properties. See PROP_* definitions for property names.
+ Context properties are read only, clients should not try to modify them.
+ @return Map of rule properties.
+ """
+ return self._props
+
+ def getID(self):
+ """
+ Get rule unique ID.
+ Same as getProperties().get(PROP_ID)
+ @return rule ID.
+ """
+ return self._props.get(PROP_ID)
+
+ def getSource(self):
+ """
+ Get compile-time file path.
+ Same as getProperties().get(PROP_SOURCE)
+ @return compile-time file path.
+ """
+ return self._props.get(PROP_SOURCE)
+
+ def getDestination(self):
+ """
+ Get run-time file path.
+ Same as getProperties().get(PROP_DESTINATION)
+ @return run-time file path.
+ """
+ return self._props.get(PROP_DESTINATION)
+
+ def getHost(self):
+ """
+ Get host name of this rule.
+ Same as getProperties().get(PROP_HOST)
+ @return host name.
+ """
+ return self._props.get(PROP_HOST)
+
+ def getProtocol(self):
+ """
+ Get file access protocol name.
+ Same as getProperties().get(PROP_PROTOCOL)
+ @return protocol name.
+ """
+ return self._props.get(PROP_PROTOCOL)
+
+
+class PathMapService(services.Service):
+ def getName(self):
+ return NAME
+
+ def get(self, done):
+ """
+ Retrieve file path mapping rules.
+
+ @param done - call back interface called when operation is completed.
+ @return - pending command handle.
+ """
+ return NotImplementedError("Abstract method")
+
+ def set(self, map, done):
+ """
+ Set file path mapping rules.
+
+ @param map - file path mapping rules.
+ @param done - call back interface called when operation is completed.
+ @return - pending command handle.
+ """
+ return NotImplementedError("Abstract method")
+
+class DoneGet(object):
+ """
+ Client call back interface for get().
+ """
+ def doneGet(self, token, error, map):
+ """
+ Called when file path mapping retrieval is done.
+ @param error - error description if operation failed, null if succeeded.
+ @param map - file path mapping data.
+ """
+ pass
+
+class DoneSet(object):
+ """
+ Client call back interface for set().
+ """
+ def doneSet(self, token, error):
+ """
+ Called when file path mapping transmission is done.
+ @param error - error description if operation failed, null if succeeded.
+ @param map - memory map data.
+ """
+ pass
diff --git a/python/src/tcf/services/remote/MemoryMapProxy.py b/python/src/tcf/services/remote/MemoryMapProxy.py
index 9e37feb9b..1897c3cba 100644
--- a/python/src/tcf/services/remote/MemoryMapProxy.py
+++ b/python/src/tcf/services/remote/MemoryMapProxy.py
@@ -34,6 +34,8 @@ class MemoryMapProxy(memorymap.MemoryMapService):
return GetCommand().token
def set(self, id, map, done):
+ if isinstance(map, memorymap.MemoryRegion) or isinstance(map, dict):
+ map = (map,)
done = self._makeCallback(done)
service = self
class SetCommand(Command):
@@ -75,9 +77,7 @@ class ChannelEventListener(channel.EventListener):
def _toMemoryMap(o):
if o is None: return None
- map = []
- for x in o: map.append(_toMemoryRegion(x))
- return map
+ return map(_toMemoryRegion, o)
def _toMemoryRegion(o):
if o is None: return None
diff --git a/python/src/tcf/services/remote/MemoryProxy.py b/python/src/tcf/services/remote/MemoryProxy.py
index f2449fcb3..10de25cff 100644
--- a/python/src/tcf/services/remote/MemoryProxy.py
+++ b/python/src/tcf/services/remote/MemoryProxy.py
@@ -229,21 +229,12 @@ class ChannelEventListener(channel.EventListener):
def _toContextArray(o):
if o is None: return None
- ctx = []
- for m in o: ctx.append(MemContext(m))
- return ctx
+ return map(MemContext, o)
def _toSizeArray(o):
if o is None: return None
- a = []
- for m in o:
- sz = m.get("size", 0)
- a.append(sz)
- return a
+ return map(lambda m: m.get("size", 0), o)
def _toAddrArray(o):
if o is None: return None
- a = []
- for m in o:
- a.append(m.get("addr"))
- return a
+ return map(lambda m: m.get("addr"), o)
diff --git a/python/src/tcf/services/remote/PathMapProxy.py b/python/src/tcf/services/remote/PathMapProxy.py
new file mode 100644
index 000000000..93e8c07b8
--- /dev/null
+++ b/python/src/tcf/services/remote/PathMapProxy.py
@@ -0,0 +1,56 @@
+# *******************************************************************************
+# * 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
+# *******************************************************************************
+
+from tcf.services import pathmap
+from tcf.channel.Command import Command
+
+class PathMapProxy(pathmap.PathMapService):
+ def __init__(self, channel):
+ self.channel = channel
+
+ def get(self, done):
+ done = self._makeCallback(done)
+ service = self
+ class GetCommand(Command):
+ def __init__(self):
+ super(GetCommand, self).__init__(service.channel, service, "get", None)
+ def done(self, error, args):
+ map = None
+ if not error:
+ assert len(args) == 2
+ error = self.toError(args[0])
+ if args[1]: map = _toPathMap(args[1])
+ done.doneGet(self.token, error, map)
+ return GetCommand().token
+
+ def set(self, map, done):
+ if isinstance(map, pathmap.PathMapRule) or isinstance(map, dict):
+ map = (map,)
+ done = self._makeCallback(done)
+ service = self
+ class SetCommand(Command):
+ def __init__(self):
+ super(SetCommand, self).__init__(service.channel, service, "set", (map,))
+ def done(self, error, args):
+ if not error:
+ assert len(args) == 1
+ error = self.toError(args[0])
+ done.doneSet(self.token, error)
+ return SetCommand().token
+
+
+def _toPathMap(o):
+ if o is None: return None
+ return map(_toPathMapRule, o)
+
+def _toPathMapRule(o):
+ if o is None: return None
+ return pathmap.PathMapRule(o)
diff --git a/python/src/tcf/tests/BasicTests.py b/python/src/tcf/tests/BasicTests.py
index da8200b12..044f94452 100644
--- a/python/src/tcf/tests/BasicTests.py
+++ b/python/src/tcf/tests/BasicTests.py
@@ -54,6 +54,7 @@ def test():
testFileSystem(c)
testMemory(c)
testMemoryMap(c)
+ testPathMap(c)
except Exception as e:
protocol.log(e)
@@ -469,7 +470,6 @@ def testMemory(c):
def testMemoryMap(c):
if not _memory: return
- from tcf.services import memorymap
cmd = sync.CommandControl(c)
try:
mm = cmd.MemoryMap
@@ -477,13 +477,75 @@ def testMemoryMap(c):
# no MemoryMap service
return
id = _memory[0]
+ lock = threading.Condition()
+ from tcf.services import memorymap
+ def getMap():
+ mm = c.getRemoteService(memorymap.NAME)
+ class DoneGet(memorymap.DoneGet):
+ def doneGet(self, token, error, map):
+ if error:
+ protocol.log("Error from MemoryMap.get", error)
+ else:
+ print map
+ with lock:
+ lock.notify()
+ mm.get(id, DoneGet())
+ with lock:
+ protocol.invokeLater(getMap)
+ lock.wait(1000)
+ def setMap():
+ mm = c.getRemoteService(memorymap.NAME)
+ class DoneSet(memorymap.DoneSet):
+ def doneSet(self, token, error):
+ if error:
+ protocol.log("Error from MemoryMap.set", error)
+ with lock:
+ lock.notify()
+ mm.set(id, {memorymap.PROP_FILE_NAME : "/tmp/system.elf"}, DoneSet())
+ with lock:
+ protocol.invokeLater(setMap)
+ lock.wait(1000)
map = mm.get(id).get()
print "Memory map:", map
- region = memorymap.MemoryRegion({memorymap.PROP_FILE_NAME : "/tmp/system.elf"})
- print "Memory map: setting map", [region]
- mm.set(id, [region]).get()
- map = mm.get(id).get()
- print "Memory map:", map
+
+def testPathMap(c):
+ cmd = sync.CommandControl(c)
+ try:
+ pm = cmd.PathMap
+ except AttributeError:
+ # no PathMap service
+ return
+ lock = threading.Condition()
+ from tcf.services import pathmap
+ def getMap():
+ pm = c.getRemoteService(pathmap.NAME)
+ class DoneGet(pathmap.DoneGet):
+ def doneGet(self, token, error, map):
+ if error:
+ protocol.log("Error from PathMap.get", error)
+ else:
+ print map
+ with lock:
+ lock.notify()
+ pm.get(DoneGet())
+ with lock:
+ protocol.invokeLater(getMap)
+ lock.wait(1000)
+ def setMap():
+ pm = c.getRemoteService(pathmap.NAME)
+ class DoneSet(pathmap.DoneSet):
+ def doneSet(self, token, error):
+ if error:
+ protocol.log("Error from PathMap.set", error)
+ with lock:
+ lock.notify()
+ pm.set({pathmap.PROP_SOURCE : "/tmp",
+ pathmap.PROP_DESTINATION : "/home"}, DoneSet())
+ with lock:
+ protocol.invokeLater(setMap)
+ lock.wait(1000)
+ map = pm.get().get()
+ print "Path map:", map
if __name__ == '__main__':
test()
diff --git a/python/todo.twiki b/python/todo.twiki
index 72bb2f848..f3c814d6c 100644
--- a/python/todo.twiki
+++ b/python/todo.twiki
@@ -20,7 +20,7 @@
* [done] FileSystem
* [done] MemoryMap
* [done] Memory
- * PathMap
+ * [done] PathMap
* Diagnostics
* Disassembly
* Streams
@@ -28,7 +28,7 @@
* SysMonitor
* Local services:
* [incomplete] ZeroCopy
- * [done] Locator service (discovery)
+ * [95%] Locator service (discovery)
* iterate over network interfaces
* Utilities:
* [done] ACPM data cache

Back to the top