OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
DataSource.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /***************************************************************************
3  *
4  * The IPPL Framework
5  *
6  *
7  * Visit http://people.web.psi.ch/adelmann/ for more details
8  *
9  ***************************************************************************/
10 
11 #ifndef DATA_SOURCE_H
12 #define DATA_SOURCE_H
13 
14 /***********************************************************************
15  *
16  * DataSource is the base class for all objects which desire to have their
17  * contents available for another program or data processing API (e.g.,
18  * visualization). It provides an interface to do the following actions:
19  * 1. CONNECT the object with the external program or API, by providing
20  * a name to use.
21  * Method: DataConnect *connect(char *name, DataConnect * = 0)
22  * 2. UPDATE the receiver end with the latest version of the data.
23  * Method: bool update()
24  * 3. INTERACT with the receiver, by handing off control to them until
25  * they are finished (for some receivers, this may be a no-op).
26  * Method: bool interact()
27  * 4. DISCONNECT from the receiver. If not done explicitely, this will
28  * be done when the DataSource is deleted.
29  * Method: bool disconnect()
30  *
31  * To construct a DataSource, a specific subclass of DataSourceObject
32  * must be created, which provides the particular implementation of
33  * these interface functions based on the type of data (ParticleAttrib
34  * or Field) and the destination of the data
35  *
36  * Objects in Ippl which want to be a source for data to some other
37  * agency should then do the following:
38  * 1. Make your new class be derived from DataSource;
39  * 2. Define a version of the protected virtual function
40  * 'makeDataSourceObject'. This function should create the proper
41  * subclass of DataSourceObject based on the new class' type and the
42  * method for connection.
43  *
44  ***********************************************************************/
45 
46 // include files
47 #include <vector>
48 
49 // forward declarations
50 class DataSourceObject;
51 class DataConnect;
52 
53 
54 // A base class for all objects in IPPL which we want to make accessible
55 // to external agencies (basically, ParticleAttrib's and Field's)
56 class DataSource {
57 
58 public:
59  // enumeration of data transfer directions:
60  // input = obtain data from external agency
61  // output = send data to external agency
62  // both = can send and receive (meaning depends on context)
63  // default = get transfer direction from default setting in connect obj
65 
66  // container type for connections
67  typedef std::vector<DataSourceObject *> container_t;
68 
69 public:
70  // constructor
71  DataSource();
72 
73  // destructor
74  virtual ~DataSource();
75 
76  //
77  // informative methods
78  //
79 
80  // are we currently connected to a DataConnect object? If an argument is
81  // given, just check if we're connected to the specified DataConnect (else,
82  // just report if we're connected to anyone).
83  bool connected(DataConnect * = 0) const;
84 
85  // find the first DataSourceObject which is connected to the given
86  // DataConnect, and return it; otherwise, return 0
88 
89  //
90  // DataSource interface ... these mainly call the virtual functions in
91  // the provided object
92  //
93 
94  // Register an object as something that can be a source of data.
95  // Arguments = name of item, connection to use, and type of
96  // connection (INPUT, OUTPUT, BOTH, or DEFAULT). If the connection
97  // has not been created yet (e.g., it is NULL), create a new default
98  // connection (or use the existing default one). Return the connection.
99  DataConnect *connect(const char *, DataConnect * = 0,
100  int = DataSource::DEFAULT);
101 
102  // Register the given DataSourceObject directly. This is simpler than
103  // the above version of connect, since the DataSourceObject has already
104  // been created. It can be used to register most any type of connection,
105  // even one using DataConnect objects that are not part of IPPL itself.
106  // Return success.
107  bool connect(DataSourceObject *);
108 
109  // Disconnect an object from the DataConnect object. Return success.
110  // If no DataConnect is specified, disconnect from ALL connections.
111  bool disconnect(DataConnect * = 0);
112 
113  // Update the object, that is, make sure the receiver of the data has a
114  // current and consistent snapshot of the current state. Return success.
115  bool updateConnection(DataConnect * = 0);
116 
117  // Indicate to the receiver that we're allowing them time to manipulate the
118  // data (e.g., for a viz program, to rotate it, change rep, etc.)
119  // This should only return when the manipulation is done. For some cases,
120  // this will be a no-op.
121  void interact(DataConnect * = 0);
122 
123  // Pass on a string to the connection, most likely to give it a
124  // command to do some action. Similar to the above interact, except
125  // the request for interaction involves the given string
126  void interact(const char *, DataConnect * = 0);
127 
128 protected:
129  // a virtual function which is called by this base class to get a
130  // specific instance of DataSourceObject based on the type of data
131  // and the connection method (the argument to the call).
132  virtual DataSourceObject *createDataSourceObject(const char *,
133  DataConnect *,
134  int) = 0;
135 
136 private:
137  // the list of connected DataSourceObject's
139 };
140 
141 #endif // DATA_SOURCE_H
142 
143 /***************************************************************************
144  * $RCSfile: DataSource.h,v $ $Author: adelmann $
145  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:25 $
146  * IPPL_VERSION_ID: $Id: DataSource.h,v 1.1.1.1 2003/01/23 07:40:25 adelmann Exp $
147  ***************************************************************************/
DataConnect * connect(const char *, DataConnect *=0, int=DataSource::DEFAULT)
Definition: DataSource.cpp:83
virtual ~DataSource()
Definition: DataSource.cpp:43
container_t ConnectionList
Definition: DataSource.h:138
std::vector< DataSourceObject * > container_t
Definition: DataSource.h:67
bool updateConnection(DataConnect *=0)
Definition: DataSource.cpp:176
void interact(DataConnect *=0)
Definition: DataSource.cpp:195
DataSourceObject * findDataSourceObject(DataConnect *) const
Definition: DataSource.cpp:55
bool connected(DataConnect *=0) const
Definition: DataSource.cpp:69
virtual DataSourceObject * createDataSourceObject(const char *, DataConnect *, int)=0
bool disconnect(DataConnect *=0)
Definition: DataSource.cpp:143