ActiveObject.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "config.h"
00032
00033 #include "ActiveObject.hpp"
00034
00035 #include <CommunicationGateway.hpp>
00036 #include <Exception.hpp>
00037
00038 #include <iostream>
00039
00040 using namespace mermaid::support::activeobject;
00041 using mermaid::support::errorhandling::Exception;
00042 using boost::shared_ptr;
00043
00044 ActiveObject::ActiveObject (ActiveObjectManager * aom)
00045 {
00046 state_ = INITIALIZING;
00047
00048 aoManager_ = aom;
00049 taskScheduler_ = shared_ptr<TaskScheduler> (new TaskScheduler());
00050
00051 commGateway_ = shared_ptr<CommunicationGateway> (new CommunicationGateway());
00052
00053 state_ = INITIALIZED;
00054 };
00055
00056
00057 ActiveObject::~ActiveObject()
00058 {
00059
00060 };
00061
00062 ActiveObjectState ActiveObject::getState()
00063 {
00064 return state_;
00065 };
00066
00067 std::string ActiveObject::getStateString()
00068 {
00069 return getStateString (state_);
00070 };
00071
00072 std::string ActiveObject::getStateString (ActiveObjectState state)
00073 {
00074
00075 if (state == INITIALIZING) {
00076 return "INITIALIZING";
00077 }
00078 else if (state == INITIALIZED) {
00079 return "INITIALIZED";
00080 }
00081 else if (state == STOPPING) {
00082 return "STOPPING";
00083 }
00084 else if (state == STOPPED) {
00085 return "STOPPED";
00086 }
00087 else if (state == PAUSING) {
00088 return "PAUSING";
00089 }
00090 else if (state == PAUSED) {
00091 return "PAUSED";
00092 }
00093 else if (state == RUNNING) {
00094 return "RUNNING";
00095 }
00096 else {
00097 return "unknown";
00098 }
00099
00100 };
00101
00102 void ActiveObject::setState (ActiveObjectState s)
00103 {
00104 if (state_ != s) {
00105 ActiveObjectState previousState = state_;
00106 state_ = s;
00107 aoManager_->notifyActiveObjectStateChange (this, previousState);
00108 }
00109 };
00110
00111
00112 void ActiveObject::addTask (shared_ptr<Task> t)
00113 {
00114
00115 if (!taskScheduler_) {
00116 throw new Exception ("ActiveObject::addTask : no available task scheduler");
00117 }
00118
00119 taskScheduler_->addTask (t);
00120 };
00121
00122
00123 shared_ptr<CommunicationGateway> ActiveObject::getCommunicationGateway()
00124 {
00125 return commGateway_;
00126 };