summaryrefslogtreecommitdiff
path: root/TAO/CIAO/DAnCE/StaticConfigurator/StaticDAnCEParser.cpp
blob: 5c44cf9c02cfdae8e7d3a1d1865ef9de88bd48a1 (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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
//=============================================================================
/**
 *  @file StaticDAnCEParser.cpp
 *
 *  $Id$
 *
 *  This parser is used in static deployment of CIAO components. This
 *  parser parses a deployment plan and generates a header file plan.h
 *  containing information about the home and servant creation
 *  function entry points. This can be used by a Static_NodeManager to
 *  instantiate instances of homes and servants just like the regular
 *  NodeManager. For more details, see
 *  $CIAO_ROOT/DAnCE/StaticConfigurator/docs/static_dance.html
 *
 *  @author Venkita Subramonian <venkita@cse.wustl.edu>
 */
//=============================================================================

#include "NodeApplicationManager/ImplementationInfo.h"
#include "ace/OS_NS_stdio.h"
#include "ace/streams.h"
#include "ace/Get_Opt.h"
#include "tao/IORTable/IORTable.h"
#include "tao/CDR.h"
#include "Config_Handlers/XML_File_Intf.h"

using namespace CIAO;

static void
usage (const ACE_TCHAR* program)
{
  ACE_ERROR ((LM_ERROR,
              ACE_TEXT ("Usage: %s -p <package URI>\n"),
              program));
}

int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  // top level package URL
  char* package_url = 0;

  // Initialize the ORB so that CORBA::Any will work
  //
  CORBA::ORB_var orb =
    CORBA::ORB_init (argc,
                     argv,
                     "");

  ACE_Get_Opt get_opt (argc, argv, ACE_TEXT ("p:"));
  int c;

  while ((c = get_opt ()) != EOF)
    {
      switch (c)
        {
          case 'p':
            package_url = get_opt.opt_arg ();
            break;

          default:
            usage(argv[0]);
            return -1;
        }
    }

  if (package_url == 0) {
    usage(argv[0]);
    return -1;
  }

  CIAO::Config_Handlers::XML_File_Intf intf (package_url);
      
  ::Deployment::DeploymentPlan_var plan =
      intf.get_plan ();

  CORBA::StringSeq dummy;
  dummy.length (0);

  NodeImplementationInfoHandler handler (plan, dummy);
  
  Deployment::NodeImplementationInfo * node_impl_info =
    handler.node_impl_info ();
  
  if (!node_impl_info)
    {
      ACE_ERROR_RETURN ((LM_ERROR, 
                  "DAnCE (%P|%t) StaticParser -"
                  "Failed to create Node Implementation Infos!\n"), 1);
      
    }

  Deployment::ContainerImplementationInfos& impl_infos = node_impl_info[0].impl_infos;

  FILE* fp = fopen ("plan.h", "w");

  CORBA::ULong i,j,num_containers,num_components;
  num_containers = impl_infos.length ();
  for (i = 0; i < num_containers; ++i)
    {
      num_components = impl_infos[i].impl_infos.length ();
      for (j = 0; j < num_components; ++j)
        {
          ACE_DEBUG ((LM_DEBUG, "The info for installation: \n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n",
                      impl_infos[i].impl_infos[j].component_instance_name.in (),
                      impl_infos[i].impl_infos[j].executor_dll.in (),
                      impl_infos[i].impl_infos[j].executor_entrypt.in (),
                      impl_infos[i].impl_infos[j].servant_dll.in (),
                      impl_infos[i].impl_infos[j].servant_entrypt.in () ));
          ACE_OS::fprintf (fp,
                           "extern \"C\" ::Components::HomeExecutorBase_ptr %s (void);\n",
                           impl_infos[i].impl_infos[j].executor_entrypt.in ());
          ACE_OS::fprintf (fp,
                           "extern \"C\" ::PortableServer::Servant %s \n",
                           impl_infos[i].impl_infos[j].servant_entrypt.in ());
          ACE_OS::fprintf (fp,
                           "\t\t(::Components::HomeExecutorBase_ptr p,\n");
          ACE_OS::fprintf (fp,
                           "\t\t::CIAO::Session_Container *c,\n");
          ACE_OS::fprintf (fp,
                           "\t\tconst char*\n");
          ACE_OS::fprintf (fp,
                           "\t\tACE_ENV_ARG_DECL_WITH_DEFAULTS);\n");
        }
    }
      
  ACE_OS::fprintf (fp, "struct HomeAttributes\n");
  ACE_OS::fprintf (fp, "{\n");
  ACE_OS::fprintf (fp, "  ACE_TString component_instance_name_;\n");
  ACE_OS::fprintf (fp, "  /// Specify the entrypoint to component executor DLL.\n");
  ACE_OS::fprintf (fp, "  ACE_TString executor_entrypt_;\n");
  ACE_OS::fprintf (fp, "  ::CIAO::HomeFactory executor_fptr_;\n");
  ACE_OS::fprintf (fp, "  /// Specify the entrypoint to component servant DLL.\n");
  ACE_OS::fprintf (fp, "  ACE_TString servant_entrypt_;\n");
  ACE_OS::fprintf (fp, "  ::CIAO::ServantFactory servant_fptr_;\n");
  ACE_OS::fprintf (fp, "};\n");
  ACE_OS::fprintf (fp, "//Homes\n");
  ACE_OS::fprintf (fp, "HomeAttributes homes_table[]= \n");
  ACE_OS::fprintf (fp, "{\n");

  num_containers = impl_infos.length ();
  for (i = 0; i < num_containers; ++i)
    {
      num_components = impl_infos[i].impl_infos.length ();
      for (j = 0; j < num_components; ++j)
        {
          ACE_OS::fprintf (fp, "\t{\"%s\", \"%s\", %s, \"%s\", %s}",
                           impl_infos[i].impl_infos[j].component_instance_name.in (),
                           impl_infos[i].impl_infos[j].executor_entrypt.in (),
                           impl_infos[i].impl_infos[j].executor_entrypt.in (),
                           impl_infos[i].impl_infos[j].servant_entrypt.in (),
                           impl_infos[i].impl_infos[j].servant_entrypt.in () );
          if (!(i == num_containers -1 && j == num_components-1))
            ACE_OS::fprintf (fp, ",\n");
        }
    }
  ACE_OS::fprintf (fp, "};\n\n");

  fclose (fp);

  return 0;
}