Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: eb7ac4084a86ed2a4f385df17be40e7be56d5a26 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
# *****************************************************************************
# * Copyright (c) 2011, 2013-2014 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.

.. |get| replace:: :meth:`~PathMapService.get`
.. |set| replace:: :meth:`~PathMapService.set`
.. |DoneGet| replace:: :class:`DoneGet`
.. |DoneSet| replace:: :class:`DoneSet`
.. |PathMapRule| replace:: :class:`PathMapRule`
.. |PathMapListener| replace:: :class:`PathMapListener`


Path Mapping Properties
-----------------------
Properties
^^^^^^^^^^
All properties are of type |basestring|.

+--------------------+--------------------------------------------------------+
| Name               | Description                                            |
+====================+========================================================+
| PROP_CONTEXT       | Symbols context group ID or name. **deprecated** - use |
|                    | ``PROP_CONTEXT_QUERY``.                                |
+--------------------+--------------------------------------------------------+
| PROP_CONTEXT_QUERY | Contexts query.                                        |
+--------------------+--------------------------------------------------------+
| PROP_DESTINATION   | Destination, or run-time file path.                    |
+--------------------+--------------------------------------------------------+
| PROP_HOST          | Host name.                                             |
+--------------------+--------------------------------------------------------+
| PROP_ID            | Rule ID.                                               |
+--------------------+--------------------------------------------------------+
| PROP_PROTOCOL      | File access protocol, see `Protocols`_, default is     |
|                    | ``PROTOCOL_FILE``.                                     |
+--------------------+--------------------------------------------------------+
| PROP_SOURCE        | Source, or compile-time file path.                     |
+--------------------+--------------------------------------------------------+

Protocols
^^^^^^^^^
All protocols are of type |basestring|.

+-----------------+-----------------------------------------------------------+
| Name            | Description                                               |
+=================+===========================================================+
| PROTOCOL_FILE   | Regular file access using system calls.                   |
+-----------------+-----------------------------------------------------------+
| PROTOCOL_HOST   | File should be accessed using File System service on host.|
+-----------------+-----------------------------------------------------------+
| PROTOCOL_TARGET | File should be accessed using File System service on.     |
|                 | target.                                                   |
+-----------------+-----------------------------------------------------------+

Service Methods
---------------
.. autodata:: NAME
.. autoclass:: PathMapService

addListener
^^^^^^^^^^^
.. automethod:: PathMapService.addListener

get
^^^
.. automethod:: PathMapService.get

getName
^^^^^^^
.. automethod:: PathMapService.getName

removeListener
^^^^^^^^^^^^^^
.. automethod:: PathMapService.removeListener

set
^^^
.. automethod:: PathMapService.set

Callback Classes
----------------
DoneGet
^^^^^^^
.. autoclass:: DoneGet
    :members:

DoneSet
^^^^^^^
.. autoclass:: DoneSet
    :members:

Listener
--------
PathMapListener
^^^^^^^^^^^^^^^
.. autoclass:: PathMapListener
    :members:

Helper Classes
--------------
PathMapRule
^^^^^^^^^^^
.. autoclass:: PathMapRule
    :members:
"""

from .. import services

NAME = "PathMap"
"""PathMap service name."""

# Path mapping rule property names.

PROP_CONTEXT_QUERY = "ContextQuery"
PROP_DESTINATION = "Destination"
PROP_HOST = "Host"
PROP_ID = "ID"
PROP_PROTOCOL = "Protocol"
PROP_SOURCE = "Source"

# @deprecated
PROP_CONTEXT = "Context"

# PROP_PROTOCOL values.
PROTOCOL_FILE = "file"
PROTOCOL_HOST = "host"
PROTOCOL_TARGET = "target"


class PathMapListener(object):
    """Pathmap event listener is notified when pathmap changes."""

    def changed(self):
        """Called when a pathmap has been changed."""
        pass


class PathMapRule(object):
    """PathMapRule represents a single file path mapping rule.

    :param props: The properties to initialise this pathmap rule with. See
                  `Properties`_.
    :type props: |dict|
    """
    def __init__(self, props):
        self._props = props or {}

    def __repr__(self):
        return self.__class__.__name__ + '(' + str(self._props) + ')'

    def __json__(self):
        return self._props

    def getContextQuery(self):
        """Get context query that defines scope of the mapping rule.

        :returns: This PathMap Rule context query expression, or **None**.
        """
        return self._props.get(PROP_CONTEXT_QUERY, None)

    def getProperties(self):
        """Get rule properties.

        See `Properties`_ definitions for property names.

        Context properties are read only, clients should not try to modify
        them.

        :returns: A |dict| class of this rule's properties.
        """
        return self._props

    def getID(self):
        """Get rule unique ID.

        :returns: A |basestring| representing this rule's ID or **None**.
        """
        return self._props.get(PROP_ID, None)

    def getSource(self):
        """Get compile-time file path.

        :returns: A |basestring| representing compile-time file path or
                  **None**.
        """
        return self._props.get(PROP_SOURCE, None)

    def getDestination(self):
        """Get run-time file path.

        :returns: A |basestring| representing run-time file path or **None**.
        """
        return self._props.get(PROP_DESTINATION, None)

    def getHost(self):
        """Get host name of this rule.

        :returns: A |basestring| representing the host name this rule applies
                  to or **None**.
        """
        return self._props.get(PROP_HOST, None)

    def getProtocol(self):
        """Get file access protocol name.

        See `Protocols`_ for path mapping protocol values.

        :returns: A |basestring| representing protocol name or
                  ``PROTOCOL_FILE``.
        """
        return self._props.get(PROP_PROTOCOL, PROTOCOL_FILE)


class PathMapService(services.Service):
    """TCF PathMap service interface."""

    def addListener(self, listener):
        """Add a pathmap listener.

        A |PathMapListener| is added to the TCF pathmap service.

        :param listener: Instance of the pathmap listener to add to service.
        :type listener: |PathMapListener|
        """
        return NotImplementedError("Abstract method")

    def getName(self):
        """Get this service name.

        :returns: The value of string :const:`NAME`
        """
        return NAME

    def get(self, done):
        """Retrieve file path mapping rules.

        :param done: Call back interface called when operation is completed.
        :type done: |DoneGet|
        """
        return NotImplementedError("Abstract method")

    def set(self, pathMap, done):  # @ReservedAssignment
        """Set file path mapping rules.

        :param pathMap: File path mapping rules.
        :type pathMap: |PathMapRule|
        :param done: Call back interface called when operation is completed.
        :type done: |DoneSet|
        """
        return NotImplementedError("Abstract method")

    def removeListener(self, listener):
        """Remove pathmap event listener.

        The PathMapListener is removed from the TCF pathmap service.

        :param listener: instance of the pathmap listener to remove from
                         service.
        :type listener: |PathMapListener|
        """
        return NotImplementedError("Abstract method")


class DoneGet(object):
    """Client call back interface for |get|."""
    def doneGet(self, token, error, pathMap):
        """Called when file path mapping retrieval is done.

        :param token: Command handle.
        :param error: Error description if operation failed, **None** if
                      succeeded.
        :param pathMap: File path mapping data.
        :type pathMap: |list| of |PathMapRule|
        """
        pass


class DoneSet(object):
    """Client call back interface for |set|."""

    def doneSet(self, token, error):
        """Called when file path mapping transmission is done.

        :param token: Command handle
        :param error: Error description if operation failed, **None** if
                      succeeded.
        """
        pass

Back to the top