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 |
| 11 | #define NDN_CLOSURE_HPP |
| 12 | |
| 13 | #include "Common.hpp" |
| 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 |
| 30 | UPCALL_CONTENT = 3, // incoming verified content |
| 31 | UPCALL_INTEREST_TIMED_OUT = 4, // interest timed out |
| 32 | UPCALL_CONTENT_UNVERIFIED = 5, // content that has not been verified |
| 33 | UPCALL_CONTENT_BAD = 6 // verification failed |
| 34 | }; |
| 35 | |
| 36 | class NDN; |
| 37 | class Interest; |
| 38 | class ContentObject; |
| 39 | |
| 40 | class UpcallInfo { |
| 41 | public: |
Jeff Thompson | 85ff99f | 2013-07-15 18:23:58 -0700 | [diff] [blame] | 42 | UpcallInfo(NDN *ndn, ptr_lib::shared_ptr<Interest> &interest, int matchedComps, ptr_lib::shared_ptr<ContentObject> &contentObject) |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 43 | { |
| 44 | ndn_ = ndn; |
| 45 | interest_ = interest; |
| 46 | contentObject_ = contentObject; |
| 47 | } |
| 48 | |
| 49 | NDN *getNDN() { return ndn_; } |
| 50 | |
Jeff Thompson | 85ff99f | 2013-07-15 18:23:58 -0700 | [diff] [blame] | 51 | ptr_lib::shared_ptr<Interest> &getInterest() { return interest_; } |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 52 | |
Jeff Thompson | 85ff99f | 2013-07-15 18:23:58 -0700 | [diff] [blame] | 53 | ptr_lib::shared_ptr<ContentObject> &getContentObject() { return contentObject_; } |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 54 | |
| 55 | private: |
| 56 | NDN *ndn_; |
| 57 | ptr_lib::shared_ptr<Interest> interest_; |
| 58 | ptr_lib::shared_ptr<ContentObject> contentObject_; |
| 59 | }; |
| 60 | |
| 61 | class Closure { |
| 62 | public: |
| 63 | virtual UpcallResult upcall(UpcallKind kind, UpcallInfo &upcallInfo) = 0; |
| 64 | }; |
| 65 | |
| 66 | } |
| 67 | |
| 68 | #endif |