summaryrefslogtreecommitdiff
path: root/indra/newview
diff options
context:
space:
mode:
authorWilliam Todd Stinson <stinson@lindenlab.com>2012-12-18 23:07:27 -0800
committerWilliam Todd Stinson <stinson@lindenlab.com>2012-12-18 23:07:27 -0800
commit6b9ead91459d702727b54ab7e51614c2d5959f5f (patch)
treea58442e1412a466972a5e890ecd522540156e7f2 /indra/newview
parentda59ef8013801eac3695cea0ae8c1097275b6832 (diff)
CHUI-499: Refactoring the LLPersistentNotificationStorage implementation for shared usage with the new LLDoNotDisturbNotificationStorage class.
Diffstat (limited to 'indra/newview')
-rw-r--r--indra/newview/llnotificationstorage.cpp69
-rw-r--r--indra/newview/llnotificationstorage.h3
-rw-r--r--indra/newview/llpersistentnotificationstorage.cpp67
3 files changed, 73 insertions, 66 deletions
diff --git a/indra/newview/llnotificationstorage.cpp b/indra/newview/llnotificationstorage.cpp
index d25a212059..4746e4bbd4 100644
--- a/indra/newview/llnotificationstorage.cpp
+++ b/indra/newview/llnotificationstorage.cpp
@@ -29,14 +29,39 @@
#include "llnotificationstorage.h"
#include <string>
+#include <map>
#include "llerror.h"
#include "llfile.h"
+#include "llnotifications.h"
#include "llpointer.h"
#include "llsd.h"
#include "llsdserialize.h"
+#include "llsingleton.h"
+#include "llviewermessage.h"
+class LLResponderRegistry : public LLSingleton<LLResponderRegistry>
+{
+public:
+ LLResponderRegistry();
+ ~LLResponderRegistry();
+
+ LLNotificationResponderInterface* createResponder(const std::string& pNotificationName, const LLSD& pParams);
+
+protected:
+
+private:
+ template<typename RESPONDER_TYPE> static LLNotificationResponderInterface* create(const LLSD& pParams);
+
+ typedef boost::function<LLNotificationResponderInterface* (const LLSD& params)> responder_constructor_t;
+
+ void add(const std::string& pNotificationName, const responder_constructor_t& pConstructor);
+
+ typedef std::map<std::string, responder_constructor_t> build_map_t;
+ build_map_t mBuildMap;
+};
+
LLNotificationStorage::LLNotificationStorage(std::string pFileName)
: mFileName(pFileName)
{
@@ -90,3 +115,47 @@ bool LLNotificationStorage::readNotifications(LLSD& pNotificationData) const
return didFileRead;
}
+
+LLNotificationResponderInterface* LLNotificationStorage::createResponder(const std::string& pNotificationName, const LLSD& pParams) const
+{
+ return LLResponderRegistry::getInstance()->createResponder(pNotificationName, pParams);
+}
+
+LLResponderRegistry::LLResponderRegistry()
+ : LLSingleton<LLResponderRegistry>()
+ , mBuildMap()
+{
+ add("ObjectGiveItem", &create<LLOfferInfo>);
+ add("UserGiveItem", &create<LLOfferInfo>);
+}
+
+LLResponderRegistry::~LLResponderRegistry()
+{
+}
+
+LLNotificationResponderInterface* LLResponderRegistry::createResponder(const std::string& pNotificationName, const LLSD& pParams)
+{
+ build_map_t::const_iterator it = mBuildMap.find(pNotificationName);
+ if(mBuildMap.end() == it)
+ {
+ return NULL;
+ }
+ responder_constructor_t ctr = it->second;
+ return ctr(pParams);
+}
+
+template<typename RESPONDER_TYPE> LLNotificationResponderInterface* LLResponderRegistry::create(const LLSD& pParams)
+{
+ RESPONDER_TYPE* responder = new RESPONDER_TYPE();
+ responder->fromLLSD(pParams);
+ return responder;
+}
+
+void LLResponderRegistry::add(const std::string& pNotificationName, const responder_constructor_t& pConstructor)
+{
+ if (mBuildMap.find(pNotificationName) != mBuildMap.end())
+ {
+ LL_ERRS("LLResponderRegistry") << "Responder is already registered : " << pNotificationName << LL_ENDL;
+ }
+ mBuildMap.insert(std::make_pair<std::string, responder_constructor_t>(pNotificationName, pConstructor));
+}
diff --git a/indra/newview/llnotificationstorage.h b/indra/newview/llnotificationstorage.h
index ab4da4e73f..7aabf7d09e 100644
--- a/indra/newview/llnotificationstorage.h
+++ b/indra/newview/llnotificationstorage.h
@@ -31,6 +31,7 @@
#include "llerror.h"
+class LLNotificationResponderInterface;
class LLSD;
class LLNotificationStorage
@@ -44,6 +45,8 @@ protected:
bool writeNotifications(const LLSD& pNotificationData) const;
bool readNotifications(LLSD& pNotificationData) const;
+ LLNotificationResponderInterface* createResponder(const std::string& pNotificationName, const LLSD& pParams) const;
+
private:
std::string mFileName;
};
diff --git a/indra/newview/llpersistentnotificationstorage.cpp b/indra/newview/llpersistentnotificationstorage.cpp
index 7aaad64fd7..224aaa2146 100644
--- a/indra/newview/llpersistentnotificationstorage.cpp
+++ b/indra/newview/llpersistentnotificationstorage.cpp
@@ -36,34 +36,6 @@
#include "llscriptfloater.h"
#include "llviewermessage.h"
-class LLResponderRegistry
-{
-public:
-
- static void registerResponders();
-
- static LLNotificationResponderInterface* createResponder(const std::string& notification_name, const LLSD& params);
-
-protected:
-
-private:
- template<typename RESPONDER_TYPE>
- static LLNotificationResponderInterface* create(const LLSD& params)
- {
- RESPONDER_TYPE* responder = new RESPONDER_TYPE();
- responder->fromLLSD(params);
- return responder;
- }
-
- typedef boost::function<LLNotificationResponderInterface* (const LLSD& params)> responder_constructor_t;
-
- static void add(const std::string& notification_name, const responder_constructor_t& ctr);
-
- typedef std::map<std::string, responder_constructor_t> build_map_t;
-
- static build_map_t sBuildMap;
-};
-
LLPersistentNotificationStorage::LLPersistentNotificationStorage()
: LLSingleton<LLPersistentNotificationStorage>()
, LLNotificationStorage(gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, "open_notifications.xml"))
@@ -114,7 +86,6 @@ static LLFastTimer::DeclareTimer FTM_LOAD_NOTIFICATIONS("Load Notifications");
void LLPersistentNotificationStorage::loadNotifications()
{
LLFastTimer _(FTM_LOAD_NOTIFICATIONS);
- LLResponderRegistry::registerResponders();
LLNotifications::instance().getChannel("Persistent")->
connectChanged(boost::bind(&LLPersistentNotificationStorage::onPersistentChannelChanged, this, _1));
@@ -144,8 +115,7 @@ void LLPersistentNotificationStorage::loadNotifications()
LLSD notification_params = *notification_it;
LLNotificationPtr notification(new LLNotification(notification_params));
- LLNotificationResponderPtr responder(LLResponderRegistry::
- createResponder(notification_params["name"], notification_params["responder"]));
+ LLNotificationResponderPtr responder(createResponder(notification_params["name"], notification_params["responder"]));
notification->setResponseFunctor(responder);
instance.add(notification);
@@ -172,39 +142,4 @@ bool LLPersistentNotificationStorage::onPersistentChannelChanged(const LLSD& pay
return false;
}
-//////////////////////////////////////////////////////////////////////////
-//////////////////////////////////////////////////////////////////////////
-//////////////////////////////////////////////////////////////////////////
-
-LLResponderRegistry::build_map_t LLResponderRegistry::sBuildMap;
-
-void LLResponderRegistry::registerResponders()
-{
- sBuildMap.clear();
-
- add("ObjectGiveItem", &create<LLOfferInfo>);
- add("UserGiveItem", &create<LLOfferInfo>);
-}
-
-LLNotificationResponderInterface* LLResponderRegistry::createResponder(const std::string& notification_name, const LLSD& params)
-{
- build_map_t::const_iterator it = sBuildMap.find(notification_name);
- if(sBuildMap.end() == it)
- {
- return NULL;
- }
- responder_constructor_t ctr = it->second;
- return ctr(params);
-}
-
-void LLResponderRegistry::add(const std::string& notification_name, const responder_constructor_t& ctr)
-{
- if(sBuildMap.find(notification_name) != sBuildMap.end())
- {
- llwarns << "Responder is already registered : " << notification_name << llendl;
- llassert(!"Responder already registered");
- }
- sBuildMap[notification_name] = ctr;
-}
-
// EOF