Ignore:
Timestamp:
11/10/03 11:14:35 (21 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/mbase
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mbase/MEvtLoop.cc

    r2459 r2490  
    9696using namespace std;
    9797
    98 
    99 //!
    100 //! Maybe we can add a static parameter list to MEvtLoop
    101 //! Also we can derive MEvtLoop from MTaskList to have a static tasklist, too
    102 //!
    103 
    104 TList *gListOfPrimitives; // forward declaration in MParContainer.h
    105 
    10698// --------------------------------------------------------------------------
    10799//
     
    372364    if (fProgress && fNumEvents>0)
    373365        fProgress->SetPosition((Double_t)num/fNumEvents);
    374 
    375366
    376367    // FIXME: This is a workaround, because TApplication::Run is not
  • trunk/MagicSoft/Mars/mbase/MEvtLoop.h

    r2438 r2490  
    8585};
    8686
    87 // FIXME: Move as (persistent) static data member to MParContainer
    88 R__EXTERN TList *gListOfPrimitives; // instantiation in MEvtLoop
    89 
    9087#endif
  • trunk/MagicSoft/Mars/mbase/MGGroupFrame.h

    r2015 r2490  
    1414class MGGroupFrame : public TGGroupFrame, public TGWidget
    1515{
    16     MGTask  *fTask;
     16    MGTask *fTask;
    1717    MGList *fList;
    1818
  • trunk/MagicSoft/Mars/mbase/MParContainer.cc

    r2470 r2490  
    5151#include "MLogManip.h"
    5252
    53 #ifndef __COSY__
    54 #include "MEvtLoop.h"     // gListOfPrimitives
    55 #else
    5653TList *gListOfPrimitives; // forard declaration in MParContainer.h
    57 #endif
    5854
    5955#undef DEBUG
  • trunk/MagicSoft/Mars/mbase/MParContainer.h

    r2470 r2490  
    132132};
    133133
     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
     140R__EXTERN TList *gListOfPrimitives; // instantiation in MEvtLoop
     141
    134142/*
    135143class MParContainer : public TNamed
  • trunk/MagicSoft/Mars/mbase/MReadSocket.cc

    r2438 r2490  
    1616!
    1717!
    18 !   Author(s): Thomas Bretz  12/2000 <mailto:tbretz@uni-sw.gwdg.de>
    19 !
    20 !   Copyright: MAGIC Software Development, 2000-2001
     18!   Author(s): Thomas Bretz, 10/2003 <mailto:tbretz@astro.uni.wuerzburg.de>
     19!
     20!   Copyright: MAGIC Software Development, 2000-2003
    2121!
    2222!
     
    2727//
    2828// 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//
    2950//
    3051//////////////////////////////////////////////////////////////////////////////
     
    4465using namespace std;
    4566
     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//
    4679MReadSocket::MReadSocket(int port, int mtu) : istream(this), fMtu(mtu), fTimeout(2500), fServSock(NULL), fRxSocket(NULL)
    4780{
     
    5083    setg(fBuffer, fBuffer, fBuffer+1);
    5184
    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//
     95MReadSocket::~MReadSocket()
     96{
     97    Close();
     98    delete fBuffer;
     99}
     100
     101void MReadSocket::OpenServerSocket(int port)
     102{
     103    if (fServSock)
     104        return;
     105
     106    cout << "Starting server socket on port #" << port << "..." << endl;
     107
     108    while (!fServSock)
    55109    {
    56110        fServSock=new TServerSocket(port, kTRUE);
    57111        if (fServSock->IsValid())
    58             break;
     112            continue;
    59113
    60114        cout << "ServerSocket not valid: ";
    61115        switch (fServSock->GetErrorCode())
    62116        {
    63         case 0: cout << "No error." << endl; break;
     117        case  0: cout << "No error." << endl; break;
    64118        case -1: cout << "low level socket() call failed." << endl; break;
    65119        case -2: cout << "low level bind() call failed." << endl; break;
     
    68122        }
    69123
    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);
    78126        return;
    79127    }
    80128
    81129    fServSock->SetOption(kNoBlock, 1);
    82 
    83     while (1)
     130}
     131
     132void MReadSocket::OpenConnection(Bool_t block)
     133{
     134    do
    84135    {
    85136        const TTime timeout = gSystem->Now() + TTime(5000);
    86137
    87138        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)
    91147        {
    92148            fRxSocket = fServSock->Accept();
    93149            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);
    96159        }
    97160
    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)
    99166            continue;
    100167
     168        //
     169        // Check if the established connection is valid
     170        //
    101171        if (fRxSocket->IsValid())
    102             break;
     172        {
     173            cout << "Connection established..." << endl;
     174            fRxSocket->SetOption(kNoBlock, 1);
     175            clear();
     176            return;
     177        }
    103178
    104179        cout << "TSocket: Connection not valid..." << endl;
    105180        delete fRxSocket;
    106     }
    107 
    108     if ((Long_t)fRxSocket<=0)
    109     {
    110         cout << "MReadSocket: TServerSocket::Accept - Connection timed out." << endl;
    111181        fRxSocket=NULL;
    112182        setstate(ios::failbit);
    113183        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//
     195Bool_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;
    119241
    120242    underflow();
    121 }
    122 
    123 // --------------------------------------------------------------------------
    124 //
    125 //  Destructor, destroying the gui mutex.
    126 //
    127 MReadSocket::~MReadSocket()
     243    return kTRUE;
     244}
     245
     246void MReadSocket::Close()
    128247{
    129248    if (fRxSocket)
     249    {
    130250        delete fRxSocket;
     251        fRxSocket=NULL;
     252    }
    131253    if (fServSock)
     254    {
     255        const Int_t port = fServSock->GetLocalPort();
     256
    132257        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);
    137264}
    138265
     
    149276int MReadSocket::underflow()
    150277{
    151     if (fail())
     278    // FIXME:     vvvvv is this correct?
     279    if (fail() || eof())
    152280    {
    153281        setg(fBuffer, fBuffer, fBuffer+fMtu);
     
    185313    return 0;
    186314}
    187 
  • trunk/MagicSoft/Mars/mbase/MReadSocket.h

    r2386 r2490  
    1919    char *fBuffer; //!
    2020
     21    int   fPort;
    2122    int   fMtu;
    2223    TTime fTimeout;
     
    2526    TSocket        *fRxSocket;
    2627
     28    void OpenServerSocket(int port);
     29    void OpenConnection(Bool_t block);
     30
    2731    int underflow();
    2832    int sync();
    2933
    3034public:
    31     MReadSocket(int port, int mtu=1500);
     35    MReadSocket(int port=-1, int mtu=1500);
    3236    MReadSocket(MReadSocket const& log) : istream((std::streambuf*)&log)
    3337    {
    3438    }
    3539    ~MReadSocket();
     40
     41    Bool_t Open(int port=-1, Bool_t block=kFALSE);
     42    void   Close();
    3643
    3744    void SetTimeout(UInt_t millisec) { fTimeout = millisec; }
  • trunk/MagicSoft/Mars/mbase/MTask.cc

    r2473 r2490  
    8383
    8484#include "MFilter.h"
    85 #include "MGGroupFrame.h"
    8685#include "MStatusDisplay.h"
    8786
Note: See TracChangeset for help on using the changeset viewer.