00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef SAMPLES_SAMPLE_HOOK_MODULE_H
00038 #define SAMPLES_SAMPLE_HOOK_MODULE_H
00039
00040
00041
00042
00043
00044 #include "Sim/Foundation/Resource/ResourceNode.h"
00045
00046 #include "Sim/Pipeline/Fetcher/Fetcher.h"
00047 #include "Sim/Pipeline/Renamer/Renamer.h"
00048 #include "Sim/Pipeline/Dispatcher/Dispatcher.h"
00049 #include "Sim/Pipeline/Scheduler/Scheduler.h"
00050 #include "Sim/Pipeline/Scheduler/FinishEvent.h"
00051 #include "Sim/Pipeline/Retirer/Retirer.h"
00052 #include "Sim/InorderList/InorderList.h"
00053 #include "Sim/System/SimulationSystem/SimulationSystem.h"
00054
00055 #include "Sim/Op/Op.h"
00056
00057
00058 namespace Onikiri
00059 {
00060
00061 class SampleHookModule : public PhysicalResourceNode
00062 {
00063 public:
00064
00065 void OnOpFetch( Fetcher::FetchHookParam* param )
00066 {
00067 if( param->op.IsNull() ){
00068 g_env.Print( "op is not fetched yet.\n" );
00069 }
00070 else{
00071 g_env.Print( "op(%s) is fetched.\n", param->op->ToString(0).c_str() );
00072 }
00073 }
00074
00075 void OnOpRename( HookParameter<Renamer>* param )
00076 {
00077 g_env.Print( "op(%s) is renamed.\n", param->GetOp()->ToString(0).c_str() );
00078 }
00079
00080 void OnOpDispatch( HookParameter<Dispatcher, Dispatcher::DispatchHookParam>* param )
00081 {
00082 g_env.Print( "op(%s) is dispatched.\n", param->GetOp()->ToString(0).c_str() );
00083 }
00084
00085 void OnOpIssue( HookParameter<Scheduler>* param )
00086 {
00087 g_env.Print( "op(%s) is issued.\n", param->GetOp()->ToString(0).c_str() );
00088 }
00089
00090 void OnOpExecutionFinish( OpIterator op, OpFinishEvent::FinishHookParam* param )
00091 {
00092 if( op.IsAlive() ){
00093 g_env.Print( "op(%s) is executed.\n", op->ToString(0).c_str() );
00094 }
00095 else{
00096 g_env.Print( "op is flushed.\n" );
00097 }
00098 }
00099
00100 void OnOpRetire( HookParameter<Retirer>* param )
00101 {
00102 g_env.Print( "op(%s) is retired.\n", param->GetOp()->ToString(0).c_str() );
00103 }
00104
00105 void OnOpFlushed( HookParameter<InorderList>* param )
00106 {
00107 g_env.Print( "op(%s) is flushed.\n", param->GetOp()->ToString(0).c_str() );
00108 }
00109
00110 void OnOpRescheduled( OpIterator op, Scheduler::RescheduleHookParam* param )
00111 {
00112 g_env.Print( "op(%s) is re-scheduled.\n", op->ToString(0).c_str() );
00113 }
00114
00115 void OnCycleBegin()
00116 {
00117 g_env.Print( "--- Cycle Begin\n" );
00118 }
00119
00120 void OnCycleEvaluate()
00121 {
00122 g_env.Print( "On a cycle evaluation phase.\n" );
00123 }
00124
00125 void OnCycleProcess()
00126 {
00127 g_env.Print( "On a cycle process phase.\n" );
00128 }
00129
00130 SampleHookModule(){};
00131 virtual ~SampleHookModule(){};
00132
00133
00134 virtual void Initialize( InitPhase phase )
00135 {
00136 if( phase == INIT_PRE_CONNECTION ){
00137
00138
00139 LoadParam();
00140 }
00141 else if ( phase == INIT_POST_CONNECTION ){
00142
00143
00144
00145
00146
00147 Fetcher::s_fetchHook.Register(
00148 this, &SampleHookModule::OnOpFetch, 0, HookType::HOOK_AFTER
00149 );
00150 Renamer::s_renameUpdateHook.Register(
00151 this, &SampleHookModule::OnOpRename, 0, HookType::HOOK_AFTER
00152 );
00153 Dispatcher::s_dispatchUpdateHook.Register(
00154 this, &SampleHookModule::OnOpDispatch, 0, HookType::HOOK_AFTER
00155 );
00156 Scheduler::s_issueHook.Register(
00157 this, &SampleHookModule::OnOpIssue, 0, HookType::HOOK_AFTER
00158 );
00159 OpFinishEvent::s_finishHook.Register(
00160 this, &SampleHookModule::OnOpExecutionFinish, 0, HookType::HOOK_AFTER
00161 );
00162
00163
00164
00165 Retirer::s_retireHook.Register(
00166 this, &SampleHookModule::OnOpRetire, 0, HookType::HOOK_BEFORE
00167 );
00168
00169
00170
00171
00172
00173 InorderList::s_opFlushHook.Register(
00174 this, &SampleHookModule::OnOpFlushed, 0, HookType::HOOK_BEFORE
00175 );
00176 Scheduler::s_rescheduleHook.Register(
00177 this, &SampleHookModule::OnOpRescheduled, 0, HookType::HOOK_AFTER
00178 );
00179
00180
00181
00182 SimulationSystem::s_cycleBeginHook.Register(
00183 this, &SampleHookModule::OnCycleBegin, 0, HookType::HOOK_AFTER
00184 );
00185 SimulationSystem::s_cycleEvaluateHook.Register(
00186 this, &SampleHookModule::OnCycleEvaluate, 0, HookType::HOOK_AFTER
00187 );
00188 SimulationSystem::s_cycleUpdateHook.Register(
00189 this, &SampleHookModule::OnCycleProcess, 0, HookType::HOOK_AFTER
00190 );
00191
00192 }
00193 }
00194
00195 virtual void Finalize()
00196 {
00197
00198 ReleaseParam();
00199 };
00200
00201
00202
00203
00204 BEGIN_PARAM_MAP("")
00205 BEGIN_PARAM_PATH( GetParamPath() )
00206 END_PARAM_PATH()
00207 BEGIN_PARAM_PATH( GetResultPath() )
00208 END_PARAM_PATH()
00209 END_PARAM_MAP()
00210
00211 BEGIN_RESOURCE_MAP()
00212 END_RESOURCE_MAP()
00213 };
00214
00215 #ifdef USE_SAMPLE_HOOK_MODULE
00216
00217
00218 static const char g_sampleHookModuleParam[] = " \n\
00219 \n\
00220 <?xml version='1.0' encoding='UTF-8'?> \n\
00221 <Session> \n\
00222 <Simulator> \n\
00223 <Configurations> \n\
00224 <DefaultConfiguration> \n\
00225 \n\
00226 <Structure> \n\
00227 <Copy> \n\
00228 <SampleHookModule \n\
00229 Count = 'CoreCount' \n\
00230 Name = 'sampleHookModule' \n\
00231 /> \n\
00232 </Copy> \n\
00233 </Structure> \n\
00234 \n\
00235 <Parameter> \n\
00236 <SampleHookModule \n\
00237 Name = 'sampleHookModule' \n\
00238 /> \n\
00239 </Parameter> \n\
00240 </DefaultConfiguration> \n\
00241 </Configurations> \n\
00242 </Simulator> \n\
00243 </Session> \n\
00244 ";
00245
00246 #endif // #ifdef USE_SAMPLE_HOOK_MODULE
00247
00248 }
00249
00250 #endif // #ifndef SAMPLES_SAMPLE_HOOK_MODULE_H