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

QUANTAdb_sharedState_c Class Reference

#include <QUANTAdb_sharedState_c.hxx>

Inheritance diagram for QUANTAdb_sharedState_c:

QUANTAmisc_observer_c List of all members.

Detailed Description

Encapsulates a shared state to be maintained between multiple users.

This class provides a base abstract class from which to derives shared state information which multiple users encounter. This state needs to be managed by a database client in order to maintain consistency, but the client itself is external to the scope of the state. This state is associated with a particular path and key that should not change throughout the life of the state.

Updates are handled through the user of the subject-observer pattern. The shared state observes the client, so when new data arrives, it will unpack the state information provided that sharing is enabled. Sharing is initially disabled for initialization purposes, but can be enabled and disabled later as required.

Subclasses of the shared state have the responsiblity of handling the format of the state for transmission. The state will need to be packed using the packer instance and then sent through the database client. This process is handled by each client because the packing will vary, and the send is dependent upon the size of the packed data. Unpacking state information, however, can be done with just the data itself.

Author:
cavern@evl.uic.edu
Version:
03/26/2000


Public Member Functions

 QUANTAdb_sharedState_c ()
 Class constructor.
 QUANTAdb_sharedState_c (QUANTAdb_client_c *dbclient, char *path, char *key)
 Class constructor.
virtual ~QUANTAdb_sharedState_c ()
 Class destructor.
bool isSharingEnabled ()
 Returns the sharing status of this state.
void enableSharing ()
 Sets the sharing enabled flag to TRUE.
void disableSharing ()
 Sets the sharing enabled flag to FALSE.
int refresh ()
 Requests a refresh of the data.
virtual void update (QUANTAmisc_subject_c *subj)
 Triggered by an observered subject's notify() method.

Protected Member Functions

virtual int packAndSendState ()
 Packs the object state and transmits it to the database server.
virtual int unpackState (char *data, const int &size=0)
 Unpacks the object state from the data buffer.

Protected Attributes

QUANTAnet_datapack_c _packer
 data packing object
QUANTAdb_client_c_dbclient
 pointer to a database client which will make the transmissions
bool _sharingEnabled
 flag for indicating whether or not sharing is enabled
char * _path
 path name in the database for storing this state
char * _key
 key name in the database for storing this state


Constructor & Destructor Documentation

QUANTAdb_sharedState_c::QUANTAdb_sharedState_c QUANTAdb_client_c dbclient,
char *  path,
char *  key
 

Class constructor.

Creating an instance of a shared state requires a reference to a database client which already exists. The state will be registered with the client as an observer. Additionally, path and key names are stored within the state for tranmitting and receiving state updates.

Parameters:
dbclient pointer to an instantiated database client
path path string to associate with this state
key key string to associate with this state


Member Function Documentation

virtual int QUANTAdb_sharedState_c::packAndSendState  )  [inline, protected, virtual]
 

Packs the object state and transmits it to the database server.

The state information must be packed into a data buffer and sent to the database server. The responsibility of packing the state AND sending are placed within this method, so subclasses must put the state information into the database themselves.

Returns:
result Result of the attempt to send the state to the server

int QUANTAdb_sharedState_c::refresh  ) 
 

Requests a refresh of the data.

This method requests the remote state information from the database. It may be useful to call after creating the state.

virtual int QUANTAdb_sharedState_c::unpackState char *  data,
const int &  size = 0
[inline, protected, virtual]
 

Unpacks the object state from the data buffer.

The state receives a data buffer from the client when an update has occurred, but the state information must be unpacked from that buffer. This virtual method must be implemented in any derived subclass to extract the appropriate information from the data buffer received from the client. It is highly advisable to check the data's path, key, and size for security.

Parameters:
data character data buffer received from the server
size size in bytes of data buffer

virtual void QUANTAdb_sharedState_c::update QUANTAmisc_subject_c subj  )  [virtual]
 

Triggered by an observered subject's notify() method.

You can think of this as the object-oriented equivalent of a callback function. This is a pure virtual function that should be implemented by classes that inherit from the observer.

Parameters:
subj This is a CAVERnmisc_subject_c pointer to the subject that woke us up. We can then access its public member variables and even execute its public methods.

Implements QUANTAmisc_observer_c.


The documentation for this class was generated from the following file:
Generated on Tue Jun 6 16:06:25 2006 for QUANTA by doxygen 1.3.8