#include <PSDL_Code_Gen.h>
Collaboration diagram for TAO_PSDL_Code_Gen:

Public Member Functions | |
| TAO_PSDL_Code_Gen (CORBA::ORB_ptr orb) | |
| ~TAO_PSDL_Code_Gen (void) | |
| int | set_codec (void) |
| int | set_name_obj_ref (const char *name, const char *string_obj_ref) |
| const char * | get_obj_ref (const char *name) |
Private Member Functions | |
| CORBA::OctetSeq * | encode (const char *string_obj_ref) |
| const char * | decode (const CORBA::OctetSeq &data) |
| Helper method to get the octet sequence. | |
Private Attributes | |
| const char * | file_name_ |
| File where the persistent data is stored. | |
| TAO_PSDL_Datastore * | psdl_datastore_ |
| Pointer to the class which accesses the database. | |
| CORBA::ORB_var | orb_ |
| Pointer to ORB. | |
| IOP::Codec_var | codec_ |
Definition at line 38 of file PSDL_Code_Gen.h.
| TAO_PSDL_Code_Gen::TAO_PSDL_Code_Gen | ( | CORBA::ORB_ptr | orb | ) |
Definition at line 12 of file PSDL_Code_Gen.cpp.
References ACE_NEW.
00013 : file_name_ ("Data_Store"), 00014 psdl_datastore_ (), 00015 orb_ (orb), 00016 codec_ (0) 00017 { 00018 this->set_codec (); 00019 ACE_NEW (this->psdl_datastore_, 00020 TAO_PSDL_Datastore); 00021 00022 }
| TAO_PSDL_Code_Gen::~TAO_PSDL_Code_Gen | ( | void | ) |
Definition at line 24 of file PSDL_Code_Gen.cpp.
References psdl_datastore_.
00025 { 00026 delete this->psdl_datastore_; 00027 }
| const char * TAO_PSDL_Code_Gen::decode | ( | const CORBA::OctetSeq & | data | ) | [private] |
Helper method to get the octet sequence.
Definition at line 139 of file PSDL_Code_Gen.cpp.
References codec_, and CORBA::string_dup().
Referenced by get_obj_ref().
00140 { 00141 const char *extracted_value; 00142 00143 // Extract the data from the octet sequence. 00144 CORBA::Any_var decoded_data = 00145 this->codec_->decode (data); 00146 00147 decoded_data.in() >>= extracted_value; 00148 00149 return CORBA::string_dup (extracted_value); 00150 }
| CORBA::OctetSeq * TAO_PSDL_Code_Gen::encode | ( | const char * | string_obj_ref | ) | [private] |
Helper method which serializes the data and saves it to the database.
Definition at line 124 of file PSDL_Code_Gen.cpp.
References codec_.
Referenced by set_name_obj_ref().
00125 { 00126 CORBA::Any data; 00127 data <<= string_obj_ref; 00128 00129 CORBA::OctetSeq *encoded_data = 0; 00130 00131 encoded_data = this->codec_->encode (data); 00132 00133 CORBA::OctetSeq_var safe_encoded_data = encoded_data; 00134 00135 return safe_encoded_data._retn (); 00136 }
| const char * TAO_PSDL_Code_Gen::get_obj_ref | ( | const char * | name | ) |
Get the stringified form of the object reference given the name of the object.
Definition at line 94 of file PSDL_Code_Gen.cpp.
References ACE_DEBUG, decode(), TAO_PSDL_Datastore::find(), LM_DEBUG, psdl_datastore_, and CORBA::string_dup().
00095 { 00096 // Get from the hash_map saved in the database, the corresponding entry 00097 // (CORBA::OctetSeq *) for the name. Then, decode the octetseq to 00098 // get the stringified object reference and return it. 00099 00100 CORBA::OctetSeq octet_seq; 00101 00102 // Find the octet_seq for the name. 00103 int result = this->psdl_datastore_->find (name, 00104 octet_seq); 00105 00106 if (result == 0) 00107 { 00108 // Decode the octet_seq. 00109 const char *obj_ref = this->decode (octet_seq); 00110 00111 return CORBA::string_dup (obj_ref); 00112 } 00113 else 00114 { 00115 ACE_DEBUG ((LM_DEBUG, 00116 "An entry for name %s is not found\n", 00117 name)); 00118 return 0; 00119 } 00120 }
| int TAO_PSDL_Code_Gen::set_codec | ( | void | ) |
Initializes a IOP::CodecFactory and IOP::Codec to take care of the marshalling and demarshalling of data.
Definition at line 30 of file PSDL_Code_Gen.cpp.
References ACE_DEBUG, codec_, TAO_Pseudo_Var_T< T >::in(), LM_DEBUG, and orb_.
00031 { 00032 00033 // Obtain a reference to the CodecFactory. 00034 CORBA::Object_var obj = 00035 this->orb_->resolve_initial_references ("CodecFactory"); 00036 00037 IOP::CodecFactory_var codec_factory = 00038 IOP::CodecFactory::_narrow (obj.in ()); 00039 00040 // Set up a structure that contains information necessary to 00041 // create a GIOP 1.1 CDR encapsulation Codec. 00042 IOP::Encoding encoding; 00043 encoding.format = IOP::ENCODING_CDR_ENCAPS; 00044 encoding.major_version = 1; 00045 encoding.minor_version = 1; 00046 00047 // Obtain the CDR encapsulation Codec. 00048 this->codec_ = 00049 codec_factory->create_codec (encoding); 00050 00051 if (this->codec_.in () == 0) 00052 { 00053 ACE_DEBUG ((LM_DEBUG, 00054 "codec pointer not set correctly\n")); 00055 return -1; 00056 } 00057 return 0; 00058 }
| int TAO_PSDL_Code_Gen::set_name_obj_ref | ( | const char * | name, | |
| const char * | string_obj_ref | |||
| ) |
Method to save the name-stringified object reference pair to the database. Returns -1 on failure.
Definition at line 61 of file PSDL_Code_Gen.cpp.
References ACE_DEBUG, TAO_PSDL_Datastore::bind(), encode(), LM_DEBUG, and psdl_datastore_.
00063 { 00064 // Invoke the helper encode method which will 00065 // convert the stringified object reference to a CORBA::OctetSeq. 00066 // Insert the name-CORBA::OCtetSeq pair to a hash_map and save the 00067 // hash_map to the database. 00068 00069 // Encode the stringified object reference to a CORBA::OctetSeq * 00070 CORBA::OctetSeq_var octet_seq = this->encode (string_obj_ref); 00071 00072 // Insert the new entry to the hash map which contains all the 00073 // name-octet_seq entries. And, write the hash_map to a file. 00074 int result = this->psdl_datastore_->bind (name, 00075 octet_seq.in ()); 00076 00077 if (result == -1) 00078 { 00079 ACE_DEBUG ((LM_DEBUG, 00080 "Bind not done successfully \n")); 00081 } 00082 else if (result == 1) 00083 { 00084 /*ACE_DEBUG ((LM_DEBUG, 00085 "Bind already done.\n")); 00086 */ 00087 return 0; 00088 } 00089 00090 return result; 00091 }
IOP::Codec_var TAO_PSDL_Code_Gen::codec_ [private] |
CDR encapsulation codec useful for encoding and decoding the data
Definition at line 80 of file PSDL_Code_Gen.h.
Referenced by decode(), encode(), and set_codec().
const char* TAO_PSDL_Code_Gen::file_name_ [private] |
CORBA::ORB_var TAO_PSDL_Code_Gen::orb_ [private] |
Pointer to the class which accesses the database.
Definition at line 73 of file PSDL_Code_Gen.h.
Referenced by get_obj_ref(), set_name_obj_ref(), and ~TAO_PSDL_Code_Gen().
1.4.7