00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00024 #ifndef __REALTIMESCHEDULER_H__
00025 #define __REALTIMESCHEDULER_H__
00026
00027 #define WANT_WINSOCK2
00028 #include <platdep/sockets.h>
00029 #include <omnetpp.h>
00030 #include <list>
00031 #include <climits>
00032
00038 class RealtimeScheduler : public cScheduler
00039 {
00040 public:
00041 class PacketBufferEntry {
00042 public:
00043 char* data;
00044 uint32_t length;
00045 sockaddr* addr;
00046 socklen_t addrlen;
00047 enum fdCommand {
00048 PACKET_DATA = 0,
00049 PACKET_FD_NEW = 1,
00050 PACKET_FD_CLOSE = 2
00051 } func;
00052 SOCKET fd;
00053 PacketBufferEntry(char* buf, uint32_t len) :
00054 data(buf), length(len), addr(0), addrlen(0), func(PACKET_DATA), fd(0) {};
00055 PacketBufferEntry(char* buf, uint32_t len, sockaddr* ad, socklen_t al) :
00056 data(buf), length(len), addr(ad), addrlen(al), func(PACKET_DATA), fd(0) {};
00057 PacketBufferEntry(char* buf, uint32_t len, fdCommand fc, int _fd) :
00058 data(buf), length(len), addr(0), addrlen(0), func(fc), fd(_fd) {};
00059 PacketBufferEntry(char* buf, uint32_t len, sockaddr* ad, socklen_t al,
00060 fdCommand fc, int _fd) :
00061 data(buf), length(len), addr(ad), addrlen(al), func(fc), fd(_fd) {};
00062 };
00063 typedef std::list<PacketBufferEntry> PacketBuffer;
00064
00065 protected:
00066
00067 fd_set all_fds;
00068 SOCKET maxfd;
00069
00070
00071 SOCKET netw_fd;
00072 cModule *module;
00073 cMessage *notificationMsg;
00074 PacketBuffer *packetBuffer;
00075 size_t buffersize;
00076
00077
00078 cModule *appModule;
00079 cMessage *appNotificationMsg;
00080 PacketBuffer *appPacketBuffer;
00081 size_t appBuffersize;
00082 int appConnectionLimit;
00083
00084 SOCKET additional_fd;
00085
00086
00087 timeval baseTime;
00088
00091 virtual int initializeNetwork() = 0;
00092
00097 virtual void additionalFD() {};
00098
00105 virtual bool receiveWithTimeout(long usec);
00106
00113 virtual int receiveUntil(const timeval& targetTime);
00114
00115 public:
00119 RealtimeScheduler();
00120
00124 virtual ~RealtimeScheduler();
00125
00129 virtual void startRun();
00130
00134 virtual void endRun();
00135
00139 virtual void executionResumed();
00140
00152 virtual void setInterfaceModule(cModule *module,
00153 cMessage *notificationMsg,
00154 PacketBuffer* buffer,
00155 int mtu,
00156 bool isApp = false);
00157
00161 virtual cMessage *getNextEvent();
00162
00169 void sendNotificationMsg(cMessage* msg, cModule* mod);
00170
00184 virtual ssize_t sendBytes(const char *buf,
00185 size_t numBytes,
00186 sockaddr* addr = 0,
00187 socklen_t addrlen = 0,
00188 bool isApp = false,
00189 SOCKET fd = INVALID_SOCKET);
00190
00194 void closeAppSocket(SOCKET fd);
00195
00196 };
00197
00198 #endif
00199