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