summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/Event/Mcast/AddrServer/Server.cpp
blob: 99d6b5c07c1ac2217e393d69587508466dcdbbf1 (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
// $Id$

// AddrServerMain.cpp
// Main program for a common Address server instance to be shared by all
// event channels

#include "TestAddrServer.h"
#include "ace/OS_NS_stdio.h"
#include "ace/OS_NS_strings.h"

int main (int argc, char* argv[])
{
#if defined ACE_HAS_IPV6
  try
    {
      // Initialize the ORB.
      CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

      const char *ior_file_name = "as.ior";
      const char* address = "224.6.6.1";
      const char* address6 = "FF01::ABCD";
      u_short port = 12345;

      for (int i = 0; argv[i] != 0; i++)
        {
          if (ACE_OS::strcasecmp(argv[i], "-o") == 0)
            {
              if (argv[i+1] != 0)
                ior_file_name = argv[++i];
            }

        }

      // Get the POA
      CORBA::Object_var tmpobj = orb->resolve_initial_references ("RootPOA");
      PortableServer::POA_var poa =
        PortableServer::POA::_narrow (tmpobj.in ());
      PortableServer::POAManager_var poa_manager = poa->the_POAManager ();
      poa_manager->activate ();

      // Initialize the address server with the desired address.
      // This will be used by the sender object and the multicast
      // receiver.
      ACE_INET_Addr addr (port, address);
      ACE_INET_Addr addr6 (port, address6);

      TestAddrServer_i impl (addr,addr6);

      PortableServer::ObjectId_var oid = poa->activate_object(&impl);
      tmpobj = poa->id_to_reference(oid.in());

      CORBA::String_var ior = orb->object_to_string (tmpobj.in());

      // Output the IOR to the <ior_output_file>
      FILE *output_file= ACE_OS::fopen (ior_file_name, "w");
      if (output_file == 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Cannot open output file for writing IOR: %s\n",
                           ior_file_name),
                          1);
      ACE_OS::fprintf (output_file, "%s", ior.in ());
      ACE_OS::fclose (output_file);

      // run the ORB
      orb->run();
      orb->destroy();
      return 0;
    }
  catch (CORBA::Exception& exc)
    {
      ACE_ERROR ((LM_ERROR,
                  "Caught CORBA::Exception\n%s (%s)\n",
                  exc._name (), exc._rep_id ()));
    }
#else
  ACE_UNUSED_ARG (argc);
  ACE_UNUSED_ARG (argv);

  ACE_ERROR ((LM_ERROR,
              ACE_TEXT ("This test requires ACE to be built ")
              ACE_TEXT ("with support for IPv6\n")));
#endif /* ACE_HAS_IPV6 */

  return 1;
}