blob: ab20de1efdfa823eb18b67ec8dbab2c6c6e1acfa [file] [log] [blame]
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -07001 /*
2 * @author: ucla-cs
3 * This class represents Interest Objects
4 */
5
Meki Cherkaoui8f173612012-06-06 01:05:40 -07006var Interest = function Interest(_Name,_FaceInstance,_MinSuffixComponents,_MaxSuffixComponents,_PublisherID, _Exclude, _ChildSelector,_AnswerOriginKind,_Scope,_InterestLifetime,_Nonce){
7
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -07008 this.Name = _Name;
9 this.FaceInstance = _FaceInstance;
10 this.MaxSuffixComponents = _MaxSuffixComponents;
11 this.MinSuffixComponents = _MinSuffixComponents;
12
Meki Cherkaoui8f173612012-06-06 01:05:40 -070013 this.PublisherID = _PublisherID;
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070014 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
35Interest.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 Cherkaoui8f173612012-06-06 01:05:40 -070051 if (PublisherID.peek(decoder)) {
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070052 this.Publisher = new PublisherID();
53 this.Publisher.decode(decoder);
Meki Cherkaoui8f173612012-06-06 01:05:40 -070054 }
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070055
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
85Interest.prototype.encode = function(/*XMLEncoder*/ encoder){
Meki Cherkaoui8f173612012-06-06 01:05:40 -070086 //Could check if name is present
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -070087
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 Cherkaoui8f173612012-06-06 01:05:40 -0700100 if (null != this.PublisherID)
101 publisherID().encode(encoder);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700102
103 //TODO Encode Exclude
104
Meki Cherkaoui8f173612012-06-06 01:05:40 -0700105 if (null != this.Exclude)
106 exclude().encode(encoder);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700107
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 Cherkaoui8f173612012-06-06 01:05:40 -0700113 encoder.writeElement(CCNProtocolDTags.AnswerOriginKind, this.AnswerOriginKind);
Meki Cherkaoui88d59cd2012-05-14 07:34:58 -0700114
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