summaryrefslogtreecommitdiff
path: root/TAO/tao/CodecFactory/CDR_Encaps_Codec.h
blob: 37672c1e4debd78e3e01d287c4d4b8cdec990c59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// -*- C++ -*-

//=============================================================================
/**
 * @file CDR_Encaps_Codec.h
 *
 * $Id$
 *
 * @author Ossama Othman <ossama@uci.edu>
 */
//=============================================================================

#ifndef TAO_CDR_ENCAPS_CODEC_H
#define TAO_CDR_ENCAPS_CODEC_H

#include /**/ "ace/pre.h"

#include "tao/CodecFactory/IOP_Codec_includeC.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "tao/LocalObject.h"

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

class TAO_Codeset_Translator_Base;

/**
 * @class TAO_CDR_Encaps_Codec
 *
 * @brief Implementation of a CDR encapsulation coder/decoder
 * (Codec).
 *
 * This coder/decoder (Codec) class encodes and decodes data to and
 * from a CDR encapsulation, respectively.  It is useful for creation
 * of octet sequences that contain CDR encapsulations.  Those octet
 * sequences can then be placed in a IOP::ServiceContext or an
 * IOP::TaggedComponent, for example.
 *
 * @note This Codec should not be used for operations internal to the
 * ORB core since it uses interpretive marshaling rather than compiled
 * marshaling.
 */
class TAO_CDR_Encaps_Codec
  : public virtual IOP::Codec,
    public virtual TAO_Local_RefCounted_Object
{
public:

  /// Constructor.
  TAO_CDR_Encaps_Codec (CORBA::Octet major,
                        CORBA::Octet minor,
                        TAO_ORB_Core * orb_core,
                        TAO_Codeset_Translator_Base * char_trans,
                        TAO_Codeset_Translator_Base * wchar_trans);

  /// Encode the given data, including the TypeCode, into an octet
  /// sequence.
  virtual CORBA::OctetSeq * encode (const CORBA::Any & data
                                    ACE_ENV_ARG_DECL_WITH_DEFAULTS)
    ACE_THROW_SPEC ((CORBA::SystemException,
                     IOP::Codec::InvalidTypeForEncoding));

  /// Extract the TypeCode and the value from the octet sequence and
  /// place them into an Any.
  virtual CORBA::Any * decode (const CORBA::OctetSeq & data
                               ACE_ENV_ARG_DECL_WITH_DEFAULTS)
    ACE_THROW_SPEC ((CORBA::SystemException,
                     IOP::Codec::FormatMismatch));

  /// Encode the given data, excluding the TypeCode, into an octet
  /// sequence.
  virtual CORBA::OctetSeq * encode_value (const CORBA::Any & data
                                          ACE_ENV_ARG_DECL_WITH_DEFAULTS)
    ACE_THROW_SPEC ((CORBA::SystemException,
                     IOP::Codec::InvalidTypeForEncoding));

  /// Extract the value from the octet sequence, based on the given
  /// TypeCode,  and place it into an Any.
  virtual CORBA::Any * decode_value (const CORBA::OctetSeq & data,
                                     CORBA::TypeCode_ptr tc
                                     ACE_ENV_ARG_DECL_WITH_DEFAULTS)
    ACE_THROW_SPEC ((CORBA::SystemException,
                     IOP::Codec::FormatMismatch,
                     IOP::Codec::TypeMismatch));

protected:

  /// Destructor.
  /**
   * Only allow this class to be instantiated on the heap since it is
   * reference counted.
   */
  virtual ~TAO_CDR_Encaps_Codec (void);

  /// Verify that it is possible to encode the given data using this
  /// Codec.
  /**
   * Typical reasons for failure include attempting to encode a type
   * that isn't supported for the version of GIOP associated with this
   * Codec.
   */
  void check_type_for_encoding (const CORBA::Any & data
                                ACE_ENV_ARG_DECL);

private:

  /// Prevent copying through the copy constructor and the assignment
  /// operator.
  TAO_CDR_Encaps_Codec (const TAO_CDR_Encaps_Codec &);
  void operator= (const TAO_CDR_Encaps_Codec &);

private:

  /// The major GIOP version associated with this Codec.
  CORBA::Octet const major_;

  /// The minor GIOP version associated with this Codec.
  CORBA::Octet const minor_;

  /// The ORB Core to be used when decoding values from a CDR
  /// encapsulation.
  TAO_ORB_Core * const orb_core_;

  /// Char codeset translator
  TAO_Codeset_Translator_Base * char_translator_;

  /// WChar codeset translator
  TAO_Codeset_Translator_Base * wchar_translator_;
};

TAO_END_VERSIONED_NAMESPACE_DECL

#include /**/ "ace/post.h"

#endif  /* TAO_CDR_ENCAPS_CODEC_H */