summaryrefslogtreecommitdiff
path: root/indra/llmessage/llexperiencecache.h
diff options
context:
space:
mode:
authorGlenn Glazer <coyot@lindenlab.com>2016-04-07 12:10:13 -0700
committerGlenn Glazer <coyot@lindenlab.com>2016-04-07 12:10:13 -0700
commit369cefd5b3f2f52ae0dd203fcd45a4618f74b0f3 (patch)
tree941d27a32099abaf71bae8a2865002e2b25a3512 /indra/llmessage/llexperiencecache.h
parent0494a502aafac73800352dc26c4eb3a27b02a8ce (diff)
parent18928ea6c6f2830a0d45ec412c915eceff1b76b0 (diff)
pull from viewer-release
Diffstat (limited to 'indra/llmessage/llexperiencecache.h')
-rw-r--r--indra/llmessage/llexperiencecache.h188
1 files changed, 134 insertions, 54 deletions
diff --git a/indra/llmessage/llexperiencecache.h b/indra/llmessage/llexperiencecache.h
index e669ee888e..1002b33f80 100644
--- a/indra/llmessage/llexperiencecache.h
+++ b/indra/llmessage/llexperiencecache.h
@@ -30,75 +30,155 @@
#define LL_LLEXPERIENCECACHE_H
#include "linden_common.h"
+#include "llsingleton.h"
+#include "llframetimer.h"
+#include "llsd.h"
+#include "llcorehttputil.h"
#include <boost/signals2.hpp>
+#include <boost/function.hpp>
class LLSD;
class LLUUID;
-
-namespace LLExperienceCache
+class LLExperienceCache: public LLSingleton < LLExperienceCache >
{
- const std::string PRIVATE_KEY = "private_id";
- const std::string MISSING = "DoesNotExist";
-
- const std::string AGENT_ID = "agent_id";
- const std::string GROUP_ID = "group_id";
- const std::string EXPERIENCE_ID = "public_id";
- const std::string NAME = "name";
- const std::string PROPERTIES = "properties";
- const std::string EXPIRES = "expiration";
- const std::string DESCRIPTION = "description";
- const std::string QUOTA = "quota";
- const std::string MATURITY = "maturity";
- const std::string METADATA = "extended_metadata";
- const std::string SLURL = "slurl";
-
-
- // should be in sync with experience-api/experiences/models.py
- const int PROPERTY_INVALID = 1 << 0;
- const int PROPERTY_PRIVILEGED = 1 << 3;
- const int PROPERTY_GRID = 1 << 4;
- const int PROPERTY_PRIVATE = 1 << 5;
- const int PROPERTY_DISABLED = 1 << 6;
- const int PROPERTY_SUSPENDED = 1 << 7;
-
-
- // default values
- const static F64 DEFAULT_EXPIRATION = 600.0;
- const static S32 DEFAULT_QUOTA = 128; // this is megabytes
-
- // Callback types for get() below
- typedef boost::signals2::signal<void (const LLSD& experience)>
- callback_signal_t;
- typedef callback_signal_t::slot_type callback_slot_t;
+ friend class LLSingleton < LLExperienceCache > ;
+
+public:
+ typedef boost::function<std::string(const std::string &)> CapabilityQuery_t;
+ typedef boost::function<void(const LLSD &)> ExperienceGetFn_t;
+
+ void setCapabilityQuery(CapabilityQuery_t queryfn);
+ void cleanup();
+
+ //-------------------------------------------
+ // Cache methods
+ void erase(const LLUUID& key);
+ bool fetch(const LLUUID& key, bool refresh = false);
+ void insert(const LLSD& experience_data);
+ const LLSD& get(const LLUUID& key);
+ void get(const LLUUID& key, ExperienceGetFn_t slot); // If name information is in cache, callback will be called immediately.
+
+ bool isRequestPending(const LLUUID& public_key);
+
+ //-------------------------------------------
+ void fetchAssociatedExperience(const LLUUID& objectId, const LLUUID& itemId, ExperienceGetFn_t fn);
+ void findExperienceByName(const std::string text, int page, ExperienceGetFn_t fn);
+ void getGroupExperiences(const LLUUID &groupId, ExperienceGetFn_t fn);
+
+ // the Get/Set Region Experiences take a CapabilityQuery to get the capability since
+ // the region being queried may not be the region that the agent is standing on.
+ void getRegionExperiences(CapabilityQuery_t regioncaps, ExperienceGetFn_t fn);
+ void setRegionExperiences(CapabilityQuery_t regioncaps, const LLSD &experiences, ExperienceGetFn_t fn);
+
+ void getExperiencePermission(const LLUUID &experienceId, ExperienceGetFn_t fn);
+ void setExperiencePermission(const LLUUID &experienceId, const std::string &permission, ExperienceGetFn_t fn);
+ void forgetExperiencePermission(const LLUUID &experienceId, ExperienceGetFn_t fn);
+
+ void getExperienceAdmin(const LLUUID &experienceId, ExperienceGetFn_t fn);
+
+ void updateExperience(LLSD updateData, ExperienceGetFn_t fn);
+ //-------------------------------------------
+ static const std::string NAME; // "name"
+ static const std::string EXPERIENCE_ID; // "public_id"
+ static const std::string AGENT_ID; // "agent_id"
+ static const std::string GROUP_ID; // "group_id"
+ static const std::string PROPERTIES; // "properties"
+ static const std::string EXPIRES; // "expiration"
+ static const std::string DESCRIPTION; // "description"
+ static const std::string QUOTA; // "quota"
+ static const std::string MATURITY; // "maturity"
+ static const std::string METADATA; // "extended_metadata"
+ static const std::string SLURL; // "slurl"
+
+ static const std::string MISSING; // "DoesNotExist"
+
+ // should be in sync with experience-api/experiences/models.py
+ static const int PROPERTY_INVALID; // 1 << 0
+ static const int PROPERTY_PRIVILEGED; // 1 << 3
+ static const int PROPERTY_GRID; // 1 << 4
+ static const int PROPERTY_PRIVATE; // 1 << 5
+ static const int PROPERTY_DISABLED; // 1 << 6
+ static const int PROPERTY_SUSPENDED; // 1 << 7
+
+private:
+ LLExperienceCache();
+ virtual ~LLExperienceCache();
+
+ virtual void initSingleton();
+
+ typedef boost::function<LLSD(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &, LLCore::HttpRequest::ptr_t, std::string)> permissionInvoker_fn;
+
+ // Callback types for get()
+ typedef boost::signals2::signal < void(const LLSD &) > callback_signal_t;
+ typedef boost::shared_ptr<callback_signal_t> signal_ptr;
+ // May have multiple callbacks for a single ID, which are
+ // represented as multiple slots bound to the signal.
+ // Avoid copying signals via pointers.
+ typedef std::map<LLUUID, signal_ptr> signal_map_t;
typedef std::map<LLUUID, LLSD> cache_t;
-
-
- void setLookupURL(const std::string& lookup_url);
- bool hasLookupURL();
-
- void setMaximumLookups(int maximumLookups);
-
- void idle();
- void exportFile(std::ostream& ostr);
- void importFile(std::istream& istr);
- void initClass();
- void bootstrap(const LLSD& legacyKeys, int initialExpiration);
- void erase(const LLUUID& key);
- bool fetch(const LLUUID& key, bool refresh=false);
- void insert(const LLSD& experience_data);
- const LLSD& get(const LLUUID& key);
-
- // If name information is in cache, callback will be called immediately.
- void get(const LLUUID& key, callback_slot_t slot);
+ typedef std::set<LLUUID> RequestQueue_t;
+ typedef std::map<LLUUID, F64> PendingQueue_t;
+ //--------------------------------------------
+ static const std::string PRIVATE_KEY; // "private_id"
+
+ // default values
+ static const F64 DEFAULT_EXPIRATION; // 600.0
+ static const S32 DEFAULT_QUOTA; // 128 this is megabytes
+ static const int SEARCH_PAGE_SIZE;
+
+//--------------------------------------------
+ void processExperience(const LLUUID& public_key, const LLSD& experience);
+
+//--------------------------------------------
+ cache_t mCache;
+ signal_map_t mSignalMap;
+ RequestQueue_t mRequestQueue;
+ PendingQueue_t mPendingQueue;
+
+ LLFrameTimer mEraseExpiredTimer; // Periodically clean out expired entries from the cache
+ CapabilityQuery_t mCapability;
+ std::string mCacheFileName;
+ bool mShutdown;
+
+ void idleCoro();
+ void eraseExpired();
+ void requestExperiencesCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &, std::string, RequestQueue_t);
+ void requestExperiences();
+
+ void fetchAssociatedExperienceCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &, LLUUID, LLUUID, ExperienceGetFn_t);
+ void findExperienceByNameCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &, std::string, int, ExperienceGetFn_t);
+ void getGroupExperiencesCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &, LLUUID , ExperienceGetFn_t);
+ void regionExperiencesCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &httpAdapter, CapabilityQuery_t regioncaps, bool update, LLSD experiences, ExperienceGetFn_t fn);
+ void experiencePermissionCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &httpAdapter, permissionInvoker_fn invokerfn, std::string url, ExperienceGetFn_t fn);
+ void getExperienceAdminCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &httpAdapter, LLUUID experienceId, ExperienceGetFn_t fn);
+ void updateExperienceCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &httpAdapter, LLSD updateData, ExperienceGetFn_t fn);
+
+ void bootstrap(const LLSD& legacyKeys, int initialExpiration);
+ void exportFile(std::ostream& ostr) const;
+ void importFile(std::istream& istr);
+
+ //
const cache_t& getCached();
// maps an experience private key to the experience id
LLUUID getExperienceId(const LLUUID& private_key, bool null_if_not_found=false);
+ //=====================================================================
+ inline friend std::ostream &operator << (std::ostream &os, const LLExperienceCache &cache)
+ {
+ cache.exportFile(os);
+ return os;
+ }
+
+ inline friend std::istream &operator >> (std::istream &is, LLExperienceCache &cache)
+ {
+ cache.importFile(is);
+ return is;
+ }
};
#endif // LL_LLEXPERIENCECACHE_H