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

src/DataSource/DataConnect.cpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /***************************************************************************
00003  *
00004  * The IPPL Framework
00005  * 
00006  * This program was prepared by PSI. 
00007  * All rights in the program are reserved by PSI.
00008  * Neither PSI nor the author(s)
00009  * makes any warranty, express or implied, or assumes any liability or
00010  * responsibility for the use of this software
00011  *
00012  * Visit http://www.acl.lanl.gov/POOMS for more details
00013  *
00014  ***************************************************************************/
00015 
00016 // -*- C++ -*-
00017 /***************************************************************************
00018  *
00019  * The IPPL Framework
00020  * 
00021  *
00022  * Visit http://people.web.psi.ch/adelmann/ for more details
00023  *
00024  ***************************************************************************/
00025 
00026 // include files
00027 #include "DataSource/DataConnect.h"
00028 #include "DataSource/DataSource.h"
00029 #include "DataSource/DataSourceObject.h"
00030 #include "DataSource/DataConnectCreator.h"
00031 #include "Utility/IpplInfo.h"
00032 #include "Profile/Profiler.h"
00033 
00034 
00036 // constructor
00037 DataConnect::DataConnect(const char *nm, const char *id, int dtm, int n)
00038   : NamedObj(nm), MyID(id), DefTransMethod(dtm), nodes(n)
00039 {
00040   if (n <= 0)
00041     nodes = DataConnectCreator::getDefaultNodes();
00042 }
00043 
00044 
00046 // destructor
00047 DataConnect::~DataConnect()
00048 {
00049   disconnectConnections();
00050 }
00051 
00052 
00054 // return true if our nodes is one of the connection nodes
00055 bool DataConnect::onConnectNode() const {
00056   return (Ippl::myNode() < getNodes());
00057 }
00058 
00059 
00061 // are we currently connected to a receiver?  The base-class default
00062 // behavior for this is to indicate that we're not connected.
00063 bool DataConnect::connected() const {
00064   return false;
00065 }
00066 
00067 
00069 // Register an object as something that can be a source of data.
00070 // Arguments = name of item, DataSource object, and transfer method
00071 // (INPUT, OUTPUT, BOTH, or DEFAULT).  If this connection object is
00072 // not actually connected, it is an error and this will return NULL.
00073 // Otherwise, if the connection works, return the connection.
00074 DataConnect *DataConnect::connect(const char *nm, DataSource *s, int tm) {
00075   TAU_PROFILE("DataConnect::connect()",
00076               "DataConnect * (char *, DataSource *, int", 
00077               TAU_VIZ);
00078   DataConnect *conn = 0;
00079   if (connected() && s != 0)
00080     conn = s->connect(nm, this, tm);
00081   return conn;
00082 }
00083 
00084 DataConnect *DataConnect::connect(const char *nm, DataSource& s, int tm) {
00085   return connect(nm, &s, tm);
00086 }
00087 
00088 
00090 // Add a new single DataSourceObject connection.  It is added to the
00091 // DataSource's list of single connections, and the DataSource will
00092 // end up being added to our list of known sources.  Return success.
00093 bool DataConnect::connect(DataSourceObject *dso) {
00094   TAU_PROFILE("DataConnect::connect()", "DataSourceObject *", TAU_VIZ);
00095 
00096   // make sure the DataSourceObject has a source and the proper DataConnect
00097   if (dso == 0 || dso->getSource() == 0 || dso->getConnection() != this)
00098     return false;
00099 
00100   // tell the relevant DataSource it has a new DataSourceObject connection.
00101   // the DataSource will check itself in to our list of DataSources.
00102   return dso->getSource()->connect(dso);
00103 }
00104 
00105 
00107 // perform update for all registered DataSource's
00108 void DataConnect::updateConnections(DataConnect *dc) {
00109   TAU_PROFILE("DataConnect::updateConnections()", "void (DataConnect *)",
00110               TAU_VIZ);
00111   for (iterator a = begin(); a != end(); ++a)
00112     (*a)->updateConnection(dc);
00113 }
00114 
00115 
00117 // disconnect all the registered DataSource's
00118 void DataConnect::disconnectConnections() {
00119   TAU_PROFILE("DataConnect::disconnectConnections()", "void ()", TAU_VIZ);
00120   while (! SourceList.empty() )
00121     checkout(SourceList.front());
00122 }
00123 
00124 
00126 // allow all connections to perform an interactive action
00127 void DataConnect::interact(const char *str, DataConnect *dc) {
00128   TAU_PROFILE("DataConnect::interact()", "void (const char *, DataConnect *)",
00129               TAU_VIZ);
00130   for (iterator a = begin(); a != end(); ++a)
00131     (*a)->interact(str, dc);
00132 }
00133 
00134 
00136 // Register a data object as connected here.  Return success.
00137 bool DataConnect::checkin(DataSource *ds) {
00138   TAU_PROFILE("DataConnect::checkin()", "bool (DataSource *)", TAU_VIZ);
00139 
00140   // make sure we do not have this DataSource already
00141   for (iterator a = begin(); a != end(); ++a) {
00142     if (*a == ds)
00143       return true;
00144   }
00145 
00146   // we don't have it, so add it to our list
00147   SourceList.push_back(ds);
00148   return true;
00149 }
00150 
00151 
00153 // remove a data object from our connected list.  Return success.
00154 bool DataConnect::checkout(DataSource *ds, bool NeedDisconnect) {
00155   TAU_PROFILE("DataConnect::checkout()", "bool (DataSource *, bool)", TAU_VIZ);
00156 
00157   //Inform dbgmsg("DataConnect::checkout", INFORM_ALL_NODES);
00158 
00159   // make sure we have it ...
00160   for (iterator a = begin(); a != end(); ++a) {
00161     if (*a == ds) {
00162       // we do have it; make sure it is disconnected,
00163       // remove it and return success
00164       //dbgmsg << "Found DataSource ... ";
00165       SourceList.erase(a);
00166       if (NeedDisconnect) {
00167         //dbgmsg << "calling disconnect." << endl;
00168         ds->disconnect(this);
00169       } else {
00170         //dbgmsg << "SKIPPING disconnect." << endl;
00171       }
00172       return true;
00173     }
00174   }
00175 
00176   // if we're here, we did not find it
00177   //dbgmsg << "Could not find specified DataSource." << endl;
00178   return false;
00179 }
00180 
00182 // wait for synchronization from outside.
00183 // default behavior is nothing.
00184 void DataConnect::ready()
00185 {
00186 }
00187 
00188 /***************************************************************************
00189  * $RCSfile: DataConnect.cpp,v $   $Author: adelmann $
00190  * $Revision: 1.1.1.1 $   $Date: 2003/01/23 07:40:24 $
00191  * IPPL_VERSION_ID: $Id: DataConnect.cpp,v 1.1.1.1 2003/01/23 07:40:24 adelmann Exp $ 
00192  ***************************************************************************/

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