summaryrefslogtreecommitdiff
path: root/modules/CIAO/DAnCE/NodeApplication/Configurator_Factory.cpp
blob: 5de92094ee82b834c8d0709eb96df381189136e8 (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// $Id$

#include "Configurator_Factory.h"
#include "NoOp_Configurator.h"
#include "ace/Null_Mutex.h"
#include "ciao/CIAO_common.h"
#include "ace/Arg_Shifter.h"

int
CIAO::NodeApplication_Options::parse_args (int &argc, char *argv[])
{
  ACE_Arg_Shifter shifter (argc, argv);

  while (shifter.is_anything_left ())
    {
      const char *parm = 0;

      if (shifter.cur_arg_strncasecmp ("-n") == 0) // Use callback.
        {
          this->use_callback_ = false;
          shifter.consume_arg ();
        }
      else if (shifter.cur_arg_strncasecmp ("-r") == 0)
        {
          this->rt_support_ = true;
          shifter.consume_arg ();
        }
      else if (ACE_OS::strncmp (shifter.get_current (),
                                "-ORB",
                                ACE_OS::strlen ("-ORB")) == 0)
        {
          // Ignore ORB parameter
          shifter.ignore_arg ();
        }
      else if (shifter.cur_arg_strncasecmp ("-o") == 0)
        {
          // This double checking is necessary to avoid the Arg_Shifter from
          // mistaking any -ORBxxx flag as -o flag.
          if ((parm = shifter.get_the_parameter ("-o")) !=0)
            {
              this->ior_output_filename_ = parm;
            }
          shifter.consume_arg ();
        }
      else if ((parm = shifter.get_the_parameter ("-k")) !=0)
        {
          this->callback_ior_ = parm;
          shifter.consume_arg ();
        }
      else if (shifter.cur_arg_strncasecmp ("-h") == 0)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                            "usage:  %s\n"
                            "-n Do not use Callback (for testing)\n"
                            "-o <ior_output_file>\n"
                            "-k <NodeApplicationManager_callback_ior>\n"
                            "-r Request RT support\n"
                            "-h Usage help"
                            "\n",
                            argv [0]),
                            -1);
          shifter.consume_arg ();
        }
      else
        {
          shifter.ignore_arg ();
        }
    }

  if (this->use_callback_ && 0 == this->callback_ior_.length ())
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "Callback IOR to NodeApplicationManager "
                         "is required.\n"),
                        -1);
    }

  return 0;
}

CIAO::NodeApp_Configurator *
CIAO::NodeApplication_Options::create_nodeapp_configurator (void)
{
  typedef CIAO::NodeApp_Configurator * (*intelligent_designer)(void);
  CIAO::NodeApp_Configurator* ptr = 0;

  if (this->rt_support_)
    {
      int const retval =
        this->config_dll_.open (
          ACE_DLL_PREFIX ACE_TEXT ("CIAO_RTNA_Configurator"),
          ACE_DEFAULT_SHLIB_MODE,
          0);

      if (0 != retval)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "%p\n",
                             "dll.open"),
                            0);
        }

      // Cast the void* to non-pointer type first - it's not legal to
      // cast a pointer-to-object directly to a pointer-to-function.
      void *void_ptr =
        this->config_dll_.symbol (ACE_TEXT ("create_nodeapp_configurator"));
      ptrdiff_t tmp = reinterpret_cast<ptrdiff_t> (void_ptr);

      // "id" is for intelligent-designer.
      intelligent_designer config_id =
        reinterpret_cast<intelligent_designer> (tmp);

      if (0 == config_id)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "%p",
                             "dll.symbol"),
                            0);
        }

      ptr = config_id ();

      if (0 == ptr)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Error creating RTNodeApp_Configurator\n"),
                            0);
        }
    }
  else
    {
      ACE_NEW_RETURN (ptr,
                      CIAO::NoOp_Configurator (),
                      0);
    }

  return ptr;
}