00001
00002
00003
00004
00005
00006
00007
00008
00011 #ifndef HxCorbaConversions_h
00012 #define HxCorbaConversions_h
00013
00014 #include <OB/CORBA.h>
00015 #include "HxServerBase.h"
00016 #include "HxBaseTieRefCount.h"
00017
00018 HxImageSignature
00019 HxConvertImageSig(HxCorba::ImageSignature sig);
00020
00021 HxCorba::ImageSignature
00022 HxConvertImageSig(HxImageSignature sig);
00023
00024 HxImageRep::ResultPrecision
00025 HxConvertPrecision(HxCorba::ResultPrecision prec);
00026
00027 HxGeoIntType
00028 HxConvertGeoIntType(HxCorba::GeoIntType gi);
00029
00030 HxGeoTransType
00031 HxConvertGeoTransType(HxCorba::GeoTransType gt);
00032
00033 HxCorba::PixValue
00034 HxConvertValue(HxValue & val);
00035
00036 HxValue
00037 HxConvertValue(const HxCorba::PixValue & val);
00038
00039 template<class CorbaT, class HxT>
00040 CorbaT
00041 HxConvertEnum(HxT* values, int nValues, HxT val)
00042 {
00043 for(int i=0; i<nValues; i++)
00044 if(val == values[i]) return (CorbaT)i;
00045
00046 return (CorbaT)0;
00047 }
00048
00049 template<class TiedSvtT>
00050 inline typename TiedSvtT::HxT&
00051 HxGetTiedObject(HxServerBase* srv, typename TiedSvtT::CorbaT* obj,
00052 typename TiedSvtT::HxT& empty)
00053 {
00054 if(CORBA::is_nil(obj)) return empty;
00055
00056 PortableServer::Servant servant = srv->getServant(obj);
00057 if(servant == NULL) return empty;
00058
00059 typename TiedSvtT::TieT* tie =
00060 dynamic_cast<typename TiedSvtT::TieT*>(servant);
00061
00062 servant->_remove_ref();
00063 return *(tie->_tied_object());
00064 }
00065
00066 template<class TiedSvtT>
00067 inline typename TiedSvtT::HxT&
00068 HxGetTiedObject(HxServerBase* srv, typename TiedSvtT::CorbaT* obj)
00069 {
00070 static typename TiedSvtT::HxT temp;
00071 temp = typename TiedSvtT::HxT();
00072 return HxGetTiedObject<TiedSvtT>(srv, obj, temp);
00073 }
00074
00075 template<class TiedSvtT>
00076 inline typename TiedSvtT::CorbaT*
00077 HxRegisterTiedServant(HxServerBase* srv, const typename TiedSvtT::HxT& obj)
00078 {
00079 TiedSvtT* tied = new TiedSvtT(obj);
00080
00081
00082 typename TiedSvtT::TieT* servant =
00083 new HxBaseTieRefCount<typename TiedSvtT::TieT, TiedSvtT>(tied);
00084 CORBA::Object_ptr objPtr = srv->registerServant(servant);
00085 servant->_remove_ref();
00086
00087 typedef typename TiedSvtT::CorbaT tempT;
00088 return tempT::_narrow(objPtr);
00089 }
00090
00091 template<class TiedSvtT, class SrcListT>
00092 inline typename TiedSvtT::SeqT*
00093 HxMakeTiedServantsList(HxServerBase* srv, SrcListT& lst)
00094 {
00095 typename TiedSvtT::SeqT* seq = new typename TiedSvtT::SeqT();
00096 seq->length(lst.size());
00097
00098 typename SrcListT::const_iterator it = lst.begin();
00099 for(int i=0; it != lst.end(); i++, it++)
00100 (*seq)[i] = HxRegisterTiedServant<TiedSvtT>(srv, *it);
00101
00102 return seq;
00103 }
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 template<class CorbaSeqT, class SrcListT>
00122 inline CorbaSeqT*
00123 HxMakeBasicList(HxServerBase* srv, SrcListT& lst)
00124 {
00125 CorbaSeqT* seq = new CorbaSeqT();
00126 seq->length(lst.size());
00127
00128 typename SrcListT::const_iterator it = lst.begin();
00129 for(int i=0; it != lst.end(); i++, it++)
00130 (*seq)[i] = *it;
00131
00132 return seq;
00133 }
00134
00135 template<class CorbaSeqT, class SrcListT>
00136 inline CorbaSeqT*
00137 HxMakeStringList(HxServerBase* srv, SrcListT& lst)
00138 {
00139 CorbaSeqT* seq = new CorbaSeqT();
00140 seq->length(lst.size());
00141
00142 typename SrcListT::const_iterator it = lst.begin();
00143 for(int i=0; it != lst.end(); i++, it++)
00144 (*seq)[i] = it->c_str();
00145
00146 return seq;
00147 }
00148
00149 template<class TiedSvtT, class DstListT>
00150 inline DstListT
00151 HxGetTiedObjectList(HxServerBase* srv, const typename TiedSvtT::SeqT& seq)
00152 {
00153 DstListT result;
00154 for(int i=0; i<seq.length(); i++)
00155 result += HxGetTiedObject<TiedSvtT>(srv, seq[i]);
00156
00157 return result;
00158 }
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172 #endif