Changeset 2490 for trunk/MagicSoft/Mars/mbase
- Timestamp:
- 11/10/03 11:14:35 (21 years ago)
- Location:
- trunk/MagicSoft/Mars/mbase
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mbase/MEvtLoop.cc
r2459 r2490 96 96 using namespace std; 97 97 98 99 //!100 //! Maybe we can add a static parameter list to MEvtLoop101 //! Also we can derive MEvtLoop from MTaskList to have a static tasklist, too102 //!103 104 TList *gListOfPrimitives; // forward declaration in MParContainer.h105 106 98 // -------------------------------------------------------------------------- 107 99 // … … 372 364 if (fProgress && fNumEvents>0) 373 365 fProgress->SetPosition((Double_t)num/fNumEvents); 374 375 366 376 367 // FIXME: This is a workaround, because TApplication::Run is not -
trunk/MagicSoft/Mars/mbase/MEvtLoop.h
r2438 r2490 85 85 }; 86 86 87 // FIXME: Move as (persistent) static data member to MParContainer88 R__EXTERN TList *gListOfPrimitives; // instantiation in MEvtLoop89 90 87 #endif -
trunk/MagicSoft/Mars/mbase/MGGroupFrame.h
r2015 r2490 14 14 class MGGroupFrame : public TGGroupFrame, public TGWidget 15 15 { 16 MGTask 16 MGTask *fTask; 17 17 MGList *fList; 18 18 -
trunk/MagicSoft/Mars/mbase/MParContainer.cc
r2470 r2490 51 51 #include "MLogManip.h" 52 52 53 #ifndef __COSY__54 #include "MEvtLoop.h" // gListOfPrimitives55 #else56 53 TList *gListOfPrimitives; // forard declaration in MParContainer.h 57 #endif58 54 59 55 #undef DEBUG -
trunk/MagicSoft/Mars/mbase/MParContainer.h
r2470 r2490 132 132 }; 133 133 134 //! 135 //! Maybe we can add a static parameter list to MEvtLoop 136 //! Also we can derive MEvtLoop from MTaskList to have a static tasklist, too 137 //! 138 139 // FIXME: Move as (persistent) static data member to MParContainer 140 R__EXTERN TList *gListOfPrimitives; // instantiation in MEvtLoop 141 134 142 /* 135 143 class MParContainer : public TNamed -
trunk/MagicSoft/Mars/mbase/MReadSocket.cc
r2438 r2490 16 16 ! 17 17 ! 18 ! Author(s): Thomas Bretz 12/2000 <mailto:tbretz@uni-sw.gwdg.de>19 ! 20 ! Copyright: MAGIC Software Development, 2000-200 118 ! Author(s): Thomas Bretz, 10/2003 <mailto:tbretz@astro.uni.wuerzburg.de> 19 ! 20 ! Copyright: MAGIC Software Development, 2000-2003 21 21 ! 22 22 ! … … 27 27 // 28 28 // MReadSocket 29 // 30 // This class acts like a standard C++ istream, but read from a socket 31 // (ifstream works similar) 32 // 33 // ios::io_state: 34 // -------------- 35 // eof() or ios::eofbit: Connection closed or not established 36 // fail() or ios::failbit: Error trying to establish connection or 37 // waiting for data in underflow() timed out 38 // good() tells you that everything is ok and we can read from the stream 39 // 40 // Example: 41 // -------- 42 // 43 // Double_t d; 44 // 45 // MReadSocket sin(1024); // open port 1024 46 // 47 // sin >> d; 48 // sin.read((char*)&d, sizeof(Double_t)); 49 // 29 50 // 30 51 ////////////////////////////////////////////////////////////////////////////// … … 44 65 using namespace std; 45 66 67 // -------------------------------------------------------------------------- 68 // 69 // You can use the constructor in two ways: 70 // 71 // MReadSocket read(7000); 72 // This opens the socket and blocks until the connection has been 73 // established. 74 // 75 // MReadSocket read; 76 // Returns immidiatly. The connection will be opend by calling 77 // read.Open(7000); 78 // 46 79 MReadSocket::MReadSocket(int port, int mtu) : istream(this), fMtu(mtu), fTimeout(2500), fServSock(NULL), fRxSocket(NULL) 47 80 { … … 50 83 setg(fBuffer, fBuffer, fBuffer+1); 51 84 52 cout << "Starting server socket on port 7000..." << endl; 53 54 while (1) 85 clear(ios::eofbit); 86 87 if (port>0) 88 Open(port); 89 } 90 91 // -------------------------------------------------------------------------- 92 // 93 // Destructor. Close an possible open connection and delete the fBuffer 94 // 95 MReadSocket::~MReadSocket() 96 { 97 Close(); 98 delete fBuffer; 99 } 100 101 void MReadSocket::OpenServerSocket(int port) 102 { 103 if (fServSock) 104 return; 105 106 cout << "Starting server socket on port #" << port << "..." << endl; 107 108 while (!fServSock) 55 109 { 56 110 fServSock=new TServerSocket(port, kTRUE); 57 111 if (fServSock->IsValid()) 58 break;112 continue; 59 113 60 114 cout << "ServerSocket not valid: "; 61 115 switch (fServSock->GetErrorCode()) 62 116 { 63 case 0: cout << "No error." << endl; break;117 case 0: cout << "No error." << endl; break; 64 118 case -1: cout << "low level socket() call failed." << endl; break; 65 119 case -2: cout << "low level bind() call failed." << endl; break; … … 68 122 } 69 123 70 delete fServSock; 71 fServSock=NULL; 72 break; 73 } 74 if (!fServSock) 75 { 76 cout << "MReadSocket: TServerSocket - Connection timed out." << endl; 77 setstate(ios::failbit); 124 Close(); 125 clear(ios::failbit); 78 126 return; 79 127 } 80 128 81 129 fServSock->SetOption(kNoBlock, 1); 82 83 while (1) 130 } 131 132 void MReadSocket::OpenConnection(Bool_t block) 133 { 134 do 84 135 { 85 136 const TTime timeout = gSystem->Now() + TTime(5000); 86 137 87 138 TDatime now; 88 cout << now.AsString() << ": Waiting for conntection on port 7000..." << endl; 89 fRxSocket = NULL; 90 while ((Long_t)fRxSocket<=0 && gSystem->Now()<timeout) 139 cout << now.AsString() << ": Waiting for connection..." << endl; 140 141 // 142 // fRxSocket<0 means: No connection,non-blocking mode 143 // fRxSocket==0 means: Error 144 // This is only done until timeout is reached 145 // 146 while (fRxSocket==0 && gSystem->Now()<timeout) 91 147 { 92 148 fRxSocket = fServSock->Accept(); 93 149 if (fRxSocket==0) 94 cout << "Error: TServerSock::Accept" << endl; 95 usleep(1); 150 { 151 cout << "MReadSocket::OpenConnection: ERROR - TServerSock::Accept()" << endl; 152 setstate(ios::failbit); 153 return; 154 } 155 if ((Long_t)fRxSocket<0) 156 fRxSocket=NULL; 157 158 usleep(10); 96 159 } 97 160 98 if ((Long_t)fRxSocket<=0) 161 // 162 // No connection has been established. Restart waiting for 163 // connection except we are in non-blocking mode. 164 // 165 if (fRxSocket==0) 99 166 continue; 100 167 168 // 169 // Check if the established connection is valid 170 // 101 171 if (fRxSocket->IsValid()) 102 break; 172 { 173 cout << "Connection established..." << endl; 174 fRxSocket->SetOption(kNoBlock, 1); 175 clear(); 176 return; 177 } 103 178 104 179 cout << "TSocket: Connection not valid..." << endl; 105 180 delete fRxSocket; 106 }107 108 if ((Long_t)fRxSocket<=0)109 {110 cout << "MReadSocket: TServerSocket::Accept - Connection timed out." << endl;111 181 fRxSocket=NULL; 112 182 setstate(ios::failbit); 113 183 return; 114 } 115 116 cout << "Connection established..." << endl; 117 118 fRxSocket->SetOption(kNoBlock, 1); 184 185 } while (block); 186 } 187 188 // -------------------------------------------------------------------------- 189 // 190 // Open the connectionj on port port. Wait until the connection has 191 // been established. If an error occures and the connection cannot 192 // be established return kFALSE. To check whether an error occured 193 // use operator!() or operator void*() or fail() 194 // 195 Bool_t MReadSocket::Open(int port, Bool_t block=kFALSE) 196 { 197 // 198 // If no port is given use the port given in the constructor 199 // 200 if (port<=0) 201 port = fPort; 202 203 // 204 // Remember port for later uses 205 // 206 if (fPort<=0) 207 fPort = port; 208 209 // 210 // Check whether a connection has already been established 211 // 212 if (fServSock) 213 { 214 // 215 // Check whether the connection has the right port 216 // 217 if (fServSock->GetLocalPort()!=port) 218 Close(); 219 } 220 221 // 222 // Check whether port is valid 223 // 224 if (port<=0) 225 { 226 cout << "Invalid port #" << port << "!" << endl; 227 clear(ios::failbit); 228 return kFALSE; 229 } 230 231 // 232 // Start server socket... 233 // 234 OpenServerSocket(port); 235 if (!fServSock) 236 return kFALSE; 237 238 OpenConnection(block); 239 if (!fRxSocket) 240 return kFALSE; 119 241 120 242 underflow(); 121 } 122 123 // -------------------------------------------------------------------------- 124 // 125 // Destructor, destroying the gui mutex. 126 // 127 MReadSocket::~MReadSocket() 243 return kTRUE; 244 } 245 246 void MReadSocket::Close() 128 247 { 129 248 if (fRxSocket) 249 { 130 250 delete fRxSocket; 251 fRxSocket=NULL; 252 } 131 253 if (fServSock) 254 { 255 const Int_t port = fServSock->GetLocalPort(); 256 132 257 delete fServSock; 133 134 delete fBuffer; 135 136 cout << "Connection on Port 7000 closed." << endl; 258 fServSock=NULL; 259 260 cout << "Connection on Port #" << port << " closed." << endl; 261 } 262 263 clear(ios::eofbit); 137 264 } 138 265 … … 149 276 int MReadSocket::underflow() 150 277 { 151 if (fail()) 278 // FIXME: vvvvv is this correct? 279 if (fail() || eof()) 152 280 { 153 281 setg(fBuffer, fBuffer, fBuffer+fMtu); … … 185 313 return 0; 186 314 } 187 -
trunk/MagicSoft/Mars/mbase/MReadSocket.h
r2386 r2490 19 19 char *fBuffer; //! 20 20 21 int fPort; 21 22 int fMtu; 22 23 TTime fTimeout; … … 25 26 TSocket *fRxSocket; 26 27 28 void OpenServerSocket(int port); 29 void OpenConnection(Bool_t block); 30 27 31 int underflow(); 28 32 int sync(); 29 33 30 34 public: 31 MReadSocket(int port , int mtu=1500);35 MReadSocket(int port=-1, int mtu=1500); 32 36 MReadSocket(MReadSocket const& log) : istream((std::streambuf*)&log) 33 37 { 34 38 } 35 39 ~MReadSocket(); 40 41 Bool_t Open(int port=-1, Bool_t block=kFALSE); 42 void Close(); 36 43 37 44 void SetTimeout(UInt_t millisec) { fTimeout = millisec; } -
trunk/MagicSoft/Mars/mbase/MTask.cc
r2473 r2490 83 83 84 84 #include "MFilter.h" 85 #include "MGGroupFrame.h"86 85 #include "MStatusDisplay.h" 87 86
Note:
See TracChangeset
for help on using the changeset viewer.