/[projects]/smsdaemon/TaskManager.cpp
ViewVC logotype

Diff of /smsdaemon/TaskManager.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 196 by torben, Thu Dec 18 06:53:29 2008 UTC revision 208 by torben, Sun Dec 21 18:41:08 2008 UTC
# Line 2  Line 2 
2  #include "TaskManager.h"  #include "TaskManager.h"
3    
4  #include "Logger.h"  #include "Logger.h"
5    #include "Common.h"
6    #include "Util.h"
7    #include "ConfigFile.h"
8    
9  #include <time.h>  #include <time.h>
10    
# Line 23  TaskManager::~TaskManager() Line 26  TaskManager::~TaskManager()
26          }          }
27  }  }
28    
29    Task* TaskManager::CreateTask(const std::string& taskName, const std::map<std::string, std::string>& arguments)
30    {
31            if (taskName =="spool")
32                    return new SpoolTask();
33    
34            return 0;
35    }
36    
37    void TaskManager::DestroyTasks()
38    {
39            std::map<std::string, Task*>::iterator it;
40            for (it = _persistant_tasks.begin(); it != _persistant_tasks.end(); ++it)
41            {
42                    delete it->second;
43            }
44            _persistant_tasks.clear();
45    }
46    
47  void TaskManager::LoadTasks()  void TaskManager::LoadTasks()
48  {  {
49          static SpoolTask task;  
50            Logger::logMessage("--------  TaskList  --------");
51            std::vector<Value> tasklist = Common::instance()->GetConfigfile()->GetValues("smsdaemon", "task");
52    
53            for (unsigned i=0; i<tasklist.size(); i++)
54            {
55                    std::string current = tasklist[i];
56    
57                    std::string name;
58                    unsigned pos = current.find(' ');
59                    std::map<std::string,std::string> args;
60    
61                    std::string argstr;
62    
63                    if (pos == std::string::npos)
64                    {
65                            name = current;
66                    }
67                    else
68                    {
69                            name = Util::str_trim(current.substr(0,pos));
70                            argstr = Util::str_trim(current.substr(pos+1,1024));
71                            args = ConfigHelper::ParseArguments(argstr);
72                    }
73    
74                    Task* task = 0;
75                    try
76                    {
77                            task = CreateTask(name, args );
78                    }
79                    catch (std::exception& e)
80                    {
81                            Logger::logMessage(std::string("Failed to load task ") + name + " with args: " + argstr);
82                            Logger::logMessage(std::string("Reason: ") + e.what());
83                            continue;
84                    }
85    
86                    if (task)
87                            AddPersistantTask(task);
88                    else
89                            Logger::logMessage( std::string("Unknown task: ")+name);
90    
91            }
92    
93          //print the loaded tasks          //print the loaded tasks
94          std::map<std::string, Task*>::iterator it;          std::map<std::string, Task*>::iterator it;

Legend:
Removed from v.196  
changed lines
  Added in v.208

  ViewVC Help
Powered by ViewVC 1.1.20