00001 00002 #ifndef APPLICATION_LAYER_H 00003 #define APPLICATION_LAYER_H 00004 00005 #include <boost/shared_ptr.hpp> 00006 00007 #include "communication_layer.hpp" 00008 00014 class ApplicationLayer : public CommunicationLayer { 00015 friend class AppEpochEvent; 00016 public: 00018 typedef boost::shared_ptr<ApplicationLayer> ApplicationLayerPtr; 00019 00023 virtual ~ApplicationLayer(); 00024 00031 virtual ApplicationLayerPtr thisApplicationLayer() = 0; 00032 00037 void start(const SimTime& startTime); 00038 00043 void stop(const SimTime& stopTime); 00044 00054 bool recvFromLayer(CommunicationLayer::Directions direction, 00055 PacketPtr packet, t_uint sendingLayerIdx); 00056 00061 inline CommunicationLayer::Types getLayerType() const; 00062 00063 protected: 00064 00066 ApplicationLayer(NodePtr node); 00067 00076 virtual bool handleRecvdPacket(PacketPtr packet, 00077 t_uint sendingLayerIdx) = 0; 00078 00082 virtual void startHandler() = 0; 00083 00087 virtual void stopHandler() = 0; 00088 00092 bool m_isRunning; 00093 00094 private: 00095 00096 }; 00097 typedef boost::shared_ptr<ApplicationLayer> ApplicationLayerPtr; 00098 00100 // Inline Functions 00102 00103 inline CommunicationLayer::Types ApplicationLayer::getLayerType() const 00104 { 00105 return CommunicationLayer::Types_Application; 00106 } 00107 00109 // Overloaded Operators 00111 00113 // Event Subclasses 00115 00122 class AppEpochEvent : public Event { 00123 public: 00125 typedef boost::shared_ptr<AppEpochEvent> AppEpochEventPtr; 00126 00131 enum Epochs { 00132 Epochs_Start, 00133 Epochs_Stop 00134 }; 00135 00140 static inline AppEpochEventPtr create(Epochs epochType, 00141 ApplicationLayerPtr appLayer) 00142 { 00143 AppEpochEventPtr p(new AppEpochEvent(epochType, appLayer)); 00144 return p; 00145 } 00146 00147 void execute() 00148 { 00149 switch(m_epochType) { 00150 case Epochs_Start: 00151 m_appLayer->m_isRunning = true; 00152 m_appLayer->startHandler(); 00153 break; 00154 case Epochs_Stop: 00155 m_appLayer->stopHandler(); 00156 m_appLayer->m_isRunning = false; 00157 break; 00158 default: 00159 assert(0); 00160 } 00161 } 00162 00163 protected: 00164 00166 AppEpochEvent(Epochs epochType, ApplicationLayerPtr appLayer) 00167 : Event() 00168 { 00169 m_epochType = epochType; 00170 m_appLayer = appLayer; 00171 } 00172 00173 private: 00174 00175 Epochs m_epochType; 00176 ApplicationLayerPtr m_appLayer; 00177 00178 }; 00179 typedef boost::shared_ptr<AppEpochEvent> AppEpochEventPtr; 00180 00181 #endif // APPLICATION_LAYER_H 00182