summaryrefslogtreecommitdiff
path: root/TAO/tests/InterOp-Naming/INS_test_client.cpp
blob: 29538e30303ff5b3a30593237f469e8b4d72b320 (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
// $Id$


#include "orbsvcs/CosNamingC.h"
#include "INSC.h"

int
main (int argc, char *argv[])
{
  ACE_DECLARE_NEW_CORBA_ENV;
  ACE_TRY
    {
      // Retrieve a reference to the ORB.
      CORBA::ORB_var orb = CORBA::ORB_init (argc,
                                            argv,
                                            0,
                                            ACE_TRY_ENV);
      ACE_TRY_CHECK;

      if (argc < 2)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "No Name specified to be resolved\n"));
          return 0;
        }

      CORBA::Object_var objref =
        orb->resolve_initial_references (argv[1], ACE_TRY_ENV);
      ACE_TRY_CHECK;

      if (CORBA::is_nil (objref.in ()))
        ACE_ERROR_RETURN ((LM_ERROR,
                           " (%P|%t) Unable to resolve the given Name.\n"),
                          -1);

      if (ACE_OS::strcmp (argv[1], "NameService") == 0)
        {
          CosNaming::NamingContext_var naming_context =
            CosNaming::NamingContext::_narrow (objref.in (),
                                               ACE_TRY_ENV);
          ACE_TRY_CHECK;
              
          ACE_DEBUG ((LM_DEBUG,
                      "Resolved IOR for %s : %s\n",
                      argv[1],
                      orb->object_to_string (naming_context.in ())));

          // Sanity check to see if the reference to Naming
          // Context is alright.
          CosNaming::Name my_name;
          my_name.length (1);
          my_name[0].id = CORBA::string_dup ("ObjName");

          naming_context->bind (my_name,
                                objref.in (),
                                ACE_TRY_ENV);
          ACE_TRY_CHECK;

          ACE_DEBUG ((LM_DEBUG,
                      "\nBind successful on the resolved Naming Context\n"));

        }
      else
        {
          INS_var server = INS::_narrow (objref.in (),
                                         ACE_TRY_ENV);
          ACE_TRY_CHECK;

          ACE_DEBUG ((LM_DEBUG,
                      "Resolved IOR for %s : %s\n",
                      argv[1],
                      orb->object_to_string (server.in ())));

          ACE_DEBUG ((LM_DEBUG,
                      "\nResult of Remote Call : %s\n",
                      server->test_ins (ACE_TRY_ENV)));
        }
    }
  ACE_CATCH (CORBA::ORB::InvalidName, name)
    {
      ACE_DEBUG ((LM_DEBUG, "Cannot resolve <%s>\n", argv[1]));
    }
  ACE_CATCHANY
    {
       ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Exception:");
    }

  ACE_ENDTRY;
  ACE_CHECK_RETURN (-1);

  return 0;
}