summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/InterfaceRepo/IFR_Inheritance_Test/main.cpp
blob: 3b0c332f536e82ba7cbb45ac0addf062d64592dc (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
// -*- C++ -*-
// $Id$

// The run_test.pl perl script will check for the expected output.

#include "tao/IFR_Client/IFR_BasicC.h"
#include "tao/ORB.h"

ACE_RCSID (IFR_Inheritance_Test,
           main,
           "$Id$")

void printContents (const CORBA::ContainedSeq& cont)
{
  try
    {
      for (CORBA::ULong i = 0; i < cont.length(); ++i)
        {
          CORBA::Contained::Description_var topdesc = cont[i]->describe ();
          if (topdesc->kind == CORBA::dk_Interface)
            {
              CORBA::InterfaceDef_var intDef =
                CORBA::InterfaceDef::_narrow (cont[i]);

              CORBA::InterfaceDef::FullInterfaceDescription_var desc =
                intDef->describe_interface ();

              //printf ("-- %s:\n", desc->name.in ());

              for (CORBA::ULong j1 = 0; j1 < desc->operations.length (); ++j1)
                ACE_OS::printf ("operation %s::%s\n",
                                desc->name.in (),
                                desc->operations[j1].name.in ());

              for (CORBA::ULong j2 = 0; j2 < desc->attributes.length (); ++j2)
                ACE_OS::printf ("attribute %s::%s\n",
                                desc->name.in (),
                                desc->attributes[j2].name.in ());
            }
          else if (topdesc->kind == CORBA::dk_Module)
            {
              CORBA::ModuleDef_var moduleDef =
                CORBA::ModuleDef::_narrow (cont[i]);

              CORBA::ContainedSeq_var moduleContents =
                moduleDef->contents (CORBA::dk_all, 1);
              printContents (moduleContents.in ());
            }
        }
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("printContents");
      ACE_OS::exit(-1); // the test has failed!
    }
}

int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
      CORBA::Object_var object =
        orb->resolve_initial_references ("InterfaceRepository");

      if (CORBA::is_nil (object.in ()))
        {
          ACE_ERROR_RETURN ((
              LM_ERROR,
              "Null objref from resolve_initial_references\n"),
             -1);
        }

      CORBA::Repository_var  ifr =
        CORBA::Repository::_narrow (object.in ());

      if (CORBA::is_nil (ifr.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "CORBA::Repository::_narrow failed\n"),
                            -1);
        }

      CORBA::ContainedSeq_var cont = ifr->contents (CORBA::dk_all, 0);

      printContents (cont.in ());

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("main");
      return -1;
    }

  return 0;
}