Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members

src/DataSource/DataConnect.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /***************************************************************************
00003  *
00004  * The IPPL Framework
00005  * 
00006  *
00007  * Visit http://people.web.psi.ch/adelmann/ for more details
00008  *
00009  ***************************************************************************/
00010 
00011 #ifndef DATA_CONNECT_H
00012 #define DATA_CONNECT_H
00013 
00014 /***********************************************************************
00015  * 
00016  * DataConnect is the base class for all objects which maintain a connection
00017  * with another program or external agency.  When constructed, it initializes
00018  * and maintains the connection, and provides information for transferral
00019  * of individual data objects such as Particles and Fields.
00020  *
00021  ***********************************************************************/
00022 
00023 // include files
00024 #include "DataSource/DataSource.h"
00025 #include "Utility/NamedObj.h"
00026 #include "Utility/Pstring.h"
00027 
00028 // forward declarations
00029 class DataSourceObject;
00030 
00031 
00032 
00033 class DataConnect : public NamedObj {
00034 
00035 public:
00036   // typedef for our list of DataSource's
00037   typedef vector<DataSource *>        container_t;
00038   typedef container_t::iterator       iterator;
00039   typedef container_t::const_iterator const_iterator;
00040 
00041 public:
00042   // constructor
00043   DataConnect(const char *nm, const char *id, int dtm = DataSource::OUTPUT,
00044               int n = 0);
00045 
00046   // destructor
00047   virtual ~DataConnect();
00048 
00049   //
00050   // informative methods
00051   //
00052 
00053   // return the ID for this object ... different types of DataConnect
00054   // subclasses have different ID's
00055   const char *ID() const { return MyID.c_str(); }
00056 
00057   // get or set our defalt data transfer method
00058   int getDefaultTransferMethod() const { return DefTransMethod; }
00059   void setDefaultTransferMethod(int m) { DefTransMethod = m; }
00060 
00061   // return the number of nodes that should be used for display
00062   int getNodes() const { return nodes; }
00063 
00064   // return true if our nodes is one of the connection nodes
00065   bool onConnectNode() const;
00066 
00067   //
00068   // iterators for our list of registered objects
00069   //
00070 
00071   iterator begin() { return SourceList.begin(); }
00072   iterator end()   { return SourceList.end(); }
00073 
00074   const_iterator begin() const { return SourceList.begin(); }
00075   const_iterator end() const   { return SourceList.end(); }
00076 
00077   //
00078   // other container-like routines
00079   //
00080 
00081   // return the number of registered DataSource's
00082   unsigned int size() const { return SourceList.size(); }
00083   unsigned int numDataSources() const { return SourceList.size(); }
00084   bool empty() const { return SourceList.empty(); }
00085 
00086   //
00087   // DataConnect virtual methods, which all have default behavior
00088   //
00089 
00090   // are we currently connected to a receiver?
00091   virtual bool connected() const;
00092 
00093   // Register an object as something that can be a source of data.
00094   // Arguments = name of item, DataSource object, and transfer method
00095   // (INPUT, OUTPUT, BOTH, or DEFAULT).  If this connection object is
00096   // not actually connected, it is an error and this will return NULL.
00097   // Otherwise, if the connection works, return the connection.
00098   virtual DataConnect *connect(const char *, DataSource *,
00099                                int=DataSource::DEFAULT);
00100   virtual DataConnect *connect(const char *, DataSource &,
00101                                int=DataSource::DEFAULT);
00102 
00103   // Add a new single DataSourceObject connection.  It is added to the
00104   // DataSource's list of single connections, and the DataSource will
00105   // end up being added to our list of known sources.  Return success.
00106   virtual bool connect(DataSourceObject *);
00107 
00108   // perform update for all registered DataSource's.  The optional
00109   // argument can be used to just update all things connected to the
00110   // current connector and any other connectors (if the pointer is 0),
00111   // to just those things that are connected to the current connector
00112   // AND are also connected to the provided connector.
00113   virtual void updateConnections(DataConnect * = 0);
00114 
00115   // disconnect all the registered DataSource's.
00116   virtual void disconnectConnections();
00117 
00118   // allow all connections to perform an interactive action.  An optional
00119   // command string can be supplied; if it is null, it will be ignored.
00120   virtual void interact(const char * = 0, DataConnect * = 0);
00121 
00122   // synchronization mechanism for waiting on some outside request.
00123   virtual void ready();
00124 
00125 private:
00126   friend class DataSource;
00127 
00128   // ID for this object
00129   string MyID;
00130 
00131   // our list of connected data objects
00132   container_t SourceList;
00133 
00134   // the number of nodes to connect with
00135   int nodes;
00136 
00137   // default transfer method
00138   int DefTransMethod;
00139 
00140   // Register a data object as connected here.  Return success.
00141   bool checkin(DataSource *);
00142 
00143   // remove a data object from our connected list.  Return success.
00144   // Argument = whether we need to have the DataSource disconnect first.
00145   bool checkout(DataSource *, bool = true);
00146 };
00147 
00148 #endif // DATA_CONNECT_H
00149 
00150 /***************************************************************************
00151  * $RCSfile: DataConnect.h,v $   $Author: adelmann $
00152  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:24 $
00153  * IPPL_VERSION_ID: $Id: DataConnect.h,v 1.1.1.1 2003/01/23 07:40:24 adelmann Exp $ 
00154  ***************************************************************************/

Generated on Fri Nov 2 01:25:55 2007 for IPPL by doxygen 1.3.5