/[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 207 by torben, Sun Dec 21 17:42:30 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    }
40    
41  void TaskManager::LoadTasks()  void TaskManager::LoadTasks()
42  {  {
43          static SpoolTask task;  
44            Logger::logMessage("--------  TaskList  --------");
45            std::vector<Value> tasklist = Common::instance()->GetConfigfile()->GetValues("smsdaemon", "task");
46    
47            for (unsigned i=0; i<tasklist.size(); i++)
48            {
49                    std::string current = tasklist[i];
50    
51                    std::string name;
52                    unsigned pos = current.find(' ');
53                    std::map<std::string,std::string> args;
54    
55                    std::string argstr;
56    
57                    if (pos == std::string::npos)
58                    {
59                            name = current;
60                    }
61                    else
62                    {
63                            name = Util::str_trim(current.substr(0,pos));
64                            argstr = Util::str_trim(current.substr(pos+1,1024));
65                            args = ConfigHelper::ParseArguments(argstr);
66                    }
67    
68                    Task* task = 0;
69                    try
70                    {
71                            task = CreateTask(name, args );
72                    }
73                    catch (std::exception& e)
74                    {
75                            Logger::logMessage(std::string("Failed to load task ") + name + " with args: " + argstr);
76                            Logger::logMessage(std::string("Reason: ") + e.what());
77                            continue;
78                    }
79    
80                    if (task)
81                            AddPersistantTask(task);
82                    else
83                            Logger::logMessage( std::string("Unknown task: ")+name);
84    
85            }
86    
87          //print the loaded tasks          //print the loaded tasks
88          std::map<std::string, Task*>::iterator it;          std::map<std::string, Task*>::iterator it;

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

  ViewVC Help
Powered by ViewVC 1.1.20