TAO_PSDL_Code_Gen Class Reference

#include <PSDL_Code_Gen.h>

Collaboration diagram for TAO_PSDL_Code_Gen:

Collaboration graph
[legend]
List of all members.

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) throw (CORBA::SystemException)
const char * get_obj_ref (const char *name) throw (CORBA::SystemException)

Private Member Functions

CORBA::OctetSeqencode (const char *string_obj_ref) throw (CORBA::SystemException)
const char * decode (const CORBA::OctetSeq &data) throw (CORBA::SystemException)
 Helper method to get the octet sequence.


Private Attributes

const char * file_name_
 File where the persistent data is stored.

TAO_PSDL_Datastorepsdl_datastore_
 Pointer to the class which accesses the database.

CORBA::ORB_var orb_
 Pointer to ORB.

IOP::Codec_var codec_

Constructor & Destructor Documentation

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, and set_codec().

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 }


Member Function Documentation

const char * TAO_PSDL_Code_Gen::decode const CORBA::OctetSeq data  )  throw (CORBA::SystemException) [private]
 

Helper method to get the octet sequence.

Definition at line 155 of file PSDL_Code_Gen.cpp.

References ACE_CHECK_RETURN, ACE_ENV_ARG_PARAMETER, and CORBA::string_dup().

00158 {
00159   const char *extracted_value;
00160 
00161   // Extract the data from the octet sequence.
00162   CORBA::Any_var decoded_data =
00163     this->codec_->decode (data
00164                           ACE_ENV_ARG_PARAMETER);
00165   ACE_CHECK_RETURN (0);
00166 
00167   decoded_data.in() >>= extracted_value;
00168 
00169   return CORBA::string_dup (extracted_value);
00170 }

CORBA::OctetSeq * TAO_PSDL_Code_Gen::encode const char *  string_obj_ref  )  throw (CORBA::SystemException) [private]
 

Helper method which serializes the data and saves it to the database.

Definition at line 137 of file PSDL_Code_Gen.cpp.

References ACE_CHECK_RETURN, and ACE_ENV_ARG_PARAMETER.

00140 {
00141   CORBA::Any data;
00142   data <<= string_obj_ref;
00143 
00144   CORBA::OctetSeq *encoded_data = 0;
00145 
00146   encoded_data = this->codec_->encode (data ACE_ENV_ARG_PARAMETER);
00147   ACE_CHECK_RETURN (0);
00148 
00149   CORBA::OctetSeq_var safe_encoded_data = encoded_data;
00150 
00151   return safe_encoded_data._retn ();
00152 }

const char * TAO_PSDL_Code_Gen::get_obj_ref const char *  name  )  throw (CORBA::SystemException)
 

Get the stringified form of the object reference given the name of the object.

Definition at line 103 of file PSDL_Code_Gen.cpp.

References ACE_CHECK_RETURN, ACE_DEBUG, ACE_ENV_ARG_PARAMETER, LM_DEBUG, and CORBA::string_dup().

00106 {
00107   // Get from the hash_map saved in the database, the corresponding entry
00108   // (CORBA::OctetSeq *) for the name. Then, decode the octetseq to
00109   // get the stringified object reference and return it.
00110 
00111   CORBA::OctetSeq octet_seq;
00112 
00113   // Find the octet_seq for the name.
00114   int result = this->psdl_datastore_->find (name,
00115                                             octet_seq);
00116 
00117   if (result == 0)
00118     {
00119       // Decode the octet_seq.
00120       const char *obj_ref = this->decode (octet_seq
00121                                           ACE_ENV_ARG_PARAMETER);
00122       ACE_CHECK_RETURN (0);
00123 
00124       return CORBA::string_dup (obj_ref);
00125     }
00126   else
00127     {
00128       ACE_DEBUG ((LM_DEBUG,
00129                   "An entry for name %s is not found\n",
00130                   name));
00131       return 0;
00132     }
00133 }

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_CHECK_RETURN, ACE_DEBUG, ACE_DECLARE_NEW_CORBA_ENV, ACE_ENV_ARG_PARAMETER, codec_, and LM_DEBUG.

