Public Member Functions | Private Member Functions | Private Attributes

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)
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_Datastorepsdl_datastore_
 Pointer to the class which accesses the database.
CORBA::ORB_var orb_
 Pointer to ORB.
IOP::Codec_var codec_

Detailed Description

Definition at line 38 of file PSDL_Code_Gen.h.


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.

  : file_name_ ("Data_Store"),
    psdl_datastore_ (),
    orb_ (orb),
    codec_ (0)
{
  this->set_codec ();
  ACE_NEW (this->psdl_datastore_,
           TAO_PSDL_Datastore);

}

TAO_PSDL_Code_Gen::~TAO_PSDL_Code_Gen ( void   ) 

Definition at line 24 of file PSDL_Code_Gen.cpp.

{
  delete this->psdl_datastore_;
}


Member Function Documentation

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.

{
  const char *extracted_value;

  // Extract the data from the octet sequence.
  CORBA::Any_var decoded_data =
    this->codec_->decode (data);

  decoded_data.in() >>= extracted_value;

  return CORBA::string_dup (extracted_value);
}

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.

{
  CORBA::Any data;
  data <<= string_obj_ref;

  CORBA::OctetSeq *encoded_data = 0;

  encoded_data = this->codec_->encode (data);

  CORBA::OctetSeq_var safe_encoded_data = encoded_data;

  return safe_encoded_data._retn ();
}

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.

{
  // Get from the hash_map saved in the database, the corresponding entry
  // (CORBA::OctetSeq *) for the name. Then, decode the octetseq to
  // get the stringified object reference and return it.

  CORBA::OctetSeq octet_seq;

  // Find the octet_seq for the name.
  int result = this->psdl_datastore_->find (name,
                                            octet_seq);

  if (result == 0)
    {
      // Decode the octet_seq.
      const char *obj_ref = this->decode (octet_seq);

      return CORBA::string_dup (obj_ref);
    }
  else
    {
      ACE_DEBUG ((LM_DEBUG,
                  "An entry for name %s is not found\n",
                  name));
      return 0;
    }
}

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.

{

  // Obtain a reference to the CodecFactory.
  CORBA::Object_var obj =
    this->orb_->resolve_initial_references ("CodecFactory");

  IOP::CodecFactory_var codec_factory =
    IOP::CodecFactory::_narrow (obj.in ());

  // Set up a structure that contains information necessary to
  // create a GIOP 1.1 CDR encapsulation Codec.
  IOP::Encoding encoding;
  encoding.format = IOP::ENCODING_CDR_ENCAPS;
  encoding.major_version = 1;
  encoding.minor_version = 1;

  // Obtain the CDR encapsulation Codec.
  this->codec_ =
    codec_factory->create_codec (encoding);

  if (this->codec_.in () == 0)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "codec pointer not set correctly\n"));
      return -1;
    }
  return 0;
}

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.

{
  // Invoke the helper encode method which will
  // convert the stringified object reference to a CORBA::OctetSeq.
  // Insert the name-CORBA::OCtetSeq pair to a hash_map and save the
  // hash_map to the database.

  // Encode the stringified object reference to a CORBA::OctetSeq *
  CORBA::OctetSeq_var octet_seq = this->encode (string_obj_ref);

  // Insert the new entry to the hash map which contains all the
  // name-octet_seq entries. And, write the hash_map to a file.
  int result = this->psdl_datastore_->bind (name,
                                            octet_seq.in ());

  if (result == -1)
    {
      ACE_DEBUG ((LM_DEBUG,
                  "Bind not done successfully\n"));
    }
  else if (result == 1)
    {
      /*ACE_DEBUG ((LM_DEBUG,
                    "Bind already done.\n"));
      */
      return 0;
    }

  return result;
}


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 80 of file PSDL_Code_Gen.h.

const char* TAO_PSDL_Code_Gen::file_name_ [private]

File where the persistent data is stored.

Definition at line 70 of file PSDL_Code_Gen.h.

Pointer to ORB.

Definition at line 76 of file PSDL_Code_Gen.h.

Pointer to the class which accesses the database.

Definition at line 73 of file PSDL_Code_Gen.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines