summaryrefslogtreecommitdiff
path: root/CIAO/connectors/dds4ccm/tests/HomeTest/HomeComp/controller.cpp
blob: de3bd67a2d25268ca9a5921cef070e342829d696 (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
98
99
100
101
102
103
104
105
106
107
108
// $Id$

//==============================================================
/**
 * @file controller.cpp
 *
 * This is a controller tat interact with the Home-component implementation.
 * This test uses the explicit factory
 * operation in the home interface to create a connector component
 * instance, run it for a while, and destroy the component instance.
 */
//==============================================================

#include "HomeT_HomeCC.h"
#include "ace/streams.h"
#include "ace/OS_NS_unistd.h"
#include "ace/Get_Opt.h"

const ACE_TCHAR *home_comp_ior_ = 0;

int
parse_args (int argc, ACE_TCHAR *argv[])
{
  ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:of"));
  int c;

  while ((c = get_opts ()) != -1)
    {
      switch (c)
        {
        case 'o':
           break;
        case 'f':
           break;
        case 'k':
         home_comp_ior_ = get_opts.opt_arg ();
          break;
        case '?':  // display help for use of the server.
        default:
          ACE_ERROR_RETURN ((LM_ERROR,
                            "usage:  %s\n"
                             "-k <HomeComponent IOR> (default is file://HomeC.ior)\n"
                             "\n",
                            argv [0]),
                            -1);
          break;
        }
    }

  if (home_comp_ior_ == 0)
    {
      home_comp_ior_ = ACE_TEXT("file://HomeC.ior");
    }

  return 0;
}


int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      // Initialize orb
      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);

      if (parse_args (argc, argv) != 0)
         {
           return -1;
         }

      // Resolve Home interface
      CORBA::Object_var obj
        = orb->string_to_object (home_comp_ior_);

      ConnHome_var home_comp
        = ConnHome::_narrow (obj.in ());
      if (CORBA::is_nil (home_comp.in ()))
        ACE_ERROR_RETURN ((LM_ERROR, "Unable to acquire ConnHome objref\n"), -1);

      // starting Connector component
      ACE_DEBUG ((LM_DEBUG, "Controller: Starting Connector component home->new_ConnComp ()\n"));

      CORBA::Object  * tmp  = home_comp->new_ConnComp ();

      if (CORBA::is_nil (tmp))
        ACE_ERROR((LM_ERROR, "Unable to start home_comp->new_ConnComp\n"));

      ACE_DEBUG ((LM_DEBUG, "Controller: Started Connector component home->new_ConnComp ()\n"));

      // Place to plug in the rate

      ACE_OS::sleep (5);

  //    home->remove_component ();

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Who is the culprit\n");
      ACE_ERROR_RETURN ((LM_ERROR,
                         "Uncaught CORBA exception\n"),
                        1);
    }

  return 0;
}