Open-Transactions  0.93.0-ge03d287
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
opentxs::OTMessageBuffer Class Reference

#include <OTMessageBuffer.hpp>

Public Member Functions

 OTMessageBuffer ()
 
EXPORT ~OTMessageBuffer ()
 
EXPORT void Clear ()
 
EXPORT void Push (OTMessage &message)
 
EXPORT OTMessagePop (const int64_t &requestNum, const OTString &serverId, const OTString &nymId)
 

Detailed Description

Definition at line 144 of file OTMessageBuffer.hpp.

Constructor & Destructor Documentation

opentxs::OTMessageBuffer::OTMessageBuffer ( )
inline

Definition at line 147 of file OTMessageBuffer.hpp.

148  {
149  }
opentxs::OTMessageBuffer::~OTMessageBuffer ( )

Definition at line 251 of file OTMessageBuffer.cpp.

252 {
253  Clear();
254 }

Member Function Documentation

void opentxs::OTMessageBuffer::Clear ( )

Definition at line 256 of file OTMessageBuffer.cpp.

257 {
258  while (!messages_.empty()) {
259  OTMessage* pMsg = messages_.front();
260  messages_.pop_front();
261 
262  if (nullptr != pMsg) delete pMsg;
263  pMsg = nullptr;
264  }
265 }
OTMessage * opentxs::OTMessageBuffer::Pop ( const int64_t &  requestNum,
const OTString serverId,
const OTString nymId 
)

Definition at line 174 of file OTMessageBuffer.cpp.

177 {
178  OTMessage* pReturnValue = nullptr;
179 
180  Messages temp_list;
181 
182  while (!messages_.empty()) {
183 
184  OTMessage* pMsg = messages_.front();
185 
186  messages_.pop_front();
187 
188  if (nullptr == pMsg) {
189  otErr << "OTMessageBuffer::Pop: Error: List of incoming server "
190  "replies "
191  "is NOT empty, yet when Pop was called, pMsg was nullptr! "
192  "(Skipping.)\n";
193  continue;
194  }
195 
196  // Below this point, pMsg has been popped, and it's NOT nullptr, and it
197  // will be lost if not tracked or returned.
198  //
199  if (!strServerID.Compare(pMsg->m_strServerID) ||
200  !strNymID.Compare(pMsg->m_strNymID)) {
201  temp_list.push_front(
202  pMsg); // Save it, so we can push it back again after this loop.
203  continue;
204  }
205  // Below this point, we KNOW that pMsg has the CORRECT ServerID and
206  // NymID.
207  // (And that all others, though popped, were pushed to temp_list in
208  // order.)
209 
210  const int64_t lMsgRequest = atol(pMsg->m_strRequestNum.Get());
211 
212  // Now we only need to see if the request number matches...
213  //
214  if (lMsgRequest == lRequestNum) {
215  pReturnValue = pMsg;
216  break;
217  }
218  else // Server/Nym IDs match, BUT -- Wrong request num! (Discard
219  // message and skip.)
220  {
221  otOut << "OTMessageBuffer::Pop: Warning: While looking for server ("
222  << strServerID << ") reply to request number " << lRequestNum
223  << " for Nym (" << strNymID
224  << "), "
225  "discovered (and discarded) an old server reply for "
226  "request number " << lMsgRequest << " "
227  "(A "
228  << pMsg->m_strCommand
229  << " command. The client should have flushed it by now "
230  "anyway, so it was probably slow on the network "
231  "and then assumed to have been dropped. It's okay--the "
232  "protocol is designed to handle these occurrences.)\n";
233  delete pMsg;
234  pMsg = nullptr;
235  continue;
236  }
237 
238  } // while
239 
240  // Put the other messages back, in order...
241  //
242  while (!temp_list.empty()) {
243  OTMessage* pMsg = temp_list.front();
244  temp_list.pop_front();
245  messages_.push_front(pMsg);
246  }
247 
248  return pReturnValue;
249 }
OTLOG_IMPORT OTLogStream otOut
OTLOG_IMPORT OTLogStream otErr
void opentxs::OTMessageBuffer::Push ( OTMessage message)

Definition at line 148 of file OTMessageBuffer.cpp.

149 {
150  messages_.push_back(&theMessage);
151 }

The documentation for this class was generated from the following files: