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             } 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     // FD set with all file descriptors
00067     fd_set all_fds;
00068     SOCKET maxfd;
00069 
00070     // Buffer, module and FD for network communication
00071     SOCKET netw_fd;
00072     cModule *module;
00073     cMessage *notificationMsg;
00074     PacketBuffer *packetBuffer;
00075     size_t buffersize;
00076 
00077     // ... for realworldapp communication
00078     cModule *appModule;
00079     cMessage *appNotificationMsg;
00080     PacketBuffer *appPacketBuffer;
00081     size_t appBuffersize;
00082     int appConnectionLimit;
00083 
00084     SOCKET additional_fd; // Can be used by concrete implementations of this class
00085 
00086     // state
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 

Generated on Wed Mar 25 16:32:49 2009 for OverSim by  doxygen 1.5.5