lltrustnet.h

Go to the documentation of this file.
00001 
00030 #ifndef LL_LLTRUSTNET_H
00031 #define LL_LLTRUSTNET_H
00032 
00033 #include <map>
00034 #include "llviewercommunication.h"
00035 #include "llviewerprecompiledheaders.h"
00036 #include "lluuid.h"
00037 #include "lltimer.h"
00038 
00042 typedef enum e_trustnet_operation
00043 {
00044         TN_UNKNOWN,
00045         TN_GET_SCORE,
00046         TN_EXPLAIN,
00047         TN_RATE
00048 } ETrustNetOperation;
00049 
00053 typedef enum e_trustnet_result
00054 {
00055         TN_OK,
00056         TN_TIMEOUT,
00057         TN_INTERNAL_ERROR,
00058         TN_ERROR
00059 } ETrustNetResult;
00060 
00071 typedef void(*trustnet_callback_t)(ETrustNetOperation operation, ETrustNetResult result, const LLUUID &avatar, void *user_data);
00072 
00073 
00074 class LLTrustNet;
00075 class LLTrustNetAvatarData;
00076 
00080 class LLTrustNetCallbackEntry
00081 {
00082 public:
00083         LLTrustNetCallbackEntry(trustnet_callback_t cb = NULL, void *ud = NULL): callback(cb), user_data(ud) {}
00084 
00085         trustnet_callback_t callback;
00086         void *user_data;
00087 };
00088 
00092 typedef enum e_trustnet_state
00093 {
00094         TRUSTNET_NO_ADAPTER,
00095         TRUSTNET_NO_CONNECTION,
00096         TRUSTNET_CONNECTING,
00097         TRUSTNET_LOGGING_IN,
00098         TRUSTNET_LOGIN_ERROR,
00099         TRUSTNET_CONNECTED
00100 } ETrustNetState;
00101 
00105 typedef enum e_trustnet_datum_state
00106 {
00107         TNS_UNKNOWN,
00108         TNS_FETCHING,
00109         TNS_RETRIEVED
00110 } ETrustNetDatumState;
00111 
00112 
00119 class LLTrustNetRequest
00120 {
00121 public:
00122         LLTrustNetRequest() {}
00126         virtual LLString asString() { return ""; }
00127         virtual ~LLTrustNetRequest() {}
00128 };
00129 
00133 class LLTrustNetScoreRequest : public LLTrustNetRequest
00134 {
00135 public:
00136         LLTrustNetScoreRequest(const LLUUID &id, const LLString &name, const LLString &type = "behavior") : mID(id), mName(name),  mType(type) {}
00137         virtual LLString asString();
00138 private:
00139         LLUUID mID;
00140         LLString mName;
00141         LLString mType;
00142 };
00143 
00147 class LLTrustNetRateRequest : public LLTrustNetRequest
00148 {
00149 public:
00150         LLTrustNetRateRequest(const LLUUID &id, const LLString &name, const LLString &type = "behavior", U32 score = 0, const LLString &comment = "")
00151         : mID(id), mName(name),  mType(type), mScore(score), mComment(comment) {}
00152         virtual LLString asString();
00153 private:
00154         LLUUID mID;
00155         LLString mName;
00156         LLString mType;
00157         U32 mScore;
00158         LLString mComment;
00159 };
00160 
00165 class LLTrustNetExplainRequest : public LLTrustNetRequest
00166 {
00167 public:
00168         LLTrustNetExplainRequest(const LLUUID &id, const LLString &name) : mID(id), mName(name) {}
00169         virtual LLString asString() { return "Explain|" + mName + "|" + mID.asString(); }
00170 private:
00171         LLUUID mID;
00172         LLString mName;
00173 };
00174 
00178 class LLTrustNetDatum
00179 {
00180 
00181 public:
00182         LLTrustNetDatum() : mOperation(TN_UNKNOWN),  mState(TNS_UNKNOWN), mParent(NULL) {}
00183 
00187         void addCallback(trustnet_callback_t callback, void *user_data = NULL);
00188 
00193         F32 getAge() const { return mTimer.getElapsedTimeF32(); }
00194 
00195         ETrustNetDatumState getState() const { return mState; }
00196 
00197 protected:
00198         friend class LLTrustNet;
00199         void setState(ETrustNetDatumState s) { mState = s; }
00200 
00206         void setParent(const LLTrustNetAvatarData *p) { mParent = p; }
00207 
00208 protected:
00213         void notify(ETrustNetResult result = TN_OK);
00214 
00218         void updated(ETrustNetResult state = TN_OK) { mTimer.start(); setState(TNS_RETRIEVED); notify(state); }
00219 
00220         ETrustNetOperation mOperation;
00221 private:
00222         std::queue<LLTrustNetCallbackEntry> mCallbacks;
00223         LLTimer mTimer;
00224 
00225         ETrustNetDatumState mState;
00226 
00231         const LLTrustNetAvatarData *mParent;
00232 };
00233 
00237 class LLTrustNetScore : public LLTrustNetDatum
00238 {
00239 public:
00240         LLTrustNetScore(const F32 score = 0.0f, const LLString comment = "");
00241 
00247         void set(F32 score, const LLString &comment = "") { mScore = score; mComments = comment; updated(); }
00248         F32 mScore;
00249         LLString mComments;
00250 private:
00251 
00252 };
00253 
00257 class LLTrustNetAvatarData
00258 {
00259 public:
00260         std::map<LLString, LLTrustNetScore> mScores;
00261 
00262         void setAvatar(const LLUUID& av) { mAvatar = av;}
00263         LLUUID getAvatar() const { return mAvatar; }
00264 protected:
00265         LLUUID mAvatar;
00266         
00267 };
00268 
00269 
00270 
00271 
00272 
00276 class LLTrustNet
00277 {
00278 public:
00279         LLTrustNet();
00280 
00287         F32 getScore(const LLUUID& avatar, const LLString& type);
00288 
00295         ETrustNetDatumState getScoreState(const LLUUID& avatar, const LLString& type);
00296 
00304         LLColor4 getScoreColor(const LLUUID& avatar, const LLString& type);
00305 
00309         void processRequests();
00310 
00314         ETrustNetState getConnectionState() const { return mConnectionState; }
00315 
00319         LLString getConnectionStateString() const;
00320 
00321         static void viewerCommCallback(LLString& data, LLViewerCircuit& circuit, void* userdata);
00322 protected:
00323         void setScore(const LLUUID &avatar, const LLString& type, F32 score);
00324 
00325         LLTrustNetScore getScoreData(const LLUUID& avatar, const LLString& type);
00326 
00327         LLViewerCircuit *mCircuit;
00328         std::map<LLUUID, LLTrustNetAvatarData> mCache;
00329         std::deque<LLTrustNetRequest*> mQueue;
00330         ETrustNetState mConnectionState;
00331 };
00332 
00333 extern LLTrustNet* gTrustNet;
00334 
00335 #endif

Generated on Thu Jul 1 06:09:23 2010 for Second Life Viewer by  doxygen 1.4.7