00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef OMNIIFR__DEPENDENCY_H
00024 #define OMNIIFR__DEPENDENCY_H
00025
00026 #include "Repository.h"
00027 #include "IdentifierUtil.h"
00028 #include <string.h>
00029
00030 namespace Omniifr {
00031
00038 inline IRObject_impl* referenceToServant(Object_ptr obj)
00039 {
00040 IRObject_impl* result =NULL;
00041 PortableServer::Servant servant =NULL;
00042
00043 try
00044 {
00045 servant=Repository_impl::inst()._poa->reference_to_servant(obj);
00046
00047 result=dynamic_cast<IRObject_impl*>(servant);
00048 }
00049 catch(PortableServer::POA::ObjectNotActive& ex)
00050 {
00051
00052 servant=NULL;
00053
00054
00055 DB(1,"?? Reference to object that doesn't exist yet. ??")
00056 }
00057 catch(PortableServer::POA::WrongAdapter& ex)
00058 {
00059 cerr<<"POA has wrong adapter for reference_to_servant()."<<endl;
00060 exit(1);
00061 }
00062 catch(PortableServer::POA::WrongPolicy& ex)
00063 {
00064 cerr<<"POA has wrong policy for reference_to_servant()."<<endl;
00065 exit(1);
00066 }
00067 catch(Exception& ex)
00068 {
00069 DB(1,"Failed to get reference_to_servant"
00070 IFELSE_OMNIORB4(" ("<<ex._name()<<")",))
00071 }
00072
00073 if(servant && !result)
00074 servant->_remove_ref();
00075 return result;
00076 }
00077
00078
00079
00080
00081
00088 template<class T_IRObject>
00089 class Dependency1 : public DependencyBase
00090 {
00091 public:
00092 Dependency1(IRObject_impl* owner)
00093 :DependencyBase(owner),_irobject(T_IRObject::_nil()),_servant(NULL){}
00094 virtual ~Dependency1(){clear();}
00095 inline typename T_IRObject::_ptr_type in() {return _irobject.in();}
00096 inline typename T_IRObject::_ptr_type copy()
00097 {
00098 return T_IRObject::_duplicate(_irobject.in());
00099 }
00100 inline void assign(typename T_IRObject::_ptr_type irobject)
00101 {
00102 typename T_IRObject::_var_type t(irobject);
00103 if(CORBA::is_nil(t.in()))
00104 throw CORBA::BAD_PARAM(
00105 IFELSE_OMNIORB4(omni::BAD_PARAM_InvalidObjectRef,43),
00106 CORBA::COMPLETED_NO
00107 );
00108 clear();
00109 set(t._retn());
00110 }
00112 inline void clear()
00113 {
00114 if(_servant)
00115 {
00116 _servant->undepend(this);
00117 _servant=NULL;
00118 }
00119 _irobject=T_IRObject::_nil();
00120 }
00121 private:
00122 typename T_IRObject::_var_type _irobject;
00123 IRObject_impl* _servant;
00124
00128 inline void set(typename T_IRObject::_ptr_type irobject)
00129 {
00130 _irobject=irobject;
00131 _servant=referenceToServant(irobject);
00132 if(_servant)
00133 {
00134 _servant->depend(this);
00135 _servant->_remove_ref();
00136 }
00137 }
00138 };
00139
00140
00142
00144
00147 template<class T_IRObjectSeq>
00148 class Dependency2 : public DependencyBase
00149 {
00150 private:
00151 T_IRObjectSeq _irobjectSeq;
00152 list<IRObject_impl*> _servants;
00153 public:
00154 Dependency2(IRObject_impl* owner)
00155 :DependencyBase(owner),_irobjectSeq(),_servants(){}
00156 virtual ~Dependency2(){}
00157 inline const T_IRObjectSeq& in(){return _irobjectSeq;}
00158 inline T_IRObjectSeq* copy() {return new T_IRObjectSeq(_irobjectSeq);}
00159 inline void assign(const T_IRObjectSeq& irobjectSeq)
00160 {
00161 check(irobjectSeq);
00162 clear();
00163 set(irobjectSeq);
00164 }
00166 inline void clear()
00167 {
00168 for(typename list<IRObject_impl*>::iterator i=_servants.begin();
00169 i!=_servants.end();
00170 ++i)
00171 {
00172 if(*i)
00173 (*i)->undepend(this);
00174 }
00175 _servants.clear();
00176 _irobjectSeq.length(0);
00177 }
00178 private:
00179
00187 inline void check(const T_IRObjectSeq& irobjectSeq)
00188 {
00189 for(CORBA::ULong i(0); i<irobjectSeq.length(); i++)
00190 {
00191 if(CORBA::is_nil(irobjectSeq[i]))
00192 throw CORBA::BAD_PARAM(
00193 IFELSE_OMNIORB4(omni::BAD_PARAM_InvalidObjectRef,43),
00194 CORBA::COMPLETED_NO
00195 );
00196 }
00197 }
00198
00202 inline void set(const T_IRObjectSeq& irobjectSeq)
00203 {
00204 assert(_servants.empty());
00205 assert(0==_irobjectSeq.length());
00206 _irobjectSeq=irobjectSeq;
00207 for(CORBA::ULong i(0); i<irobjectSeq.length(); i++)
00208 {
00209 IRObject_impl* irobject =referenceToServant(irobjectSeq[i]);
00210 if(irobject)
00211 {
00212 irobject->depend(this);
00213 irobject->_remove_ref();
00214 }
00215 _servants.push_back(irobject);
00216 }
00217 }
00218 };
00219
00220
00221
00223
00225
00230 template<class T_xxxDescriptionSeq>
00231 class Dependency3 : public DependencyBase
00232 {
00233 private:
00234 T_xxxDescriptionSeq _descriptionSeq;
00235 list<IRObject_impl*> _servants;
00236 public:
00237 Dependency3(IRObject_impl* owner)
00238 :DependencyBase(owner),_descriptionSeq(),_servants(){}
00239 virtual ~Dependency3(){}
00240 inline const T_xxxDescriptionSeq& in(){return _descriptionSeq;}
00241 inline T_xxxDescriptionSeq* copy()
00242 {
00243 return new T_xxxDescriptionSeq(_descriptionSeq);
00244 }
00245 inline void assign(const T_xxxDescriptionSeq& descriptionSeq)
00246 {
00247 check(descriptionSeq);
00248 uncheckedAssign(descriptionSeq);
00249 }
00253 inline void uncheckedAssign(const T_xxxDescriptionSeq& descriptionSeq)
00254 {
00255 clear();
00256 set(descriptionSeq);
00257 }
00259 inline void clear()
00260 {
00261 for(typename list<IRObject_impl*>::iterator i=_servants.begin();
00262 i!=_servants.end();
00263 ++i)
00264 {
00265 if(*i)
00266 (*i)->undepend(this);
00267 }
00268 _servants.clear();
00269 _descriptionSeq.length(0);
00270 }
00271 private:
00272
00280 inline void check(const T_xxxDescriptionSeq& descriptionSeq)
00281 {
00282 for(CORBA::ULong i(0); i<descriptionSeq.length(); i++)
00283 {
00284 IdentifierUtil::checkInvalid(descriptionSeq[i].name);
00285 if(CORBA::is_nil(descriptionSeq[i].type_def))
00286 throw CORBA::BAD_PARAM(
00287 IFELSE_OMNIORB4(omni::BAD_PARAM_InvalidObjectRef,43),
00288 CORBA::COMPLETED_NO
00289 );
00290 for(CORBA::ULong j(i+1); j<descriptionSeq.length(); j++)
00291 {
00292 if(0==strcasecmp(descriptionSeq[i].name,descriptionSeq[j].name))
00293 throw CORBA::BAD_PARAM(
00294 IFELSE_OMNIORB4(omni::BAD_PARAM_InvalidMemberName,17),
00295 CORBA::COMPLETED_NO
00296 );
00297 }
00298 }
00299 }
00300
00304 inline void set(const T_xxxDescriptionSeq& descriptionSeq)
00305 {
00306 assert(_servants.empty());
00307 assert(0==_descriptionSeq.length());
00308 _descriptionSeq=descriptionSeq;
00309 for(CORBA::ULong i(0); i<descriptionSeq.length(); i++)
00310 {
00311
00312 IRObject_impl* irobject =referenceToServant(descriptionSeq[i].type_def);
00313 if(irobject)
00314 {
00315 irobject->depend(this);
00316
00317 irobject->_remove_ref();
00318 }
00319 _servants.push_back(irobject);
00320 }
00321 }
00322 };
00323
00324 }
00325
00326 #endif // OMNIIFR__DEPENDENCY_H