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 ~RequestIDCacheValue() { }
00040
00041 virtual Type getType() const = 0;
00042 };
00043
00044 class UserInfoCacheValue : public RequestIDCacheValue {
00045 private:
00046 ContactRef m_contact;
00047
00048 public:
00049 UserInfoCacheValue(ContactRef c) : m_contact(c) { }
00050 unsigned int getUIN() const { return m_contact->getUIN(); }
00051 ContactRef getContact() const { return m_contact; }
00052
00053 Type getType() const { return UserInfo; }
00054 };
00055
00056 class SMSEventCacheValue : public RequestIDCacheValue {
00057 private:
00058 SMSMessageEvent *m_ev;
00059
00060 public:
00061 SMSEventCacheValue( SMSMessageEvent *ev ) : m_ev(ev) { }
00062 virtual ~SMSEventCacheValue() { delete m_ev; }
00063 SMSMessageEvent* getEvent() const { return m_ev; }
00064 ContactRef getContact() const { return m_ev->getContact(); }
00065
00066 Type getType() const { return SMSMessage; }
00067 };
00068
00069 class SearchCacheValue : public RequestIDCacheValue {
00070 private:
00071 SearchResultEvent *m_ev;
00072
00073 public:
00074 SearchCacheValue( SearchResultEvent *ev ) : m_ev(ev) { }
00075 SearchResultEvent* getEvent() const { return m_ev; }
00076 Type getType() const { return Search; }
00077 };
00078
00079 class RequestIDCache : public Cache<unsigned int, RequestIDCacheValue*> {
00080 public:
00081 RequestIDCache() { }
00082
00083 SigC::Signal1<void,RequestIDCacheValue*> expired;
00084
00085 void expireItem(const RequestIDCache::literator& l) {
00086 expired.emit( (*l).getValue() );
00087 Cache<unsigned int, RequestIDCacheValue*>::expireItem(l);
00088 }
00089
00090 void removeItem(const RequestIDCache::literator& l) {
00091 delete ((*l).getValue());
00092 Cache<unsigned int, RequestIDCacheValue*>::removeItem(l);
00093 }
00094
00095 };
00096
00097 }
00098
00099 #endif