Tiny bit of lleventnotifier cleanup. Only functional difference is that server is notified when an event notification response is handled... also the notifier is deleted (leakfix? I can't find where it was deleted on this case before this new change)..

This commit is contained in:
Shyotl
2011-09-03 06:05:23 -05:00
parent f36e1d23ea
commit 39b8abc4cf
3 changed files with 54 additions and 57 deletions

View File

@@ -78,24 +78,42 @@ void LLEventNotifier::update()
{
LLEventNotification *np = iter->second;
iter++;
if (np->getEventDate() < (alert_time))
{
LLSD args;
args["NAME"] = np->getEventName();
args["DATE"] = np->getEventDateStr();
LLNotifications::instance().add("EventNotification", args, LLSD(),
boost::bind(&LLEventNotification::handleResponse, np, _1, _2));
mEventNotifications.erase(iter++);
}
else
{
iter++;
boost::bind(&LLEventNotifier::handleResponse, this, np->getEventID(), np->getEventPosGlobal(), _1, _2));
remove(np->getEventID());
}
}
mNotificationTimer.reset();
}
}
bool LLEventNotifier::handleResponse(U32 eventId, LLVector3d eventPos, const LLSD& notification, const LLSD& response)
{
S32 option = LLNotification::getSelectedOption(notification, response);
switch (option)
{
case 0:
gAgent.teleportViaLocation(eventPos);
gFloaterWorldMap->trackLocation(eventPos);
break;
case 1:
gDisplayEventHack = TRUE;
LLFloaterDirectory::showEvents(eventId);
break;
case 2:
break;
}
// We could clean up the notification on the server now if we really wanted to.
return true;
}
void LLEventNotifier::load(const LLUserAuth::options_t& event_options)
{
LLUserAuth::options_t::const_iterator resp_it;
@@ -117,6 +135,19 @@ void LLEventNotifier::load(const LLUserAuth::options_t& event_options)
}
}
void LLEventNotifier::add(U32 eventId)
{
gMessageSystem->newMessageFast(_PREHASH_EventInfoRequest);
gMessageSystem->nextBlockFast(_PREHASH_AgentData);
gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID() );
gMessageSystem->nextBlockFast(_PREHASH_EventData);
gMessageSystem->addU32Fast(_PREHASH_EventID, eventId);
gAgent.sendReliableMessage();
}
BOOL LLEventNotifier::hasNotification(const U32 event_id)
{
if (mEventNotifications.find(event_id) != mEventNotifications.end())
@@ -137,14 +168,7 @@ void LLEventNotifier::add(LLEventInfo &event_info)
return;
}
// Push up a message to tell the server we have this notification.
gMessageSystem->newMessage("EventNotificationAddRequest");
gMessageSystem->nextBlockFast(_PREHASH_AgentData);
gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
gMessageSystem->nextBlock("EventData");
gMessageSystem->addU32("EventID", event_info.mID);
gAgent.sendReliableMessage();
serverPushRequest(event_info.mID, true);
LLEventNotification *enp = new LLEventNotification;
enp->load(event_info);
@@ -161,17 +185,22 @@ void LLEventNotifier::remove(const U32 event_id)
return;
}
// Push up a message to tell the server to remove this notification.
gMessageSystem->newMessage("EventNotificationRemoveRequest");
serverPushRequest(event_id, false);
delete iter->second;
mEventNotifications.erase(iter);
}
void LLEventNotifier::serverPushRequest(U32 event_id, bool add)
{
// Push up a message to tell the server we have this notification.
gMessageSystem->newMessage(add?"EventNotificationAddRequest":"EventNotificationRemoveRequest");
gMessageSystem->nextBlockFast(_PREHASH_AgentData);
gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
gMessageSystem->nextBlock("EventData");
gMessageSystem->addU32("EventID", event_id);
gAgent.sendReliableMessage();
delete iter->second;
mEventNotifications.erase(iter);
}
LLEventNotification::LLEventNotification() :
@@ -185,26 +214,6 @@ LLEventNotification::~LLEventNotification()
{
}
bool LLEventNotification::handleResponse(const LLSD& notification, const LLSD& response)
{
S32 option = LLNotification::getSelectedOption(notification, response);
switch (option)
{
case 0:
gAgent.teleportViaLocation(getEventPosGlobal());
gFloaterWorldMap->trackLocation(getEventPosGlobal());
break;
case 1:
gDisplayEventHack = TRUE;
LLFloaterDirectory::showEvents(getEventID());
break;
case 2:
break;
}
// We could clean up the notification on the server now if we really wanted to.
return false;
}
BOOL LLEventNotification::load(const LLUserAuth::response_t &response)
{

View File

@@ -39,6 +39,7 @@
class LLEventInfo;
class LLEventNotification;
class LLMessageSystem;
class LLEventNotifier
@@ -48,14 +49,17 @@ public:
virtual ~LLEventNotifier();
void update(); // Notify the user of the event if it's coming up
void add(LLEventInfo &event_info); // Add a new notification for an event
void add(U32 eventId);
void load(const LLUserAuth::options_t& event_options); // In the format that it comes in from LLUserAuth
void add(LLEventInfo &event_info); // Add a new notification for an event
void remove(U32 event_id);
BOOL hasNotification(const U32 event_id);
void serverPushRequest(U32 event_id, bool add);
typedef std::map<U32, LLEventNotification *> en_map;
bool handleResponse(U32 eventId, LLVector3d eventPos, const LLSD& notification, const LLSD& response);
protected:
en_map mEventNotifications;
@@ -78,7 +82,6 @@ public:
time_t getEventDate() const { return mEventDate; }
const std::string &getEventDateStr() const { return mEventDateStr; }
LLVector3d getEventPosGlobal() const { return mEventPosGlobal; }
bool handleResponse(const LLSD& notification, const LLSD& payload);
protected:
U32 mEventID; // EventID for this event
std::string mEventName;

View File

@@ -114,25 +114,10 @@ void LLPanelEvent::setEventID(const U32 event_id)
if (event_id != 0)
{
sendEventInfoRequest();
gEventNotifier.add(event_id);
}
}
void LLPanelEvent::sendEventInfoRequest()
{
LLMessageSystem *msg = gMessageSystem;
msg->newMessageFast(_PREHASH_EventInfoRequest);
msg->nextBlockFast(_PREHASH_AgentData);
msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID() );
msg->nextBlockFast(_PREHASH_EventData);
msg->addU32Fast(_PREHASH_EventID, mEventID);
gAgent.sendReliableMessage();
}
//static
void LLPanelEvent::processEventInfoReply(LLMessageSystem *msg, void **)
{