blob: 15770c432f69d07b895db96afe6f77e4c1791b76 [file] [log] [blame]
Jeff Thompson34419762012-10-15 22:24:12 -07001/*
Jeff Thompson146d7de2012-11-17 16:15:28 -08002 * @author: Jeff Thompson
Jeff Thompson34419762012-10-15 22:24:12 -07003 * See COPYING for copyright and distribution information.
4 * Provide the callback closure for the async communication methods in the NDN class.
5 * This is a port of Closure.py from PyCCN, written by:
6 * Derek Kulinski <takeda@takeda.tk>
7 * Jeff Burke <jburke@ucla.edu>
8 */
9
10/*
11 * Create a subclass of Closure and pass an object to async calls.
12 */
13var Closure = function Closure() {
14 // I don't think storing NDN's closure is needed
15 // and it creates a reference loop, as of now both
16 // of those variables are never set -- Derek
17 //
18 // Use instance variables to return data to callback
19 this.ndn_data = null; // this holds the ndn_closure
20 this.ndn_data_dirty = false;
21};
22
23// Upcall result
24Closure.RESULT_ERR = -1; // upcall detected an error
25Closure.RESULT_OK = 0; // normal upcall return
26Closure.RESULT_REEXPRESS = 1; // reexpress the same interest again
27Closure.RESULT_INTEREST_CONSUMED = 2; // upcall claims to consume interest
28Closure.RESULT_VERIFY = 3; // force an unverified result to be verified
Jeff Thompson27a9ef82012-10-21 11:27:43 -070029Closure.RESULT_FETCHKEY = 4; // get the key in the key locator and re-call the interest
30 // with the key available in the local storage
Jeff Thompson34419762012-10-15 22:24:12 -070031
32// Upcall kind
33Closure.UPCALL_FINAL = 0; // handler is about to be deregistered
34Closure.UPCALL_INTEREST = 1; // incoming interest
35Closure.UPCALL_CONSUMED_INTEREST = 2; // incoming interest, someone has answered
36Closure.UPCALL_CONTENT = 3; // incoming verified content
37Closure.UPCALL_INTEREST_TIMED_OUT = 4; // interest timed out
38Closure.UPCALL_CONTENT_UNVERIFIED = 5; // content that has not been verified
39Closure.UPCALL_CONTENT_BAD = 6; // verification failed
40
41/*
42 * Override this in your subclass.
43 * If you're getting strange errors in upcall()
44 * check your code whether you're returning a value.
45 */
46Closure.prototype.upcall = function(kind, upcallInfo) {
47 //dump('upcall ' + this + " " + kind + " " + upcallInfo + "\n");
48 return Closure.RESULT_OK;
49};
50
51var UpcallInfo = function UpcallInfo(ndn, interest, matchedComps, contentObject) {
52 this.ndn = ndn; // NDN object (not used)
53 this.interest = interest; // Interest object
54 this.matchedComps = matchedComps; // int
55 this.contentObject = contentObject; // Content object
56};
57
58UpcallInfo.prototype.toString = function() {
59 var ret = "ndn = " + this.ndn;
60 ret += "\nInterest = " + this.interest;
61 ret += "\nmatchedComps = " + this.matchedComps;
62 ret += "\nContentObject: " + this.contentObject;
63 return ret;
64}