00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef REQUESTIDCACHE_H
00023 #define REQUESTIDCACHE_H
00024
00025 #include <libicq2000/Cache.h>
00026
00027 #include <sigc++/signal_system.h>
00028
00029 namespace ICQ2000 {
00030
00031 class RequestIDCacheValue {
00032 public:
00033 enum Type {
00034 UserInfo,
00035 SMSMessage,
00036 Search
00037 };
00038
00039 virtual Type getType() const = 0;
00040 };
00041
00042 class UserInfoCacheValue : public RequestIDCacheValue {
00043 private:
00044 Contact *m_contact;
00045
00046 public:
00047 UserInfoCacheValue(Contact *c) : m_contact(c) { }
00048 unsigned int getUIN() const { return m_contact->getUIN(); }
00049 Contact* getContact() const { return m_contact; }
00050
00051 Type getType() const { return UserInfo; }
00052 };
00053
00054 class SMSEventCacheValue : public RequestIDCacheValue {
00055 private:
00056 SMSMessageEvent *m_ev;
00057
00058 public:
00059 SMSEventCacheValue( SMSMessageEvent *ev ) : m_ev(ev) { }
00060 ~SMSEventCacheValue() { delete m_ev; }
00061 SMSMessageEvent* getEvent() const { return m_ev; }
00062 Contact* getContact() const { return m_ev->getContact(); }
00063
00064 Type getType() const { return SMSMessage; }
00065 };
00066
00067 class SearchCacheValue : public RequestIDCacheValue {
00068 private:
00069 SearchResultEvent *m_ev;
00070
00071 public:
00072 SearchCacheValue( SearchResultEvent *ev ) : m_ev(ev) { }
00073 SearchResultEvent* getEvent() const { return m_ev; }
00074 Type getType() const { return Search; }
00075 };
00076
00077 class RequestIDCache : public Cache<unsigned int, RequestIDCacheValue*> {
00078 public:
00079 RequestIDCache() { }
00080
00081 SigC::Signal1<void,RequestIDCacheValue*> expired;
00082
00083 void expireItem(const RequestIDCache::literator& l) {
00084 expired.emit( (*l).getValue() );
00085 Cache<unsigned int, RequestIDCacheValue*>::expireItem(l);
00086 }
00087
00088 void removeItem(const RequestIDCache::literator& l) {
00089 delete ((*l).getValue());
00090 Cache<unsigned int, RequestIDCacheValue*>::removeItem(l);
00091 }
00092
00093 void removeContact(Contact *c) {
00094 literator curr = m_list.begin();
00095 literator next = curr;
00096 while ( curr != m_list.end() ) {
00097 ++next;
00098 RequestIDCacheValue *cv = (*curr).getValue();
00099 if ( cv->getType() == RequestIDCacheValue::UserInfo ) {
00100 UserInfoCacheValue *ccv = static_cast<UserInfoCacheValue*>(cv);
00101 if (ccv->getContact() == c) removeItem(curr);
00102 } else if (cv->getType() == RequestIDCacheValue::SMSMessage ) {
00103 SMSEventCacheValue *ccv = static_cast<SMSEventCacheValue*>(cv);
00104 if (ccv->getContact() == c) removeItem(curr);
00105 }
00106
00107 curr = next;
00108 }
00109 }
00110
00111 };
00112
00113 }
00114
00115 #endif