blob: 1faf5c637da7467d20cc5886ad6880c124b0dfe4 [file] [log] [blame]
Alexander Afanasyev2d600f72013-11-21 18:20:37 -08001.. _Face:
2
3Face Class
4==========
5
6:[C++]:
7 Namespace: ``ndn``
8
9:[Python]:
10 Module: ``pyndn``
11
Alexander Afanasyev06e798c2013-11-26 19:10:29 -080012Face Constructors
13-----------------
14
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080015Face Constructor (explicit Transport)
Alexander Afanasyev06e798c2013-11-26 19:10:29 -080016^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080017
18Create a new Face object with the given Transport to manage NDN communication.
19
20:[C++]:
21
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -080022 .. code-block:: c++
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080023
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -080024 Face(
25
26 const ptr_lib::shared_ptr<Transport>& transport
27 const ptr_lib::shared_ptr<const Transport::ConnectionInfo>& connectionInfo
28
29 );
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080030
31:[JavaScript]:
32
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -080033 .. code-block:: javascript
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080034
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -080035 var Face = function Face(
36
37 [settings // associative array]
38
39 )
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080040
41:[Python]:
42
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -080043 .. code-block:: python
44
45 def __init__(self)
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080046
47:Parameters:
48
49 - ``transport``
50 An object of a subclass of Transport to use for communication.
51
52 - ``connectionInfo``
53 This must be a ConnectionInfo from the same subclass of Transport as transport.
54
55 - ``settings``
56 (JavaScript only) An associative array with the following defaults:
57
58 .. code-block:: javascript
59
60 getTransport: function() { return new WebSocketTransport(); },
61 getHostAndPort: transport.defaultGetHostAndPort,
62 // a function, on each call it returns a new { host: host, port: port } or null if there are no more hosts.
63 host: null, // If null, use getHostAndPort when connecting.
64 port: 9696
65
66Face Constructor (default Transport)
Alexander Afanasyev06e798c2013-11-26 19:10:29 -080067^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080068
69Create a new Face object with optional settings to manage NDN communication.
70
71:[C++]:
72
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -080073 .. code-block:: c++
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080074
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -080075 Face(
76
77 [const char* host]
78 [, unsigned short port]
79
80 );
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080081
82:[JavaScript]:
83
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -080084 .. code-block:: javascript
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080085
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -080086 var Face = function Face(
87
88 [settings // associative array]
89
90 )
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080091
92:[Python]:
93
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -080094 .. code-block:: python
95
96 def __init__(self)
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080097
98:Parameters:
99
100 - ``host``
101 (optional) The host to connect to. If omitted, use localhost with the default TcpTransport.
102
103 - ``port``
104 (optional) The port to connect to. If omitted, use 6363 with the default TcpTransport.
105
106 - ``settings``
107 (JavaScript only) (optional) An associative array with the following defaults:
108
109 .. code-block:: javascript
110
111 getTransport: function() { return new WebSocketTransport(); },
112 getHostAndPort: transport.defaultGetHostAndPort,
113 // a function, on each call it returns a new { host: host, port: port } or null if there are no more hosts.
114 host: null, // If null, use getHostAndPort when connecting.
115 port: 9696
116
Alexander Afanasyev06e798c2013-11-26 19:10:29 -0800117Face.expressInterest Methods
118----------------------------
119
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800120Face.expressInterest Method (from Interest)
Alexander Afanasyev06e798c2013-11-26 19:10:29 -0800121^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800122
123Send the interest through the transport, read the entire response and call onData. If the interest times out according to interest lifetime, call onTimeout (if not omitted).
124
125C++ only: Your application must call processEvents.
126
127:[C++]:
128
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800129 .. code-block:: c++
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800130
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800131 unsigned int expressInterest(
132
133 const Interest& interest,
134 const OnData& onData,
135 [, const OnTimeout& onTimeout]
136 [, WireFormat& wireFormat]
137
138 );
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800139
140:[JavaScript]:
141
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800142 .. code-block:: javascript
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800143
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800144 Face.prototype.expressInterest = function(
145
146 interest // Interest
147 onData, // function
148 [, onTimeout // function]
149
150 )
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800151
152:Parameters:
153
154 - ``interest``
155 The Interest to send which includes the interest lifetime for the timeout.
156
157 - ``onData``
158 When a matching data packet is received, this calls ``onData(interest, data)`` where:
159
160 - ``interest`` is the interest given to expressInterest.
161 - ``data`` is the received Data object.
162
163 - ``onTimeout``
164 (optional) If the interest times out according to the interest lifetime, this calls ``onTimeout(interest)`` where:
165
166 - ``interest`` is the interest given to expressInterest.
167
168 - ``wireFormat``
169 (optional) A WireFormat object used to encode the message. If omitted, use WireFormat getDefaultWireFormat ().
170
171:Returns:
172
173 The pending interest ID which can be used with removePendingInterest.
174
175Face.expressInterest Method (from Name)
Alexander Afanasyev06e798c2013-11-26 19:10:29 -0800176^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800177
178Encode name as an Interest, using the interestTemplate if supplied, send the interest through the transport, read the entire response and call onData. If the interest times out according to interest lifetime, call onTimeout (if not omitted).
179C++ only: Your application must call processEvents.
180
181:[C++]:
182
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800183 .. code-block:: c++
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800184
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800185 unsigned int expressInterest(
186
187 const Name& name,
188 [, const Interest* interestTemplate]
189 const OnData& onData,
190 [, const OnTimeout& onTimeout]
191 [, WireFormat& wireFormat]
192
193 );
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800194
195:[JavaScript]:
196
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800197 .. code-block:: javascript
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800198
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800199 Face.prototype.expressInterest = function(
200
201 name, // Name
202 [, interestTemplate // Interest]
203 onData, // function
204 [, onTimeout // function]
205
206 )
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800207
208:[Python]:
209
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800210 .. code-block:: python
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800211
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800212 def expressInterest(self,
213
214 name # Name
215 closure # Closure
216 [, interestTemplate # Interest]
217
218 )
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800219
220:Parameters:
221
222 - ``name``
223 The Name for the interest.
224
225 - ``interestTemplate``
226 (optional) If not omitted, copy the interest selectors from this Interest. If omitted, use a default interest lifetime.
227
228 - ``onData``
229 When a matching data packet is received, this calls ``onData(interest, data)`` where:
230
231 - ``interest`` is the interest given to expressInterest.
232 - ``data`` is the received Data object.
233
234 - ``onTimeout``
235 (optional) If the interest times out according to the interest lifetime, this calls ``onTimeout(interest)`` where:
236
237 - ``interest`` is the interest given to expressInterest.
238
239 - ``wireFormat``
240 (optional) A WireFormat object used to encode the message. If omitted, use WireFormat getDefaultWireFormat ().
241
242:Returns:
243
244 The pending interest ID which can be used with removePendingInterest.
245
246Face.removePendingInterest Method
247---------------------------------
248
249Remove the pending interest entry with the pendingInterestId from the pending interest table. This does not affect another pending interest with a different pendingInterestId, even it if has the same interest name. If there is no entry with the pendingInterestId, do nothing.
250
251:[C++]:
252
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800253 .. code-block:: c++
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800254
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800255 void removePendingInterest(
256
257 unsigned int pendingInterestId
258
259 );
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800260
261:Parameters:
262
263 - ``pendingInterestId``
264 The ID returned from expressInterest.
265
266Face.registerPrefix Method
267--------------------------
268
269Register prefix with the connected NDN hub and call onInterest when a matching interest is received.
270
271C++ only: Your application must call processEvents.
272
273:[C++]:
274
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800275 .. code-block:: c++
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800276
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800277 unsigned int registerPrefix(
278
279 const Name& prefix,
280 const OnInterest& onInterest,
281 const OnRegisterFailed& onRegisterFailed,
282 [, ForwardingFlags flags]
283 [, WireFormat& wireFormat]
284
285 );
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800286
287:[JavaScript]:
288
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800289 .. code-block:: javascript
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800290
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800291 Face.prototype.registerPrefix = function(
292
293 name, // Name
294 onInterest // function
295 onRegisterFailed // function
296 [, flags // ForwardingFlags]
297
298 )
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800299
300:[Python]:
301
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800302 .. code-block:: python
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800303
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800304 def setInterestFilter(self,
305
306 name # Name
307 closure # Closure
308 [, flags # int]
309
310 )
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800311
312:Parameters:
313
314 - ``prefix``
315 The Name prefix.
316
317 - ``onInterest``
318 When an interest is received which matches the name prefix, this calls ``onInterest(prefix, interest, transport, registeredPrefixId)`` where:
319
320 - ``prefix`` is the prefix given to registerPrefix.
321 - ``interest`` is the received interest.
322 - ``transport`` is the Transport with the connection which received the interest. You must encode a signed Data packet and send it using transport.send().
323 - ``registeredPrefixId`` is the registered prefix ID which can be used with removeRegisteredPrefix.
324
325 - ``onRegisterFailed``
326 If failed to retrieve the connected hub's ID or failed to register the prefix, this calls onRegisterFailed(prefix) where:
327 - ``prefix`` is the prefix given to registerPrefix.
328
329 - ``flags``
330 (optional) The flags for finer control of which interests are forward to the application. If omitted, use the default flags defined by the default ForwardingFlags constructor.
331
332 - ``wireFormat``
333 (optional) A WireFormat object used to encode the message. If omitted, use WireFormat getDefaultWireFormat ().
334
335:Returns:
336
337 The registered prefix ID which can be used with removeRegisteredPrefix.
338
339Face.removeRegisteredPrefix Method
340----------------------------------
341
342Remove the registered prefix entry with the registeredPrefixId from the pending interest table. This does not affect another registered prefix with a different registeredPrefixId, even it if has the same prefix name. If there is no entry with the registeredPrefixId, do nothing.
343
344:[C++]:
345
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800346 .. code-block:: c++
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800347
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800348 void removeRegisteredPrefix(
349
350 unsigned int registeredPrefixId
351
352 );
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800353
354:Parameters:
355
356 - ``registeredPrefixId``
357 The ID returned from registerPrefix.
358
359Face.processEvents Method
360-------------------------
361
362C++ only: Process any data to receive and call data or timeout callbacks. This is non-blocking and will return immediately if there is no data to receive. You should repeatedly call this from an event loop, with calls to sleep as needed so that the loop doesn't use 100% of the CPU. Since processEvents modifies the pending interest table, your application should make sure that it calls processEvents in the same thread as expressInterest (which also modifies the pending interest table).
363
364:[C++]:
365
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800366 .. code-block:: c++
367
368 void processEvents();
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800369
370:Throw:
371
372 This may throw an exception for reading data or in the callback for processing the data. If you call this from an main event loop, you may want to catch and log/disregard all exceptions.
373