00001
00034 #include "linden_common.h"
00035 #include "lllogtextmessage.h"
00036
00037 #include "message.h"
00038
00039
00040 LLLogTextMessage::~LLLogTextMessage()
00041 {
00042 S32 queue_size = (S32)mQueue.size();
00043 if(queue_size > 0)
00044 {
00045 llwarns << "Deleting queus with messages still on it." << llendl;
00046 }
00047 }
00048
00049 void LLLogTextMessage::log(
00050 const LLUUID& from,
00051 const LLUUID& to,
00052 const char* mesg)
00053 {
00054 const F64 F64_ZERO = 0.0;
00055 log(from, to, F64_ZERO, F64_ZERO, mesg);
00056 }
00057
00058 void LLLogTextMessage::log(
00059 const LLUUID& from,
00060 F64 global_x,
00061 F64 global_y,
00062 const char* mesg)
00063 {
00064 log(from, LLUUID::null, global_x, global_y, mesg);
00065 }
00066
00067 void LLLogTextMessage::log(
00068 const LLUUID& from,
00069 const LLUUID& to,
00070 F64 global_x,
00071 F64 global_y,
00072 const char* mesg)
00073 {
00074 const S32 OVERHEAD = (2*sizeof(LLUUID))+(2*sizeof(F64))+(sizeof(S32));
00075 const U32 MAX_LOGS_PER_MSG = 100;
00076 const U32 LOG_MTU = 4000;
00077 LLLogTextMessageData data(from, to, global_x, global_y, mesg);
00078 mQueue.push_back(data);
00079 mPendingSize += (S32)(OVERHEAD + data.mMessage.size());
00080 if((mQueue.size() >= MAX_LOGS_PER_MSG) || (mPendingSize > (S32)LOG_MTU))
00081 {
00082 flush();
00083 }
00084 }
00085
00086 void LLLogTextMessage::flush()
00087 {
00088 mPendingSize = 0;
00089 if(mQueue.empty()) return;
00090 LLMessageSystem* msg = gMessageSystem;
00091 msg->newMessageFast(_PREHASH_LogTextMessage);
00092 while(!mQueue.empty())
00093 {
00094 LLLogTextMessageData data(mQueue.front());
00095 mQueue.pop_front();
00096 msg->nextBlockFast(_PREHASH_DataBlock);
00097 msg->addUUIDFast(_PREHASH_FromAgentId, data.mFromID);
00098 msg->addUUIDFast(_PREHASH_ToAgentId, data.mToID);
00099 msg->addF64Fast(_PREHASH_GlobalX, data.mGlobalX);
00100 msg->addF64Fast(_PREHASH_GlobalY, data.mGlobalY);
00101 msg->addU32Fast(_PREHASH_Time, data.mTime);
00102 msg->addStringFast(_PREHASH_Message, data.mMessage.c_str());
00103 }
00104
00105
00106 msg->sendReliable(mDataserver, 3, TRUE, 0.f, NULL, NULL);
00107 }
00108
00109 LLLogTextMessage::LLLogTextMessageData::LLLogTextMessageData(
00110 const LLUUID& from,
00111 const LLUUID& to,
00112 const F64& global_x,
00113 const F64& gloabl_y,
00114 const char* message) :
00115 mFromID(from),
00116 mToID(to),
00117 mGlobalX(global_x),
00118 mGlobalY(gloabl_y),
00119 mMessage(message)
00120 {
00121 mTime = (S32)time(NULL);
00122 }