Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

OperationDef.cc

Go to the documentation of this file.
00001 //                            Package   : omniIFR
00002 //  OperationDef.cc           Created   : 2004/02/22
00003 //                            Author    : Alex Tingle
00004 //
00005 //    Copyright (C) 2004 Alex Tingle.
00006 //
00007 //    This file is part of the omniIFR application.
00008 //
00009 //    omniIFR is free software; you can redistribute it and/or
00010 //    modify it under the terms of the GNU Lesser General Public
00011 //    License as published by the Free Software Foundation; either
00012 //    version 2.1 of the License, or (at your option) any later version.
00013 //
00014 //    omniIFR is distributed in the hope that it will be useful,
00015 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 //    Lesser General Public License for more details.
00018 //
00019 //    You should have received a copy of the GNU Lesser General Public
00020 //    License along with this library; if not, write to the Free Software
00021 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 #include "OperationDef.h"
00024 
00025 #include "idltype.h"
00026 #include "Container.h"
00027 #include "ExceptionDef.h"
00028 #include "PersistNode.h"
00029 #include "string_to.h"
00030 
00031 namespace Omniifr {
00032 
00033 TypeCode_ptr
00034 OperationDef_impl::result()
00035 {
00036   return TypeCode::_duplicate(_result.in());
00037 }
00038 
00039 IDLType_ptr
00040 OperationDef_impl::result_def()
00041 {
00042   return IDLType::_duplicate(_result_def.in());
00043 }
00044 
00045 void
00046 OperationDef_impl::result_def(IDLType_ptr v)
00047 {
00048   checkReadonly();
00049   checkOneway(_mode,_params.in(),v); // throws BAD_PARAM if check fails
00050   _result_def.assign(IDLType::_duplicate(v));
00051   _result=v->type();
00052 }
00053 
00054 ParDescriptionSeq* OperationDef_impl::params()
00055 {
00056   return _params.copy();
00057 }
00058 
00059 void OperationDef_impl::params(const ParDescriptionSeq& v)
00060 {
00061   checkReadonly();
00062   checkOneway(_mode,v,_result_def.in()); // throws BAD_PARAM if check fails
00063   _params.assign(v);
00064 }
00065 
00066 OperationMode OperationDef_impl::mode()
00067 {
00068   return _mode;
00069 }
00070 
00071 void OperationDef_impl::mode(OperationMode v)
00072 {
00073   checkReadonly();
00074   if(v!=OP_NORMAL && v!=OP_ONEWAY)
00075       throw CORBA::BAD_PARAM(
00076         IFELSE_OMNIORB4(omni::BAD_PARAM_EnumValueOutOfRange,25),
00077         CORBA::COMPLETED_NO
00078       );
00079   checkOneway(v,_params.in(),_result_def.in());
00080   _mode=v;
00081 }
00082 
00083 ContextIdSeq* OperationDef_impl::contexts()
00084 {
00085   return new ContextIdSeq(_contexts);
00086 }
00087 
00088 void OperationDef_impl::contexts(const ContextIdSeq& v)
00089 {
00090   checkReadonly();
00091   _contexts=v;
00092 }
00093 
00094 ExceptionDefSeq* OperationDef_impl::exceptions()
00095 {
00096   return _exceptions.copy();
00097 }
00098 
00099 void OperationDef_impl::exceptions(const ExceptionDefSeq& v)
00100 {
00101   checkReadonly();
00102   // Construct a new ExcDescriptionSeq, ready to assign to _excDescriptionSeq.
00103   // (Checks for problems before we do anything irrevocable.)
00104   ExcDescriptionSeq eds;
00105   eds.length(v.length());
00106   for(CORBA::ULong i=0; i<v.length(); i++)
00107   {
00108     CORBA::Contained::Description_var description =v[i]->describe();
00109     const ExceptionDescription* exceptionDescription;
00110     Boolean ok( description->value >>= exceptionDescription );
00111     if(!ok)
00112         throw CORBA::BAD_PARAM(
00113           IFELSE_OMNIORB4(omni::BAD_PARAM_EnumValueOutOfRange,25),
00114           CORBA::COMPLETED_NO
00115         );
00116     eds[i]=*exceptionDescription; // take a copy
00117     // No need to delete exceptionDescription - it's still owned by the Any.
00118   }
00119   // Perform the following two assignments in the correct order to ensure that
00120   // both _exceptions & _excDescriptionSeq remain untouched if an exception
00121   // occurs.
00122   _exceptions.assign(v); // may throw BAD_PARAM
00123   _excDescriptionSeq=eds; // does not throw.
00124 }
00125 
00126 CORBA::Contained::Description* OperationDef_impl::describe()
00127 {
00128   OperationDescription_var desc =new OperationDescription();
00129   desc->name       = name();
00130   desc->id         = id();
00131   desc->version    = version();
00132   desc->result     = result();
00133   desc->mode       = _mode;
00134   desc->contexts   = _contexts;
00135   desc->parameters = _params.in();
00136   desc->exceptions = _excDescriptionSeq;
00137   desc->defined_in = definedInId();
00138 
00139   CORBA::Contained::Description_var description =
00140     new CORBA::Contained::Description();
00141   description->kind  =   def_kind();
00142   description->value <<= desc._retn();
00143 
00144   return description._retn();
00145 }
00146 
00147 void OperationDef_impl::uncheckedDestroy()
00148 {
00149   _result_def.clear();
00150   _params.clear();
00151   _exceptions.clear();
00152   Contained_impl::uncheckedDestroy(); // superclass
00153 }
00154 
00155 void OperationDef_impl::reincarnate(const PersistNode& node)
00156 {
00157   _result_def.assign(
00158     string_to_<CORBA::IDLType>(node.attrString("result_def").c_str())
00159   );
00160   // Read state.
00161   // Order must match that in OperationDef_impl::output():
00162   cdrMemoryStream memstr =node.attrCdrStream("state");
00163   _result=TypeCode::unmarshalTypeCode(memstr);  // _result
00164   ParDescriptionSeq       p;                    // _params
00165                           p<<=memstr;
00166   _params.uncheckedAssign(p);
00167   _mode<<=memstr;                               // _mode
00168   _contexts<<=memstr;                           // _contexts
00169   ExceptionDefSeq    e;                         // _exceptions
00170                      e<<=memstr;
00171   _exceptions.assign(e);
00172   _excDescriptionSeq<<=memstr;                  // _excDescriptionSeq
00173 }
00174 
00175 void OperationDef_impl::output(ostream &os)
00176 {
00177   outputSelf(os,"OperationDef");
00178   PersistNode::outputIOR(os,_result_def.in(),"\n result_def=");
00179   cdrMemoryStream memstr(CORBA::ULong(0),CORBA::Boolean(1)/*clearMemory*/);
00180   TypeCode::marshalTypeCode(_result.in(),memstr);
00181   _params.in()>>=memstr;
00182   _mode>>=memstr;
00183   _contexts>>=memstr;
00184   _exceptions.in()>>=memstr;
00185   _excDescriptionSeq>>=memstr;
00186   PersistNode::outputCdrMemoryStream(os,memstr,"\n state=");
00187   os<<" ;;\n";
00188 }
00189 
00190 void OperationDef_impl::checkOneway(
00191   const OperationMode      mode,
00192   const ParDescriptionSeq& params,
00193   IDLType_ptr              result_def
00194 ) const
00195 {
00196   // Only worry about oneway operations.
00197   // If result_def is not yet set, then don't perform the check. This should
00198   // only happen during a call to InterfaceDef_impl::create_operation().
00199   if(mode==OP_ONEWAY && !CORBA::is_nil(result_def))
00200   {
00201     // Return type must be void.
00202     TypeCode_var resultTc =result_def->type();
00203     if(resultTc->kind()!=tk_void)
00204         throw CORBA::BAD_PARAM(31,CORBA::COMPLETED_NO);
00205 
00206     // Parameters' modes must be PARAM_IN.
00207     for(ULong i=0; i<params.length(); ++i)
00208     {
00209       if(params[i].mode!=PARAM_IN)
00210         throw CORBA::BAD_PARAM(31,CORBA::COMPLETED_NO);
00211     }
00212   }
00213 }
00214 
00215 } // end namespace Omniifr

Generated on Fri Mar 4 13:03:23 2005 for OmniIFR by  doxygen 1.4.1