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

ColCOWS_NodeServant.hh

00001 //===========================================================================//
00002 //    
00003 //    Description: Implementation of ColCOWS Node interface 
00004 //    Filename: colcows/ColCOWS_NodeServant.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_IMPL_HH__
00029 #define __COLCOWS_NODE_IMPL_HH__
00030 
00031 //---------------------------------------------------------------------------//
00032 #include "ColCOWS_Include.hh"
00033 #include "ColCOWS_Debug.hh" 
00034 #include "ColCOWS_Corba.hh"
00035 //---------------------------------------------------------------------------//
00036 
00037 __COLCOWS_BEGIN__
00038 
00039 //! standard output stream operator
00040 std::ostream& operator <<(std::ostream& stream, const IdlWorkspaceDesc& wsdesc);
00041 //! standard output stream operator
00042 std::ostream& operator <<(std::ostream& stream, const IdlWorkspaceDescSeq& wsdesc_seq);
00043 
00044 //! standard output stream operator
00045 std::ostream& operator <<(std::ostream& stream, const IdlNodeDesc& wsnode);
00046 //! standard output stream operator
00047 std::ostream& operator <<(std::ostream& stream, const IdlNodeDescSeq& wsnode_seq);
00048 
00049 //! standard output stream operator
00050 std::ostream& operator <<(std::ostream& stream, const IdlObjectDesc& ref);
00051 //! standard output stream operator
00052 std::ostream& operator <<(std::ostream& stream, const IdlObjectDescSeq& ref_seq);
00053 
00054 //===========================================================================//
00055 //                       collective node class                               //
00056 //===========================================================================//
00057 
00058 class Node;
00059 
00060 
00061 //! ColCOWS node interface implementation
00062 /** 
00063  * The NodeServant is the implementation of the NodeInterface defined in the IDL.
00064  * This class is in charge of the operations between the nodes of a workspace as well
00065  * as the operations between workspaces.
00066  */
00067 class NodeServant : 
00068   public virtual POA_ColCOWS::NodeInterface,
00069   public virtual PortableServer::RefCountServantBase
00070 {
00071 
00072   //=========== friend classes ===========//
00073   friend class Node;
00074 
00075   //================================================//
00076   //=========== class standard interface ===========//
00077 public:
00078   
00079   //! constructor
00080   NodeServant();
00081   
00082   //! destructor
00083   virtual ~NodeServant();
00084 
00085   static NodeServant * New(const char* ws_id, 
00086                            const char* ws_kind, 
00087                            const char* node_kind, 
00088                            unsigned long num_node, 
00089                            unsigned long max_descendant, 
00090                            unsigned long nb_nodes,
00091                            unsigned long num_father,
00092                            CORBA::ORB_ptr orbp  ) ;
00093 
00094  //=========================================//
00095   //=========== public  interface ===========//
00096 public:
00097 
00098   //! print self
00099   virtual void printself(std::ostream & stream) const;  
00100 
00101   //! standard output stream operator
00102   friend std::ostream& operator <<(std::ostream& stream, const NodeServant& _this);
00103 
00104   //! lock children mutex
00105   inline void lockChildrenMutex() { pthread_mutex_lock(&_children_mut); }
00106 
00107   //! unlock children mutex
00108   inline void unlockChildrenMutex() { pthread_mutex_unlock(&_children_mut); }
00109 
00110   //! lock activation mutex
00111   inline void lockActivationMutex() { pthread_mutex_lock(&_activation_mut); }
00112 
00113   //! unlock activation mutex
00114   inline void unlockActivationMutex() { pthread_mutex_unlock(&_activation_mut); }
00115 
00116 protected:
00117 
00118   //! activate this node
00119   void activate( ) ;
00120 
00121   //! deactivate this node
00122   void deactivate( ) ;
00123 
00124   //! connect a remote workspace identified with an ID and a Kind on another NameService
00125   unsigned long connect( const std::string & ws_id, const std::string & ws_kind, const std::string & nameservice_str) ;
00126 
00127   //! connect a remote workspace
00128   void disconnect( unsigned long num_connection ) ;
00129 
00130   //! connect a remote workspace
00131   void disconnectAll( ) ;
00132 
00133   //! register this node to his father
00134   bool registerToFather( unsigned long max_retry = 0 ) ;
00135 
00136 private:
00137 
00138   //! get the storage index of the connection
00139   long indexConnection( CORBA::ULong num_connection );  
00140 
00141   //==============================================//
00142   //=========== public corba interface ===========//
00143 public:
00144 
00145   //! set the workspace description [public]
00146   virtual void setWorkspace(const IdlWorkspaceDesc& ws_desc);
00147 
00148   //! set child node description 
00149   virtual void setChildNode(const IdlNodeDesc& node_desc) throw (CorbaException) ;
00150 
00151   //=======================================//
00152 
00153   //! test if the collective node is activated
00154   virtual CORBA::Boolean isActivated() throw (CorbaException) ;
00155 
00156   //! test if the workspace is ready to receive connections [public]  
00157   virtual CORBA::Boolean isReady() throw (CorbaException) ;
00158 
00159   //! test if the connection exists
00160   virtual CORBA::Boolean isConnected( CORBA::ULong num_connection ) throw (CorbaException) ;
00161 
00162   //! test if the collective node id is connected
00163   virtual CORBA::ULong getNumConnection(const char* ws_id, const char * ws_kind ) throw (CorbaException) ;
00164 
00165   //! get a unige connection number
00166   virtual void getCommonNumConnection( CORBA::ULong & num_connection_proposal )throw (CorbaException)  ;
00167 
00168   //=======================================//
00169     
00170   //! get a node description 
00171   virtual void getNode(CORBA::ULong num_node, IdlNodeDesc_out node_desc) throw (CorbaException) ;
00172 
00173   //! get the workspace description [public]
00174   virtual void getWorkspace(IdlWorkspaceDesc_out ws_desc) throw (CorbaException) ;
00175 
00176   //! get the remote workspace description [public]
00177   virtual void getRemoteWorkspace(CORBA::ULong num_connection, IdlWorkspaceDesc_out ws_desc) throw (CorbaException) ;
00178     
00179   //! set the remote workspace description [public]
00180   virtual void setRemoteWorkspace(CORBA::ULong num_connection, 
00181                                   const IdlWorkspaceDesc& ws_desc, 
00182                                   CORBA::Boolean connection_initiator);
00183 
00184    //! remove the remote workspace description [public]
00185    virtual void releaseRemoteWorkspace( CORBA::ULong num_connection );
00186 
00187   //=======================================//
00188   //=========== internal fields ===========//
00189 protected:
00190 
00191   //! Description of this Workspace Node
00192   IdlNodeDesc_var        _my_node;
00193   //! Description of the father Workspace Node
00194   IdlNodeDesc_var        _father_node;
00195   //! Descriptions of the children Workspace Nodes
00196   //! \bug suppress _children_nodes and use directly _my_node->children_seq
00197   IdlNodeDescSeq_var     _children_nodes;
00198 
00199   //! Description of the local Workspace 
00200   IdlWorkspaceDesc_var     _local_workspace;
00201   //! Description of the connected Workspaces
00202   IdlWorkspaceDescSeq_var  _remote_workspaces;
00203 
00204 
00205 protected:
00206 
00207   //! Pointer on the ORB
00208   CORBA::ORB_ptr _orbp;
00209 
00210   // root context of the Naming Service
00211   CosNaming::NamingContext_var _naming_ctxt;
00212 
00213   //! POA
00214   PortableServer::POA_var _root_poa;
00215 
00216   //! POA
00217   PortableServer::POA_var _colcows_poa;
00218 
00219   //! POA manager
00220   PortableServer::POAManager_var  _colcows_pman;
00221   
00222   //! ready to receive connections
00223   bool _ready;
00224 
00225   //! need auto-activation
00226   bool _auto_activation;
00227 
00228   //! is registred to father
00229   bool _registred_to_father;
00230 
00231   //! next number of connection
00232   unsigned long _current_num_connection;
00233 
00234   //! access to children desc mutex
00235   pthread_mutex_t _children_mut;
00236 
00237   //! activation mutex
00238   pthread_mutex_t _activation_mut;
00239 
00240   //! activation condition variable
00241   pthread_cond_t _activation_cond;
00242 
00243   //! associated Node
00244   Node * _colcows_node;
00245 };
00246 
00247 __COLCOWS_END__
00248 
00249 #endif // __COLCOWS_NODE_IMPL_HH__
00250 
00251 // EOF
00252 

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