00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
00054 const unsigned int WAITING_TIMEOUT = 2;
00055
00056
00057 const unsigned int WAITING_RETRY = 10;
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 class Node : public NodeDesc
00074 {
00075
00076
00077 friend class NodeServant;
00078
00079
00080
00081
00082 public:
00083
00084
00085 Node();
00086
00087
00088 virtual ~Node();
00089
00090
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
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
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
00117 static Node * NewProxy( std::string ws_id,
00118 std::string ws_kind,
00119 unsigned long nb_nodes,
00120 CORBA::ORB * orbp ) ;
00121
00122
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
00131
00132 public:
00133
00134
00135 virtual void printself(std::ostream & stream, int indent = 0) const;
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 void activate( ) ;
00147
00148
00149
00150 void deactivate( ) ;
00151
00152
00153 inline bool isActivated() const { return _local_workspace->getActivated(); }
00154
00155
00156
00157
00158
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
00163
00164 unsigned long connect( const std::string & ws_id, const std::string & ws_kind, const std::string & nameservice_str) ;
00165
00166
00167
00168 void disconnect( unsigned long num_connection ) ;
00169
00170
00171
00172 void disconnectAll( ) ;
00173
00174
00175 bool isConnected( std::string ws_id, std::string ws_kind ) const ;
00176
00177
00178 inline bool isConnected( unsigned long num_connection ) const
00179 { return (_remote_workspace_manager->find(num_connection) != _remote_workspace_manager->end() ); }
00180
00181
00182 unsigned long getNumConnection( std::string ws_id , std::string ws_kind ) ;
00183
00184
00185 void getNumConnectionVec( std::vector<unsigned long> & num_connection_vec ,
00186 std::string ws_id = "" ,
00187 std::string ws_kind = "" ) ;
00188
00189
00190
00191
00192 unsigned long getRemoteNbNodes( unsigned long num_connection, std::string node_kind = "" );
00193
00194
00195 std::string getRemoteWorkspaceID( unsigned long num_connection );
00196
00197
00198 std::string getRemoteWorkspaceKind( unsigned long num_connection );
00199
00200
00201 inline WorkspaceDesc * getRemoteWorkspace( unsigned int num_connection )
00202 { return _remote_workspace_manager->getRemoteWorkspace(num_connection); }
00203
00204
00205 inline unsigned long getLocalNbNodes( std::string node_kind = "" ) const
00206 { return _local_workspace->getNbNodes( node_kind ); }
00207
00208
00209 inline std::string getLocalWorkspaceID( ) const
00210 { return _local_workspace->getId( ); }
00211
00212
00213 inline std::string getLocalWorkspaceKind( ) const
00214 { return _local_workspace->getKind( ); }
00215
00216
00217 inline WorkspaceDesc * getLocalWorkspace() { return _local_workspace; }
00218
00219
00220
00221
00222 public:
00223
00224
00225 unsigned int addEventHandler( EventHandler * event_handler );
00226
00227
00228 void removeEventHandler( unsigned int key );
00229
00230
00231 void removeEventHandler( EventHandler * event_handler );
00232
00233
00234
00235
00236
00237 bool waitActivation( bool use_timeout = true );
00238
00239
00240
00241 bool waitDeactivation( bool use_timeout = true );
00242
00243
00244
00245
00246
00247 unsigned long waitConnection( std::string ws_id, std::string ws_kind, bool use_timeout = true );
00248
00249
00250
00251 unsigned long waitAllDisconnection( bool use_timeout = true );
00252
00253
00254
00255 unsigned long waitDisconnection( std::string ws_id, std::string ws_kind, bool use_timeout = true );
00256
00257 protected:
00258
00259
00260 void onActivation( const IdlWorkspaceDesc& ws_desc ) ;
00261
00262
00263 void onDeactivation( const IdlWorkspaceDesc& ws_desc ) ;
00264
00265
00266 void onConnection( unsigned long num_connection, const IdlWorkspaceDesc& ws_desc, bool initiator ) ;
00267
00268
00269 void onDisconnection( unsigned long num_connection ) ;
00270
00271
00272
00273
00274
00275 protected:
00276
00277
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
00286 public:
00287
00288
00289 inline EventHandlerManager * getEventHandlerManager() {return _event_handler_manager;}
00290
00291
00292 void setEventHandlerManager(EventHandlerManager * event_handler_manager);
00293
00294
00295 inline RemoteWorkspaceManager * getRemoteWorkspaceManager( ) { return _remote_workspace_manager; }
00296
00297
00298 inline CORBA::ORB * getORB( ) const { return _orbp;}
00299
00300
00301 inline void setORB( CORBA::ORB * orbp ) { _orbp = orbp;}
00302
00303
00304
00305 protected:
00306
00307
00308 CORBA::ORB * _orbp;
00309
00310
00311 EventHandlerManager * _event_handler_manager;
00312
00313
00314 NodeServant * _node_servant;
00315
00316
00317 WorkspaceDesc * _local_workspace;
00318
00319
00320 RemoteWorkspaceManager * _remote_workspace_manager;
00321
00322
00323 bool _fully_activated;
00324
00325
00326 pthread_mutex_t _event_mut;
00327
00328
00329 pthread_cond_t _event_cond;
00330
00331 };
00332
00333
00334
00335
00336 std::ostream& operator <<(std::ostream& stream, const Node& _this);
00337
00338 __COLCOWS_END__
00339
00340 #endif // __COLCOWS_NODE_HH__
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353