TAO下IDL结构定义编译文件分析

每个IDL的定义的结构经过TAOIDL编译器编译将生成一些结构编码的函数的定义。主要分为TypeCode的处理函数和Any的处理函及其CDR编码的处理。由结构到Any的流化和解析,析构,及其结构与TypedCode处理组成。结构到Any类型是通过TAO的内部模板TAO::Any_Dual_Impl_T来实现。结构流编码通过TAO_OutputCDR,TAO_inputCDR.
IDL
定义如下
    // 告警信息定义
    struct AlarmInfo {
        GeneralizedTime         eventTime;
        ObjectInstance          source;
        ObjectClass             sourceClass;
        NotificationIdentifier  notificationId;
        CorrelatedNotifications alarmInfoCorrelatedNotifications;
        ProbableCause           alarmInfoProbableCause;
        SpecificProblems        alarmInfoSpecificProblems;
        PerceivedSeverity       alarmInfoPerceivedSeverity;
        boolean                 backedUpStatus;
        ObjectInstance          backUpObject;
        TrendIndication         alarmInfoTrendIndication;
        ThresholdInfo           alarmInfoThresholdInfo;
        AttributeChangeList     stateChangeDefinition;
        AttributeList           monitoredAttributes;

        ProposedRepairActions   alarmInfoProposedRepairActions;
        AdditionalString          additionalText;
        AdditionalInformation   additionalInfo;
    };       
编译生成的文件*C.h/cpp
  struct  AlarmInfo
  {
    typedef AlarmInfo_var _var_type;

    
    static void _tao_any_destructor (void *);
    TAO_String_Manager eventTime;
    nms::ObjectInstance source;
    nms::ObjectClass sourceClass;
    nms::NotificationIdentifier notificationId;
    nms::CorrelatedNotifications alarmInfoCorrelatedNotifications;
    nms::ProbableCause alarmInfoProbableCause;
    nms::SpecificProblems alarmInfoSpecificProblems;
    nms::PerceivedSeverity alarmInfoPerceivedSeverity;
   CORBA::Boolean backedUpStatus;
    nms::ObjectInstance backUpObject;
    nms::TrendIndication alarmInfoTrendIndication;
    nms::ThresholdInfo alarmInfoThresholdInfo;
    nms::AttributeChangeList stateChangeDefinition;
    nms::AttributeList monitoredAttributes;
    nms::ProposedRepairActions alarmInfoProposedRepairActions;
    TAO_String_Manager additionalText;
    nms::AdditionalInformation additionalInfo;
  };
1 里面包含一个静态成员函数是析构AlarmInfo指针内存空间
void
nms::AlarmInfo::_tao_any_destructor (

    void *_tao_void_pointer
  )
{
  AlarmInfo *_tao_tmp_pointer =
    ACE_static_cast (AlarmInfo *, _tao_void_pointer);
  delete _tao_tmp_pointer;
}
CPP还定义的Typdecode的函数,并设置函数指针
static CORBA::TypeCode _tc_TAO_tc_nms_AlarmInfo (
    CORBA::tk_struct,
   sizeof (_oc_nms_AlarmInfo),
    (char *) &_oc_nms_AlarmInfo,
    0,
    sizeof (nms::AlarmInfo)
  );
namespace nms
{
  ::CORBA::TypeCode_ptr _tc_AlarmInfo =
    &_tc_TAO_tc_nms_AlarmInfo;
}
2
定义AlarmInfo 到的Any析构的函数
void
nms::AlarmInfo::_tao_any_destructor (

    void *_tao_void_pointer
  )
{
  AlarmInfo *_tao_tmp_pointer =
    ACE_static_cast (AlarmInfo *, _tao_void_pointer);
  delete _tao_tmp_pointer;
}
3 结构对象AlarmInfo放入Any的打包
void operator<<= (
    CORBA::Any &_tao_any,
    const nms::AlarmInfo &_tao_elem
  )
{
  TAO::Any_Dual_Impl_T<nms::AlarmInfo>::insert_copy (
      _tao_any,
      nms::AlarmInfo::_tao_any_destructor,
      nms::_tc_AlarmInfo,
      _tao_elem
    );
}
4 结构对象AlarmInfoAny的解析出来
// Extraction to non-const pointer (deprecated).
CORBA::Boolean operator>>= (
    const CORBA::Any &_tao_any,
    nms::AlarmInfo *&_tao_elem
  )
{
  return _tao_any >>= ACE_const_cast (
      const nms::AlarmInfo *&,
      _tao_elem
    );
}
结构与TAO内部的实现类的关系
  TAO::Any_Dual_Impl_T<nms::AlarmInfo>::insert_copy ()
