Jeff Thompson | 3441976 | 2012-10-15 22:24:12 -0700 | [diff] [blame^] | 1 | /* |
| 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 | */ |
| 13 | var 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 |
| 24 | Closure.RESULT_ERR = -1; // upcall detected an error |
| 25 | Closure.RESULT_OK = 0; // normal upcall return |
| 26 | Closure.RESULT_REEXPRESS = 1; // reexpress the same interest again |
| 27 | Closure.RESULT_INTEREST_CONSUMED = 2; // upcall claims to consume interest |
| 28 | Closure.RESULT_VERIFY = 3; // force an unverified result to be verified |
| 29 | |
| 30 | // Upcall kind |
| 31 | Closure.UPCALL_FINAL = 0; // handler is about to be deregistered |
| 32 | Closure.UPCALL_INTEREST = 1; // incoming interest |
| 33 | Closure.UPCALL_CONSUMED_INTEREST = 2; // incoming interest, someone has answered |
| 34 | Closure.UPCALL_CONTENT = 3; // incoming verified content |
| 35 | Closure.UPCALL_INTEREST_TIMED_OUT = 4; // interest timed out |
| 36 | Closure.UPCALL_CONTENT_UNVERIFIED = 5; // content that has not been verified |
| 37 | Closure.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 | */ |
| 44 | Closure.prototype.upcall = function(kind, upcallInfo) { |
| 45 | //dump('upcall ' + this + " " + kind + " " + upcallInfo + "\n"); |
| 46 | return Closure.RESULT_OK; |
| 47 | }; |
| 48 | |
| 49 | var 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 | |
| 56 | UpcallInfo.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 | } |