Referenced by TAO_PSDL_Code_Gen().

00031 {
00032   ACE_DECLARE_NEW_CORBA_ENV;
00033 
00034   // Obtain a reference to the CodecFactory.
00035   CORBA::Object_var obj =
00036     this->orb_->resolve_initial_references ("CodecFactory"
00037                                             ACE_ENV_ARG_PARAMETER);
00038   ACE_CHECK_RETURN (-1);
00039 
00040   IOP::CodecFactory_var codec_factory =
00041     IOP::CodecFactory::_narrow (obj.in () ACE_ENV_ARG_PARAMETER);
00042   ACE_CHECK_RETURN (-1);
00043 
00044   // Set up a structure that contains information necessary to
00045   // create a GIOP 1.1 CDR encapsulation Codec.
00046   IOP::Encoding encoding;
00047   encoding.format = IOP::ENCODING_CDR_ENCAPS;
00048   encoding.major_version = 1;
00049   encoding.minor_version = 1;
00050 
00051   // Obtain the CDR encapsulation Codec.
00052   this->codec_ =
00053     codec_factory->create_codec (encoding ACE_ENV_ARG_PARAMETER);
00054   ACE_CHECK_RETURN (-1);
00055 
00056   if (this->codec_.in () == 0)
00057     {
00058       ACE_DEBUG ((LM_DEBUG,
00059                   "codec pointer not set correctly\n"));
00060       return -1;
00061     }
00062   return 0;
00063 }

int TAO_PSDL_Code_Gen::set_name_obj_ref const char *  name,
const char *  string_obj_ref
throw (CORBA::SystemException)
 

Method to save the name-stringified object reference pair to the database. Returns -1 on failure.

Definition at line 66 of file PSDL_Code_Gen.cpp.

References ACE_CHECK_RETURN, ACE_DEBUG, ACE_ENV_ARG_PARAMETER, and LM_DEBUG.

00070 {
00071   // Invoke the helper encode method which will
00072   // convert the stringified object reference to a CORBA::OctetSeq.
00073   // Insert the name-CORBA::OCtetSeq pair to a hash_map and save the
00074   // hash_map to the database.
00075 
00076   // Encode the stringified object reference to a CORBA::OctetSeq *
00077   CORBA::OctetSeq_var octet_seq = this->encode (string_obj_ref
00078                                                 ACE_ENV_ARG_PARAMETER);
00079   ACE_CHECK_RETURN (-1);
00080 
00081   // Insert the new entry to the hash map which contains all the
00082   // name-octet_seq entries. And, write the hash_map to a file.
00083   int result = this->psdl_datastore_->bind (name,
00084                                             octet_seq.in ());
00085 
00086   if (result == -1)
00087     {
00088       ACE_DEBUG ((LM_DEBUG,
00089                   "Bind not done successfully \n"));
00090     }
00091   else if (result == 1)
00092     {
00093       /*ACE_DEBUG ((LM_DEBUG,
00094                     "Bind already done.\n"));
00095       */
00096       return 0;
00097     }
00098 
00099   return result;
00100 }


Member Data Documentation

IOP::Codec_var TAO_PSDL_Code_Gen::codec_ [private]
 

CDR encapsulation codec useful for encoding and decoding the data

Definition at line 88 of file PSDL_Code_Gen.h.

Referenced by set_codec().

const char* TAO_PSDL_Code_Gen::file_name_ [private]
 

File where the persistent data is stored.

Definition at line 78 of file PSDL_Code_Gen.h.

CORBA::ORB_var TAO_PSDL_Code_Gen::orb_ [private]
 

Pointer to ORB.

Definition at line 84 of file PSDL_Code_Gen.h.

TAO_PSDL_Datastore* TAO_PSDL_Code_Gen::psdl_datastore_ [private]
 

Pointer to the class which accesses the database.

Definition at line 81 of file PSDL_Code_Gen.h.

Referenced by ~TAO_PSDL_Code_Gen().


The documentation for this class was generated from the following files:
Generated on Thu Nov 9 14:08:36 2006 for TAO_PSS by doxygen 1.3.6