具体的结构到Any的模板实现类,放入insert,吸取extract,结构对象指针value,编码,解码。
  template<typename T>
  class Any_Basic_Impl_T : public Any_Impl

  {
  public:
    Any_Basic_Impl_T (CORBA::TypeCode_ptr,
                      const T & val);
    virtual ~Any_Basic_Impl_T (void);
    static void
insert (CORBA::Any &,
                        CORBA::TypeCode_ptr,
                        const T &);
    static CORBA::Boolean
extract
(const CORBA::Any &,
                                   CORBA::TypeCode_ptr,
                                   T &);
    virtual CORBA::Boolean marshal_value (TAO_OutputCDR &);
    CORBA::Boolean demarshal_value (TAO_InputCDR &);
    virtual void _tao_decode (TAO_InputCDR &
                              ACE_ENV_ARG_DECL_WITH_DEFAULTS);
    virtual const void *
value
(void) const;
    static Any_Basic_Impl_T<T> *create_empty (CORBA::TypeCode_ptr);
  private:
    T value_;
  };
在编译的IDL的文件中产生了一个*C.i的文件,该文件主要是将定义的数据结构类型流化到CDR的对象中,及其从CDR流中解析出来。
结构到ANY的操作符
void operator<<= (CORBA::Any &, const nms::AlarmInfo &); // copying version
void operator<<= (CORBA::Any &, nms::AlarmInfo*); // noncopying version
CORBA::Boolean operator>>= (const CORBA::Any &, nms::AlarmInfo *&); // deprecated
CORBA::Boolean operator>>= (const CORBA::Any &, const nms::AlarmInfo *&);
结构到CDR的流化和解码处理

CORBA::Boolean operator<< (TAO_OutputCDR &, const nms::AlarmInfo &);
CORBA::Boolean operator>> (TAO_InputCDR &, nms::AlarmInfo &);
流化成CDR格式的流

ACE_INLINE
CORBA::Boolean operator<< (
    TAO_OutputCDR &strm,
    const nms::AlarmInfo &_tao_aggregate
  )
{
  return
    (strm << _tao_aggregate.eventTime.in ()) &&
    (strm << _tao_aggregate.source) &&
    (strm << _tao_aggregate.sourceClass) &&
    (strm << _tao_aggregate.notificationId) &&
    (strm << _tao_aggregate.alarmInfoCorrelatedNotifications) &&
    (strm << _tao_aggregate.alarmInfoProbableCause) &&
    (strm << _tao_aggregate.alarmInfoSpecificProblems) &&
    (strm << _tao_aggregate.alarmInfoPerceivedSeverity) &&
    (strm << CORBA::Any::from_boolean (_tao_aggregate.backedUpStatus)) &&
    (strm << _tao_aggregate.backUpObject) &&
    (strm << _tao_aggregate.alarmInfoTrendIndication) &&
    (strm << _tao_aggregate.alarmInfoThresholdInfo) &&
    (strm << _tao_aggregate.stateChangeDefinition) &&
    (strm << _tao_aggregate.monitoredAttributes) &&
    (strm << _tao_aggregate.alarmInfoProposedRepairActions) &&
    (strm << _tao_aggregate.additionalText.in ()) &&
    (strm << _tao_aggregate.additionalInfo);
}
可以见到IDL的数据结构与流化是比较独立分开的。CORBACDR编码是通过IDL中规范定义的基本数据类型来判断类型的流化。经过编译的IDL定义的生成的C++结构是比较干净,基本不带其他信息,或者成员,所以在编写CORBA的程序的时候,我们不要再定义相同的C++数据结构,我们可以直接使用IDL编译后的C++结构。


来源:linweixuan的专栏

http://blog.csdn.net/linweixuan/archive/ 2005/09/21 /486634.aspx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值