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 #include "ColCOWS_NodeDesc.hh"
00028 #include "ColCOWS_Corba.hh"
00029
00030 using namespace std;
00031
00032 __COLCOWS_BEGIN__
00033
00034
00035
00036 void NodeDesc::getObjectDescVec( ExtObjectDescVec & object_desc_vec, std::string obj_id, std::string obj_kind ) const
00037 {
00038 COLCOWS_IN_DEBUG( );
00039
00040 for( const_iterator it = begin(); it != end(); ++it )
00041 {
00042 if ( ( obj_id.empty() || (obj_id == it->second.obj_id) ) &&
00043 ( obj_kind.empty() || (obj_kind == it->second.obj_kind) ) )
00044 {
00045 ExtObjectDesc new_desc = it->second ;
00046 new_desc.num_node = _num_node;
00047 object_desc_vec.push_back(new_desc);
00048 }
00049 }
00050
00051 COLCOWS_OUT_DEBUG( );
00052 return;
00053 }
00054
00055
00056
00057 void NodeDesc::convertFromIdl( const IdlNodeDesc & idl_node_desc )
00058 {
00059 COLCOWS_IN_DEBUG( );
00060
00061 clear();
00062
00063 _node_kind = idl_node_desc.node_kind;
00064 _num_node = idl_node_desc.num_node;
00065 _max_descendant = idl_node_desc.max_descendant;
00066 _activated = idl_node_desc.activated;
00067
00068 for(unsigned int i = 0 ; i < idl_node_desc.ref_seq.length(); ++i )
00069 {
00070 string id = (const char *) idl_node_desc.ref_seq[i].obj_id;
00071 string kind = (const char *) idl_node_desc.ref_seq[i].obj_kind;
00072 CORBA::Object_ptr ref;
00073 idl_node_desc.ref_seq[i].obj_ref >>= CORBA::Any::to_object(ref);
00074
00075 insert(make_pair(id, ObjectDesc(id, kind, ref)));
00076 }
00077
00078 COLCOWS_OUT_DEBUG( );
00079 }
00080
00081
00082
00083 void NodeDesc::convertToIdl( IdlNodeDesc & idl_node_desc ) const
00084 {
00085 COLCOWS_IN_DEBUG( );
00086
00087 idl_node_desc.node_kind = CORBA::string_dup( _node_kind.c_str() );
00088 idl_node_desc.num_node = _num_node;
00089 idl_node_desc.max_descendant = _max_descendant;
00090 idl_node_desc.activated = _activated;
00091
00092
00093 idl_node_desc.ref_seq.length( size() );
00094
00095 unsigned int i;
00096 const_iterator it;
00097
00098 for( i = 0 , it = begin() ; (i < idl_node_desc.ref_seq.length()) && (it != end()); ++i , ++it )
00099 {
00100 idl_node_desc.ref_seq[i].obj_id = CORBA::string_dup( it->second.obj_id.c_str() );
00101 idl_node_desc.ref_seq[i].obj_kind = CORBA::string_dup( it->second.obj_kind.c_str() );
00102 idl_node_desc.ref_seq[i].obj_ref <<= it->second.obj_ref;
00103 }
00104
00105 return;
00106 COLCOWS_OUT_DEBUG( );
00107 }
00108
00109
00110
00111 void NodeDesc::updateIdl( IdlNodeDesc & idl_node_desc ) const
00112 {
00113 COLCOWS_IN_DEBUG( );
00114
00115 COLCOWS_ASSERT( ( _node_kind == (char*)idl_node_desc.node_kind ), "Node kinds do not match" );
00116 COLCOWS_ASSERT( ( _num_node == idl_node_desc.num_node ), "Node numbers do not match" );
00117 COLCOWS_ASSERT( ( !idl_node_desc.activated ), "IDL node description is activated" );
00118
00119 idl_node_desc.ref_seq.length( size() );
00120
00121 unsigned int i;
00122 const_iterator it;
00123
00124 for( i = 0 , it = begin() ; (i < idl_node_desc.ref_seq.length()) && (it != end()); ++i , ++it )
00125 {
00126 idl_node_desc.ref_seq[i].obj_id = CORBA::string_dup( it->second.obj_id.c_str() );
00127 idl_node_desc.ref_seq[i].obj_kind = CORBA::string_dup( it->second.obj_kind.c_str() );
00128 idl_node_desc.ref_seq[i].obj_ref <<= it->second.obj_ref;
00129 }
00130
00131 return;
00132 COLCOWS_OUT_DEBUG( );
00133 }
00134
00135
00136
00137 void NodeDesc::addReference( std::string obj_id, std::string obj_kind, CORBA::Object * ref)
00138 {
00139 COLCOWS_IN_DEBUG( );
00140
00141 COLCOWS_ASSERT( !_activated , "Node description is activated" );
00142 COLCOWS_ASSERT( (find(obj_id) == end()) , "Reference " << obj_id << " already in this node description");
00143
00144 insert(make_pair(obj_id, ObjectDesc(obj_id, obj_kind, ref)));
00145
00146 return;
00147 COLCOWS_OUT_DEBUG( );
00148 }
00149
00150
00151
00152 CORBA::Object * NodeDesc::getReference( std::string obj_id ) const
00153 {
00154 COLCOWS_IN_DEBUG( );
00155
00156 const_iterator it = find(obj_id);
00157
00158 COLCOWS_ASSERT( (it != end()) , "Cannot find reference " << obj_id << " in this node description");
00159
00160 return it->second.obj_ref;
00161 COLCOWS_OUT_DEBUG( );
00162 }
00163
00164
00165
00166 void NodeDesc::clearReferences( )
00167 {
00168 COLCOWS_IN_DEBUG( );
00169
00170 COLCOWS_ASSERT( !_activated , "Node description is activated" );
00171 clear();
00172
00173 return;
00174 COLCOWS_OUT_DEBUG( );
00175 }
00176
00177
00178
00179 void NodeDesc::printself( std::ostream & stream, int indent ) const
00180 {
00181 std::string space;
00182 for(int i = 0; i < indent; i++, space += COLCOWS_TAB);
00183
00184 stream << space << "node kind: " << _node_kind << std::endl;
00185 stream << space << "num node: " << _num_node << std::endl;
00186 stream << space << "activated: " << boolalpha << _activated << std::endl;
00187 stream << space << "objects: " << std::endl;
00188
00189 for( const_iterator it = begin(); it != end() ; ++it ) {
00190 stream << "-" ;
00191 it->second.printself(stream, indent + 1);
00192 stream << endl;
00193 }
00194 }
00195
00196
00197 __COLCOWS_END__
00198
00199
00200