00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __freRegistrationProcessEventHandler_txx
00024 #define __freRegistrationProcessEventHandler_txx
00025
00026 #include "freRegistrationProcessEventHandler.h"
00027 #include "freControllerCentral.h"
00028
00029 namespace FREE
00030 {
00031
00032 template <class TRegistrationProcessor>
00033 void
00034 RegistrationProcessEventHandler<TRegistrationProcessor>::
00035 SetSessionInfo(SessionInfo* pSessionInfo)
00036 {
00037 m_pSessionInfo = pSessionInfo;
00038 };
00039
00040 template <class TRegistrationProcessor>
00041 void
00042 RegistrationProcessEventHandler<TRegistrationProcessor>::
00043 SetComponentCache(SessionComponentCache* pCache)
00044 {
00045 m_pCache = pCache;
00046 if (!m_pCache)
00047 {
00048 m_pProcessor = 0;
00049 }
00050 else
00051 {
00052 try
00053 {
00054 m_pProcessor = dynamic_cast<TRegistrationProcessor*>(m_pCache->Component().GetPointer());
00055 }
00056 catchAllNPassMacro("Error. Cache component is no registration processor.");
00057 if (!m_pProcessor) throwExceptionMacro("Error. Cache component is no registration processor. IDPath: " << m_pCache->GetIDPath().ToStr());
00058
00059 m_pProcessor->fnOnNextLevel = m_LevelEvent;
00060 m_pProcessor->fnOnNextIteration = m_IterationEvent;
00061 m_pProcessor->fnOnProgress = m_RegistrationProgressEvent;
00062 }
00063 };
00064
00065 template <class TRegistrationProcessor>
00066 RegistrationProcessEventHandler<TRegistrationProcessor>::
00067 RegistrationProcessEventHandler()
00068 {
00069 this->m_IterationEvent = IterationEvent<Self>::New(this, &Self::OnNextIteration);
00070 this->m_LevelEvent = LevelEvent<Self>::New(this, &Self::OnNextLevel);
00071 this->m_RegistrationProgressEvent = RegistrationProgressEvent<Self>::New(this, &Self::OnRegistrationProgressEvent);
00072
00073 m_pRegistrationEntry = 0;
00074 m_pLevelEntry = 0;
00075 m_pIterationEntry = 0;
00076 };
00077
00078 template <class TRegistrationProcessor>
00079 void
00080 RegistrationProcessEventHandler<TRegistrationProcessor>::
00081 OnNextLevel(const unsigned int iLevel, void* pSender, long threadID)
00082 {
00083 if (m_pCache)
00084 {
00085 if (m_pSessionInfo->GetStatistic() && (m_pRegistrationEntry!=0))
00086 {
00087 StatisticEntryDefinition* pEntryDef = m_pSessionInfo->GetStatistic()->GetDictionary().GetEntryDefinitionByName(m_pCache->GetIDPath(),"Level");
00088 if (!pEntryDef)
00089 {
00090 pEntryDef = m_pSessionInfo->GetStatistic()->GetDictionary().AddEntryDefinition(m_pCache->GetIDPath(),"Level",m_pCache->GetControllerID(),"a registration level");
00091 }
00092
00093 StatisticValueDefinition* pValueDef = m_pSessionInfo->GetStatistic()->GetDictionary().GetValueDefinitionByName(m_pCache->GetIDPath(),"LevelID");
00094 if (!pValueDef)
00095 {
00096 pValueDef = m_pSessionInfo->GetStatistic()->GetDictionary().AddValueDefinition(m_pCache->GetIDPath(),"LevelID","ID/Number of the registration level");
00097 }
00098
00099 m_pLevelEntry = m_pRegistrationEntry->CreateChildEntry();
00100 m_pLevelEntry->SetRefID(pEntryDef->GetRefID());
00101 m_pLevelEntry->AddValue(Convert::ToStr(iLevel),pValueDef->GetRefID());
00102 }
00103 ControllerCentral::TriggerControllerProgressEvent(m_pCache->GetIDPath(),2,"Added new registration level: "+Convert::ToStr(iLevel), m_pCache, threadID);
00104 };
00105 };
00106
00107 template <class TRegistrationProcessor>
00108 void
00109 RegistrationProcessEventHandler<TRegistrationProcessor>::
00110 OnNextIteration(const long lIteration, Statistics* pStatistic, void* pSender, long threadID)
00111 {
00112 if (m_pCache)
00113 {
00114 if (m_pSessionInfo->GetStatistic() && (m_pRegistrationEntry!=0))
00115 {
00116 if (!m_pLevelEntry) OnNextLevel(0, pSender, threadID);
00117
00118 StatisticEntryDefinition* pEntryDef = m_pSessionInfo->GetStatistic()->GetDictionary().GetEntryDefinitionByName(m_pCache->GetIDPath(),"Iteration");
00119 if (!pEntryDef)
00120 {
00121 pEntryDef = m_pSessionInfo->GetStatistic()->GetDictionary().AddEntryDefinition(m_pCache->GetIDPath(),"Iteration",m_pCache->GetControllerID(),"an iteration of the registration");
00122 }
00123
00124 StatisticValueDefinition* pValueDef = m_pSessionInfo->GetStatistic()->GetDictionary().GetValueDefinitionByName(m_pCache->GetIDPath(),"IterationID");
00125 if (!pValueDef)
00126 {
00127 pValueDef = m_pSessionInfo->GetStatistic()->GetDictionary().AddValueDefinition(m_pCache->GetIDPath(),"IterationID","ID/Number of the registration iteration");
00128 }
00129
00130 m_pIterationEntry = m_pLevelEntry->PostCreateChildEntry();
00131 m_pIterationEntry->SetRefID(pEntryDef->GetRefID());
00132 m_pIterationEntry->AddValue(Convert::ToStr(lIteration),pValueDef->GetRefID());
00133
00134
00135 m_pCache->Controller()->SetStatisticEntry(*m_pIterationEntry,m_pCache,m_pSessionInfo);
00136
00137 m_pIterationEntry->CloseEntry();
00138 }
00139 ControllerCentral::TriggerControllerProgressEvent(m_pCache->GetIDPath(),3,Convert::ToStr(lIteration), m_pCache, threadID);
00140 };
00141 };
00142
00143 template <class TRegistrationProcessor>
00144 void
00145 RegistrationProcessEventHandler<TRegistrationProcessor>::
00146 OnRegistrationProgressEvent(const RegistrationStatusType status,
00147 const std::string sComment,
00148 void* pSender,
00149 long threadID)
00150 {
00151 if (m_pCache)
00152 {
00153 ControllerCentral::TriggerControllerProgressEvent(m_pCache->GetIDPath(),1000+status,sComment, m_pCache, threadID);
00154 };
00155 };
00156
00157 template <class TRegistrationProcessor>
00158 void
00159 RegistrationProcessEventHandler<TRegistrationProcessor>::
00160 SetRegistrationEntry(StatisticEntry* pEntry)
00161 {
00162 if (pEntry!=m_pRegistrationEntry)
00163 {
00164 m_pRegistrationEntry = pEntry;
00165 m_pLevelEntry = 0;
00166 m_pIterationEntry = 0;
00167 }
00168 };
00169
00170 template <class TRegistrationProcessor>
00171 StatisticEntry*
00172 RegistrationProcessEventHandler<TRegistrationProcessor>::
00173 GetRegistrationEntry()
00174 {
00175 return m_pRegistrationEntry;
00176 };
00177
00178 template <class TRegistrationProcessor>
00179 StatisticEntry*
00180 RegistrationProcessEventHandler<TRegistrationProcessor>::
00181 GetLevelEntry()
00182 {
00183 return m_pLevelEntry;
00184 };
00185
00186 template <class TRegistrationProcessor>
00187 StatisticEntry*
00188 RegistrationProcessEventHandler<TRegistrationProcessor>::
00189 GetIterationEntry()
00190 {
00191 return m_pIterationEntry;
00192 };
00193
00194
00195 }
00196 #endif