Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "DcEnginesSet.h"
00025
00026 void CdcEnginesSet::Login ()
00027 {
00028 if (nEngineTimeLimit > 0)
00029 {
00030 isReleseThreadGo = new volatile bool (true);
00031 poLimitMutex = new CdcMutex ();
00032
00033 oReleaseThread.CloseThread ();
00034 oReleaseThread.MakeThread (DcReleaseEngine, (void*) this);
00035 oReleaseThread.SetPriority (DC_TP_LOW);
00036 }
00037 }
00038
00039
00040 void CdcEnginesSet::Logout ()
00041 {
00042 if (nEngineTimeLimit > 0 && isReleseThreadGo)
00043 *isReleseThreadGo = false;
00044 if (poLimitMutex) poLimitMutex->Lock ();
00045 for (CdcEnginesSet::t_engines_map::iterator pos = mEngines.begin ();
00046 pos != mEngines.end (); ++pos)
00047 if (pos->second)
00048 {
00049 mEngines.erase (pos);
00050 if (pos->second->pEngine)
00051 delete (pos->second->pEngine);
00052 delete pos->second;
00053 }
00054 if (poLimitMutex) poLimitMutex->Unlock ();
00055 }
00056
00057
00058 IdcEngine* CdcEnginesSet::GetEngine (const CdcString& name)
00059 {
00060 IdcEngine* peng = NULL;
00061 oMutex.Lock ();
00062
00063 CdcEnginesSet::t_engines_map::iterator itr =
00064 mEngines.find (name);
00065 if (itr != mEngines.end () && itr->second != NULL)
00066 {
00067 peng = itr->second->pEngine;
00068 delete (itr->second);
00069 mEngines.erase (itr);
00070 }
00071 oMutex.Unlock ();
00072 return peng;
00073 }
00074
00075 bool CdcEnginesSet::PutEngine (const CdcString& name, IdcEngine* peng)
00076 {
00077 oMutex.Lock ();
00078 bool ret = false;
00079
00080 CdcEnginesSet::t_engines_map::iterator itr =
00081 mEngines.find (name);
00082 if (itr == mEngines.end () && peng)
00083 {
00084 peng->Stored ();
00085 mEngines[name] = new CdcEngineNode (peng);
00086 ret = true;
00087 }
00088 oMutex.Unlock ();
00089 return ret;
00090 }
00091
00092 int DcReleaseEngine (void* pParam)
00093 {
00094 CdcEnginesSet* pThis = (CdcEnginesSet*)pParam;
00095 if (pThis == NULL) return 1;
00096 volatile bool* pRun = pThis->isReleseThreadGo;
00097 CdcMutex* pMutex = pThis->poLimitMutex;
00098 int time_limit = pThis->nEngineTimeLimit;
00099 while (*pRun)
00100 {
00101 Sleep (10000);
00102 pMutex->Lock ();
00103 if (*pRun == false) break;
00104 CdcHttpTime now = CdcHttpTime::GetCurrentTime ();
00105 for (CdcEnginesSet::t_engines_map::iterator pos =
00106 pThis->mEngines.begin (); pos != pThis->mEngines.end (); ++pos)
00107 if (pos->second != NULL &&
00108 now - pos->second->tStartIdle > time_limit)
00109 {
00110 pThis->oMutex.Lock ();
00111 if (pos->second->pEngine)
00112 delete (pos->second->pEngine);
00113 delete (pos->second);
00114 pThis->mEngines.erase (pos);
00115 pThis->oMutex.Unlock ();
00116 break;
00117 }
00118 pMutex->Unlock ();
00119 }
00120 delete pRun;
00121 delete pMutex;
00122 return 0;
00123 }