diff options
author | William Todd Stinson <stinson@lindenlab.com> | 2012-12-18 23:07:27 -0800 |
---|---|---|
committer | William Todd Stinson <stinson@lindenlab.com> | 2012-12-18 23:07:27 -0800 |
commit | 6b9ead91459d702727b54ab7e51614c2d5959f5f (patch) | |
tree | a58442e1412a466972a5e890ecd522540156e7f2 /indra/newview/llnotificationstorage.cpp | |
parent | da59ef8013801eac3695cea0ae8c1097275b6832 (diff) |
CHUI-499: Refactoring the LLPersistentNotificationStorage implementation for shared usage with the new LLDoNotDisturbNotificationStorage class.
Diffstat (limited to 'indra/newview/llnotificationstorage.cpp')
-rw-r--r-- | indra/newview/llnotificationstorage.cpp | 69 |
1 files changed, 69 insertions, 0 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)); +} |