00001
00002
00003
00004 #include "PSDL_Code_Gen.h"
00005 #include "PSDL_Datastore.h"
00006 #include "tao/OctetSeqC.h"
00007 #include "tao/AnyTypeCode/Any.h"
00008 #include "tao/CodecFactory/CodecFactory.h"
00009
00010 ACE_RCSID (PSS, PSDL_Code_Gen, "PSDL_Code_Gen.cpp,v 1.4 2005/08/19 08:02:26 jwillemsen Exp")
00011
00012 TAO_PSDL_Code_Gen::TAO_PSDL_Code_Gen (CORBA::ORB_ptr orb)
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 }
00023
00024 TAO_PSDL_Code_Gen::~TAO_PSDL_Code_Gen (void)
00025 {
00026 delete this->psdl_datastore_;
00027 }
00028
00029 int
00030 TAO_PSDL_Code_Gen::set_codec (void)
00031 {
00032 ACE_DECLARE_NEW_CORBA_ENV;
00033
00034
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
00045
00046 IOP::Encoding encoding;
00047 encoding.format = IOP::ENCODING_CDR_ENCAPS;
00048 encoding.major_version = 1;
00049 encoding.minor_version = 1;
00050
00051
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 }
00064
00065 int
00066 TAO_PSDL_Code_Gen::set_name_obj_ref (const char *name,
00067 const char *string_obj_ref
00068 ACE_ENV_ARG_DECL)
00069 ACE_THROW_SPEC ((CORBA::SystemException))
00070 {
00071
00072
00073
00074
00075
00076
00077 CORBA::OctetSeq_var octet_seq = this->encode (string_obj_ref
00078 ACE_ENV_ARG_PARAMETER);
00079 ACE_CHECK_RETURN (-1);
00080
00081
00082
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
00094
00095
00096 return 0;
00097 }
00098
00099 return result;
00100 }
00101
00102 const char *
00103 TAO_PSDL_Code_Gen::get_obj_ref (const char *name
00104 ACE_ENV_ARG_DECL)
00105 ACE_THROW_SPEC ((CORBA::SystemException))
00106 {
00107
00108
00109
00110
00111 CORBA::OctetSeq octet_seq;
00112
00113
00114 int result = this->psdl_datastore_->find (name,
00115 octet_seq);
00116
00117 if (result == 0)
00118 {
00119
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 }
00134
00135
00136 CORBA::OctetSeq *
00137 TAO_PSDL_Code_Gen::encode (const char *string_obj_ref
00138 ACE_ENV_ARG_DECL)
00139 ACE_THROW_SPEC ((CORBA::SystemException))
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 }
00153
00154 const char *
00155 TAO_PSDL_Code_Gen::decode (const CORBA::OctetSeq &data
00156 ACE_ENV_ARG_DECL)
00157 ACE_THROW_SPEC ((CORBA::SystemException))
00158 {
00159 const char *extracted_value;
00160
00161
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 }