📄 application_layer.hpp
字号:
#ifndef APPLICATION_LAYER_H #define APPLICATION_LAYER_H #include <boost/shared_ptr.hpp> #include "communication_layer.hpp" class ApplicationLayer : public CommunicationLayer { friend class AppEpochEvent; public: typedef boost::shared_ptr<ApplicationLayer> ApplicationLayerPtr; virtual ~ApplicationLayer(); virtual ApplicationLayerPtr thisApplicationLayer() = 0; void start(const SimTime& startTime); void stop(const SimTime& stopTime); bool recvFromLayer(CommunicationLayer::Directions direction, PacketPtr packet, t_uint sendingLayerIdx); inline CommunicationLayer::Types getLayerType() const; protected: ApplicationLayer(NodePtr node); virtual bool handleRecvdPacket(PacketPtr packet, t_uint sendingLayerIdx) = 0; virtual void startHandler() = 0; virtual void stopHandler() = 0; bool m_isRunning; private: }; typedef boost::shared_ptr<ApplicationLayer> ApplicationLayerPtr; // Inline Functions inline CommunicationLayer::Types ApplicationLayer::getLayerType() const { return CommunicationLayer::Types_Application; } // Overloaded Operators // Event Subclasses class AppEpochEvent : public Event { public: typedef boost::shared_ptr<AppEpochEvent> AppEpochEventPtr; enum Epochs { Epochs_Start, Epochs_Stop }; static inline AppEpochEventPtr create(Epochs epochType, ApplicationLayerPtr appLayer) { AppEpochEventPtr p(new AppEpochEvent(epochType, appLayer)); return p; } void execute() { switch(m_epochType) { case Epochs_Start: m_appLayer->m_isRunning = true; m_appLayer->startHandler(); break; case Epochs_Stop: m_appLayer->stopHandler(); m_appLayer->m_isRunning = false; break; default: assert(0); } } protected: AppEpochEvent(Epochs epochType, ApplicationLayerPtr appLayer) : Event() { m_epochType = epochType; m_appLayer = appLayer; } private: Epochs m_epochType; ApplicationLayerPtr m_appLayer; }; typedef boost::shared_ptr<AppEpochEvent> AppEpochEventPtr; #endif // APPLICATION_LAYER_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -