00001 /* 00002 Copyright 2007, 2008, 2009, 2010, 2011 Instituto de Sistemas e Robotica, Instituto Superior Tecnico 00003 00004 This file is part of MeRMaID. 00005 00006 MeRMaID is free software: you can redistribute it and/or modify 00007 it under the terms of the GNU Lesser General Public License as published by 00008 the Free Software Foundation, either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 MeRMaID is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public License 00017 along with MeRMaID. If not, see <http://www.gnu.org/licenses/>. 00018 */ 00019 00020 00021 00022 /** 00023 * @Filename ActiveObject.hpp 00024 * @Description ActiveObject declaration 00025 * @Status Work in Progress 00026 * @Version $Id: ActiveObject.hpp 1 2011-03-04 18:13:18Z jreis $ 00027 * @Maintainer Marco Barbosa 00028 */ 00029 00030 #ifndef __ACTIVEOBJECT_ACTIVEOBJECT_H 00031 #define __ACTIVEOBJECT_ACTIVEOBJECT_H 00032 00033 #include "ActiveObjectManager.hpp" 00034 #include "ActiveObjectState.hpp" 00035 #include "Task.hpp" 00036 #include "TaskScheduler.hpp" 00037 00038 #include <CommunicationGateway.hpp> 00039 00040 00041 #include <string> 00042 00043 namespace mermaid 00044 { 00045 namespace support 00046 { 00047 namespace activeobject 00048 { 00049 00050 using mermaid::support::communication::CommunicationGateway; 00051 using boost::shared_ptr; 00052 00053 /** 00054 * @Class ActiveObject ActiveObject.hpp "ActiveObject.hpp" 00055 * @Description ActiveObject interface 00056 * @Author Marco Barbosa + Nelson Ramos 00057 */ 00058 class ActiveObject 00059 { 00060 00061 public: 00062 00063 friend class ActiveObjectManager; 00064 00065 /** 00066 * @Description Destructor. 00067 * @Author Marco Barbosa + Nelson Ramos 00068 */ 00069 virtual ~ActiveObject(); 00070 00071 00072 /** 00073 * @Description Getter for the current state of the ActiveObject. 00074 * @Returns ActiveObjectState representing the current state of the ActiveObject. 00075 * @Author Marco Barbosa + Nelson Ramos 00076 */ 00077 ActiveObjectState getState(); 00078 00079 /** 00080 * @Description Gets a string representation of the current ActiveObject's state. 00081 * @Returns string of the current state. 00082 * @Author Marco Barbosa + Nelson Ramos 00083 */ 00084 std::string getStateString(); 00085 00086 /** 00087 * @Description Helper function that translates a given ActiveObjectState to a string. 00088 * @Argument state The state for which a string representation is needed. 00089 * @Returns string of the given state. 00090 * @Author Marco Barbosa + Nelson Ramos 00091 */ 00092 static std::string getStateString (ActiveObjectState state); 00093 00094 00095 /** 00096 * @Description This method starts the ActiveObject. 00097 * @Author Marco Barbosa + Nelson Ramos 00098 */ 00099 virtual void start() = 0; 00100 00101 /** 00102 * @Description This method stops the ActiveObject. 00103 * @Author Marco Barbosa + Nelson Ramos 00104 */ 00105 virtual void stop() = 0; 00106 00107 /** 00108 * @Description Getter for the communication gateway. 00109 * @Description This methd should only be used in the execution context of the ActiveObject 00110 * @Author Marco Barbosa 00111 */ 00112 shared_ptr<CommunicationGateway> getCommunicationGateway(); 00113 00114 //mermaid internal stuff 00115 00116 /** 00117 * @Description This method adds a task to be executed by the ActiveObject. 00118 * @Description It should only be called from OUTSIDE the context of an ActiveObject. Calling it in the context of an ActiveObject will block the ActiveObject. 00119 * @Author Marco Barbosa + Nelson Ramos 00120 */ 00121 virtual void addTask (shared_ptr<Task> t); 00122 00123 00124 protected: 00125 00126 /** 00127 * @Description Default constructor. 00128 * @Author Marco Barbosa + Nelson Ramos 00129 */ 00130 ActiveObject (ActiveObjectManager * aom); 00131 00132 /** 00133 * @Description Setter for the current state of the ActiveObject. 00134 * @Argument s State to which the ActiveObject should be set. 00135 * @Author Marco Barbosa + Nelson Ramos 00136 */ 00137 void setState (ActiveObjectState s); 00138 00139 //! Reference to the TaskScheduler used by this ActiveObject. 00140 shared_ptr<TaskScheduler> taskScheduler_; 00141 00142 //! Reference to the ActiveObjectManager instance. 00143 ActiveObjectManager * aoManager_; 00144 00145 private: 00146 00147 shared_ptr<CommunicationGateway> commGateway_; //!Reference to the CommunicationGateway used by this ActiveObject. 00148 00149 ActiveObjectState state_; //! Current ActiveObject's state. 00150 00151 }; // ActiveObject 00152 } // namespace activeobject 00153 } // namespace support 00154 } // namespace mermaid 00155 00156 00157 #endif // __ACTIVEOBJECT_ACTIVEOBJECT_H