Changeset 1417:af5cb44c12fc


Ignore:
Timestamp:
11/22/09 16:42:53 (2 years ago)
Author:
niam
Branch:
default
Message:

pc::execution::scheduler: work with const-referenced objects

Location:
sources
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • sources/examples/pc_job/test.cc

    r1415 r1417  
    4949        const int amount = 10; 
    5050 
    51         execution::thread periodic(::job0, (void *)"periodic", execution::ON_DESTRUCTION_STOP); 
    52         execution::thread oneshot0(::job0, (void *)"oneshot", execution::ON_DESTRUCTION_STOP); 
    53         execution::process oneshot1(::job0, (void *)"oneshot", execution::ON_DESTRUCTION_STOP); 
    5451        execution::scheduler scheduler; 
    5552 
    56         unsigned long pID = scheduler.schedule(&periodic, 1000, true); 
    57         scheduler.schedule(&oneshot0, 2000); 
    58         scheduler.schedule(&oneshot1, 3000); 
     53        unsigned long pID = scheduler.schedule(execution::thread(::job0, (void *)"periodic", execution::ON_DESTRUCTION_STOP), 1000, true); 
     54        scheduler.schedule(execution::thread(::job0, (void *)"oneshot thread", execution::ON_DESTRUCTION_STOP), 2000); 
     55        scheduler.schedule(execution::process(::job0, (void *)"oneshot process", execution::ON_DESTRUCTION_STOP), 3000); 
    5956 
    6057        execution::manager manager; 
     
    9087            cout << "Job #"<< pos[i] << " is " << (manager.isRunning(pos[i])?"running":"not running") << endl; 
    9188 
    92         pID = scheduler.schedule(&periodic, 100, true); 
     89        pID = scheduler.schedule(execution::thread(::job0, (void *)"periodic", execution::ON_DESTRUCTION_STOP), 100, true); 
    9390        cout << tools::time::millinow() << endl; 
    9491        tools::os::sleep(2); 
  • sources/include/libdodo/pcExecutionJob.h

    r1415 r1417  
    3939        namespace execution { 
    4040            class manager; 
     41            class scheduler; 
    4142 
    4243            /** 
     
    6263            class job { 
    6364                friend class manager; 
     65                friend class scheduler; 
    6466 
    6567              public: 
  • sources/include/libdodo/pcExecutionManagerEx.h

    r1415 r1417  
    5151#define PCEXECUTIONMANAGEREX_NOTFOUND_STR    "Job was not found" 
    5252#define PCEXECUTIONMANAGEREX_UNKNOWNJOB_STR  "Unknown type of job" 
     53 
    5354            /** 
    5455             * ID of function where exception was thrown 
  • sources/include/libdodo/pcExecutionScheduler.h

    r1410 r1417  
    7272                 * @param repeat defines if job should be rescheduled again 
    7373                 */ 
    74                 unsigned long schedule(execution::job *job, 
     74                unsigned long schedule(const execution::job &job, 
    7575                                       unsigned long timeout, 
    7676                                       bool repeat = false); 
  • sources/include/libdodo/pcExecutionSchedulerEx.h

    r1410 r1417  
    3939        namespace execution { 
    4040            /** 
     41             * libdodo defined errors 
     42             */ 
     43            enum schedulerExR { 
     44                SCHEDULEREX_UNKNOWNJOB, 
     45            }; 
     46 
     47            /** 
     48             * libdodo defined errors explanation 
     49             */ 
     50#define PCEXECUTIONSCHEDULEREX_UNKNOWNJOB_STR  "Unknown type of job" 
     51 
     52            /** 
    4153             * ID of function where exception was thrown 
    4254             */ 
     
    4456                SCHEDULEREX___MANAGER__CONSTRUCTOR, 
    4557                SCHEDULEREX_CONSTRUCTOR, 
     58                SCHEDULEREX_SCHEDULE, 
    4659            }; 
    4760        }; 
  • sources/src/pcExecutionManager.cc

    r1415 r1417  
    8181 
    8282        default: 
    83             throw exception::basic(exception::MODULE_PCEXECUTIONMANAGER, MANAGEREX_RUN, exception::ERRNO_LIBDODO, MANAGEREX_UNKNOWNJOB, PCEXECUTIONMANAGEREX_UNKNOWNJOB_STR, __LINE__, __FILE__); 
     83            throw exception::basic(exception::MODULE_PCEXECUTIONMANAGER, MANAGEREX_ADD, exception::ERRNO_LIBDODO, MANAGEREX_UNKNOWNJOB, PCEXECUTIONMANAGEREX_UNKNOWNJOB_STR, __LINE__, __FILE__); 
    8484    } 
    8585 
  • sources/src/pcExecutionScheduler.cc

    r1410 r1417  
    7777#include <libdodo/pcExecutionSchedulerEx.h> 
    7878#include <libdodo/pcExecutionJob.h> 
     79#include <libdodo/pcExecutionThread.h> 
     80#include <libdodo/pcExecutionProcess.h> 
    7981#include <libdodo/types.h> 
    8082#include <libdodo/pcSyncThread.h> 
     
    249251 
    250252unsigned long 
    251 scheduler::schedule(execution::job *job, 
     253scheduler::schedule(const execution::job &job, 
    252254                    unsigned long timeout, 
    253255                    bool repeat) 
     
    255257    pc::sync::stack tg(keeper); 
    256258 
    257     __job__ j = {job, timeout, tools::time::millinow(), repeat}; 
     259    execution::job *_job; 
     260 
     261    execution::job *orig = const_cast<execution::job *>(&job); 
     262 
     263    switch (job.type) { 
     264        case execution::job::TYPE_PROCESS: 
     265            _job = new process(*dynamic_cast<process *>(orig)); 
     266 
     267            break; 
     268 
     269        case execution::job::TYPE_THREAD: 
     270            _job = new thread(*dynamic_cast<thread *>(orig)); 
     271 
     272            break; 
     273 
     274        default: 
     275            throw exception::basic(exception::MODULE_PCEXECUTIONSCHEDULER, SCHEDULEREX_SCHEDULE, exception::ERRNO_LIBDODO, SCHEDULEREX_UNKNOWNJOB, PCEXECUTIONSCHEDULEREX_UNKNOWNJOB_STR, __LINE__, __FILE__); 
     276    } 
     277 
     278    __job__ j = {_job, timeout, tools::time::millinow(), repeat}; 
    258279 
    259280    handles.insert(std::make_pair(counter, j)); 
Note: See TracChangeset for help on using the changeset viewer.