- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# /Users/fpy/titan-1-5-MBARI/Mers/Interfaces/TimedExecutionInterface.cpp

    00001
    00002 //
    00003 // Copyright (c) 2004           Model-based Embedded and Robotic Systems Group
    00004 // All Rights Reserved          Massachusetts Institute of Technology
    00005 //
    00006 // This software is provided as is. Model-based Embedded and Robotic Systems
    00007 // (MERS) group does not assume any responsibility.
    00008 //
    00009 // Organization:        Model-based Embedded and Robotic Systems Group
    00010 //                                      Massachusetts Institute of Technology
    00011 //
    00013
    00014 #include "TimedExecutionInterface.h"
    00015
    00016 #include "TimedTask.h"
    00017 #include "TimedTaskFactory.h"
    00018
    00020
    00021 using namespace Mers::Interfaces;
    00022 using Mers::Utils::Lang::String;
    00023 using Mers::Utils::Lang::Time;
    00024 using Mers::Utils::Containers::SharedPointer;
    00025 using std::vector;
    00026 using std::string;
    00027 using std::map;
    00028
    00030
    00031 TimedExecutionInterface::TimedExecutionInterface( TimedTaskFactory *pTimedTaskFactory )
    00032         : ExecutionInterfaceBase( pTimedTaskFactory ), mTimedTasks()
    00033 {
    00034         mTimedTaskFactory = pTimedTaskFactory;
    00035         mTimedTaskFactory->addReference();
    00036 }
    00037
    00039
    00040 TimedExecutionInterface::~TimedExecutionInterface()
    00041 {
    00042         mTimedTaskFactory->removeReference();
    00043 }
    00044
    00046
    00047 ExecutionInterfaceBase::TaskIdentifier
    00048 TimedExecutionInterface::createTask( const char * taskName )
    00049 {
    00050         SharedPointer< TimedTask > task = mTimedTaskFactory->createTask(taskName);
    00051         map<TaskIdentifier, TimedTask *>::value_type entry(task, task);
    00052         mTimedTasks.insert(entry);
    00053         return task;
    00054 }
    00055
    00057
    00058 ExecutionInterfaceBase::TaskIdentifier
    00059 TimedExecutionInterface::createTask( const char * taskName,
    00060         vector<string *> const &parameters )
    00061 {
    00062         SharedPointer< TimedTask > task =
    00063                 mTimedTaskFactory->createTask(taskName, parameters);
    00064         map<TaskIdentifier, TimedTask *>::value_type entry(task, task);
    00065         mTimedTasks.insert(entry);
    00066         return task;
    00067 }
    00068
    00070
    00071 ExecutionInterfaceBase::TaskIdentifier
    00072 TimedExecutionInterface::createTask( const char * taskName,
    00073         Time const & tStart, Time const & duration )
    00074 {
    00075         SharedPointer< TimedTask > task =
    00076                 mTimedTaskFactory->createTask(taskName, tStart, duration);
    00077         map<TaskIdentifier, TimedTask *>::value_type entry(task, task);
    00078         mTimedTasks.insert(entry);
    00079         return task;
    00080 }
    00081
    00083
    00084 ExecutionInterfaceBase::TaskIdentifier
    00085 TimedExecutionInterface::createTask( const char * taskName,
    00086         vector<string *> const &parameters,
    00087         Time const & tStart, Time const & duration )
    00088 {
    00089         SharedPointer< TimedTask > task =
    00090                 mTimedTaskFactory->createTask(taskName, parameters, tStart, duration);
    00091         map<TaskIdentifier, TimedTask *>::value_type entry(task, task);
    00092         mTimedTasks.insert(entry);
    00093         return task;
    00094 }
    00095
    00097
    00098 void TimedExecutionInterface::deleteTask(TaskIdentifier taskID)
    00099 {
    00100         map<TaskIdentifier, TimedTask *>::iterator iMap = mTimedTasks.find(taskID);
    00101         if(iMap != mTimedTasks.end()) {
    00102                 mTimedTasks.erase(iMap);
    00103         }
    00104 }
    00105
    00107
    00108 void TimedExecutionInterface::setTaskFactory(TimedTaskFactory * tFactory)
    00109 {
    00110         if(tFactory != NULL) {
    00111                 ExecutionInterfaceBase::setTaskFactory(tFactory);
    00112                 tFactory->addReference();
    00113                 mTimedTaskFactory->removeReference();
    00114                 mTimedTaskFactory = tFactory;
    00115         }
    00116 }
    00117
    00119
    00120 TimedTaskFactory * TimedExecutionInterface::getTaskFactory()
    00121 {
    00122         return mTimedTaskFactory;
    00123 }
    00124
    00126
    00127 TimedTask * TimedExecutionInterface::getTask(TaskIdentifier task)
    00128 {
    00129         map<TaskIdentifier, TimedTask *>::iterator iMap = mTimedTasks.find(task);
    00130         if(iMap != mTimedTasks.end()) {
    00131                 return (*iMap).second;
    00132         } else {
    00133                 return NULL;
    00134         }
    00135 }
    00136
    00138