blob: 210ad17b28e7bc83385a2a990c6b2a4c1decf685 [file] [log] [blame]
Jeff Thompsonb982b6d2013-07-15 18:15:45 -07001/**
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 Thompson2d27e2f2013-08-09 12:55:00 -070011#define NDN_CLOSURE_HPP
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070012
Jeff Thompson285e63b2013-08-05 10:43:30 -070013#include "common.hpp"
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070014
15namespace ndn {
16
17enum 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
26enum 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 Thompson56ec9e22013-08-02 11:34:07 -070030 UPCALL_DATA = 3, // incoming verified data packet
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070031 UPCALL_INTEREST_TIMED_OUT = 4, // interest timed out
Jeff Thompson56ec9e22013-08-02 11:34:07 -070032 UPCALL_DATA_UNVERIFIED = 5, // data packet that has not been verified
33 UPCALL_DATA_BAD = 6 // verification failed
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070034};
35
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070036class Node;
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070037class Interest;
Jeff Thompson56ec9e22013-08-02 11:34:07 -070038class Data;
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070039
40class UpcallInfo {
41public:
Jeff Thompsone60caeb2013-08-21 16:14:36 -070042 UpcallInfo(Node *node, const ptr_lib::shared_ptr<const Interest> &interest, int matchedComps, const ptr_lib::shared_ptr<Data> &data)
Jeff Thompson2c322a82013-08-21 15:56:52 -070043 : node_(node), interest_(interest), data_(data)
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070044 {
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070045 }
46
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070047 Node *getNode() { return node_; }
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070048
Jeff Thompsone60caeb2013-08-21 16:14:36 -070049 const ptr_lib::shared_ptr<const Interest> &getInterest() const { return interest_; }
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070050
Jeff Thompsone60caeb2013-08-21 16:14:36 -070051 const ptr_lib::shared_ptr<Data> &getData() const { return data_; }
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070052
53private:
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070054 Node *node_;
Jeff Thompsone60caeb2013-08-21 16:14:36 -070055 ptr_lib::shared_ptr<const Interest> interest_;
Jeff Thompson56ec9e22013-08-02 11:34:07 -070056 ptr_lib::shared_ptr<Data> data_;
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070057};
58
59class Closure {
60public:
Jeff Thompsone60caeb2013-08-21 16:14:36 -070061 virtual UpcallResult upcall(UpcallKind kind, const UpcallInfo &upcallInfo) = 0;
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070062};
63
64}
65
66#endif