blob: 28699fab3d75767f99e8860f2a80af42ca0a14be [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,
Alexander Afanasyev57e20ed2013-11-26 19:14:19 -080062 // a function, on each call it returns
63 // a new { host: host, port: port } or null if there are no more hosts.
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080064 host: null, // If null, use getHostAndPort when connecting.
65 port: 9696
66
67Face Constructor (default Transport)
Alexander Afanasyev06e798c2013-11-26 19:10:29 -080068^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080069
70Create a new Face object with optional settings to manage NDN communication.
71
72:[C++]:
73
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -080074 .. code-block:: c++
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080075
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -080076 Face(
77
78 [const char* host]
79 [, unsigned short port]
80
81 );
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080082
83:[JavaScript]:
84
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -080085 .. code-block:: javascript
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080086
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -080087 var Face = function Face(
88
89 [settings // associative array]
90
91 )
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080092
93:[Python]:
94
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -080095 .. code-block:: python
96
97 def __init__(self)
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080098
99:Parameters:
100
101 - ``host``
102 (optional) The host to connect to. If omitted, use localhost with the default TcpTransport.
103
104 - ``port``
105 (optional) The port to connect to. If omitted, use 6363 with the default TcpTransport.
106
107 - ``settings``
108 (JavaScript only) (optional) An associative array with the following defaults:
109
110 .. code-block:: javascript
111
112 getTransport: function() { return new WebSocketTransport(); },
113 getHostAndPort: transport.defaultGetHostAndPort,
Alexander Afanasyev57e20ed2013-11-26 19:14:19 -0800114 // a function, on each call it returns a new
115 // { host: host, port: port } or null if there are no more hosts.
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800116 host: null, // If null, use getHostAndPort when connecting.
117 port: 9696
118
Alexander Afanasyev06e798c2013-11-26 19:10:29 -0800119Face.expressInterest Methods
120----------------------------
121
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800122Face.expressInterest Method (from Interest)
Alexander Afanasyev06e798c2013-11-26 19:10:29 -0800123^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800124
125Send 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).
126
127C++ only: Your application must call processEvents.
128
129:[C++]:
130
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800131 .. code-block:: c++
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800132
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800133 unsigned int expressInterest(
134
135 const Interest& interest,
136 const OnData& onData,
137 [, const OnTimeout& onTimeout]
138 [, WireFormat& wireFormat]
139
140 );
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800141
142:[JavaScript]:
143
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800144 .. code-block:: javascript
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800145
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800146 Face.prototype.expressInterest = function(
147
148 interest // Interest
149 onData, // function
150 [, onTimeout // function]
151
152 )
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800153
154:Parameters:
155
156 - ``interest``
157 The Interest to send which includes the interest lifetime for the timeout.
158
159 - ``onData``
160 When a matching data packet is received, this calls ``onData(interest, data)`` where:
161
162 - ``interest`` is the interest given to expressInterest.
163 - ``data`` is the received Data object.
164
165 - ``onTimeout``
166 (optional) If the interest times out according to the interest lifetime, this calls ``onTimeout(interest)`` where:
167
168 - ``interest`` is the interest given to expressInterest.
169
170 - ``wireFormat``
171 (optional) A WireFormat object used to encode the message. If omitted, use WireFormat getDefaultWireFormat ().
172
173:Returns:
174
175 The pending interest ID which can be used with removePendingInterest.
176
177Face.expressInterest Method (from Name)
Alexander Afanasyev06e798c2013-11-26 19:10:29 -0800178^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800179
180Encode 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).
181C++ only: Your application must call processEvents.
182
183:[C++]:
184
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800185 .. code-block:: c++
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800186
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800187 unsigned int expressInterest(
188
189 const Name& name,
190 [, const Interest* interestTemplate]
191 const OnData& onData,
192 [, const OnTimeout& onTimeout]
193 [, WireFormat& wireFormat]
194
195 );
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800196
197:[JavaScript]:
198
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800199 .. code-block:: javascript
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800200
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800201 Face.prototype.expressInterest = function(
202
203 name, // Name
204 [, interestTemplate // Interest]
205 onData, // function
206 [, onTimeout // function]
207
208 )
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800209
210:[Python]:
211
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800212 .. code-block:: python
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800213
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800214 def expressInterest(self,
215
216 name # Name
217 closure # Closure
218 [, interestTemplate # Interest]
219
220 )
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800221
222:Parameters:
223
224 - ``name``
225 The Name for the interest.
226
227 - ``interestTemplate``
228 (optional) If not omitted, copy the interest selectors from this Interest. If omitted, use a default interest lifetime.
229
230 - ``onData``
231 When a matching data packet is received, this calls ``onData(interest, data)`` where:
232
233 - ``interest`` is the interest given to expressInterest.
234 - ``data`` is the received Data object.
235
236 - ``onTimeout``
237 (optional) If the interest times out according to the interest lifetime, this calls ``onTimeout(interest)`` where:
238
239 - ``interest`` is the interest given to expressInterest.
240
241 - ``wireFormat``
242 (optional) A WireFormat object used to encode the message. If omitted, use WireFormat getDefaultWireFormat ().
243
244:Returns:
245
246 The pending interest ID which can be used with removePendingInterest.
247
248Face.removePendingInterest Method
249---------------------------------
250
251Remove 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.
252
253:[C++]:
254
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800255 .. code-block:: c++
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800256
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800257 void removePendingInterest(
258
259 unsigned int pendingInterestId
260
261 );
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800262
263:Parameters:
264
265 - ``pendingInterestId``
266 The ID returned from expressInterest.
267
268Face.registerPrefix Method
269--------------------------
270
271Register prefix with the connected NDN hub and call onInterest when a matching interest is received.
272
273C++ only: Your application must call processEvents.
274
275:[C++]:
276
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800277 .. code-block:: c++
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800278
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800279 unsigned int registerPrefix(
280
281 const Name& prefix,
282 const OnInterest& onInterest,
283 const OnRegisterFailed& onRegisterFailed,
284 [, ForwardingFlags flags]
285 [, WireFormat& wireFormat]
286
287 );
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800288
289:[JavaScript]:
290
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800291 .. code-block:: javascript
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800292
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800293 Face.prototype.registerPrefix = function(
294
295 name, // Name
296 onInterest // function
297 onRegisterFailed // function
298 [, flags // ForwardingFlags]
299
300 )
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800301
302:[Python]:
303
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800304 .. code-block:: python
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800305
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800306 def setInterestFilter(self,
307
308 name # Name
309 closure # Closure
310 [, flags # int]
311
312 )
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800313
314:Parameters:
315
316 - ``prefix``
317 The Name prefix.
318
319 - ``onInterest``
320 When an interest is received which matches the name prefix, this calls ``onInterest(prefix, interest, transport, registeredPrefixId)`` where:
321
322 - ``prefix`` is the prefix given to registerPrefix.
323 - ``interest`` is the received interest.
324 - ``transport`` is the Transport with the connection which received the interest. You must encode a signed Data packet and send it using transport.send().
325 - ``registeredPrefixId`` is the registered prefix ID which can be used with removeRegisteredPrefix.
326
327 - ``onRegisterFailed``
328 If failed to retrieve the connected hub's ID or failed to register the prefix, this calls onRegisterFailed(prefix) where:
329 - ``prefix`` is the prefix given to registerPrefix.
330
331 - ``flags``
332 (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.
333
334 - ``wireFormat``
335 (optional) A WireFormat object used to encode the message. If omitted, use WireFormat getDefaultWireFormat ().
336
337:Returns:
338
339 The registered prefix ID which can be used with removeRegisteredPrefix.
340
341Face.removeRegisteredPrefix Method
342----------------------------------
343
344Remove 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.
345
346:[C++]:
347
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800348 .. code-block:: c++
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800349
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800350 void removeRegisteredPrefix(
351
352 unsigned int registeredPrefixId
353
354 );
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800355
356:Parameters:
357
358 - ``registeredPrefixId``
359 The ID returned from registerPrefix.
360
361Face.processEvents Method
362-------------------------
363
364C++ 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).
365
366:[C++]:
367
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800368 .. code-block:: c++
369
370 void processEvents();
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800371
372:Throw:
373
374 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.
375