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_SOURCE_OBJECT_H 00012 #define DATA_SOURCE_OBJECT_H 00013 00014 /*********************************************************************** 00015 * 00016 * DataSourceObject is used basically as a type-independent interface 00017 * to store the specific object which is being connected with a receiver, 00018 * and to provide the actual implementations of the interface functions 00019 * described above. These are implemented in DataSourceObject as virtual 00020 * functions; a specific, derived version of DataSourceObject for the 00021 * different types of objects to connect (e.g. Field or ParticleAttrib) 00022 * must be given to the constructor of DataSource. The specific 00023 * implementation (a class derived from DataSourceObject) must also be 00024 * customized to the type of data receivers, either a PAWS connection or 00025 * another external program or an API within the same process. 00026 * 00027 * While a single DataSource may be connected to several DataConnect's, and 00028 * a DataConnect may have several DataSource objects connected to it, there 00029 * is exactly one DataSourceObject per DataSource <---> DataConnect pair. 00030 * This class carries out the actual work to tranfer the data for one data 00031 * object from a sender to a receiver. 00032 * 00033 * The def type of data source to use for a particular invocation of a IPPL 00034 * application is selected via a command-line option; the IpplInfo class 00035 * will save this information, which is used by the templated global 00036 * function 'make_DataSourceObject'. There should be a version of this 00037 * function provided for each type of object in IPPL we want to connect, 00038 * basically Field's and ParticleAttrib's. 00039 * 00040 ***********************************************************************/ 00041 00042 // include files 00043 #include "DataSource/DataSource.h" 00044 #include "Utility/NamedObj.h" 00045 00046 // forward declarations 00047 class DataConnect; 00048 00049 00050 // The interface class for objects we wish to connect to other agencies. 00051 // The function 'make_DataSourceObject' in DataSource/MakeDataSource.h will 00052 // create the proper subclass of this object, for use by DataSource. 00053 class DataSourceObject : public NamedObj { 00054 00055 public: 00056 // Constructor 00057 DataSourceObject(const char *nm, DataSource *ds, DataConnect *dc, int tm) 00058 : NamedObj(nm), Source(ds), Connection(dc), TransferMethod(tm) { } 00059 00060 // Default constructor 00061 DataSourceObject() 00062 : Source(0), Connection(0), TransferMethod(DataSource::OUTPUT) { } 00063 00064 // Destructor: make it virtual, but it does nothing. 00065 virtual ~DataSourceObject() { } 00066 00067 // are we currently connected? 00068 bool connected() const { return (Connection != 0 && Source != 0); } 00069 00070 // who are we connected to? 00071 DataConnect *getConnection() { return Connection; } 00072 00073 // who are we connected from? 00074 DataSource *getSource() { return Source; } 00075 00076 // 00077 // 00078 // virtual function interface. The default versions of these objects 00079 // do nothing, so that we can have a default behavior. Note that the 00080 // 'connect' and 'disconnect' functionality should be implemented in the 00081 // derived classes constructor and destructor, respectively. 00082 // 00083 00084 // Update the object, that is, make sure the receiver of the data has a 00085 // current and consistent snapshot of the current state. Return success. 00086 virtual bool update() { return false; } 00087 00088 // Indicate to the receiver that we're allowing them time to manipulate the 00089 // data (e.g., for a viz program, to rotate it, change representation, etc.) 00090 // This should only return when the manipulation is done. 00091 // Optionally, a string can be passed on to the connection, possibly for 00092 // use as an interactive command. 00093 virtual void interact(const char * = 0) { } 00094 00095 protected: 00096 // our current connection ... if the connection was not successful, this 00097 // should be set to 0 00098 DataConnect *Connection; 00099 00100 // our current source ... if the connection was not successful, this 00101 // should be set to 0 00102 DataSource *Source; 00103 00104 // our transfer method, as requested by the user ... some subclasses may 00105 // not support all types of transfer, if the user asks for one which is 00106 // not supported, the connection should fail 00107 int TransferMethod; 00108 }; 00109 00110 #endif // DATA_SOURCE_OBJECT_H 00111 00112 /*************************************************************************** 00113 * $RCSfile: DataSourceObject.h,v $ $Author: adelmann $ 00114 * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:25 $ 00115 * IPPL_VERSION_ID: $Id: DataSourceObject.h,v 1.1.1.1 2003/01/23 07:40:25 adelmann Exp $ 00116 ***************************************************************************/