aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/lleventpoll.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:02 -0500
committerJacek Antonelli2008-08-15 23:45:02 -0500
commitd644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd (patch)
tree7ed0c2c27d717801238a2e6b5749cd5bf88c3059 /linden/indra/newview/lleventpoll.cpp
parentSecond Life viewer sources 1.17.3.0 (diff)
downloadmeta-impy-d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd.zip
meta-impy-d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd.tar.gz
meta-impy-d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd.tar.bz2
meta-impy-d644fc64407dcd14ffcee6a0e9fbe28ee3a4e9bd.tar.xz
Second Life viewer sources 1.18.0.6
Diffstat (limited to 'linden/indra/newview/lleventpoll.cpp')
-rw-r--r--linden/indra/newview/lleventpoll.cpp261
1 files changed, 134 insertions, 127 deletions
diff --git a/linden/indra/newview/lleventpoll.cpp b/linden/indra/newview/lleventpoll.cpp
index dd59a06..755c622 100644
--- a/linden/indra/newview/lleventpoll.cpp
+++ b/linden/indra/newview/lleventpoll.cpp
@@ -36,155 +36,162 @@
36#include "llviewerregion.h" 36#include "llviewerregion.h"
37#include "message.h" 37#include "message.h"
38 38
39class LLEventPoll::Impl : LLHTTPClient::Responder 39namespace
40{ 40{
41public: 41 class LLEventPollResponder : public LLHTTPClient::Responder
42 static Impl& start(const std::string& pollURL); 42 {
43 void stop(); 43 public:
44 44
45private: 45 static LLHTTPClient::ResponderPtr start(const std::string& pollURL, const LLHost& sender);
46 Impl(const std::string& pollURL); 46 void stop();
47 ~Impl(); 47
48 48 private:
49 void makeRequest(); 49 LLEventPollResponder(const std::string& pollURL, const LLHost& sender);
50 void handleMessage(const LLSD& content); 50 ~LLEventPollResponder();
51 virtual void error(U32 status, const std::string& reason); 51
52 virtual void result(const LLSD& content); 52 void makeRequest();
53 53 void handleMessage(const LLSD& content);
54private: 54 virtual void error(U32 status, const std::string& reason);
55 typedef LLHTTPClient::ResponderPtr Ptr; 55 virtual void result(const LLSD& content);
56 56
57 Ptr mPtr; 57 private:
58 bool mDone; 58
59 59 bool mDone;
60 std::string mPollURL; 60
61 std::string mSender; 61 std::string mPollURL;
62 62 std::string mSender;
63 LLSD mAcknowledge; 63
64 64 LLSD mAcknowledge;
65 // these are only here for debugging so we can see which poller is which 65
66 static int sCount; 66 // these are only here for debugging so we can see which poller is which
67 int mCount; 67 static int sCount;
68}; 68 int mCount;
69 69 };
70//static 70
71LLEventPoll::Impl& LLEventPoll::Impl::start( 71 //static
72 const std::string& pollURL) 72 LLHTTPClient::ResponderPtr LLEventPollResponder::start(
73{ 73 const std::string& pollURL, const LLHost& sender)
74 Impl* i = new Impl(pollURL);
75 llinfos << "LLEventPoll::Impl::start <" << i->mCount << "> "
76 << pollURL << llendl;
77 return *i;
78}
79
80void LLEventPoll::Impl::stop()
81{
82 lldebugs << "LLEventPoll::Impl::stop <" << mCount << "> "
83 << mPollURL << llendl;
84 // there should be a way to stop a LLHTTPClient request in progress
85 mDone = true;
86 mPtr = NULL;
87}
88
89int LLEventPoll::Impl::sCount = 0;
90
91LLEventPoll::Impl::Impl(const std::string& pollURL)
92 : mPtr(NULL), mDone(false),
93 mPollURL(pollURL),
94 mCount(++sCount)
95{
96 mPtr = this;
97 //extract host and port of simulator to set as sender
98 LLViewerRegion *regionp = gAgent.getRegion();
99 if (!regionp)
100 { 74 {
101 llerrs << "LLEventPoll initialized before region is added." << llendl; 75 LLHTTPClient::ResponderPtr result = new LLEventPollResponder(pollURL, sender);
76 llinfos << "LLEventPollResponder::start <" << sCount << "> "
77 << pollURL << llendl;
78 return result;
102 } 79 }
103 mSender = regionp->getHost().getIPandPort();
104 llinfos << "LLEventPoll initialized with sender " << mSender << llendl;
105 makeRequest();
106}
107 80
108LLEventPoll::Impl::~Impl() 81 void LLEventPollResponder::stop()
109{ 82 {
110 lldebugs << "LLEventPoll::Impl::~Impl <" << mCount << "> " 83 llinfos << "LLEventPollResponder::stop <" << mCount << "> "
111 << mPollURL << llendl; 84 << mPollURL << llendl;
112} 85 // there should be a way to stop a LLHTTPClient request in progress
113 86 mDone = true;
114void LLEventPoll::Impl::makeRequest() 87 }
115{
116 LLSD request;
117 request["ack"] = mAcknowledge;
118 request["done"] = mDone;
119
120 lldebugs << "LLEventPoll::Impl::makeRequest <" << mCount << "> ack = "
121 << LLSDXMLStreamer(mAcknowledge) << llendl;
122 LLHTTPClient::post(mPollURL, request, mPtr);
123}
124 88
125void LLEventPoll::Impl::handleMessage(const LLSD& content) 89 int LLEventPollResponder::sCount = 0;
126{
127 std::string msg_name = content["message"];
128 LLSD message;
129 message["sender"] = mSender;
130 message["body"] = content["body"];
131 LLMessageSystem::dispatch(msg_name, message);
132}
133 90
134//virtual 91 LLEventPollResponder::LLEventPollResponder(const std::string& pollURL, const LLHost& sender)
135void LLEventPoll::Impl::error(U32 status, const std::string& reason) 92 : mDone(false),
136{ 93 mPollURL(pollURL),
137 if (mDone) return; 94 mCount(++sCount)
95 {
96 //extract host and port of simulator to set as sender
97 LLViewerRegion *regionp = gAgent.getRegion();
98 if (!regionp)
99 {
100 llerrs << "LLEventPoll initialized before region is added." << llendl;
101 }
102 mSender = sender.getIPandPort();
103 llinfos << "LLEventPoll initialized with sender " << mSender << llendl;
104 makeRequest();
105 }
138 106
139 if(status != 499) 107 LLEventPollResponder::~LLEventPollResponder()
140 { 108 {
141 llwarns << "LLEventPoll::Impl::error: <" << mCount << "> got "
142 << status << ": " << reason
143 << (mDone ? " -- done" : "") << llendl;
144 stop(); 109 stop();
145 return; 110 lldebugs << "LLEventPollResponder::~Impl <" << mCount << "> "
111 << mPollURL << llendl;
146 } 112 }
147 113
148 makeRequest(); 114 void LLEventPollResponder::makeRequest()
149} 115 {
116 LLSD request;
117 request["ack"] = mAcknowledge;
118 request["done"] = mDone;
119
120 lldebugs << "LLEventPollResponder::makeRequest <" << mCount << "> ack = "
121 << LLSDXMLStreamer(mAcknowledge) << llendl;
122 LLHTTPClient::post(mPollURL, request, this);
123 }
150 124
151//virtual 125 void LLEventPollResponder::handleMessage(const LLSD& content)
152void LLEventPoll::Impl::result(const LLSD& content)
153{
154 lldebugs << "LLEventPoll::Impl::result <" << mCount << ">"
155 << (mDone ? " -- done" : "") << llendl;
156
157 if (mDone) return;
158
159 mAcknowledge = content["id"];
160 LLSD events = content["events"];
161
162 if(mAcknowledge.isUndefined())
163 { 126 {
164 llwarns << "LLEventPoll::Impl: id undefined" << llendl; 127 std::string msg_name = content["message"];
128 LLSD message;
129 message["sender"] = mSender;
130 message["body"] = content["body"];
131 LLMessageSystem::dispatch(msg_name, message);
165 } 132 }
166 133
167 llinfos << "LLEventPoll::Impl::completed <" << mCount << "> " << events.size() << "events (id " 134 //virtual
168 << LLSDXMLStreamer(mAcknowledge) << ")" << llendl; 135 void LLEventPollResponder::error(U32 status, const std::string& reason)
169
170 LLSD::array_const_iterator i = events.beginArray();
171 LLSD::array_const_iterator end = events.endArray();
172 for (; i != end; ++i)
173 { 136 {
174 if (i->has("message")) 137 if (mDone) return;
138
139 if(status != 499)
175 { 140 {
176 handleMessage(*i); 141 llwarns << "LLEventPollResponder::error: <" << mCount << "> got "
142 << status << ": " << reason
143 << (mDone ? " -- done" : "") << llendl;
144 stop();
145 return;
177 } 146 }
147
148 makeRequest();
178 } 149 }
179 150
180 makeRequest(); 151 //virtual
152 void LLEventPollResponder::result(const LLSD& content)
153 {
154 lldebugs << "LLEventPollResponder::result <" << mCount << ">"
155 << (mDone ? " -- done" : "") << llendl;
156
157 if (mDone) return;
158
159 if (!content.get("events") ||
160 !content.get("id"))
161 {
162 llwarns << "received event poll with no events or id key" << llendl;
163 return;
164 }
165
166 mAcknowledge = content["id"];
167 LLSD events = content["events"];
168
169 if(mAcknowledge.isUndefined())
170 {
171 llwarns << "LLEventPollResponder: id undefined" << llendl;
172 }
173
174 llinfos << "LLEventPollResponder::completed <" << mCount << "> " << events.size() << "events (id "
175 << LLSDXMLStreamer(mAcknowledge) << ")" << llendl;
176
177 LLSD::array_const_iterator i = events.beginArray();
178 LLSD::array_const_iterator end = events.endArray();
179 for (; i != end; ++i)
180 {
181 if (i->has("message"))
182 {
183 handleMessage(*i);
184 }
185 }
186
187 makeRequest();
188 }
181} 189}
182 190
183LLEventPoll::LLEventPoll(const std::string& pollURL) 191LLEventPoll::LLEventPoll(const std::string& pollURL, const LLHost& sender)
184 : impl(Impl::start(pollURL)) 192 : mImpl(LLEventPollResponder::start(pollURL, sender))
185 { } 193 { }
186 194
187LLEventPoll::~LLEventPoll() 195LLEventPoll::~LLEventPoll()
188{ 196{
189 impl.stop();
190} 197}