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
|
// -*- C++ -*-
#include "tao/CodecFactory/CodecFactory.h"
#include "testC.h"
#include "ace/Log_Msg.h"
#include "ace/Argv_Type_Converter.h"
ACE_RCSID (Codec,
client,
"$Id$")
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
ACE_Argv_Type_Converter convert (argc, argv);
ACE_DECLARE_NEW_CORBA_ENV;
ACE_TRY
{
CORBA::ORB_var orb =
CORBA::ORB_init (convert.get_argc(), convert.get_ASCII_argv(),
"my_orb"
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
// Obtain a reference to the CodecFactory.
CORBA::Object_var obj =
orb->resolve_initial_references ("CodecFactory"
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
IOP::CodecFactory_var codec_factory =
IOP::CodecFactory::_narrow (obj.in ()
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
// ----------------------------------------------------------
// Set up a structure that contains information necessary to
// create a GIOP 1.1 CDR encapsulation Codec.
IOP::Encoding encoding;
encoding.format = IOP::ENCODING_CDR_ENCAPS;
encoding.major_version = 1;
encoding.minor_version = 1;
// Obtain the CDR encapsulation Codec.
IOP::Codec_var codec =
codec_factory->create_codec (encoding
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
// ----------------------------------------------------------
{
CORBA::OctetSeq_var encoded_data;
CORBA::Any_var decoded_data;
Foo::type_ulong l = 9192631;
CORBA::Any tmp;
tmp <<= l;
encoded_data =
codec->encode_value (tmp
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
decoded_data =
codec->decode_value (encoded_data.in (),
Foo::_tc_type_ulong
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
Foo::type_ulong check = 0;
if (!(decoded_data >>= check))
ACE_ERROR_RETURN ((LM_ERROR,
"ERROR: Unable to extract typedefed decoded "
"data from Any\n"),
-1);
if (check != l)
ACE_ERROR_RETURN ((LM_ERROR,
"ERROR: Extracted value not equal "
"to the encoded value \n"),
-1);
}
ACE_DEBUG ((LM_DEBUG,
"(%P|%t) Test passed \n"));
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
"Bug_1693_Test test:");
return -1;
}
ACE_ENDTRY;
return 0;
}
|