Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 1 | .. _Face: |
| 2 | |
| 3 | Face Class |
| 4 | ========== |
| 5 | |
| 6 | :[C++]: |
| 7 | Namespace: ``ndn`` |
| 8 | |
| 9 | :[Python]: |
| 10 | Module: ``pyndn`` |
| 11 | |
Alexander Afanasyev | 06e798c | 2013-11-26 19:10:29 -0800 | [diff] [blame] | 12 | Face Constructors |
| 13 | ----------------- |
| 14 | |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 15 | Face Constructor (explicit Transport) |
Alexander Afanasyev | 06e798c | 2013-11-26 19:10:29 -0800 | [diff] [blame] | 16 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 17 | |
| 18 | Create a new Face object with the given Transport to manage NDN communication. |
| 19 | |
| 20 | :[C++]: |
| 21 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 22 | .. code-block:: c++ |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 23 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 24 | Face( |
| 25 | |
| 26 | const ptr_lib::shared_ptr<Transport>& transport |
Alexander Afanasyev | d265734 | 2013-12-17 16:07:14 -0800 | [diff] [blame] | 27 | const ptr_lib::shared_ptr<const Transport::ConnectionInfo>& |
| 28 | connectionInfo |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 29 | |
| 30 | ); |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 31 | |
| 32 | :[JavaScript]: |
| 33 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 34 | .. code-block:: javascript |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 35 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 36 | var Face = function Face( |
| 37 | |
| 38 | [settings // associative array] |
| 39 | |
| 40 | ) |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 41 | |
| 42 | :[Python]: |
| 43 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 44 | .. code-block:: python |
| 45 | |
| 46 | def __init__(self) |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 47 | |
| 48 | :Parameters: |
| 49 | |
| 50 | - ``transport`` |
| 51 | An object of a subclass of Transport to use for communication. |
| 52 | |
| 53 | - ``connectionInfo`` |
| 54 | This must be a ConnectionInfo from the same subclass of Transport as transport. |
| 55 | |
| 56 | - ``settings`` |
| 57 | (JavaScript only) An associative array with the following defaults: |
| 58 | |
| 59 | .. code-block:: javascript |
| 60 | |
Alexander Afanasyev | d265734 | 2013-12-17 16:07:14 -0800 | [diff] [blame] | 61 | getTransport: function() |
| 62 | { return new WebSocketTransport(); }, |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 63 | getHostAndPort: transport.defaultGetHostAndPort, |
Alexander Afanasyev | 57e20ed | 2013-11-26 19:14:19 -0800 | [diff] [blame] | 64 | // a function, on each call it returns |
Alexander Afanasyev | d265734 | 2013-12-17 16:07:14 -0800 | [diff] [blame] | 65 | // a new { host: host, port: port } |
| 66 | // or null if there are no more hosts. |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 67 | host: null, // If null, use getHostAndPort when connecting. |
| 68 | port: 9696 |
| 69 | |
| 70 | Face Constructor (default Transport) |
Alexander Afanasyev | 06e798c | 2013-11-26 19:10:29 -0800 | [diff] [blame] | 71 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 72 | |
| 73 | Create a new Face object with optional settings to manage NDN communication. |
| 74 | |
| 75 | :[C++]: |
| 76 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 77 | .. code-block:: c++ |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 78 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 79 | Face( |
| 80 | |
| 81 | [const char* host] |
| 82 | [, unsigned short port] |
| 83 | |
| 84 | ); |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 85 | |
| 86 | :[JavaScript]: |
| 87 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 88 | .. code-block:: javascript |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 89 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 90 | var Face = function Face( |
| 91 | |
| 92 | [settings // associative array] |
| 93 | |
| 94 | ) |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 95 | |
| 96 | :[Python]: |
| 97 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 98 | .. code-block:: python |
| 99 | |
| 100 | def __init__(self) |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 101 | |
| 102 | :Parameters: |
| 103 | |
| 104 | - ``host`` |
| 105 | (optional) The host to connect to. If omitted, use “localhost” with the default TcpTransport. |
| 106 | |
| 107 | - ``port`` |
| 108 | (optional) The port to connect to. If omitted, use 6363 with the default TcpTransport. |
| 109 | |
| 110 | - ``settings`` |
| 111 | (JavaScript only) (optional) An associative array with the following defaults: |
| 112 | |
| 113 | .. code-block:: javascript |
| 114 | |
Alexander Afanasyev | d265734 | 2013-12-17 16:07:14 -0800 | [diff] [blame] | 115 | getTransport: function() |
| 116 | { return new WebSocketTransport(); }, |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 117 | getHostAndPort: transport.defaultGetHostAndPort, |
Alexander Afanasyev | 57e20ed | 2013-11-26 19:14:19 -0800 | [diff] [blame] | 118 | // a function, on each call it returns a new |
Alexander Afanasyev | d265734 | 2013-12-17 16:07:14 -0800 | [diff] [blame] | 119 | // { host: host, port: port } |
| 120 | // or null if there are no more hosts. |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 121 | host: null, // If null, use getHostAndPort when connecting. |
| 122 | port: 9696 |
| 123 | |
Alexander Afanasyev | 06e798c | 2013-11-26 19:10:29 -0800 | [diff] [blame] | 124 | Face.expressInterest Methods |
| 125 | ---------------------------- |
| 126 | |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 127 | Face.expressInterest Method (from Interest) |
Alexander Afanasyev | 06e798c | 2013-11-26 19:10:29 -0800 | [diff] [blame] | 128 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 129 | |
| 130 | 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). |
| 131 | |
| 132 | C++ only: Your application must call processEvents. |
| 133 | |
| 134 | :[C++]: |
| 135 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 136 | .. code-block:: c++ |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 137 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 138 | unsigned int expressInterest( |
| 139 | |
| 140 | const Interest& interest, |
| 141 | const OnData& onData, |
| 142 | [, const OnTimeout& onTimeout] |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 143 | |
| 144 | ); |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 145 | |
| 146 | :[JavaScript]: |
| 147 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 148 | .. code-block:: javascript |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 149 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 150 | Face.prototype.expressInterest = function( |
| 151 | |
| 152 | interest // Interest |
| 153 | onData, // function |
| 154 | [, onTimeout // function] |
| 155 | |
| 156 | ) |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 157 | |
| 158 | :Parameters: |
| 159 | |
| 160 | - ``interest`` |
| 161 | The Interest to send which includes the interest lifetime for the timeout. |
| 162 | |
| 163 | - ``onData`` |
| 164 | When a matching data packet is received, this calls ``onData(interest, data)`` where: |
| 165 | |
| 166 | - ``interest`` is the interest given to expressInterest. |
| 167 | - ``data`` is the received Data object. |
| 168 | |
| 169 | - ``onTimeout`` |
| 170 | (optional) If the interest times out according to the interest lifetime, this calls ``onTimeout(interest)`` where: |
| 171 | |
| 172 | - ``interest`` is the interest given to expressInterest. |
| 173 | |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 174 | :Returns: |
| 175 | |
| 176 | The pending interest ID which can be used with removePendingInterest. |
| 177 | |
| 178 | Face.expressInterest Method (from Name) |
Alexander Afanasyev | 06e798c | 2013-11-26 19:10:29 -0800 | [diff] [blame] | 179 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 180 | |
| 181 | Encode 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). |
| 182 | C++ only: Your application must call processEvents. |
| 183 | |
| 184 | :[C++]: |
| 185 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 186 | .. code-block:: c++ |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 187 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 188 | unsigned int expressInterest( |
| 189 | |
| 190 | const Name& name, |
| 191 | [, const Interest* interestTemplate] |
| 192 | const OnData& onData, |
| 193 | [, const OnTimeout& onTimeout] |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 194 | |
| 195 | ); |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 196 | |
| 197 | :[JavaScript]: |
| 198 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 199 | .. code-block:: javascript |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 200 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 201 | Face.prototype.expressInterest = function( |
| 202 | |
| 203 | name, // Name |
| 204 | [, interestTemplate // Interest] |
| 205 | onData, // function |
| 206 | [, onTimeout // function] |
| 207 | |
| 208 | ) |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 209 | |
| 210 | :[Python]: |
| 211 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 212 | .. code-block:: python |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 213 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 214 | def expressInterest(self, |
| 215 | |
| 216 | name # Name |
| 217 | closure # Closure |
| 218 | [, interestTemplate # Interest] |
| 219 | |
| 220 | ) |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 221 | |
| 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 | |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 241 | :Returns: |
| 242 | |
| 243 | The pending interest ID which can be used with removePendingInterest. |
| 244 | |
| 245 | Face.removePendingInterest Method |
| 246 | --------------------------------- |
| 247 | |
| 248 | Remove 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. |
| 249 | |
| 250 | :[C++]: |
| 251 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 252 | .. code-block:: c++ |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 253 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 254 | void removePendingInterest( |
| 255 | |
| 256 | unsigned int pendingInterestId |
| 257 | |
| 258 | ); |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 259 | |
| 260 | :Parameters: |
| 261 | |
| 262 | - ``pendingInterestId`` |
| 263 | The ID returned from expressInterest. |
| 264 | |
Alexander Afanasyev | ce6daac | 2013-11-26 19:49:37 -0800 | [diff] [blame] | 265 | .. _registerPrefix: |
| 266 | |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 267 | Face.registerPrefix Method |
| 268 | -------------------------- |
| 269 | |
Alexander Afanasyev | ce6daac | 2013-11-26 19:49:37 -0800 | [diff] [blame] | 270 | Request NDN network to forward Interests for the specified :ref:`name prefix <Name>` towards the face. |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 271 | |
Alexander Afanasyev | ce6daac | 2013-11-26 19:49:37 -0800 | [diff] [blame] | 272 | .. note:: |
| 273 | |
| 274 | The current API is limited to registering the specified prefix only on a direclty connected NDN hub (e.g., local NDN daemon). |
| 275 | |
| 276 | .. note:: |
| 277 | |
| 278 | **C++ only**: Your application must call :ref:`processEvents`. |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 279 | |
| 280 | :[C++]: |
| 281 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 282 | .. code-block:: c++ |
Alexander Afanasyev | ce6daac | 2013-11-26 19:49:37 -0800 | [diff] [blame] | 283 | |
| 284 | void registerPrefix( |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 285 | |
Alexander Afanasyev | ce6daac | 2013-11-26 19:49:37 -0800 | [diff] [blame] | 286 | const Name &prefix, |
| 287 | const OnRegisterSucceed &onRegisterSucceed, |
| 288 | const onRegisterFailed &onRegisterFailed |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 289 | [, ForwardingFlags flags] |
Alexander Afanasyev | ce6daac | 2013-11-26 19:49:37 -0800 | [diff] [blame] | 290 | ) |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 291 | |
| 292 | :[JavaScript]: |
| 293 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 294 | .. code-block:: javascript |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 295 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 296 | Face.prototype.registerPrefix = function( |
| 297 | |
Alexander Afanasyev | ce6daac | 2013-11-26 19:49:37 -0800 | [diff] [blame] | 298 | prefix, // Name |
| 299 | OnRegisterSucceed, // function |
| 300 | onRegisterFailed // function |
| 301 | [, flags] // ForwardingFlags |
| 302 | |
| 303 | ) |
| 304 | |
| 305 | :[Python]: |
| 306 | |
| 307 | .. code-block:: python |
| 308 | |
| 309 | def registerPrefix(self, |
| 310 | |
| 311 | prefix, # Name |
| 312 | OnRegisterSucceed, # function |
| 313 | OnRegisterFailed # function |
| 314 | [, flags] # ForwardingFlags |
| 315 | ) |
| 316 | |
| 317 | :Parameters: |
| 318 | |
| 319 | - ``prefix`` |
| 320 | The :ref:`Name prefix <Name>` to register in NDN network. |
| 321 | |
| 322 | - ``onRegisterSucceed`` |
| 323 | Callback that is fired when the prefix is successfully registered within the NDN network. |
| 324 | The prototype for the callback is ``onRegisterSucceed(prefix)``, where: |
| 325 | - ``prefix`` is the prefix given to registerPrefix. |
| 326 | |
| 327 | - ``onRegisterFailed`` |
| 328 | If failed to set Interest filter for any reason, this calls ``onRegisterFailed(prefix)`` where: |
| 329 | - ``prefix`` is the prefix given to registerPrefix. |
| 330 | |
| 331 | - ``flags`` |
| 332 | (optional) The flags for finer control of how and which Interests should be forwarded towards the face. |
| 333 | If omitted, use the default flags defined by the default :ref:`ForwardingFlags <ForwardingFlags>` constructor. |
| 334 | |
| 335 | .. _deregisterPrefix: |
| 336 | |
| 337 | Face.deregisterPrefix Method |
| 338 | ---------------------------- |
| 339 | |
| 340 | Deregister the previously registered :ref:`prefix <Name>` from the NDN network. |
| 341 | |
| 342 | .. note:: |
| 343 | |
| 344 | The current API is limited to deregistering the specified prefix only on a direclty connected NDN hub (e.g., local NDN daemon). |
| 345 | |
| 346 | :[C++]: |
| 347 | |
| 348 | .. code-block:: c++ |
| 349 | |
| 350 | void deregisterPrefix( |
| 351 | |
| 352 | const Name &prefix |
| 353 | [, const onDeregisterSucceed &onDeregisterSucceed] |
| 354 | [, const onDeregisterFailed &onDeregisterFailed] |
| 355 | ) |
| 356 | |
| 357 | :[JavaScript]: |
| 358 | |
| 359 | .. code-block:: javascript |
| 360 | |
| 361 | Face.prototype.deregisterPrefix = function( |
| 362 | |
| 363 | prefix // Name |
| 364 | [, OnDeregisterSucceed] // function |
| 365 | [, OnDeregisterFailed] // function |
| 366 | |
| 367 | ) |
| 368 | |
| 369 | :[Python]: |
| 370 | |
| 371 | .. code-block:: python |
| 372 | |
| 373 | def deregisterPrefix(self, |
| 374 | |
| 375 | prefix # Name |
| 376 | [, OnDeregisterSucceed] # function |
| 377 | [, OnDeregisterFailed] # function |
| 378 | ) |
| 379 | |
| 380 | :Parameters: |
| 381 | |
| 382 | - ``prefix`` |
| 383 | The :ref:`Name prefix <Name>` to deregister in NDN network. |
| 384 | |
| 385 | - ``onDeregisterSucceed`` |
| 386 | (Optional) Callback that is fired when the prefix is successfully deregistered within the NDN network. |
| 387 | The prototype for the callback is ``onDeregisterSucceed(prefix)``, where: |
| 388 | - ``prefix`` is the prefix given to ``deregisterPrefix``. |
| 389 | |
| 390 | - ``onRegisterFailed`` |
| 391 | (Optional) If failed to set Interest filter for any reason, this calls ``onDeregisterFailed(prefix)`` where: |
| 392 | - ``prefix`` is the prefix given to ``deregisterPrefix``. |
| 393 | |
| 394 | .. _setInterestFilter: |
| 395 | |
| 396 | Face.setInterestFilter Method |
| 397 | ----------------------------- |
| 398 | |
| 399 | Register ``onInterest`` callback when an Interest mathing the :ref:`filter <InterestFilter>` is received on the face. |
| 400 | |
| 401 | |
| 402 | :[C++]: |
| 403 | |
| 404 | .. code-block:: c++ |
| 405 | |
| 406 | unsigned int setInterestFilter( |
| 407 | |
| 408 | const InterestFilter& filter, |
| 409 | const OnInterest& onInterest, |
| 410 | |
| 411 | ); |
| 412 | |
| 413 | :[JavaScript]: |
| 414 | |
| 415 | .. code-block:: javascript |
| 416 | |
| 417 | Face.prototype.setInterestFilter = function( |
| 418 | |
| 419 | filter, // InterestFilter |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 420 | onInterest // function |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 421 | |
| 422 | ) |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 423 | |
| 424 | :[Python]: |
| 425 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 426 | .. code-block:: python |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 427 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 428 | def setInterestFilter(self, |
| 429 | |
Alexander Afanasyev | ce6daac | 2013-11-26 19:49:37 -0800 | [diff] [blame] | 430 | filter, # InterestFilter |
| 431 | onInterest # function |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 432 | |
| 433 | ) |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 434 | |
| 435 | :Parameters: |
| 436 | |
Alexander Afanasyev | ce6daac | 2013-11-26 19:49:37 -0800 | [diff] [blame] | 437 | - ``filter`` |
| 438 | The :ref:`InterestFilter <InterestFilter>` to match Interests. |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 439 | |
| 440 | - ``onInterest`` |
Alexander Afanasyev | ce6daac | 2013-11-26 19:49:37 -0800 | [diff] [blame] | 441 | When an interest is received which matches the name prefix, this calls ``onInterest(face, filter, interest)`` where: |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 442 | |
Alexander Afanasyev | ce6daac | 2013-11-26 19:49:37 -0800 | [diff] [blame] | 443 | - ``face`` is the :ref:`Face` on which the Interest is received. |
| 444 | An application can satisfy this Interest using :ref:`put` |
| 445 | - ``filter`` is the filter given to ``setInterestFilter``. |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 446 | - ``interest`` is the received interest. |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 447 | |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 448 | :Returns: |
| 449 | |
Alexander Afanasyev | ce6daac | 2013-11-26 19:49:37 -0800 | [diff] [blame] | 450 | The interest filter ID which can be used with :ref:`removeInterestFilter`. |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 451 | |
Alexander Afanasyev | ce6daac | 2013-11-26 19:49:37 -0800 | [diff] [blame] | 452 | .. _removeInterestFilter: |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 453 | |
Alexander Afanasyev | ce6daac | 2013-11-26 19:49:37 -0800 | [diff] [blame] | 454 | Face.removeInterestFilter Method |
| 455 | -------------------------------- |
| 456 | |
| 457 | Remove the previously set Interest filter with the ``interestFilterId`` from the pending interest table. This does not affect any other interest filters with different IDs, even it if has the same prefix name. If there is no entry with the ``interestFilterId``, do nothing. |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 458 | |
| 459 | :[C++]: |
| 460 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 461 | .. code-block:: c++ |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 462 | |
Alexander Afanasyev | ce6daac | 2013-11-26 19:49:37 -0800 | [diff] [blame] | 463 | void removeInterestFilter( |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 464 | |
Alexander Afanasyev | ce6daac | 2013-11-26 19:49:37 -0800 | [diff] [blame] | 465 | unsigned int interestFilterId |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 466 | |
| 467 | ); |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 468 | |
| 469 | :Parameters: |
| 470 | |
Alexander Afanasyev | ce6daac | 2013-11-26 19:49:37 -0800 | [diff] [blame] | 471 | - ``interestFilterId`` |
| 472 | The ID returned from :ref:`setInterestFilter`. |
| 473 | |
| 474 | .. _put: |
| 475 | |
| 476 | Face.put Method |
| 477 | --------------- |
| 478 | |
| 479 | Put (publish) the encoded and signed Data packet on a Face. |
| 480 | |
| 481 | This method essentially satisfies any pending Interest that matches the name of the published Data packet. |
| 482 | If there are no outstanding Interests, directly connected NDN daemon (e.g., local NDN daemon) puts the Data packet into its packet buffer. |
| 483 | |
| 484 | :[C++]: |
| 485 | |
| 486 | .. code-block:: c++ |
| 487 | |
| 488 | void put( |
| 489 | |
| 490 | ptr_lib::shared_ptr<const Data> data |
| 491 | |
| 492 | ); |
| 493 | |
| 494 | :Parameters: |
| 495 | |
| 496 | - ``data`` |
| 497 | The encoded and signed Data packet |
| 498 | |
| 499 | |
| 500 | .. _processEvents: |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 501 | |
| 502 | Face.processEvents Method |
| 503 | ------------------------- |
| 504 | |
| 505 | C++ 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). |
| 506 | |
| 507 | :[C++]: |
| 508 | |
Alexander Afanasyev | 1efe4a3 | 2013-11-21 18:46:34 -0800 | [diff] [blame] | 509 | .. code-block:: c++ |
| 510 | |
| 511 | void processEvents(); |
Alexander Afanasyev | 2d600f7 | 2013-11-21 18:20:37 -0800 | [diff] [blame] | 512 | |
| 513 | :Throw: |
| 514 | |
| 515 | 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. |
| 516 | |