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

« back to all changes in this revision

Viewing changes to TAO/orbsvcs/tests/Security/Crash_Test/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.3 2003/11/27 23:42:40 bala Exp
2
 
 
3
 
#include "ace/Get_Opt.h"
4
 
#include "ace/OS_NS_stdio.h"
5
 
#include "ace/OS_NS_unistd.h"
6
 
#include "test_i.h"
7
 
 
8
 
ACE_RCSID(Send_File, server, "server.cpp,v 1.3 2003/11/27 23:42:40 bala Exp")
9
 
 
10
 
const char *ior_output_file = 0;
11
 
 
12
 
int
13
 
parse_args (int argc, char *argv[])
14
 
{
15
 
  ACE_Get_Opt get_opts (argc, argv, "o:");
16
 
  int c;
17
 
 
18
 
  while ((c = get_opts ()) != -1)
19
 
    switch (c)
20
 
      {
21
 
      case 'o':
22
 
        ior_output_file = get_opts.opt_arg ();
23
 
        break;
24
 
      case '?':
25
 
      default:
26
 
        ACE_ERROR_RETURN ((LM_ERROR,
27
 
                           "SERVER (%P): usage:  %s "
28
 
                           "-o <iorfile> -w <wait-time>"
29
 
                           "\n",
30
 
                           argv [0]),
31
 
                          -1);
32
 
      }
33
 
  // Indicates sucessful parsing of the command line
34
 
  return 0;
35
 
}
36
 
 
37
 
int
38
 
main (int argc, char *argv[])
39
 
{
40
 
  ACE_DECLARE_NEW_CORBA_ENV;
41
 
 
42
 
  ACE_TRY
43
 
    {
44
 
      CORBA::ORB_var orb =
45
 
        CORBA::ORB_init (argc, argv, "" ACE_ENV_ARG_PARAMETER);
46
 
      ACE_TRY_CHECK;
47
 
 
48
 
      CORBA::Object_var poa_object =
49
 
        orb->resolve_initial_references ("RootPOA" ACE_ENV_ARG_PARAMETER);
50
 
      ACE_TRY_CHECK;
51
 
 
52
 
      if (CORBA::is_nil (poa_object.in ()))
53
 
        ACE_ERROR_RETURN ((LM_ERROR,
54
 
                           "SERVER (%P): Unable to initialize the POA.\n"),
55
 
                          1);
56
 
 
57
 
      PortableServer::POA_var root_poa =
58
 
        PortableServer::POA::_narrow (poa_object.in () ACE_ENV_ARG_PARAMETER);
59
 
      ACE_TRY_CHECK;
60
 
 
61
 
      PortableServer::POAManager_var poa_manager =
62
 
        root_poa->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER);
63
 
      ACE_TRY_CHECK;
64
 
 
65
 
      if (parse_args (argc, argv) != 0)
66
 
        return 1;
67
 
 
68
 
      Simple_Server_i server_impl (orb.in ());
69
 
 
70
 
      CORBA::PolicyList policies (2);
71
 
      policies.length (2);
72
 
 
73
 
      policies[0] =
74
 
        root_poa->create_id_assignment_policy (PortableServer::USER_ID
75
 
                                               ACE_ENV_ARG_PARAMETER);
76
 
      ACE_TRY_CHECK;
77
 
 
78
 
      policies[1] =
79
 
        root_poa->create_lifespan_policy (PortableServer::PERSISTENT
80
 
                                          ACE_ENV_ARG_PARAMETER);
81
 
      ACE_TRY_CHECK;
82
 
 
83
 
      PortableServer::POA_var persistent_poa =
84
 
        root_poa->create_POA ("PersistentPOA",
85
 
                              poa_manager.in (),
86
 
                              policies
87
 
                              ACE_ENV_ARG_PARAMETER);
88
 
      ACE_TRY_CHECK;
89
 
 
90
 
      PortableServer::ObjectId_var oid =
91
 
        PortableServer::string_to_ObjectId ("object1");
92
 
      ACE_TRY_CHECK;
93
 
 
94
 
      persistent_poa->activate_object_with_id (oid.in (),
95
 
                                               &server_impl
96
 
                                               ACE_ENV_ARG_PARAMETER);
97
 
      ACE_TRY_CHECK;
98
 
 
99
 
 
100
 
      CORBA::Object_var server =
101
 
        persistent_poa->create_reference_with_id (oid.in (),
102
 
                                                  "IDL:Simple_Server:1.0"
103
 
                                                  ACE_ENV_ARG_PARAMETER);
104
 
      ACE_TRY_CHECK;
105
 
 
106
 
      CORBA::String_var ior =
107
 
        orb->object_to_string (server.in () ACE_ENV_ARG_PARAMETER);
108
 
      ACE_TRY_CHECK;
109
 
 
110
 
      // If the ior_output_file exists, output the ior to it
111
 
      if (ior_output_file != 0)
112
 
        {
113
 
          FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
114
 
          if (output_file == 0)
115
 
            ACE_ERROR_RETURN ((LM_ERROR,
116
 
                               "SERVER (%P): Cannot open output file "
117
 
                               "for writing IOR: %s",
118
 
                               ior_output_file),
119
 
                              1);
120
 
          ACE_OS::fprintf (output_file, "%s", ior.in ());
121
 
          ACE_OS::fclose (output_file);
122
 
 
123
 
          ACE_DEBUG ((LM_DEBUG,
124
 
                      "SERVER (%P): Activated as file://%s\n",
125
 
                      ior_output_file));
126
 
        }
127
 
      else
128
 
        {
129
 
          ACE_DEBUG ((LM_DEBUG,
130
 
                      "SERVER (%P): Activated as <%s>\n",
131
 
                      ior.in ()));
132
 
        }
133
 
 
134
 
 
135
 
      poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER);
136
 
      ACE_TRY_CHECK;
137
 
 
138
 
      orb->run (ACE_ENV_SINGLE_ARG_PARAMETER);
139
 
      ACE_TRY_CHECK;
140
 
 
141
 
      ACE_DEBUG ((LM_DEBUG, "SERVER (%P): Event loop finished.\n"));
142
 
 
143
 
      persistent_poa->destroy (1, 1 ACE_ENV_ARG_PARAMETER);
144
 
      ACE_TRY_CHECK;
145
 
 
146
 
      root_poa->destroy (1, 1 ACE_ENV_ARG_PARAMETER);
147
 
      ACE_TRY_CHECK;
148
 
 
149
 
      ACE_OS::sleep (1);
150
 
    }
151
 
  ACE_CATCHANY
152
 
    {
153
 
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,
154
 
                           "SERVER (%P): Caught exception:");
155
 
      return 1;
156
 
    }
157
 
  ACE_ENDTRY;
158
 
 
159
 
  return 0;
160
 
}