blob: 6348245bc463ada49cdc28a0257bb363b861c588 [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]
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800138
139 );
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800140
141:[JavaScript]:
142
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800143 .. code-block:: javascript
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800144
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800145 Face.prototype.expressInterest = function(
146
147 interest // Interest
148 onData, // function
149 [, onTimeout // function]
150
151 )
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800152
153:Parameters:
154
155 - ``interest``
156 The Interest to send which includes the interest lifetime for the timeout.
157
158 - ``onData``
159 When a matching data packet is received, this calls ``onData(interest, data)`` where:
160
161 - ``interest`` is the interest given to expressInterest.
162 - ``data`` is the received Data object.
163
164 - ``onTimeout``
165 (optional) If the interest times out according to the interest lifetime, this calls ``onTimeout(interest)`` where:
166
167 - ``interest`` is the interest given to expressInterest.
168
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800169:Returns:
170
171 The pending interest ID which can be used with removePendingInterest.
172
173Face.expressInterest Method (from Name)
Alexander Afanasyev06e798c2013-11-26 19:10:29 -0800174^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800175
176Encode 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).
177C++ only: Your application must call processEvents.
178
179:[C++]:
180
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800181 .. code-block:: c++
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800182
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800183 unsigned int expressInterest(
184
185 const Name& name,
186 [, const Interest* interestTemplate]
187 const OnData& onData,
188 [, const OnTimeout& onTimeout]
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800189
190 );
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800191
192:[JavaScript]:
193
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800194 .. code-block:: javascript
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800195
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800196 Face.prototype.expressInterest = function(
197
198 name, // Name
199 [, interestTemplate // Interest]
200 onData, // function
201 [, onTimeout // function]
202
203 )
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800204
205:[Python]:
206
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800207 .. code-block:: python
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800208
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800209 def expressInterest(self,
210
211 name # Name
212 closure # Closure
213 [, interestTemplate # Interest]
214
215 )
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800216
217:Parameters:
218
219 - ``name``
220 The Name for the interest.
221
222 - ``interestTemplate``
223 (optional) If not omitted, copy the interest selectors from this Interest. If omitted, use a default interest lifetime.
224
225 - ``onData``
226 When a matching data packet is received, this calls ``onData(interest, data)`` where:
227
228 - ``interest`` is the interest given to expressInterest.
229 - ``data`` is the received Data object.
230
231 - ``onTimeout``
232 (optional) If the interest times out according to the interest lifetime, this calls ``onTimeout(interest)`` where:
233
234 - ``interest`` is the interest given to expressInterest.
235
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800236:Returns:
237
238 The pending interest ID which can be used with removePendingInterest.
239
240Face.removePendingInterest Method
241---------------------------------
242
243Remove 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.
244
245:[C++]:
246
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800247 .. code-block:: c++
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800248
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800249 void removePendingInterest(
250
251 unsigned int pendingInterestId
252
253 );
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800254
255:Parameters:
256
257 - ``pendingInterestId``
258 The ID returned from expressInterest.
259
260Face.registerPrefix Method
261--------------------------
262
263Register prefix with the connected NDN hub and call onInterest when a matching interest is received.
264
265C++ only: Your application must call processEvents.
266
267:[C++]:
268
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800269 .. code-block:: c++
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800270
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800271 unsigned int registerPrefix(
272
273 const Name& prefix,
274 const OnInterest& onInterest,
275 const OnRegisterFailed& onRegisterFailed,
276 [, ForwardingFlags flags]
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800277
278 );
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800279
280:[JavaScript]:
281
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800282 .. code-block:: javascript
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800283
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800284 Face.prototype.registerPrefix = function(
285
286 name, // Name
287 onInterest // function
288 onRegisterFailed // function
289 [, flags // ForwardingFlags]
290
291 )
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800292
293:[Python]:
294
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800295 .. code-block:: python
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800296
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800297 def setInterestFilter(self,
298
299 name # Name
300 closure # Closure
301 [, flags # int]
302
303 )
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800304
305:Parameters:
306
307 - ``prefix``
308 The Name prefix.
309
310 - ``onInterest``
311 When an interest is received which matches the name prefix, this calls ``onInterest(prefix, interest, transport, registeredPrefixId)`` where:
312
313 - ``prefix`` is the prefix given to registerPrefix.
314 - ``interest`` is the received interest.
315 - ``transport`` is the Transport with the connection which received the interest. You must encode a signed Data packet and send it using transport.send().
316 - ``registeredPrefixId`` is the registered prefix ID which can be used with removeRegisteredPrefix.
317
318 - ``onRegisterFailed``
319 If failed to retrieve the connected hub's ID or failed to register the prefix, this calls onRegisterFailed(prefix) where:
320 - ``prefix`` is the prefix given to registerPrefix.
321
322 - ``flags``
323 (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.
324
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800325:Returns:
326
327 The registered prefix ID which can be used with removeRegisteredPrefix.
328
329Face.removeRegisteredPrefix Method
330----------------------------------
331
332Remove 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.
333
334:[C++]:
335
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800336 .. code-block:: c++
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800337
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800338 void removeRegisteredPrefix(
339
340 unsigned int registeredPrefixId
341
342 );
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800343
344:Parameters:
345
346 - ``registeredPrefixId``
347 The ID returned from registerPrefix.
348
349Face.processEvents Method
350-------------------------
351
352C++ 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).
353
354:[C++]:
355
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800356 .. code-block:: c++
357
358 void processEvents();
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800359
360:Throw:
361
362 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.
363