summaryrefslogtreecommitdiff
path: root/TAO/tests/POA/RootPOA/RootPOA.cpp
blob: d28918a8c8403fd664751651ba95c4e3e3c3d2ca (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

// $Id$


//==================================================================================
//
// = LIBRARY
//     TAO/tests/POA/RootPOA
//
//
// = FILENAME
//     RootPOA.cpp
//
// = DESCRIPTION
//     This program gets the name of the Root POA and prints it out on
//     the standard output.
//
// = AUTHOR
//     Irfan Pyarali
//
//==================================================================================

#include "ace/streams.h"
#include "tao/corba.h"

int
main (int argc, char **argv)
{
  CORBA::Environment env;

  // Initilize the ORB
  CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, 0, env);
  if (env.exception () != 0)
    {
      env.print_exception ("CORBA::ORB_init");
      return -1;
    }

  // Resolve the initial references for the name RootPOA thus getting
  // an object of type CORBA::Object.
  CORBA::Object_var obj =
    orb->resolve_initial_references ("RootPOA");

  // apply _narrow on the object of type CORBA::Object, to make it a
  // POA class Object.
  PortableServer::POA_var root_poa =
    PortableServer::POA::_narrow (obj.in (), env);

  if (env.exception () != 0)
    {
      env.print_exception ("PortableServer::POA::_narrow");
      return -1;
    }

  // Get the name of the root POA.
  CORBA::String_var poa_name =
    root_poa->the_name (env);

  if (env.exception () != 0)
    {
      env.print_exception ("PortableServer::POA::_narrow");
      return -1;
    }

  cout << "The RootPOA is : " << poa_name.in () << endl;

  // Destroy the POA object,also destroys the child POAs if any.
  root_poa->destroy (CORBA::B_TRUE,
                     CORBA::B_TRUE,
                     env);
  if (env.exception () != 0)
    {
      env.print_exception ("PortableServer::POA::destroy");
      return -1;
    }

  return 0;
}