00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "utils/tokencollector.hpp"
00022
00023
00024
00025
00026
00027
00028
00029
00030 void TokenCollectorBase::insertClient(const std::string &token, intptr_t data)
00031 {
00032 for (std::list<Item>::reverse_iterator it = mPendingConnects.rbegin(),
00033 it_end = mPendingConnects.rend(); it != it_end; ++it)
00034 {
00035 if (it->token == token)
00036 {
00037 foundMatch(data, it->data);
00038 mPendingConnects.erase(--it.base());
00039 return;
00040 }
00041 }
00042
00043 time_t current = time(NULL);
00044
00045 Item item;
00046 item.token = token;
00047 item.data = data;
00048 item.timeStamp = current;
00049 mPendingClients.push_back(item);
00050
00051 removeOutdated(current);
00052 }
00053
00054 void TokenCollectorBase::insertConnect(const std::string &token, intptr_t data)
00055 {
00056 for (std::list<Item>::reverse_iterator it = mPendingClients.rbegin(),
00057 it_end = mPendingClients.rend(); it != it_end; ++it)
00058 {
00059 if (it->token == token)
00060 {
00061 foundMatch(it->data, data);
00062 mPendingClients.erase(--it.base());
00063 return;
00064 }
00065 }
00066
00067 time_t current = time(NULL);
00068
00069 Item item;
00070 item.token = token;
00071 item.data = data;
00072 item.timeStamp = current;
00073 mPendingConnects.push_back(item);
00074
00075 removeOutdated(current);
00076 }
00077
00078 void TokenCollectorBase::removeClient(intptr_t data)
00079 {
00080 for (std::list<Item>::iterator it = mPendingClients.begin(),
00081 it_end = mPendingClients.end(); it != it_end; ++it)
00082 {
00083 if (it->data == data)
00084 {
00085 mPendingClients.erase(it);
00086 return;
00087 }
00088 }
00089 }
00090
00091 void TokenCollectorBase::removeOutdated(time_t current)
00092 {
00093
00094 time_t threshold = current - 30;
00095 if (threshold < mLastCheck) return;
00096
00097 std::list<Item>::iterator it;
00098
00099 it = mPendingConnects.begin();
00100 while (it != mPendingConnects.end() && it->timeStamp < threshold)
00101 {
00102 removedConnect(it->data);
00103 it = mPendingConnects.erase(it);
00104 }
00105
00106 it = mPendingClients.begin();
00107 while (it != mPendingClients.end() && it->timeStamp < threshold)
00108 {
00109 removedClient(it->data);
00110 it = mPendingClients.erase(it);
00111 }
00112
00113 mLastCheck = current;
00114 }
00115
00116 TokenCollectorBase::TokenCollectorBase():
00117 mLastCheck(time(NULL))
00118 {
00119 }
00120
00121 TokenCollectorBase::~TokenCollectorBase()
00122 {
00123
00124 }