Changeset 230


Ignore:
Timestamp:
01/07/10 08:10:43 (2 years ago)
Author:
mickem
Message:

improved the scheduled module and re-added the settings command line toy (so now you can migrate settings again)
Schedule module is 80% finished but notification channel subsystem is still missing.

Location:
trunk
Files:
1 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/settings/Settings.h

    r216 r230  
    754754                get()->set_int(*cit, *citk, strEx::stoi(desc.defValue)); 
    755755              else 
    756                 throw SettingsException(_T("Unknown keytype for: ") + *cit + _T(".") + *citk); 
     756                get_logger()->err(__FILEW__, __LINE__, _T("Unknown keytype for: ") + *cit + _T(".") + *citk); 
    757757            } else { 
    758               get_logger()->debug(__FILEW__, __LINE__, _T("Skipping (already exists): ") + *cit + _T(".") + *citk); 
     758              std::wstring val = get()->get_string(*cit, *citk); 
     759              get_logger()->debug(__FILEW__, __LINE__, _T("Setting old (already exists): ") + *cit + _T(".") + *citk + _T(" = ") + val); 
     760              if (desc.type == key_string) 
     761                get()->set_string(*cit, *citk, val); 
     762              else if (desc.type == key_bool) 
     763                get()->set_bool(*cit, *citk, val==_T("true")); 
     764              else if (desc.type == key_integer) 
     765                get()->set_int(*cit, *citk, strEx::stoi(val)); 
     766              else 
     767                get_logger()->err(__FILEW__, __LINE__, _T("Unknown keytype for: ") + *cit + _T(".") + *citk); 
    759768            } 
    760769          } else { 
  • trunk/include/settings/macros.h

    r207 r230  
    8383#define CHECK_SYSTEM_SERVICES_SECTION "/settings/system/services" 
    8484#define NSCA_SECTION "/settings/NSCA" 
     85#define SCHEDULER_SECTION "/settings/scheduler" 
     86#define SCHEDULER_SECTION_SCH "/settings/scheduler/schedules" 
     87#define SCHEDULER_SECTION_FAKE "/settings/scheduler/schedules/<schedule name>" 
     88#define SCHEDULER_SECTION_DEF "/settings/scheduler/default" 
    8589#define NSCA_SERVER_SECTION "/settings/NSCA/server" 
    8690#define NSCA_CMD_SECTION "/settings/NSCA/server/commands" 
     
    310314  } 
    311315 
     316 
    312317  namespace nsca { 
    313318    DEFINE_PATH(SECTION, NSCA_SECTION); 
     
    349354    DEFINE_SETTING_S(TIME_DELTA_DEFAULT, NSCA_SECTION, "delay", "0"); 
    350355    DESCRIBE_SETTING(TIME_DELTA_DEFAULT, "TODO", "TODO"); 
    351      
     356 
    352357    DEFINE_SETTING_I(PAYLOAD_LENGTH, NSCA_SECTION, "payload length", 512); 
    353358    DESCRIBE_SETTING_ADVANCED(PAYLOAD_LENGTH, "PAYLOAD LENGTH", "Length of payload to/from the NSCA agent. This is a hard specific value so you have to \"configure\" (read recompile) your NSCA server to use the same value for it to work."); 
     
    355360    DEFINE_SETTING_I(READ_TIMEOUT, NSCA_SERVER_SECTION, GENERIC_KEY_SOCK_READ_TIMEOUT, 30); 
    356361    DESCRIBE_SETTING(READ_TIMEOUT, "SOCKET TIMEOUT", "Timeout when reading packets on incoming sockets. If the data has not arrived withint this time we will bail out."); 
     362 
     363  } 
     364 
     365  namespace scheduler { 
     366    DEFINE_PATH(SECTION, SCHEDULER_SECTION); 
     367    DESCRIBE_SETTING(SECTION, "SCHEDULER SECTION", "Section for the Scheduler module."); 
     368 
     369    DEFINE_PATH(SCHEDULES_SECTION, SCHEDULER_SECTION_SCH); 
     370    DESCRIBE_SETTING(SCHEDULES_SECTION, "SCHEDULES SECTION", "Section for defining schedules for the Scheduler module."); 
     371 
     372    DEFINE_PATH(DEFAULT_SCHEDULE_SECTION, SCHEDULER_SECTION_DEF); 
     373    DESCRIBE_SETTING(DEFAULT_SCHEDULE_SECTION, "DEFAULT SCHEDULER SECTION", "Default settings for all scheduled commands"); 
     374 
     375    DEFINE_SETTING_I(THREADS, SCHEDULER_SECTION, "debug threads", 1); 
     376    DESCRIBE_SETTING_ADVANCED(THREADS, "THREADS", "Number of threads to use int he thread pool (increase if you have many scheduled items)"); 
     377 
     378    DEFINE_SETTING_S(INTERVAL, SCHEDULER_SECTION_FAKE, "interval", "5m"); 
     379    DESCRIBE_SETTING(INTERVAL, "SCHEDULE INTERVAL", "Time in seconds between each check"); 
     380 
     381    DEFINE_SETTING_S(COMMAND, SCHEDULER_SECTION_FAKE, "command", "check_ok"); 
     382    DESCRIBE_SETTING(COMMAND, "SCHEDULE COMMAND", "Command to run"); 
     383 
     384    DEFINE_SETTING_S(CHANNEL, SCHEDULER_SECTION_FAKE, "channel", "NSCA"); 
     385    DESCRIBE_SETTING(CHANNEL, "SCHEDULE CHANNEL", "Channel to send results on"); 
     386 
     387    DEFINE_SETTING_S(REPORT_MODE, SCHEDULER_SECTION_FAKE, "report", "all"); 
     388    DESCRIBE_SETTING(REPORT_MODE, "REPORT MODE", "What to report to the server (any of the following: all, critical, warning, unknown, ok)"); 
     389 
     390    DEFINE_SETTING_S(INTERVAL_D, SCHEDULER_SECTION_DEF, "interval", "5m"); 
     391    DESCRIBE_SETTING(INTERVAL_D, "SCHEDULE INTERVAL", "Time in seconds between each check"); 
     392 
     393    DEFINE_SETTING_S(COMMAND_D, SCHEDULER_SECTION_DEF, "command", "check_ok"); 
     394    DESCRIBE_SETTING(COMMAND_D, "SCHEDULE COMMAND", "Command to run"); 
     395 
     396    DEFINE_SETTING_S(CHANNEL_D, SCHEDULER_SECTION_DEF, "channel", "NSCA"); 
     397    DESCRIBE_SETTING(CHANNEL_D, "SCHEDULE CHANNEL", "Channel to send results on"); 
     398 
     399    DEFINE_SETTING_S(REPORT_MODE_D, SCHEDULER_SECTION_DEF, "report", "all"); 
     400    DESCRIBE_SETTING(REPORT_MODE_D, "REPORT MODE", "What to report to the server (any of the following: all, critical, warning, unknown, ok)"); 
    357401 
    358402  } 
  • trunk/include/settings/settings_ini.hpp

    r216 r230  
    7878    /// @author mickem 
    7979    virtual bool has_real_key(SettingsCore::key_path_type key) { 
    80       return false; 
     80      return ini.GetValue(key.first.c_str(), key.second.c_str()) != NULL; 
    8181    } 
    8282    ////////////////////////////////////////////////////////////////////////// 
     
    115115        strEx::replace(comment, _T("\n"), _T(" ")); 
    116116        get_core()->get_logger()->quick_debug(_T("saving: ") + key.first + _T("//") + key.second); 
     117         
     118        ini.Delete(key.first.c_str(), key.second.c_str()); 
    117119        ini.SetValue(key.first.c_str(), key.second.c_str(), value.get_string().c_str(), comment.c_str()); 
    118120      } catch (KeyNotFoundException e) { 
    119         ini.SetValue(key.first.c_str(), key.second.c_str(), value.get_string().c_str()); 
     121        ini.SetValue(key.first.c_str(), key.second.c_str(), value.get_string().c_str(), _T("; Undocumented key")); 
    120122      } catch (SettingsException e) { 
    121123        get_core()->get_logger()->err(__FILEW__, __LINE__, std::wstring(_T("Failed to write key: ") + e.getError())); 
  • trunk/include/strEx.h

    r216 r230  
    366366  inline unsigned stoui_as_time(std::wstring time, unsigned int smallest_unit = 1000) { 
    367367    std::wstring::size_type p = time.find_first_of(_T("sSmMhHdDwW")); 
    368     unsigned int value = boost::lexical_cast<unsigned int>(time.c_str()); 
     368    std::wstring::size_type pend = time.find_first_not_of(_T("0123456789")); 
     369    unsigned int value = boost::lexical_cast<unsigned int>(pend==std::wstring::npos?time:time.substr(0,pend).c_str()); 
    369370    if (p == std::wstring::npos) 
    370371      return value * smallest_unit; 
  • trunk/modules/Scheduler/Scheduler.cpp

    r229 r230  
    2424#include <time.h> 
    2525#include <utils.h> 
     26#include <settings/macros.h> 
    2627 
    2728Scheduler gInstance; 
    2829 
     30bool Scheduler::loadModule(NSCAPI::moduleLoadMode mode) { 
     31  try { 
     32    SETTINGS_REG_PATH(scheduler::SECTION); 
     33    SETTINGS_REG_PATH(scheduler::DEFAULT_SCHEDULE_SECTION); 
     34    SETTINGS_REG_PATH(scheduler::SCHEDULES_SECTION); 
    2935 
    30 bool Scheduler::loadModule(NSCAPI::moduleLoadMode mode) { 
    31   if (mode == NSCAPI::normalStart) { 
    32     scheduler_.start(); 
     36    SETTINGS_REG_KEY_S(scheduler::INTERVAL_D); 
     37    SETTINGS_REG_KEY_S(scheduler::COMMAND_D); 
     38    SETTINGS_REG_KEY_S(scheduler::CHANNEL_D); 
     39    SETTINGS_REG_KEY_S(scheduler::REPORT_MODE_D); 
     40 
     41    SETTINGS_REG_KEY_I(scheduler::THREADS); 
     42  } catch (NSCModuleHelper::NSCMHExcpetion &e) { 
     43    NSC_LOG_ERROR_STD(_T("Failed to register command: ") + e.msg_); 
     44  } catch (...) { 
     45    NSC_LOG_ERROR_STD(_T("Failed to register command.")); 
    3346  } 
    34   add_schedule(_T("test 001")); 
    35   add_schedule(_T("test 002")); 
     47 
     48 
     49  try { 
     50 
     51    scheduler_.set_threads(SETTINGS_GET_INT(scheduler::THREADS)); 
     52 
     53    if (mode == NSCAPI::normalStart) { 
     54      scheduler_.start(); 
     55    } 
     56 
     57    bool found = false; 
     58    scheduler::target def = read_schedule(setting_keys::scheduler::DEFAULT_SCHEDULE_SECTION_PATH); 
     59    std::list<std::wstring> items = NSCModuleHelper::getSettingsSection(setting_keys::scheduler::SCHEDULES_SECTION_PATH); 
     60 
     61    for (std::list<std::wstring>::const_iterator cit = items.begin(); cit != items.end(); ++cit) { 
     62      found = true; 
     63      add_schedule(*cit, def); 
     64    } 
     65 
     66    if (!found) { 
     67      NSC_DEBUG_MSG_STD(_T("No scheduled commands found!")); 
     68      SETTINGS_REG_KEY_S(scheduler::INTERVAL); 
     69      SETTINGS_REG_KEY_S(scheduler::COMMAND); 
     70      SETTINGS_REG_KEY_S(scheduler::CHANNEL); 
     71      SETTINGS_REG_KEY_S(scheduler::REPORT_MODE); 
     72 
     73    } 
     74/* 
     75    add_schedule(_T("test: FIRST")); 
     76    for (int i=0;i<1000;i++) 
     77      add_schedule(_T("test: ") + to_wstring(i)); 
     78    add_schedule(_T("test: LAST")); 
     79    */ 
     80  } catch (NSCModuleHelper::NSCMHExcpetion &e) { 
     81    NSC_LOG_ERROR_STD(_T("Exception in module Scheduler: ") + e.msg_); 
     82    return false; 
     83  } catch (...) { 
     84    NSC_LOG_ERROR_STD(_T("Unknown Exception in module Scheduler!")); 
     85    return false; 
     86  } 
    3687  return true; 
    3788} 
    3889 
     90scheduler::target Scheduler::read_schedule(std::wstring path) { 
     91  scheduler::target item; 
     92  item.channel = NSCModuleHelper::getSettingsString(path, setting_keys::scheduler::CHANNEL, setting_keys::scheduler::CHANNEL_DEFAULT); 
     93  item.command = NSCModuleHelper::getSettingsString(path, setting_keys::scheduler::COMMAND, setting_keys::scheduler::COMMAND_PATH); 
     94  /* 
     95  std::wstring report = SETTINGS_GET_STRING(scheduler::REPORT_MODE); 
     96  item.report = parse_report_string(report); 
     97  */ 
     98  std::wstring duration = NSCModuleHelper::getSettingsString(path, setting_keys::scheduler::INTERVAL, setting_keys::scheduler::INTERVAL_DEFAULT); 
     99  item.duration = boost::posix_time::seconds(strEx::stoui_as_time(duration)); 
     100  return item; 
     101} 
     102scheduler::target Scheduler::read_schedule(std::wstring path, scheduler::target def) { 
     103  scheduler::target item; 
     104   
     105  item.channel = NSCModuleHelper::getSettingsString(path, setting_keys::scheduler::CHANNEL, def.channel); 
     106  item.command = NSCModuleHelper::getSettingsString(path, setting_keys::scheduler::COMMAND, def.command); 
     107  /* 
     108  std::wstring report = NSCModuleHelper::getSettingsString(path, setting_keys::scheduler::REPORT_MODE, def.report); 
     109  item.report = parse_report_string(report); 
     110  */ 
     111  std::wstring duration = NSCModuleHelper::getSettingsString(path, setting_keys::scheduler::INTERVAL, to_wstring(def.duration.total_seconds()) + _T("s")); 
     112  item.duration = boost::posix_time::seconds(strEx::stoui_as_time(duration)); 
     113  return item; 
     114} 
    39115 
    40 void Scheduler::add_schedule(std::wstring command) { 
    41   scheduler::target item; 
     116void Scheduler::add_schedule(std::wstring command, scheduler::target def) { 
     117  NSC_DEBUG_MSG_STD(_T("Adding scheduled command: ") + command); 
     118  scheduler::target item = read_schedule(setting_keys::scheduler::SCHEDULES_SECTION_PATH + _T("/") + command, def); 
     119 
     120//  std::wstring report = SETTINGS_GET_STRING(scheduler::REPORT_MODE); 
     121//  report_ = parse_report_string(report); 
     122 
    42123  item.command = command; 
    43   item.duration = boost::posix_time::time_duration(0,0,5); 
     124  item.set_duration(boost::posix_time::seconds(5)); 
     125  scheduler_.add_task(item); 
     126  /* 
    44127  std::wcout << _T("*** DURATION ") << item.duration << _T(" ***") << std::endl; 
    45   scheduler_.add_task(item); 
     128  */ 
    46129} 
    47130bool Scheduler::unloadModule() { 
  • trunk/modules/Scheduler/Scheduler.h

    r229 r230  
    3939 
    4040 
    41   void add_schedule(std::wstring command); 
     41  void add_schedule(std::wstring command, scheduler::target def); 
     42  scheduler::target read_schedule(std::wstring path, scheduler::target def); 
     43  scheduler::target read_schedule(std::wstring path); 
    4244 
    4345  std::wstring getModuleName() { 
  • trunk/modules/Scheduler/simple_scheduler.cpp

    r229 r230  
    1818    targets_.erase(it); 
    1919  } 
    20   target simple_scheduler::get_task(int id) { 
     20  boost::optional<target> simple_scheduler::get_task(int id) { 
    2121    boost::mutex::scoped_lock l(mutex_); 
    2222    target_list_type::iterator it = targets_.find(id); 
    23     if (it == targets_.end()) 
    24       return target::empty(); 
    25     return (*it).second; 
     23    if (it == targets_.end()) 
     24      return boost::optional<target>(); 
     25    return boost::optional<target>((*it).second); 
    2626  } 
    2727 
    2828  void simple_scheduler::start() { 
     29    running_ = true; 
    2930    if (!queue_.empty()) 
    3031      start_thread(); 
    3132  } 
    3233  void simple_scheduler::stop() { 
    33     if (thread_) 
    34       return; 
     34    running_ = false; 
     35    //if (!thread_) 
     36    //  return; 
    3537    stop_requested_ = true; 
    36     thread_->join(); 
     38    threads_.interrupt_all(); 
     39    threads_.join_all(); 
     40    /* 
     41    if (!threads.join_all(boost::posix_time::seconds(5))) { 
     42      std::wcout << _T("FAILED TO TERMINATE!!!") << std::endl; 
     43    } else { 
     44      std::wcout << _T("THREAD TERMINATED NICELY!") << std::endl; 
     45    } 
     46    */ 
    3747  } 
    3848 
    3949  void simple_scheduler::start_thread() { 
     50    if (!running_) 
     51      return; 
    4052    stop_requested_ = false; 
    41     thread_ = boost::shared_ptr<boost::thread>(new boost::thread(boost::bind(&simple_scheduler::thread_proc, this))); 
     53    int missing_threads = thread_count_ - threads_.size(); 
     54    if (missing_threads > 0 && missing_threads <= thread_count_) { 
     55      for (int i=0;i<missing_threads;i++) { 
     56        std::wcout << _T("***START_THREAD***") << std::endl; 
     57        threads_.create_thread(boost::bind(&simple_scheduler::thread_proc, this)); 
     58      } 
     59    } 
     60    //thread_ = boost::shared_ptr<boost::thread>(new boost::thread(boost::bind(&simple_scheduler::thread_proc, this))); 
    4261  } 
    4362 
    4463  void simple_scheduler::thread_proc() { 
    4564    int iteration = 0; 
    46     schedule_instance instance; 
     65    schedule_queue_type::value_type instance; 
    4766    while (!stop_requested_) { 
    48       { 
    49         boost::mutex::scoped_lock l(mutex_); 
    50         //std::wcout << _T("#### COUNT: ") << queue_.size() << _T(" ####") << std::endl; 
    51         if (queue_.empty()) 
     67      instance = queue_.pop(); 
     68      if (!instance) 
     69        return; 
     70 
     71      try { 
     72 
     73        boost::posix_time::time_duration off = now() - (*instance).time; 
     74        if (off.total_seconds() > 0) { 
     75          std::wcout << _T("MISSED IT!") << off.total_seconds() << std::endl; 
     76        } 
     77        boost::thread::sleep((*instance).time); 
     78      } catch (boost::thread_interrupted  &e) { 
     79        if (!queue_.push(*instance)) 
     80          std::wcout << _T("ERROR") << std::endl; 
     81        if (stop_requested_) 
    5282          return; 
    53         instance = queue_.top(); 
    54         queue_.pop(); 
    55       } 
    56       target item = get_task(instance.schedule_id); 
    57       //boost::posix_time::ptime delay = now() + instance.time; 
    58        
    59       try { 
    60         boost::thread::sleep(instance.time); 
     83        continue; 
    6184      } catch (...) { 
    62         std::wcout << _T("Excepting...") << std::endl; 
     85        if (!queue_.push(*instance)) 
     86          std::wcout << _T("ERROR") << std::endl; 
     87        std::wcout << _T("ERROR!!!") << std::endl; 
    6388        return; 
    6489      } 
    65       boost::posix_time::ptime ctime = now(); 
    66       execute(item); 
    67       reschedule(item,ctime); 
     90 
     91      boost::posix_time::ptime now_time = now(); 
     92      boost::optional<target> item = get_task((*instance).schedule_id); 
     93      if (item) { 
     94        try { 
     95          execute(*item); 
     96          reschedule(*item,now_time); 
     97        } catch (...) { 
     98          std::wcout << _T("UNKNOWN ERROR RUNING TASK: ") << std::endl; 
     99          reschedule(*item); 
     100        } 
     101      } else { 
     102        std::wcout << _T("Task not found: ") << (*instance).schedule_id << std::endl; 
     103      } 
    68104    } 
    69105  } 
    70106 
    71107  void simple_scheduler::reschedule(target item) { 
    72     reschedule(item, now()); 
     108    reschedule_wnext(item, now() + boost::posix_time::seconds(rand()%item.duration.total_seconds())); 
    73109  } 
    74110  void simple_scheduler::reschedule(target item, boost::posix_time::ptime now) { 
    75     boost::mutex::scoped_lock l(mutex_); 
     111    reschedule_wnext(item, now + item.duration); 
     112  } 
     113  void simple_scheduler::reschedule_wnext(target item, boost::posix_time::ptime next) { 
    76114    schedule_instance instance; 
    77115    instance.schedule_id = item.id; 
    78     instance.time = now + item.duration; 
    79     queue_.push(instance); 
    80     if (!thread_) 
    81       start_thread(); 
     116    instance.time = next; 
     117    if (!queue_.push(instance)) { 
     118      std::wcout << _T("ERROR") << std::endl; 
     119    } 
     120    start_thread(); 
    82121  } 
    83122  void simple_scheduler::execute(target item) { 
    84     std::wcout << _T("Running: ") << item.command << std::endl; 
     123    //std::wcout << _T("Running: ") << item.command << std::endl; 
    85124  } 
    86  
    87125 
    88126} 
  • trunk/modules/Scheduler/simple_scheduler.hpp

    r229 r230  
    88#include <boost/thread.hpp> 
    99#include <boost/date_time/local_time/local_time.hpp> 
     10#include <boost/optional.hpp> 
    1011 
    1112namespace scheduler { 
    1213 
     14  class task_not_found { 
     15    int id_; 
     16  public: 
     17    task_not_found(int id) : id_(id) {} 
     18    int get_id() {return id_; } 
     19  }; 
    1320  class target { 
    1421  public: 
     
    1825    std::wstring tag; 
    1926    boost::posix_time::time_duration duration; 
     27    std::wstring  channel; 
     28    //std::wstring duration; 
    2029 
    21     target() {} 
    22     target(const target &other) : id(other.id), command(other.command), duration(other.duration) {} 
     30 
     31    void set_duration(boost::posix_time::time_duration duration_) { 
     32      duration = duration_; 
     33      // TODO! 
     34    } 
     35 
     36    target() : duration(boost::posix_time::minutes(0)) 
     37    {} 
     38     
     39    target(const target &other) : id(other.id), command(other.command), duration(other.duration) {} 
    2340    target& operator=(target const& other) { 
    2441      command = other.command; 
     
    2744      return *this; 
    2845    } 
    29     static target empty() { 
    30       return target(); 
    31     } 
     46    ~target() {} 
    3247  }; 
    3348  struct schedule_instance { 
     
    3954  }; 
    4055 
     56  template<typename T> 
     57  class safe_schedule_queue { 
     58  public: 
     59    typedef boost::optional<T> value_type; 
     60  private: 
     61    typedef std::priority_queue<T> schedule_queue_type; 
     62    schedule_queue_type queue_; 
     63    boost::shared_mutex mutex_; 
     64  public: 
     65    bool empty(unsigned int timeout = 5) { 
     66      boost::shared_lock<boost::shared_mutex> lock(mutex_, boost::get_system_time() + boost::posix_time::seconds(5)); 
     67      if (!lock.owns_lock())  
     68        return false; 
     69      return queue_.empty(); 
     70    } 
     71 
     72    boost::optional<T> top(unsigned int timeout = 5) { 
     73      boost::shared_lock<boost::shared_mutex> lock(mutex_, boost::get_system_time() + boost::posix_time::seconds(5)); 
     74      if (!lock || queue_.empty()) 
     75        return boost::optional<T>(); 
     76      return boost::optional<T>(queue_.top()); 
     77    } 
     78 
     79    boost::optional<T> pop(unsigned int timeout = 5) { 
     80      boost::unique_lock<boost::shared_mutex> lock(mutex_, boost::get_system_time() + boost::posix_time::seconds(timeout)); 
     81      if (!lock || queue_.empty()) 
     82        return boost::optional<T>(); 
     83      boost::optional<T>  ret = queue_.top(); 
     84      queue_.pop(); 
     85      return ret; 
     86    } 
     87 
     88    bool push(T instance, unsigned int timeout = 5) { 
     89      boost::unique_lock<boost::shared_mutex> lock(mutex_, boost::get_system_time() + boost::posix_time::seconds(timeout)); 
     90      if (!lock) { 
     91        return false; 
     92      } 
     93      queue_.push(instance); 
     94      return true; 
     95    } 
     96  }; 
     97 
    4198  class simple_scheduler { 
    4299  private: 
    43100    typedef std::map<int,target> target_list_type; 
    44     typedef std::priority_queue<schedule_instance> schedule_queue_type; 
     101    typedef safe_schedule_queue<schedule_instance> schedule_queue_type; 
    45102    target_list_type targets_; 
    46103    unsigned int target_id_; 
    47104    schedule_queue_type queue_; 
     105    unsigned int thread_count_; 
    48106 
    49107 
    50108    // thread variables 
    51109    volatile bool stop_requested_; 
    52     boost::shared_ptr<boost::thread> thread_; 
     110    volatile bool running_; 
     111    boost::thread_group threads_; 
     112    //boost::shared_ptr<boost::thread> thread_; 
    53113    boost::mutex mutex_; 
    54114 
    55115  public: 
    56116 
    57     simple_scheduler() : target_id_(0) {} 
     117    simple_scheduler() : target_id_(0), stop_requested_(false), running_(false), thread_count_(10) {} 
    58118    ~simple_scheduler() {} 
    59119 
     
    61121    int add_task(target item); 
    62122    void remove_task(int id); 
    63     target get_task(int id); 
     123    boost::optional<target> get_task(int id); 
    64124     
    65125    void start(); 
    66126    void stop(); 
     127 
     128    void set_threads(int threads) { 
     129      thread_count_ = threads; 
     130      start_thread(); 
     131    } 
    67132 
    68133 
     
    72137    void reschedule(target item); 
    73138    void reschedule(target item, boost::posix_time::ptime now); 
     139    void reschedule_wnext(target item, boost::posix_time::ptime next); 
    74140    void execute(target item); 
    75141    void start_thread(); 
    76142 
    77     boost::posix_time::ptime now() { 
     143    inline boost::posix_time::ptime now() { 
    78144      return boost::get_system_time(); 
    79145    } 
  • trunk/service/CMakeLists.txt

    r219 r230  
    3333    settings_manager_impl.h 
    3434    simple_client.hpp 
     35    settings_client.hpp 
    3536     
    3637    commands.hpp 
  • trunk/service/NSCPlugin.cpp

    r220 r230  
    253253void NSCPlugin::unload() { 
    254254  if (!isLoaded()) 
    255     throw NSPluginException(module_, _T("Library is not loaded")); 
     255    return; 
    256256  bLoaded_ = false; 
    257257  if (!fUnLoadModule) 
  • trunk/service/NSClient++.cpp

    r224 r230  
    3737#include <NSCHelper.h> 
    3838#include "simple_client.hpp" 
     39#include "settings_client.hpp" 
    3940#include "service_manager.hpp" 
    4041 
     
    396397      client.start(); 
    397398      return 0; 
     399    } else if ( _wcsicmp( _T("settings"), argv[1]+1 ) == 0 ) { 
     400      nsclient::settings_client client(&mainClient); 
     401      g_bConsoleLog = true; 
     402      if (argc > 2) 
     403        client.parse(argv[2], argc-3, argv+3); 
     404      else 
     405        client.help(); 
     406      return 0; 
    398407    } else { 
    399408      std::wcerr << _T("Usage: -version, -about, -install, -uninstall, -start, -stop, -encrypt -settings") << std::endl; 
     
    491500        } else { 
    492501          std::wstring desc; 
     502          std::wstring name = file.string(); 
    493503          try { 
    494504            NSCPlugin plugin(modPath / file); 
     505            name = plugin.getModule(); 
    495506            plugin.load_dll(); 
    496507            plugin.load_plugin(mode); 
     
    505516            LOG_CRITICAL_STD(_T("Unknown Error loading: ") + file.string()); 
    506517          } 
    507           settings_manager::get_core()->register_key(MAIN_MODULES_SECTION, file.string(), Settings::SettingsCore::key_string, desc, desc, _T("disabled"), false); 
     518          settings_manager::get_core()->register_key(MAIN_MODULES_SECTION, name, Settings::SettingsCore::key_string, desc, desc, _T("disabled"), false); 
    508519        } 
    509520      } 
     
    643654 
    644655  if (enable_shared_session_) { 
    645     LOG_MESSAGE_STD(_T("Enabling shared session...")); 
     656    LOG_DEBUG_STD(_T("Enabling shared session...")); 
    646657    if (boot) { 
    647       LOG_MESSAGE_STD(_T("Starting shared session...")); 
     658      LOG_MESSAGE_STD(_T("shared session not ported yet!...")); 
    648659//      try { 
    649660//        shared_server_.reset(new nsclient_session::shared_server_session(this)); 
     
    662673//      } 
    663674    } else { 
    664       LOG_MESSAGE_STD(_T("Attaching to shared session...")); 
     675      LOG_MESSAGE_STD(_T("shared session not ported yet!...")); 
    665676//      try { 
    666677//        std::wstring id = _T("_attached_") + strEx::itos(GetCurrentProcessId()) + _T("_"); 
     
    10181029      try { 
    10191030        if (!(*it)->load_plugin(NSCAPI::normalStart)) { 
     1031          LOG_ERROR_CORE_STD(_T("Plugin refused to load: ") + (*it)->getModule()); 
    10201032          it = plugins_.erase(it); 
    1021           LOG_ERROR_CORE_STD(_T("Plugin refused to load: ") + (*it)->getModule()); 
    1022         } 
    1023         ++it; 
     1033        } else 
     1034          ++it; 
    10241035      } catch (NSPluginException e) { 
    10251036        it = plugins_.erase(it); 
     
    10731084    if (plugin->hasMessageHandler()) 
    10741085      messageHandlers_.insert(messageHandlers_.end(), plugin); 
    1075     settings_manager::get_core()->register_key(_T("/modules"), plugin->getFilename(), Settings::SettingsCore::key_string, plugin->getName(), plugin->getDescription(), _T(""), false); 
     1086    settings_manager::get_core()->register_key(_T("/modules"), plugin->getModule(), Settings::SettingsCore::key_string, plugin->getName(), plugin->getDescription(), _T(""), false); 
    10761087  } 
    10771088  return plugin; 
     
    12461257#ifdef WIN32 
    12471258  OutputDebugString(msg.c_str()); 
     1259#else 
     1260  std::wcout << _T("--BROKEN MESSAGE: ") << msg << _T("--") << std::endl; 
    12481261#endif 
    1249   std::wcout << msg << std::endl; 
    12501262} 
    12511263/** 
  • trunk/service/NSClient++.h

    r220 r230  
    201201 
    202202 
    203  
    204 private: 
    205   plugin_type addPlugin(plugin_type plugin); 
    206   void load_all_plugins(int mode); 
     203  public: 
     204    void load_all_plugins(int mode); 
     205 
     206 
     207  private: 
     208    plugin_type addPlugin(plugin_type plugin); 
    207209}; 
    208210 
Note: See TracChangeset for help on using the changeset viewer.