Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * @author: ucla-cs |
| 3 | * This class represents Interest Objects |
| 4 | */ |
| 5 | |
| 6 | var Interest = function Interest(_Name,_FaceInstance,_MinSuffixComponents,_MaxSuffixComponents,_PublisherPublicKeyDigest, _Exclude, _ChildSelector,_AnswerOriginKind,_Scope,_InterestLifetime,_Nonce){ |
Meki Cherkaoui | e37e9af | 2012-05-18 16:48:49 -0700 | [diff] [blame^] | 7 | |
| 8 | //Setting fields |
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 9 | this.Name = _Name; |
| 10 | this.FaceInstance = _FaceInstance; |
| 11 | this.MaxSuffixComponents = _MaxSuffixComponents; |
| 12 | this.MinSuffixComponents = _MinSuffixComponents; |
| 13 | |
| 14 | this.PublisherKeyDigest = _PublisherPublicKeyDigest; |
| 15 | this.Exclude = _Exclude; |
| 16 | this.ChildSelector = _ChildSelector; |
| 17 | this.AnswerOriginKind = _AnswerOriginKind; |
| 18 | this.Scope = _Scope; |
| 19 | this.InterestLifetime = null; // For now we don't have the ability to set an interest lifetime |
| 20 | this.Nonce = _Nonce; |
| 21 | |
| 22 | |
| 23 | this.RECURSIVE_POSTFIX = "*"; |
| 24 | |
| 25 | this.CHILD_SELECTOR_LEFT = 0; |
| 26 | this.CHILD_SELECTOR_RIGHT = 1; |
| 27 | this.ANSWER_CONTENT_STORE = 1; |
| 28 | this.ANSWER_GENERATED = 2; |
| 29 | this.ANSWER_STALE = 4; // Stale answer OK |
| 30 | this.MARK_STALE = 16; // Must have Scope 0. Michael calls this a "hack" |
| 31 | |
| 32 | this.DEFAULT_ANSWER_ORIGIN_KIND = this.ANSWER_CONTENT_STORE | this.ANSWER_GENERATED; |
| 33 | |
| 34 | }; |
| 35 | |
| 36 | Interest.prototype.decode = function(/*XMLDecoder*/ decoder) { |
| 37 | |
| 38 | decoder.readStartElement(CCNProtocolDTags.Interest); |
| 39 | |
| 40 | this.Name = new ContentName(); |
| 41 | this.Name.decode(decoder); |
| 42 | |
| 43 | if (decoder.peekStartElement(CCNProtocolDTags.MinSuffixComponents)) { |
| 44 | this.MinSuffixComponents = decoder.readIntegerElement(CCNProtocolDTags.MinSuffixComponents); |
| 45 | } |
| 46 | |
| 47 | if (decoder.peekStartElement(CCNProtocolDTags.MaxSuffixComponents)) { |
| 48 | this.MaxSuffixComponents = decoder.readIntegerElement(CCNProtocolDTags.MaxSuffixComponents); |
| 49 | } |
| 50 | |
| 51 | //TODO decode PublisherID |
| 52 | /*if (PublisherID.peek(decoder)) { |
| 53 | this.Publisher = new PublisherID(); |
| 54 | this.Publisher.decode(decoder); |
| 55 | }*/ |
| 56 | |
| 57 | if (decoder.peekStartElement(CCNProtocolDTags.Exclude)) { |
| 58 | this.Exclude = new Exclude(); |
| 59 | this.Exclude.decode(decoder); |
| 60 | } |
| 61 | |
| 62 | if (decoder.peekStartElement(CCNProtocolDTags.ChildSelector)) { |
| 63 | this.ChildSelector = decoder.readIntegerElement(CCNProtocolDTags.ChildSelector); |
| 64 | } |
| 65 | |
| 66 | if (decoder.peekStartElement(CCNProtocolDTags.AnswerOriginKind)) { |
| 67 | // call setter to handle defaulting |
| 68 | this.AnswerOriginKind = decoder.readIntegerElement(CCNProtocolDTags.AnswerOriginKind); |
| 69 | } |
| 70 | |
| 71 | if (decoder.peekStartElement(CCNProtocolDTags.Scope)) { |
| 72 | this.Scope = decoder.readIntegerElement(CCNProtocolDTags.Scope); |
| 73 | } |
| 74 | |
| 75 | if (decoder.peekStartElement(CCNProtocolDTags.InterestLifetime)) { |
| 76 | this.InterestLifetime = decoder.readBinaryElement(CCNProtocolDTags.InterestLifetime); |
| 77 | } |
| 78 | |
| 79 | if (decoder.peekStartElement(CCNProtocolDTags.Nonce)) { |
| 80 | this.Nonce = decoder.readBinaryElement(CCNProtocolDTags.Nonce); |
| 81 | } |
| 82 | |
| 83 | decoder.readEndElement(); |
| 84 | }; |
| 85 | |
| 86 | Interest.prototype.encode = function(/*XMLEncoder*/ encoder){ |
| 87 | /*if (!validate()) { |
| 88 | throw new ContentEncodingException("Cannot encode " + this.getClass().getName() + ": field values missing."); |
| 89 | }*/ |
| 90 | |
| 91 | encoder.writeStartElement(CCNProtocolDTags.Interest); |
| 92 | |
| 93 | this.Name.encode(encoder); |
| 94 | |
| 95 | if (null != this.MinSuffixComponents) |
| 96 | encoder.writeElement(CCNProtocolDTags.MinSuffixComponents, this.MinSuffixComponents); |
| 97 | |
| 98 | if (null != this.MaxSuffixComponents) |
| 99 | encoder.writeElement(CCNProtocolDTags.MaxSuffixComponents, this.MaxSuffixComponents); |
| 100 | |
| 101 | //TODO Encode PublisherID |
| 102 | |
| 103 | /*if (null != this.PublisherID) |
| 104 | publisherID().encode(encoder);*/ |
| 105 | |
| 106 | //TODO Encode Exclude |
| 107 | |
| 108 | //if (null != this.Exclude) |
| 109 | //exclude().encode(encoder); |
| 110 | |
| 111 | if (null != this.ChildSelector) |
| 112 | encoder.writeElement(CCNProtocolDTags.ChildSelector, this.ChildSelector); |
| 113 | |
| 114 | //TODO Encode OriginKind |
| 115 | if (this.DEFAULT_ANSWER_ORIGIN_KIND != this.AnswerOriginKind && this.AnswerOriginKind!=null) |
| 116 | //encoder.writeElement(CCNProtocolDTags.AnswerOriginKind, this.AnswerOriginKind); |
| 117 | |
| 118 | if (null != this.Scope) |
| 119 | encoder.writeElement(CCNProtocolDTags.Scope, this.Scope); |
| 120 | |
| 121 | if (null != this.Nonce) |
| 122 | encoder.writeElement(CCNProtocolDTags.Nonce, this.Nonce); |
| 123 | |
| 124 | encoder.writeEndElement(); |
| 125 | |
| 126 | }; |
| 127 | |