blob: 77cce7fc812a5342c3f1b21c94a099b822b867d2 [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
12Face Constructor (explicit Transport)
13-------------------------------------
14
15Create a new Face object with the given Transport to manage NDN communication.
16
17:[C++]:
18
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -080019 .. code-block:: c++
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080020
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -080021 Face(
22
23 const ptr_lib::shared_ptr<Transport>& transport
24 const ptr_lib::shared_ptr<const Transport::ConnectionInfo>& connectionInfo
25
26 );
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080027
28:[JavaScript]:
29
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -080030 .. code-block:: javascript
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080031
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -080032 var Face = function Face(
33
34 [settings // associative array]
35
36 )
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080037
38:[Python]:
39
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -080040 .. code-block:: python
41
42 def __init__(self)
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080043
44:Parameters:
45
46 - ``transport``
47 An object of a subclass of Transport to use for communication.
48
49 - ``connectionInfo``
50 This must be a ConnectionInfo from the same subclass of Transport as transport.
51
52 - ``settings``
53 (JavaScript only) An associative array with the following defaults:
54
55 .. code-block:: javascript
56
57 getTransport: function() { return new WebSocketTransport(); },
58 getHostAndPort: transport.defaultGetHostAndPort,
59 // a function, on each call it returns a new { host: host, port: port } or null if there are no more hosts.
60 host: null, // If null, use getHostAndPort when connecting.
61 port: 9696
62
63Face Constructor (default Transport)
64------------------------------------
65
66Create a new Face object with optional settings to manage NDN communication.
67
68:[C++]:
69
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -080070 .. code-block:: c++
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080071
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -080072 Face(
73
74 [const char* host]
75 [, unsigned short port]
76
77 );
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080078
79:[JavaScript]:
80
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -080081 .. code-block:: javascript
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080082
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -080083 var Face = function Face(
84
85 [settings // associative array]
86
87 )
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080088
89:[Python]:
90
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -080091 .. code-block:: python
92
93 def __init__(self)
Alexander Afanasyev2d600f72013-11-21 18:20:37 -080094
95:Parameters:
96
97 - ``host``
98 (optional) The host to connect to. If omitted, use localhost with the default TcpTransport.
99
100 - ``port``
101 (optional) The port to connect to. If omitted, use 6363 with the default TcpTransport.
102
103 - ``settings``
104 (JavaScript only) (optional) An associative array with the following defaults:
105
106 .. code-block:: javascript
107
108 getTransport: function() { return new WebSocketTransport(); },
109 getHostAndPort: transport.defaultGetHostAndPort,
110 // a function, on each call it returns a new { host: host, port: port } or null if there are no more hosts.
111 host: null, // If null, use getHostAndPort when connecting.
112 port: 9696
113
114Face.expressInterest Method (from Interest)
115-------------------------------------------
116
117Send 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).
118
119C++ only: Your application must call processEvents.
120
121:[C++]:
122
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800123 .. code-block:: c++
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800124
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800125 unsigned int expressInterest(
126
127 const Interest& interest,
128 const OnData& onData,
129 [, const OnTimeout& onTimeout]
130 [, WireFormat& wireFormat]
131
132 );
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800133
134:[JavaScript]:
135
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800136 .. code-block:: javascript
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800137
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800138 Face.prototype.expressInterest = function(
139
140 interest // Interest
141 onData, // function
142 [, onTimeout // function]
143
144 )
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800145
146:Parameters:
147
148 - ``interest``
149 The Interest to send which includes the interest lifetime for the timeout.
150
151 - ``onData``
152 When a matching data packet is received, this calls ``onData(interest, data)`` where:
153
154 - ``interest`` is the interest given to expressInterest.
155 - ``data`` is the received Data object.
156
157 - ``onTimeout``
158 (optional) If the interest times out according to the interest lifetime, this calls ``onTimeout(interest)`` where:
159
160 - ``interest`` is the interest given to expressInterest.
161
162 - ``wireFormat``
163 (optional) A WireFormat object used to encode the message. If omitted, use WireFormat getDefaultWireFormat ().
164
165:Returns:
166
167 The pending interest ID which can be used with removePendingInterest.
168
169Face.expressInterest Method (from Name)
170---------------------------------------
171
172Encode 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).
173C++ only: Your application must call processEvents.
174
175:[C++]:
176
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800177 .. code-block:: c++
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800178
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800179 unsigned int expressInterest(
180
181 const Name& name,
182 [, const Interest* interestTemplate]
183 const OnData& onData,
184 [, const OnTimeout& onTimeout]
185 [, WireFormat& wireFormat]
186
187 );
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800188
189:[JavaScript]:
190
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800191 .. code-block:: javascript
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800192
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800193 Face.prototype.expressInterest = function(
194
195 name, // Name
196 [, interestTemplate // Interest]
197 onData, // function
198 [, onTimeout // function]
199
200 )
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800201
202:[Python]:
203
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800204 .. code-block:: python
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800205
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800206 def expressInterest(self,
207
208 name # Name
209 closure # Closure
210 [, interestTemplate # Interest]
211
212 )
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800213
214:Parameters:
215
216 - ``name``
217 The Name for the interest.
218
219 - ``interestTemplate``
220 (optional) If not omitted, copy the interest selectors from this Interest. If omitted, use a default interest lifetime.
221
222 - ``onData``
223 When a matching data packet is received, this calls ``onData(interest, data)`` where:
224
225 - ``interest`` is the interest given to expressInterest.
226 - ``data`` is the received Data object.
227
228 - ``onTimeout``
229 (optional) If the interest times out according to the interest lifetime, this calls ``onTimeout(interest)`` where:
230
231 - ``interest`` is the interest given to expressInterest.
232
233 - ``wireFormat``
234 (optional) A WireFormat object used to encode the message. If omitted, use WireFormat getDefaultWireFormat ().
235
236: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]
277 [, WireFormat& wireFormat]
278
279 );
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800280
281:[JavaScript]:
282
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800283 .. code-block:: javascript
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800284
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800285 Face.prototype.registerPrefix = function(
286
287 name, // Name
288 onInterest // function
289 onRegisterFailed // function
290 [, flags // ForwardingFlags]
291
292 )
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800293
294:[Python]:
295
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800296 .. code-block:: python
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800297
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800298 def setInterestFilter(self,
299
300 name # Name
301 closure # Closure
302 [, flags # int]
303
304 )
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800305
306:Parameters:
307
308 - ``prefix``
309 The Name prefix.
310
311 - ``onInterest``
312 When an interest is received which matches the name prefix, this calls ``onInterest(prefix, interest, transport, registeredPrefixId)`` where:
313
314 - ``prefix`` is the prefix given to registerPrefix.
315 - ``interest`` is the received interest.
316 - ``transport`` is the Transport with the connection which received the interest. You must encode a signed Data packet and send it using transport.send().
317 - ``registeredPrefixId`` is the registered prefix ID which can be used with removeRegisteredPrefix.
318
319 - ``onRegisterFailed``
320 If failed to retrieve the connected hub's ID or failed to register the prefix, this calls onRegisterFailed(prefix) where:
321 - ``prefix`` is the prefix given to registerPrefix.
322
323 - ``flags``
324 (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.
325
326 - ``wireFormat``
327 (optional) A WireFormat object used to encode the message. If omitted, use WireFormat getDefaultWireFormat ().
328
329:Returns:
330
331 The registered prefix ID which can be used with removeRegisteredPrefix.
332
333Face.removeRegisteredPrefix Method
334----------------------------------
335
336Remove 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.
337
338:[C++]:
339
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800340 .. code-block:: c++
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800341
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800342 void removeRegisteredPrefix(
343
344 unsigned int registeredPrefixId
345
346 );
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800347
348:Parameters:
349
350 - ``registeredPrefixId``
351 The ID returned from registerPrefix.
352
353Face.processEvents Method
354-------------------------
355
356C++ 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).
357
358:[C++]:
359
Alexander Afanasyev1efe4a32013-11-21 18:46:34 -0800360 .. code-block:: c++
361
362 void processEvents();
Alexander Afanasyev2d600f72013-11-21 18:20:37 -0800363
364:Throw:
365
366 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.
367