realtimescheduler.h

Go to the documentation of this file.
00001 //
00002 // Copyright (C) 2006 Institut fuer Telematik, Universitaet Karlsruhe (TH)
00003 //
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU General Public License
00006 // as published by the Free Software Foundation; either version 2
00007 // of the License, or (at your option) any later version.
00008 //
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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                 PACKET_APPTUN_DATA = 3
00052             } func;
00053             SOCKET fd;
00054             PacketBufferEntry(char* buf, uint32_t len) :
00055                     data(buf), length(len), addr(0), addrlen(0), func(PACKET_DATA), fd(0) {};
00056             PacketBufferEntry(char* buf, uint32_t len, sockaddr* ad, socklen_t al) :
00057                     data(buf), length(len), addr(ad), addrlen(al), func(PACKET_DATA), fd(0) {};
00058                 PacketBufferEntry(char* buf, uint32_t len, fdCommand fc, int _fd) :
00059                     data(buf), length(len), addr(0), addrlen(0), func(fc), fd(_fd) {};
00060             PacketBufferEntry(char* buf, uint32_t len, sockaddr* ad, socklen_t al,
00061                               fdCommand fc, int _fd) :
00062                     data(buf), length(len), addr(ad), addrlen(al), func(fc), fd(_fd) {};
00063     };
00064     typedef std::list<PacketBufferEntry> PacketBuffer;
00065 
00066 protected:
00067     // FD set with all file descriptors
00068     fd_set all_fds;
00069     SOCKET maxfd;
00070 
00071     // Buffer, module and FD for network communication
00072     SOCKET netw_fd;
00073     SOCKET apptun_fd;
00074     cModule *module;
00075     cMessage *notificationMsg;
00076     PacketBuffer *packetBuffer;
00077     size_t buffersize;
00078 
00079     // ... for realworldapp communication
00080     cModule *appModule;
00081     cMessage *appNotificationMsg;
00082     PacketBuffer *appPacketBuffer;
00083     size_t appBuffersize;
00084     int appConnectionLimit;
00085 
00086     SOCKET additional_fd; // Can be used by concrete implementations of this class
00087 
00088     // state
00089     timeval baseTime;
00090 
00093     virtual int initializeNetwork() = 0;
00094 
00099     virtual void additionalFD() {};
00100 
00107     virtual bool receiveWithTimeout(long usec);
00108 
00115     virtual int receiveUntil(const timeval& targetTime);
00116 
00117 public:
00121     RealtimeScheduler();
00122 
00126     virtual ~RealtimeScheduler();
00127 
00131     virtual void startRun();
00132 
00136     virtual void endRun();
00137 
00141     virtual void executionResumed();
00142 
00154     virtual void setInterfaceModule(cModule *module,
00155                                     cMessage *notificationMsg,
00156                                     PacketBuffer* buffer,
00157                                     int mtu,
00158                                     bool isApp = false);
00159 
00163     virtual cMessage *getNextEvent();
00164 
00171     void sendNotificationMsg(cMessage* msg, cModule* mod);
00172 
00186     virtual ssize_t sendBytes(const char *buf,
00187                               size_t numBytes,
00188                               sockaddr* addr = 0,
00189                               socklen_t addrlen = 0,
00190                               bool isApp = false,
00191                               SOCKET fd = INVALID_SOCKET);
00192 
00196     void closeAppSocket(SOCKET fd);
00197 
00203     virtual SOCKET getAppTunFd() { return apptun_fd; };
00204 
00205 };
00206 
00207 #endif
00208 
Generated on Wed May 26 16:21:15 2010 for OverSim by  doxygen 1.6.3