lluseroperation.cpp

Go to the documentation of this file.
00001 
00032 #include "linden_common.h"
00033 
00034 #include "lluseroperation.h"
00035 
00039 
00040 LLUserOperationMgr* gUserOperationMgr = NULL;
00041 
00045 
00046 LLUserOperation::LLUserOperation(const LLUUID& agent_id)
00047 :       mAgentID(agent_id),
00048         mTimer(),
00049         mNoExpire(FALSE)
00050 {
00051         mTransactionID.generate();
00052 }
00053 
00054 LLUserOperation::LLUserOperation(const LLUUID& agent_id,
00055                                                                  const LLUUID& transaction_id) :
00056         mAgentID(agent_id),
00057         mTransactionID(transaction_id),
00058         mTimer(),
00059         mNoExpire(FALSE)
00060 {
00061 }
00062 
00063 // protected constructor which is used by base classes that determine
00064 // transaction, agent, et. after construction.
00065 LLUserOperation::LLUserOperation() :
00066         mTimer(),
00067         mNoExpire(FALSE)
00068 {
00069 }
00070 
00071 LLUserOperation::~LLUserOperation()
00072 {
00073 }
00074 
00075 void LLUserOperation::SetNoExpireFlag(const BOOL flag)
00076 {
00077         mNoExpire = flag;
00078 }
00079 
00080 BOOL LLUserOperation::isExpired()
00081 {
00082         if (!mNoExpire)
00083         {
00084                 const F32 EXPIRE_TIME_SECS = 10.f;
00085                 return mTimer.getElapsedTimeF32() > EXPIRE_TIME_SECS;
00086         }
00087         return FALSE;
00088 }
00089 
00090 void LLUserOperation::expire()
00091 {
00092         // by default, do do anything.
00093 }
00094 
00098 
00099 LLUserOperationMgr::LLUserOperationMgr()
00100 {
00101 }
00102 
00103 
00104 LLUserOperationMgr::~LLUserOperationMgr()
00105 {
00106         if (mUserOperationList.size() > 0)
00107         {
00108                 llwarns << "Exiting with user operations pending." << llendl;
00109         }
00110 }
00111 
00112 
00113 void LLUserOperationMgr::addOperation(LLUserOperation* op)
00114 {
00115         if(!op)
00116         {
00117                 llwarns << "Tried to add null op" << llendl;
00118                 return;
00119         }
00120         LLUUID id = op->getTransactionID();
00121         llassert(mUserOperationList.count(id) == 0);
00122         mUserOperationList[id] = op;
00123 }
00124 
00125 
00126 LLUserOperation* LLUserOperationMgr::findOperation(const LLUUID& tid)
00127 {
00128         user_operation_list_t::iterator iter = mUserOperationList.find(tid);
00129         if (iter != mUserOperationList.end())
00130                 return iter->second;
00131         else
00132                 return NULL;
00133 }
00134 
00135 
00136 BOOL LLUserOperationMgr::deleteOperation(LLUserOperation* op)
00137 {
00138         size_t rv = 0;
00139         if(op)
00140         {
00141                 LLUUID id = op->getTransactionID();
00142                 rv = mUserOperationList.erase(id);
00143                 delete op;
00144                 op = NULL;
00145         }
00146         return rv ? TRUE : FALSE;
00147 }
00148 
00149 void LLUserOperationMgr::deleteExpiredOperations()
00150 {
00151         const S32 MAX_OPS_CONSIDERED = 2000;
00152         S32 ops_left = MAX_OPS_CONSIDERED;
00153         LLUserOperation* op = NULL;
00154         user_operation_list_t::iterator it;
00155         if(mLastOperationConsidered.isNull())
00156         {
00157                 it = mUserOperationList.begin();
00158         }
00159         else
00160         {
00161                 it = mUserOperationList.lower_bound(mLastOperationConsidered);
00162         }
00163         while((ops_left--) && (it != mUserOperationList.end()))
00164         {
00165                 op = (*it).second;
00166                 if(op && op->isExpired())
00167                 {
00168                         lldebugs << "expiring: " << (*it).first << llendl;
00169                         op->expire();
00170                         mUserOperationList.erase(it++);
00171                         delete op;
00172                 }
00173                 else if(op)
00174                 {
00175                         ++it;
00176                 }
00177                 else
00178                 {
00179                         mUserOperationList.erase(it++);
00180                 }
00181         }
00182         if(it != mUserOperationList.end())
00183         {
00184                 mLastOperationConsidered = (*it).first;
00185         }
00186         else
00187         {
00188                 mLastOperationConsidered.setNull();
00189         }
00190 }
00191 
00192 

Generated on Thu Jul 1 06:09:24 2010 for Second Life Viewer by  doxygen 1.4.7