Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 1 | /** |
| 2 | * @author: Jeff Thompson |
| 3 | * This is a port of py from PyCCN, written by: |
| 4 | * Derek Kulinski <takeda@takeda.tk> |
| 5 | * Jeff Burke <jburke@ucla.edu> |
| 6 | * |
| 7 | * See COPYING for copyright and distribution information. |
| 8 | */ |
| 9 | |
| 10 | #ifndef NDN_CLOSURE_HPP |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 11 | #define NDN_CLOSURE_HPP |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 12 | |
Jeff Thompson | 285e63b | 2013-08-05 10:43:30 -0700 | [diff] [blame] | 13 | #include "common.hpp" |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 14 | |
| 15 | namespace ndn { |
| 16 | |
| 17 | enum UpcallResult { |
| 18 | CLOSURE_RESULT_ERR = -1, // upcall detected an error |
| 19 | CLOSURE_RESULT_OK = 0, // normal upcall return |
| 20 | CLOSURE_RESULT_REEXPRESS = 1, // reexpress the same interest again |
| 21 | CLOSURE_RESULT_INTEREST_CONSUMED = 2, // upcall claims to consume interest |
| 22 | CLOSURE_RESULT_VERIFY = 3, // force an unverified result to be verified |
| 23 | CLOSURE_RESULT_FETCHKEY = 4 // get the key in the key locator and re-call the interest |
| 24 | }; |
| 25 | |
| 26 | enum UpcallKind { |
| 27 | UPCALL_FINAL = 0, // handler is about to be deregistered |
| 28 | UPCALL_INTEREST = 1, // incoming interest |
| 29 | UPCALL_CONSUMED_INTEREST = 2, // incoming interest, someone has answered |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 30 | UPCALL_DATA = 3, // incoming verified data packet |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 31 | UPCALL_INTEREST_TIMED_OUT = 4, // interest timed out |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 32 | UPCALL_DATA_UNVERIFIED = 5, // data packet that has not been verified |
| 33 | UPCALL_DATA_BAD = 6 // verification failed |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 34 | }; |
| 35 | |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 36 | class Node; |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 37 | class Interest; |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 38 | class Data; |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 39 | |
| 40 | class UpcallInfo { |
| 41 | public: |
Jeff Thompson | e60caeb | 2013-08-21 16:14:36 -0700 | [diff] [blame] | 42 | UpcallInfo(Node *node, const ptr_lib::shared_ptr<const Interest> &interest, int matchedComps, const ptr_lib::shared_ptr<Data> &data) |
Jeff Thompson | 2c322a8 | 2013-08-21 15:56:52 -0700 | [diff] [blame] | 43 | : node_(node), interest_(interest), data_(data) |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 44 | { |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 47 | Node *getNode() { return node_; } |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 48 | |
Jeff Thompson | e60caeb | 2013-08-21 16:14:36 -0700 | [diff] [blame] | 49 | const ptr_lib::shared_ptr<const Interest> &getInterest() const { return interest_; } |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 50 | |
Jeff Thompson | e60caeb | 2013-08-21 16:14:36 -0700 | [diff] [blame] | 51 | const ptr_lib::shared_ptr<Data> &getData() const { return data_; } |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 52 | |
| 53 | private: |
Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame] | 54 | Node *node_; |
Jeff Thompson | e60caeb | 2013-08-21 16:14:36 -0700 | [diff] [blame] | 55 | ptr_lib::shared_ptr<const Interest> interest_; |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 56 | ptr_lib::shared_ptr<Data> data_; |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | class Closure { |
| 60 | public: |
Jeff Thompson | e60caeb | 2013-08-21 16:14:36 -0700 | [diff] [blame] | 61 | virtual UpcallResult upcall(UpcallKind kind, const UpcallInfo &upcallInfo) = 0; |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | } |
| 65 | |
| 66 | #endif |