~ubuntu-branches/ubuntu/breezy/ace/breezy

« back to all changes in this revision

Viewing changes to TAO/tests/Smart_Proxies/server.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad, Benjamin Montgomery, Adam Conrad
  • Date: 2005-09-18 22:51:38 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge) (0.1.2 woody)
  • Revision ID: james.westby@ubuntu.com-20050918225138-seav22q6fyylb536
Tags: 5.4.7-3ubuntu1
[ Benjamin Montgomery ]
* Added a patch for amd64 and powerpc that disables the compiler
  option -fvisibility-inlines-hidden

[ Adam Conrad ]
* Added DPATCH_OPTION_CPP=1 to debian/patches/00options to make
  Benjamin's above changes work correctly with dpatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// server.cpp,v 1.10 2003/11/04 08:13:00 dhinton Exp
2
 
 
3
 
//========================================================================
4
 
//
5
 
// = LIBRARY
6
 
//     TAO/tests/Smart_Proxy
7
 
//
8
 
// = FILENAME
9
 
//     server.cpp
10
 
//
11
 
// = DESCRIPTION
12
 
//     This is the server program that tests TAO's Smart Proxy extension.
13
 
//
14
 
// = AUTHOR
15
 
//     Kirthika Parameswaran <kirthika@cs.wustl.edu>
16
 
//
17
 
//=========================================================================
18
 
 
19
 
#include "testS.h"
20
 
#include "ace/Get_Opt.h"
21
 
#include "ace/OS_NS_string.h"
22
 
 
23
 
ACE_RCSID(Smart_Proxy, server, "server.cpp,v 1.10 2003/11/04 08:13:00 dhinton Exp")
24
 
 
25
 
// The servant
26
 
 
27
 
class Test_i : public POA_Test
28
 
{
29
 
public:
30
 
  Test_i (CORBA::ORB_ptr orb);
31
 
 
32
 
  CORBA::Short method  (CORBA::Short boo
33
 
                        ACE_ENV_ARG_DECL)
34
 
    ACE_THROW_SPEC ((CORBA::SystemException,
35
 
                     Test::Oops));
36
 
 
37
 
  void shutdown  (ACE_ENV_SINGLE_ARG_DECL)
38
 
    ACE_THROW_SPEC ((CORBA::SystemException));
39
 
 
40
 
private:
41
 
  CORBA::ORB_var orb_;
42
 
 
43
 
};
44
 
 
45
 
Test_i::Test_i (CORBA::ORB_ptr orb)
46
 
  : orb_ (CORBA::ORB::_duplicate (orb))
47
 
{
48
 
}
49
 
 
50
 
CORBA::Short
51
 
Test_i :: method (CORBA::Short boo
52
 
                  ACE_ENV_ARG_DECL)
53
 
  ACE_THROW_SPEC ((CORBA::SystemException,
54
 
                   Test::Oops))
55
 
{
56
 
  ACE_DEBUG ((LM_DEBUG,
57
 
              ACE_TEXT ("Test_i::method () invoked\n")));
58
 
  if (boo == 5)
59
 
    ACE_THROW_RETURN (Test::Oops ("Invalid boo\n"),
60
 
                      -1);
61
 
 
62
 
  return 0;
63
 
}
64
 
 
65
 
void
66
 
Test_i::shutdown (ACE_ENV_SINGLE_ARG_DECL_NOT_USED)
67
 
  ACE_THROW_SPEC ((CORBA::SystemException))
68
 
{
69
 
  this->orb_->shutdown ();
70
 
}
71
 
 
72
 
static const char *ior_output_file = 0;
73
 
 
74
 
int
75
 
parse_args (int argc, char *argv[])
76
 
{
77
 
  ACE_Get_Opt get_opts (argc, argv, "o:");
78
 
  int c;
79
 
 
80
 
  while ((c = get_opts ()) != -1)
81
 
    switch (c)
82
 
      {
83
 
      case 'o':
84
 
        ior_output_file = ACE_OS::strdup (get_opts.opt_arg ());
85
 
        break;
86
 
      case '?':
87
 
      default:
88
 
        ACE_ERROR_RETURN ((LM_ERROR,
89
 
                           "usage:  %s "
90
 
                           "-o <iorfile>"
91
 
                           "\n",
92
 
                           argv [0]),
93
 
                          -1);
94
 
      }
95
 
  // Indicates sucessful parsing of the command line
96
 
  return 0;
97
 
}
98
 
 
99
 
int
100
 
main (int argc, char *argv[])
101
 
{
102
 
  ACE_DECLARE_NEW_CORBA_ENV;
103
 
 
104
 
  ACE_TRY
105
 
    {
106
 
      if (parse_args (argc, argv) != 0)
107
 
        return 1;
108
 
 
109
 
      CORBA::ORB_var orb = CORBA::ORB_init (argc,
110
 
                                            argv,
111
 
                                            ""
112
 
                                            ACE_ENV_ARG_PARAMETER);
113
 
      ACE_TRY_CHECK;
114
 
 
115
 
      Test_i servant (orb.in ());
116
 
      // Obtain RootPOA.
117
 
      CORBA::Object_var object =
118
 
        orb->resolve_initial_references ("RootPOA"
119
 
                                         ACE_ENV_ARG_PARAMETER);
120
 
 
121
 
      PortableServer::POA_var root_poa =
122
 
        PortableServer::POA::_narrow (object.in ()
123
 
                                      ACE_ENV_ARG_PARAMETER);
124
 
 
125
 
      ACE_TRY_CHECK;
126
 
 
127
 
      // Get the POAManager of the RootPOA.
128
 
      PortableServer::POAManager_var poa_manager =
129
 
        root_poa->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER);
130
 
      ACE_TRY_CHECK;
131
 
 
132
 
      Test_var Test_object =
133
 
        servant._this (ACE_ENV_SINGLE_ARG_PARAMETER);
134
 
      ACE_TRY_CHECK;
135
 
 
136
 
      CORBA::String_var ior =
137
 
        orb->object_to_string (Test_object.in ()
138
 
                               ACE_ENV_ARG_PARAMETER);
139
 
 
140
 
      // If the ior_output_file exists, output the ior to it
141
 
      if (ior_output_file != 0)
142
 
        {
143
 
          FILE *output_file =
144
 
            ACE_OS::fopen (ior_output_file, "w");
145
 
 
146
 
          if (output_file == 0)
147
 
            ACE_ERROR_RETURN ((LM_ERROR,
148
 
                               "Cannot open output file for writing IOR: %s",
149
 
                               ior_output_file),
150
 
                              1);
151
 
 
152
 
          ACE_OS::fprintf (output_file,
153
 
                           "%s",
154
 
                           ior.in ());
155
 
          ACE_OS::fclose (output_file);
156
 
        }
157
 
 
158
 
      poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER);
159
 
      ACE_TRY_CHECK;
160
 
 
161
 
      orb->run (ACE_ENV_SINGLE_ARG_PARAMETER);
162
 
      ACE_TRY_CHECK;
163
 
 
164
 
      ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
165
 
 
166
 
      root_poa->destroy (1,
167
 
                         1
168
 
                         ACE_ENV_ARG_PARAMETER);
169
 
      ACE_TRY_CHECK;
170
 
    }
171
 
  ACE_CATCHANY
172
 
    {
173
 
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
174
 
                           "Exception in setting up server");
175
 
      ACE_ASSERT (0);
176
 
    }
177
 
  ACE_ENDTRY;
178
 
  return 0;
179
 
}