blob: 909c3c8aac186b6b48f32dbe17c487987b6a921d [file] [log] [blame]
Jeff Thompson34419762012-10-15 22:24:12 -07001/*
2 * @author: ucla-cs
3 * 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
29
30// Upcall kind
31Closure.UPCALL_FINAL = 0; // handler is about to be deregistered
32Closure.UPCALL_INTEREST = 1; // incoming interest
33Closure.UPCALL_CONSUMED_INTEREST = 2; // incoming interest, someone has answered
34Closure.UPCALL_CONTENT = 3; // incoming verified content
35Closure.UPCALL_INTEREST_TIMED_OUT = 4; // interest timed out
36Closure.UPCALL_CONTENT_UNVERIFIED = 5; // content that has not been verified
37Closure.UPCALL_CONTENT_BAD = 6; // verification failed
38
39/*
40 * Override this in your subclass.
41 * If you're getting strange errors in upcall()
42 * check your code whether you're returning a value.
43 */
44Closure.prototype.upcall = function(kind, upcallInfo) {
45 //dump('upcall ' + this + " " + kind + " " + upcallInfo + "\n");
46 return Closure.RESULT_OK;
47};
48
49var UpcallInfo = function UpcallInfo(ndn, interest, matchedComps, contentObject) {
50 this.ndn = ndn; // NDN object (not used)
51 this.interest = interest; // Interest object
52 this.matchedComps = matchedComps; // int
53 this.contentObject = contentObject; // Content object
54};
55
56UpcallInfo.prototype.toString = function() {
57 var ret = "ndn = " + this.ndn;
58 ret += "\nInterest = " + this.interest;
59 ret += "\nmatchedComps = " + this.matchedComps;
60 ret += "\nContentObject: " + this.contentObject;
61 return ret;
62}