Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | Related Pages | Examples

ColCOWS_Node.hh

00001 //===========================================================================//
00002 //    
00003 //    Description: ColCOWS Nodes
00004 //    Filename: colcows/ColCOWS_Node.hh
00005 //    Authors: Michael Dussere and Aurélien Esnard
00006 //    
00007 //===========================================================================//
00008 //    
00009 //    Copyright (C) 2003 INRIA and CNRS
00010 //    
00011 //    This library is free software; you can redistribute it and/or
00012 //    modify it under the terms of the GNU Lesser General Public
00013 //    License as published by the Free Software Foundation; either
00014 //    version 2.1 of the License, or (at your option) any later version.
00015 //    
00016 //    This library is distributed in the hope that it will be useful,
00017 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 //    Lesser General Public License for more details.
00020 //    
00021 //    You should have received a copy of the GNU Lesser General Public
00022 //    License along with this library; if not, write to the Free Software
00023 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024 //    
00025 //===========================================================================//
00026 
00027 
00028 #ifndef __COLCOWS_NODE_HH__
00029 #define __COLCOWS_NODE_HH__
00030 
00031 //---------------------------------------------------------------------------//
00032 #include "ColCOWS_Include.hh"
00033 #include "ColCOWS_Debug.hh" 
00034 //---------------------------------------------------------------------------//
00035 #include "ColCOWS_NodeDesc.hh" 
00036 #include "ColCOWS_WorkspaceDesc.hh" 
00037 #include "ColCOWS_RemoteWorkspaceManager.hh" 
00038 //---------------------------------------------------------------------------//
00039 
00040 namespace CORBA {
00041   class ORB;
00042 }
00043 
00044 namespace ColCOWS {
00045   class NodeServant;
00046   struct IdlWorkspaceDesc;
00047   class EventHandler;
00048   class EventHandlerManager;
00049 };
00050 
00051 __COLCOWS_BEGIN__
00052 
00053 //! associated timeout (sec)
00054 const unsigned int  WAITING_TIMEOUT = 2;
00055 
00056 //! associated timeout (sec)
00057 const unsigned int  WAITING_RETRY = 10;
00058 
00059 //===========================================================================//
00060 //                          ColCOWS node class                               //
00061 //===========================================================================//
00062 
00063 //! ColCOWS Node class
00064 /** 
00065  * The Node class is the front end of ColCOWS library, the one appearing in the user source code.
00066  * It manages the local CORBA object references and the workspace descriptions, local and remote.
00067  * The class provides the user with methods for controlling the workspace life-cycle (activation/deactivation,  
00068  * connection/disconnection) and for exploring the references of the local and remote workspaces.
00069  *
00070  * \todo Use separate classes for the management of the workspace descriptions
00071  * \todo Allow several event handlers to be connected
00072  */
00073 class Node : public NodeDesc
00074 {
00075 
00076   //=========== friend classes ===========//
00077   friend class NodeServant;
00078 
00079   //================================================//
00080   //=========== class standard interface ===========//
00081 
00082 public:
00083   
00084   //! constructor
00085   Node();
00086   
00087   //! destructor
00088   virtual ~Node();
00089 
00090   //! create a new node, full details
00091   static Node * New( std::string ws_id, 
00092                      std::string ws_kind, 
00093                      std::string node_kind, 
00094                      unsigned long num_node, 
00095                      unsigned long max_descendant, 
00096                      unsigned long nb_nodes,
00097                      unsigned long num_father,
00098                      CORBA::ORB * orbp  ) ;
00099 
00100   //! create a new node, in hierarchy
00101   static Node * NewHierachical( std::string ws_id,
00102                                 std::string ws_kind, 
00103                                 unsigned long num_node, 
00104                                 unsigned long nb_nodes, 
00105                                 unsigned long base,
00106                                 CORBA::ORB * orbp  ) ;
00107 
00108   //! create a new node, generical
00109   static Node * NewNode( std::string ws_id,
00110                          std::string ws_kind, 
00111                          std::string node_kind, 
00112                          unsigned long num_node,
00113                          unsigned long nb_nodes,
00114                          CORBA::ORB * orbp  ) ;
00115   
00116   //! create a new node, as proxy
00117   static Node * NewProxy( std::string ws_id,
00118                           std::string ws_kind, 
00119                           unsigned long nb_nodes,
00120                           CORBA::ORB * orbp  ) ;
00121   
00122   //! create a new node, as node
00123   static Node * NewPort( std::string ws_id,
00124                          std::string ws_kind, 
00125                          unsigned long num_node, 
00126                          unsigned long nb_nodes,
00127                          CORBA::ORB * orbp  ) ;
00128 
00129   //=========================================//
00130   //=========== public  interface ===========//
00131   //=========================================//
00132 public:
00133 
00134   //! print self
00135   virtual void printself(std::ostream & stream, int indent = 0) const;  
00136 
00137   //====================================//
00138   //============ Interface =============//
00139 
00140   //============ Activation =============//
00141 
00142   //! activate this node
00143   /** Do not ensure the workspace is activated after the return nor the "onActivation" treatments are done. 
00144    *  Must call "waitActivation" 
00145    **/
00146   void activate( ) ;
00147 
00148   //! deactivate this node
00149   /** Ensure the workspace is deactivated and the "onDeactivation" treatments are done **/
00150   void deactivate( ) ;
00151 
00152   //! test if the collective node is activated
00153   inline bool isActivated() const { return _local_workspace->getActivated(); }
00154 
00155   //=========== Connection =============//
00156 
00157   //! connect a remote workspace identified with an ID and a Kind on the local NameService
00158   /** Ensure the workspace is connected and the "onConnection" treatments are done **/
00159   inline unsigned long connect( const std::string & ws_id, const std::string & ws_kind )
00160   { return connect( ws_id, ws_kind, std::string() ); }
00161 
00162   //! connect a remote workspace identified with an ID and a Kind on another NameService
00163   /** Ensure the workspace is connected and the "onConnection" treatments are done **/
00164   unsigned long connect( const std::string & ws_id, const std::string & ws_kind, const std::string & nameservice_str) ;
00165 
00166   //! disconnect a remote workspace
00167   /** Ensure the workspace is disconnected and the "onDisonnection" treatments are done **/
00168   void disconnect( unsigned long num_connection ) ;
00169 
00170   //! disconnect all the remote workspaces
00171   /** Ensure all the connection are closed and all the "onDisonnection" treatments are done **/
00172   void disconnectAll( ) ;
00173 
00174   //! test if a workspace named 'ws_id' of kind 'ws_kind' is connected and return its connection number
00175   bool isConnected( std::string ws_id, std::string ws_kind ) const ;
00176 
00177   //! test if a workspace with num_connection is connected and return its connection number
00178   inline bool isConnected( unsigned long num_connection ) const
00179   { return (_remote_workspace_manager->find(num_connection) != _remote_workspace_manager->end() ); }
00180 
00181   //! test if a workspace named 'ws_id' of kind 'ws_kind' is connected and return its connection number
00182   unsigned long getNumConnection( std::string ws_id , std::string ws_kind ) ;
00183 
00184   //! get a vector of connection numbers according to id or kind critera
00185   void getNumConnectionVec( std::vector<unsigned long> & num_connection_vec ,
00186                             std::string ws_id = "" , 
00187                             std::string ws_kind = "" ) ;
00188 
00189   //=========== Description =============//
00190 
00191   //! get size of a remote workspace
00192   unsigned long getRemoteNbNodes( unsigned long num_connection, std::string node_kind = "" );
00193 
00194   //! get id of a remote workspace
00195   std::string getRemoteWorkspaceID( unsigned long num_connection );
00196 
00197   //! get kind of a remote workspace
00198   std::string getRemoteWorkspaceKind( unsigned long num_connection );
00199 
00200   //! get a remote remote workspace description
00201   inline WorkspaceDesc * getRemoteWorkspace( unsigned int num_connection )
00202   { return _remote_workspace_manager->getRemoteWorkspace(num_connection); }
00203 
00204   //! get size of the local workspace
00205   inline unsigned long getLocalNbNodes( std::string node_kind = "" ) const 
00206   { return _local_workspace->getNbNodes( node_kind ); }
00207 
00208   //! get id of the local workspace
00209   inline std::string getLocalWorkspaceID( ) const 
00210   { return _local_workspace->getId( ); }
00211 
00212   //! get kind of the local workspace
00213   inline std::string getLocalWorkspaceKind( ) const 
00214   { return _local_workspace->getKind( ); }
00215 
00216   //! get the local workspace description
00217   inline WorkspaceDesc * getLocalWorkspace() { return _local_workspace; }
00218 
00219   //==========================================//
00220   //============ Events Handling =============//
00221 
00222 public:
00223 
00224   //! add an event handler in the manager
00225   unsigned int addEventHandler( EventHandler * event_handler );
00226 
00227   //! remove an event handler from the manager
00228   void removeEventHandler( unsigned int key ); 
00229 
00230   //! remove an event handler from the manager
00231   void removeEventHandler( EventHandler * event_handler );
00232 
00233   //============ Activation =================//
00234 
00235   //! wait end of activation
00236   /** Ensure local onActivation treatments are done **/
00237   bool waitActivation( bool use_timeout = true ); 
00238 
00239   //! wait end of deactivation
00240   /** Ensure local onDeactivation treatments are done **/
00241   bool waitDeactivation( bool use_timeout = true );
00242 
00243   //=========== Connection ==================//
00244 
00245   //! wait the connection of a remote workspace
00246   /** Ensure local onConnection treatments are done **/
00247   unsigned long waitConnection( std::string ws_id, std::string ws_kind, bool use_timeout = true ); 
00248 
00249   //! wait the disconnection of all the remote workspace
00250   /** Ensure local onDisconnection treatments are done **/
00251   unsigned long waitAllDisconnection( bool use_timeout = true );
00252 
00253   //! wait the disconnection of a remote workspace
00254   /** Ensure local onDisconnection treatments are done **/
00255   unsigned long waitDisconnection( std::string ws_id, std::string ws_kind, bool use_timeout = true );
00256 
00257 protected:
00258 
00259   //! treatment on the activation of the workspace
00260   void onActivation( const IdlWorkspaceDesc& ws_desc ) ;
00261 
00262   //! treatment on the deactivation of the workspace
00263   void onDeactivation( const IdlWorkspaceDesc& ws_desc ) ;
00264 
00265   //! treatment on the connection of a remote workspace
00266   void onConnection( unsigned long num_connection, const IdlWorkspaceDesc& ws_desc, bool initiator ) ;
00267 
00268   //! treatment on the disconnection of a remote workspace
00269   void onDisconnection( unsigned long num_connection ) ;
00270 
00271   //============================================//
00272   //=========== protected  interface ===========//
00273   //============================================//
00274 
00275 protected:
00276 
00277   //=========== helpers ===========//
00278 
00279   static unsigned long calculNumFather(unsigned long min, unsigned long max, unsigned long num_child, unsigned long base);
00280 
00281   static unsigned long calculMaxDescend(unsigned long min, unsigned long max, unsigned long num_child, unsigned long base);
00282   
00283 
00284   //=======================================//
00285   //============== Accessors ==============//
00286 public:
00287   
00288   //! get a pointer on the associated event handler
00289   inline EventHandlerManager * getEventHandlerManager() {return _event_handler_manager;}
00290 
00291   //! associate an event handler with the workspace
00292   void setEventHandlerManager(EventHandlerManager * event_handler_manager);
00293 
00294   //! get a remote remote workspace manager
00295   inline RemoteWorkspaceManager * getRemoteWorkspaceManager( ) { return _remote_workspace_manager; }
00296 
00297   //! get the ORB pointer
00298   inline CORBA::ORB * getORB( ) const { return _orbp;}
00299 
00300   //! set the ORB pointer
00301   inline void setORB( CORBA::ORB * orbp ) { _orbp = orbp;}
00302 
00303   //=======================================//
00304   //=========== internal fields ===========//
00305 protected:
00306   
00307   //! Pointer on the ORB
00308   CORBA::ORB * _orbp;
00309 
00310   //! event handler
00311   EventHandlerManager * _event_handler_manager;
00312 
00313   //! Implementation of CORBA interface
00314   NodeServant * _node_servant;
00315 
00316   //! local workspace description
00317   WorkspaceDesc * _local_workspace;
00318 
00319   //! remote workspace manager
00320   RemoteWorkspaceManager * _remote_workspace_manager;
00321 
00322   //! boolean indicates the user activation treatements are terminated
00323   bool _fully_activated;
00324 
00325   //! event mutex
00326   pthread_mutex_t _event_mut;
00327 
00328   //! event condition variable
00329   pthread_cond_t _event_cond;
00330 
00331 };
00332 
00333 //===========================================================================//
00334 
00335 //! standard output stream operator
00336 std::ostream& operator <<(std::ostream& stream, const Node& _this);
00337 
00338 __COLCOWS_END__
00339 
00340 #endif // __COLCOWS_NODE_HH__
00341 
00342 //===========================================================================//
00343 
00344 /** \example TestClient.cc */
00345 /** \example TestClient2.cc */
00346 /** \example TestServer.cc */
00347 /** \example TestClient2_MPI.cc */
00348 /** \example TestServer_MPI.cc */
00349 
00350 //===========================================================================//
00351 
00352 // EOF
00353 

Generated on Tue Jun 21 12:55:56 2005 for ColCOWS by  doxygen 1.4.1