//------------------------------------------------------------------------------ // Task master -- // (C) Piero Giubilato 2008-2010, Berkeley Lab -- //------------------------------------------------------------------------------ //______________________________________________________________________________ // {Trace} // [File name] "task_Master.cpp" // [Author] "Piero Giubilato" // [Version] "0.1" // [Modified by] "Piero Giubilato" // [Last revision] "10 Feb 2009" // [Language] "C++" // [Compiler] "Visual C++ 8.x 9.x" // [Member of] "Cool SEAL" // [Project] "SEAL" // [Description] "Application task master" // [Key documentation] // "Visual C++ Reference Help" // {Trace} //______________________________________________________________________________ // Standard components // Root components // Application components #include "global.h" #include "task_Master.h" // Tasks #include "cool.h" #include "task_Default.h" #include "task_Demo.h" #include "task_DAQ.h" //______________________________________________________________________________ // Static members initialization task_Master* task_Master::inst_Handle = 0; int task_Master::inst_Count = 0; //______________________________________________________________________________ // Provides a safe self-destruction mechanism in case of missed destruction class TaskCleaner { public: ~TaskCleaner() {task_Master::instance_Destroy();} } TaskCleanerInst; //______________________________________________________________________________ task_Master* task_Master::instance_Load() { // Loads one instance of the class dbg_Print("task_Master::instance_Load: singleton initializer called", DBG_LVL_ZERO); // Just loads one class instance if (inst_Count == 0) { inst_Handle = new task_Master(); inst_Count ++; } // Returns the instance handle return inst_Handle; } //______________________________________________________________________________ void task_Master::instance_Destroy() { // Kills the active instance dbg_Print("task_Master::instance_Destroy: singleton destroyer called", DBG_LVL_ZERO); // Deletes the current class instance if (inst_Handle) { inst_Handle = 0; inst_Count = 0; } } //______________________________________________________________________________ task_Master::task_Master() { // Standard constructor dbg_Print("task_Master::task_Master: constructor called", DBG_LVL_ZERO); // Clears the task handle task_run_Hnd = 0; // Populates the available task list task_List.clear(); task_List.push_back("Default"); task_List.push_back("Demo"); task_List.push_back("DAQ"); } //______________________________________________________________________________ task_Master::~task_Master() { // Standard constructor dbg_Print("task_Master::~task_Master: destructor called", DBG_LVL_ZERO); } //______________________________________________________________________________ void task_Master::task_Run(unsigned int task_ID) { // Runs a task from its ID, if it is known dbg_Print("task_Master::task_Run: launching task (ID)", DBG_LVL_ZERO); // Search through the list if (task_ID < task_List.size()) { task_Run(task_List[task_ID]); } } //______________________________________________________________________________ void task_Master::task_Run(std::string task_Name) { // Runs a task from its string name, if it is known dbg_Print("task_Master::task_Run: launching task (string)", DBG_LVL_ZERO); // Chek if there is another task already running if (task_run_Hnd) { dbg_Print("task_Master::task_Run: killing unterminated task", DBG_LVL_PLAY); delete task_run_Hnd; } // Search through the list bool found = false; for (int i = 0; i < task_List.size(); i++) { if (task_Name == task_List[i]) { // Launches the task task_run_ID = i; switch (i) { case 0: task_run_Hnd = new task_Default(); break; case 1: task_run_Hnd = new task_Demo(); break; case 2: task_run_Hnd = new task_DAQ(); break; } found = true; break; } } // Warns if no task found if (!found) cool::Out->Print("No task found!\n", LYELLOW);; }