00001
00032 #include "linden_common.h"
00033
00034 #include "llhash.h"
00035
00036 #include "llmessagethrottle.h"
00037 #include "llframetimer.h"
00038
00039
00040 bool eq_message_throttle_entry(LLMessageThrottleEntry a, LLMessageThrottleEntry b)
00041 { return a.getHash() == b.getHash(); }
00042
00043 const U64 SEC_TO_USEC = 1000000;
00044
00045
00046 const U64 MAX_MESSAGE_AGE[MTC_EOF] =
00047 {
00048 10 * SEC_TO_USEC,
00049 10 * SEC_TO_USEC
00050 };
00051
00052 LLMessageThrottle::LLMessageThrottle()
00053 {
00054 }
00055
00056 LLMessageThrottle::~LLMessageThrottle()
00057 {
00058 }
00059
00060 void LLMessageThrottle::pruneEntries()
00061 {
00062
00063 S32 cat;
00064 for (cat = 0; cat < MTC_EOF; cat++)
00065 {
00066 message_list_t* message_list = &(mMessageList[cat]);
00067
00068
00069 message_list_reverse_iterator_t r_iterator = message_list->rbegin();
00070 message_list_reverse_iterator_t r_last = message_list->rend();
00071
00072
00073 F32 max_age = (F32)MAX_MESSAGE_AGE[cat];
00074 BOOL found = FALSE;
00075 while (r_iterator != r_last && !found)
00076 {
00077 if ( LLFrameTimer::getTotalTime() - (*r_iterator).getEntryTime() < max_age )
00078 {
00079
00080 found = TRUE;
00081
00082
00083 if (r_iterator != message_list->rbegin())
00084 {
00085
00086 message_list->erase(r_iterator.base(), message_list->end());
00087 }
00088 }
00089 else
00090 {
00091 r_iterator++;
00092 }
00093 }
00094
00095
00096 if (!found)
00097 {
00098 message_list->clear();
00099 }
00100 }
00101 }
00102
00103 BOOL LLMessageThrottle::addViewerAlert(const LLUUID& to, const char* mesg)
00104 {
00105 message_list_t* message_list = &(mMessageList[MTC_VIEWER_ALERT]);
00106
00107
00108 std::ostringstream full_mesg;
00109 full_mesg << to << mesg;
00110
00111
00112 size_t hash = llhash<const char*> (full_mesg.str().c_str());
00113 LLMessageThrottleEntry entry(hash, LLFrameTimer::getTotalTime());
00114
00115
00116 message_list_iterator_t found = std::search_n(message_list->begin(), message_list->end(),
00117 1, entry, eq_message_throttle_entry);
00118
00119 if (found == message_list->end())
00120 {
00121
00122 message_list->push_front(entry);
00123 return TRUE;
00124 }
00125 else
00126 {
00127
00128 return FALSE;
00129 }
00130 }
00131
00132 BOOL LLMessageThrottle::addAgentAlert(const LLUUID& agent, const LLUUID& task, const char* mesg)
00133 {
00134 message_list_t* message_list = &(mMessageList[MTC_AGENT_ALERT]);
00135
00136
00137 std::ostringstream full_mesg;
00138 full_mesg << agent << task << mesg;
00139
00140
00141 size_t hash = llhash<const char*> (full_mesg.str().c_str());
00142 LLMessageThrottleEntry entry(hash, LLFrameTimer::getTotalTime());
00143
00144
00145 message_list_iterator_t found = std::search_n(message_list->begin(), message_list->end(),
00146 1, entry, eq_message_throttle_entry);
00147
00148 if (found == message_list->end())
00149 {
00150
00151 message_list->push_front(entry);
00152 return TRUE;
00153 }
00154 else
00155 {
00156
00157 return FALSE;
00158 }
00159 }
00160