> cd descriptors
> $CIAO_ROOT/tools/static_configurator/Static_Assembly_Parser
-a BasicSP.cad
The following files are generated -
Static_Assembly_Config.h
Static_CCM_App.cpp
Static_CCM_App.mpc
Static_Assembly_Config.h contains the intermediate representation of all the parsed component and assembly information obtained from the XML files. Static_CCM_App.cpp contains the main driver application. Here a runtime static configuration engine is used to create containers, homes, components, etc and then establish necessary connections between the components. In the BasicSP example, an external controller (see $CIAO_ROOT/examples/OEP/BasicSP/README) is used to start or stop a pulser. The generated main driver application (Static_CCM_App.cpp) is modified to add code to trigger the pulser object on. The generated .mpc file is modified to add all other necessary files so that the application can be built statically. Note that the static configurator only generates only certain file names in the .mpc file. These filenames are obtained from the XML descriptor files. All other necessary files have to be added manually as indicated.
Now the static build files can be generated by running the mpc utility.
> cd ..
> $ACE_ROOT/bin/mpc -static Static_CCM_App.mpc
Static_Assembly_Config.h
#include "Static_Assembly.h"
#include "CCM_ContainerC.h"
#include "Container_Base.h"
//Containers
CIAO::Static_Config::ContainerAttributes
containers_table_[]=
{
{"", 0}
};
extern "C"
::Components::HomeExecutorBase_ptr
createECHome_Impl (void);
extern "C" ::PortableServer::Servant
createECHome_Servant
(::Components::HomeExecutorBase_ptr
p,
::CIAO::Session_Container *c
ACE_ENV_ARG_DECL_WITH_DEFAULTS);
extern "C" ::Components::HomeExecutorBase_ptr
createBMDeviceHome_Impl (void);
extern "C" ::PortableServer::Servant
createBMDeviceHome_Servant
(::Components::HomeExecutorBase_ptr
p,
::CIAO::Session_Container *c
ACE_ENV_ARG_DECL_WITH_DEFAULTS);
extern "C" ::Components::HomeExecutorBase_ptr
createBMClosedEDHome_Impl (void);
extern "C" ::PortableServer::Servant
createBMClosedEDHome_Servant
(::Components::HomeExecutorBase_ptr
p,
::CIAO::Session_Container *c
ACE_ENV_ARG_DECL_WITH_DEFAULTS);
extern "C" ::Components::HomeExecutorBase_ptr
createBMDisplayHome_Impl (void);
extern "C" ::PortableServer::Servant
createBMDisplayHome_Servant
(::Components::HomeExecutorBase_ptr
p,
::CIAO::Session_Container *c
ACE_ENV_ARG_DECL_WITH_DEFAULTS);
//Homes
CIAO::Static_Config::HomeAttributes
homes_table_[]=
{
{"a_ECHome",
"DCE:3148F760-F2ED-4204-A775-6B972C10E8CB",
"createECHome_Impl", createECHome_Impl,
"DCE:75309233-0E0A-4cfb-B186-3E99F69B1D40",
"createECHome_Servant", createECHome_Servant, 0, 0 },
{"a_BMDeviceHome",
"DCE:82C2B032-37F0-4315-A59F-7020D3264E4D",
"createBMDeviceHome_Impl", createBMDeviceHome_Impl,
"DCE:93D254CF-9538-44e8-BB98-AABCD134ADD3",
"createBMDeviceHome_Servant", createBMDeviceHome_Servant, 0, 0 },
{"a_BMClosedEDHome",
"DCE:8E6C468D-A39F-46b4-962B-265F1AA8D538",
"createBMClosedEDHome_Impl", createBMClosedEDHome_Impl,
"DCE:CDC06FCA-50FC-43ca-8ECC-BEFBD33FEE78",
"createBMClosedEDHome_Servant", createBMClosedEDHome_Servant, 0, 0 },
{"a_BMDisplayHome",
"DCE:8E92655E-CA07-46C8-B127-0F0872A8CC29",
"createBMDisplayHome_Impl", createBMDisplayHome_Impl,
"DCE:D7984625-8561-431d-9927-4E498B317C02",
"createBMDisplayHome_Servant", createBMDisplayHome_Servant, 0, 0 }
};
//Components
CIAO::Static_Config::ComponentAttributes
components_table_[]=
{
{"a_EC", 0, 0, 0 },
{"a_BMDevice", -1, -1, 1 },
{"a_BMClosedED", -1, -1, 2 },
{"a_BMDisplay", -1, -1, 3 }
};
//Component Registrations
CIAO::Assembly_Placement::componentinstantiation::Register_Info
component_registrations_table_[]=
{
{CIAO::Assembly_Placement::componentinstantiation::COMPONENT,
CIAO::Assembly_Placement::componentinstantiation::IORFILE, "", "ec.ior"
}
};
//Connections
CIAO::Static_Config::ConnectionAttributes
connections_table_[]=
{
{CIAO::Assembly_Connection::PUBLISHER_CONSUMER,
"", "timeout", 0, 1, 0, 0 },
{CIAO::Assembly_Connection::PUBLISHER_CONSUMER,
"", "data_available", 3, 4, 0, 0 },
{CIAO::Assembly_Connection::PUBLISHER_CONSUMER,
"", "out_avail", 6, 7, 0, 0 },
{CIAO::Assembly_Connection::INTERFACE,
"", "datain", 9, 10, 0, 0 },
{CIAO::Assembly_Connection::INTERFACE,
"", "comp_data", 12, 13, 0, 0 }
};
//Resolver Infos
CIAO::Static_Config::ResolveInfoAttributes
resolvers_table_[]=
{
{CIAO::Assembly_Connection::COMP_IDREF,
"a_EC", -1, 0 },
{CIAO::Assembly_Connection::CONSUMER,
"timeout", 2, 0 },
{CIAO::Assembly_Connection::COMP_IDREF,
"a_BMDevice", -1, 0 },
{CIAO::Assembly_Connection::COMP_IDREF,
"a_BMDevice", -1, 0 },
{CIAO::Assembly_Connection::CONSUMER,
"in_avail", 5, 0 },
{CIAO::Assembly_Connection::COMP_IDREF,
"a_BMClosedED", -1, 0 },
{CIAO::Assembly_Connection::COMP_IDREF,
"a_BMClosedED", -1, 0 },
{CIAO::Assembly_Connection::CONSUMER,
"data_ready", 8, 0 },
{CIAO::Assembly_Connection::COMP_IDREF,
"a_BMDisplay", -1, 0 },
{CIAO::Assembly_Connection::COMP_IDREF,
"a_BMClosedED", -1, 0 },
{CIAO::Assembly_Connection::PROVIDER,
"data_read", 11, 0 },
{CIAO::Assembly_Connection::COMP_IDREF,
"a_BMDevice", -1, 0 },
{CIAO::Assembly_Connection::COMP_IDREF,
"a_BMDisplay", -1, 0 },
{CIAO::Assembly_Connection::PROVIDER,
"dataout", 14, 0 },
{CIAO::Assembly_Connection::COMP_IDREF,
"a_BMClosedED", -1, 0 }
};
Static_CCM_App.cpp
#include "ComponentServer_Impl.h"
#include "CIAO_ServersC.h"
#include "Server_init.h"
#include "Static_Configurator.h"
#include "ace/SString.h"
#include "ace/Get_Opt.h"
#include "Static_Assembly_Config.h"
char *ior_file_name_ = "comp_serv.ior";
int
parse_args (int argc, char *argv[])
{
ACE_Get_Opt get_opts (argc, argv,
"k:o:");
int c;
while ((c = get_opts ()) != -1)
switch (c)
{
case
'o':
// get the file name to write to
ior_file_name_
= get_opts.opt_arg ();
break;
case
'?':
// display help for use of the server.
default:
ACE_ERROR_RETURN ((LM_ERROR,
"usage: %s\n"
"-o <ior_output_file>\n"
"\n",
argv [0]),
-1);
}
return 0;
}
int
main (int argc, char *argv[])
{
ACE_TRY_NEW_ENV
{
// Initialize
orb
CORBA::ORB_var
orb = CORBA::ORB_init (argc,
argv,
0
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
CIAO::Server_init (orb.in ());
if
(parse_args
(argc, argv) != 0)
return -1;
// Get
reference
to Root POA.
CORBA::Object_var
obj
= orb->resolve_initial_references ("RootPOA"
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
PortableServer::POA_var
poa
= PortableServer::POA::_narrow (obj.in ()
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
// Activate
POA manager
PortableServer::POAManager_var
mgr
= poa->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
mgr->activate
(ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
CIAO::ComponentServer_Impl *comserv_servant;
CIAO::Static_Configurator
configurator;
int
containers_table_size
=
sizeof
(containers_table_)/sizeof(CIAO::Static_Config::ContainerAttributes);
int
homes_table_size
=
sizeof (homes_table_)/sizeof(CIAO::Static_Config::HomeAttributes);
int
components_table_size
=
sizeof
(components_table_)/sizeof(CIAO::Static_Config::ComponentAttributes);
int
component_registrations_table_size
=
sizeof
(component_registrations_table_)/sizeof(CIAO::Assembly_Placement::componentinstantiation::Register_Info);
int
connections_table_size
=
sizeof
(connections_table_)/sizeof(CIAO::Static_Config::ConnectionAttributes);
int
resolvers_table_size
=
sizeof
(resolvers_table_)/sizeof(CIAO::Static_Config::ResolveInfoAttributes);
CIAO::HOMECREATOR_FUNCPTR_MAP
home_creator_fptr_map;
CIAO::HOMESERVANTCREATOR_FUNCPTR_MAP
homesvnt_creator_fptr_map;
CIAO::Static_Config_EntryPoints_Maps
maps;
maps.home_creator_funcptr_map_
= &home_creator_fptr_map;
maps.home_servant_creator_funcptr_map_
= &homesvnt_creator_fptr_map;
int i=0;
for (i=0;
i<homes_table_size; ++i)
{
home_creator_fptr_map.bind (homes_table_[i].executor_entrypt_,
homes_table_[i].executor_fptr_);
homesvnt_creator_fptr_map.bind (homes_table_[i].servant_entrypt_,
homes_table_[i].servant_fptr_);
}
ACE_NEW_RETURN
(comserv_servant,
CIAO::ComponentServer_Impl (orb.in (),
poa.in (),
1,
&maps),
-1);
PortableServer::ServantBase_var safe_servant (comserv_servant);
Components::ConfigValues configs;
comserv_servant->init
(configs
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
//
Configuring
ComponentServer.
PortableServer::ObjectId_var
cs_oid
= poa->activate_object (comserv_servant
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
obj =
poa->id_to_reference
(cs_oid.in ()
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
Components::Deployment::ComponentServer_var
comserv_obj =
Components::Deployment::ComponentServer::_narrow (obj.in ()
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
if
(CORBA::is_nil
(comserv_obj.in ()))
ACE_ERROR_RETURN ((LM_ERROR, "Unable to activate ComponentServer
object\n"),
-1);
Components::Deployment::ServerActivator_var
activator;
Components::ConfigValues_var
config = new Components::ConfigValues;
comserv_servant->set_objref
(activator.in (),
config,
comserv_obj.in ()
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
configurator.configure
(orb.in (),
comserv_obj.in (),
containers_table_,
containers_table_size,
homes_table_,
homes_table_size,
components_table_,
components_table_size,
component_registrations_table_,
component_registrations_table_size,
connections_table_,
connections_table_size,
resolvers_table_,
resolvers_table_size);
CORBA::String_var
str = orb->object_to_string (comserv_obj.in ()
ACE_ENV_ARG_PARAMETER);
CIAO::Utility::write_IOR
(ior_file_name_, str.in ());
ACE_DEBUG
((LM_INFO, "ComponentServer IOR: %s\n", str.in ()));
ACE_DEBUG
((LM_DEBUG,
"Running ComponentServer...\n"));
// Run the
main event loop for the ORB.
orb->run
(ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION
(ACE_ANY_EXCEPTION,
"server::main \n");
return 1;
}
ACE_ENDTRY;
return 0;
}
Static_CCM_App.mpc
project(Static_CCM_App) : ciao_server,
ciao_client,
rtcorba, rtportableserver, iortable, acexml {
includes +=
$(ACE_ROOT)/TAO/CIAO/tools/Assembly_Deployer
includes +=
$(ACE_ROOT)/TAO/CIAO/tools/static_configurator
libs += CIAO_XML_Helpers Static_Configurator
after += CIAO_XML_Helpers Static_Configurator
libs += EC_exec
after += EC_exec
libs += EC_svnt
after += EC_svnt
libs += BMDevice_exec
after += BMDevice_exec
libs += BMDevice_svnt
after += BMDevice_svnt
libs += BMClosedED_exec
after += BMClosedED_exec
libs += BMClosedED_svnt
after += BMClosedED_svnt
libs += BMDisplay_exec
after += BMDisplay_exec
libs += BMDisplay_svnt
after += BMDisplay_svnt
Source_Files {
Static_CCM_App.cpp
}
IDL_Files {
}
}
(Highlighted text is
manually added to the
generated .cpp file)
#include "ComponentServer_Impl.h"
#include "CIAO_ServersC.h"
#include "Server_init.h"
#include "Static_Configurator.h"
#include "ace/SString.h"
#include "ace/Get_Opt.h"
#include "Static_Assembly_Config.h"
char *ior_file_name_ = "comp_serv.ior";
int rate = 2;
int
parse_args (int argc, char *argv[])
{
ACE_Get_Opt get_opts (argc, argv, "k:o:");
int c;
while ((c = get_opts ()) != -1)
switch (c)
{
case 'o': // get the file
name to write to
ior_file_name_ =
get_opts.opt_arg
();
break;
case '?': // display help
for
use of the server.
default:
ACE_ERROR_RETURN
((LM_ERROR,
"usage: %s\n"
"-o <ior_output_file>\n"
"\n",
argv [0]),
-1);
}
return 0;
}
int
main (int argc, char *argv[])
{
ACE_TRY_NEW_ENV
{
// Initialize orb
CORBA::ORB_var orb = CORBA::ORB_init
(argc,
argv,
0
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
CIAO::Server_init (orb.in ());
if (parse_args (argc, argv) != 0)
return -1;
// Get reference to Root POA.
CORBA::Object_var obj
=
orb->resolve_initial_references
("RootPOA"
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
PortableServer::POA_var poa
=
PortableServer::POA::_narrow
(obj.in ()
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
// Activate POA manager
PortableServer::POAManager_var mgr
= poa->the_POAManager
(ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
mgr->activate
(ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
CIAO::ComponentServer_Impl *comserv_servant;
CIAO::Static_Configurator
configurator;
int containers_table_size =
sizeof
(containers_table_)/sizeof(CIAO::Static_Config::ContainerAttributes);
int homes_table_size =
sizeof
(homes_table_)/sizeof(CIAO::Static_Config::HomeAttributes);
int components_table_size =
sizeof
(components_table_)/sizeof(CIAO::Static_Config::ComponentAttributes);
int
component_registrations_table_size
=
sizeof
(component_registrations_table_)/sizeof(CIAO::Assembly_Placement::componentinstantiation::Register_Info);
int connections_table_size =
sizeof
(connections_table_)/sizeof(CIAO::Static_Config::ConnectionAttributes);
int resolvers_table_size =
sizeof
(resolvers_table_)/sizeof(CIAO::Static_Config::ResolveInfoAttributes);
CIAO::HOMECREATOR_FUNCPTR_MAP
home_creator_fptr_map;
CIAO::HOMESERVANTCREATOR_FUNCPTR_MAP
homesvnt_creator_fptr_map;
CIAO::Static_Config_EntryPoints_Maps
maps;
maps.home_creator_funcptr_map_ =
&home_creator_fptr_map;
maps.home_servant_creator_funcptr_map_
= &homesvnt_creator_fptr_map;
int i=0;
for (i=0; i<homes_table_size;
++i)
{
home_creator_fptr_map.bind
(homes_table_[i].executor_entrypt_,
homes_table_[i].executor_fptr_);
homesvnt_creator_fptr_map.bind
(homes_table_[i].servant_entrypt_,
homes_table_[i].servant_fptr_);
}
ACE_NEW_RETURN (comserv_servant,
CIAO::ComponentServer_Impl (orb.in (),
poa.in (),
1,
&maps),
-1);
PortableServer::ServantBase_var safe_servant (comserv_servant);
Components::ConfigValues configs;
comserv_servant->init (configs
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
// Configuring ComponentServer.
PortableServer::ObjectId_var cs_oid
=
poa->activate_object
(comserv_servant
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
obj = poa->id_to_reference
(cs_oid.in
()
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
Components::Deployment::ComponentServer_var
comserv_obj =
Components::Deployment::ComponentServer::_narrow
(obj.in ()
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
if (CORBA::is_nil (comserv_obj.in
()))
ACE_ERROR_RETURN
((LM_ERROR,
"Unable to activate ComponentServer object\n"), -1);
Components::Deployment::ServerActivator_var
activator;
Components::ConfigValues_var config
= new Components::ConfigValues;
comserv_servant->set_objref
(activator.in
(),
config,
comserv_obj.in ()
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
configurator.configure (orb.in (),
comserv_obj.in (),
containers_table_,
containers_table_size,
homes_table_,
homes_table_size,
components_table_,
components_table_size,
component_registrations_table_,
component_registrations_table_size,
connections_table_,
connections_table_size,
resolvers_table_,
resolvers_table_size);
CORBA::String_var str =
orb->object_to_string
(comserv_obj.in ()
ACE_ENV_ARG_PARAMETER);
CIAO::Utility::write_IOR
(ior_file_name_,
str.in ());
ACE_DEBUG ((LM_INFO,
"ComponentServer
IOR: %s\n", str.in ()));
ACE_DEBUG ((LM_DEBUG,
"Running ComponentServer...\n"));
CORBA::Object_var
pulser_obj
= orb->string_to_object ("file://ec.ior"
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
BasicSP::EC_var
pulser
= BasicSP::EC::_narrow (pulser_obj.in ()
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
if
(CORBA::is_nil
(pulser.in ()))
ACE_ERROR_RETURN ((LM_ERROR, "Unable to acquire 'EC' objref\n"), -1);
pulser->hertz
(rate
ACE_ENV_ARG_PARAMETER);
ACE_TRY_CHECK;
ACE_DEBUG ((LM_DEBUG, "Start up the Event services\n"));
pulser->start
(ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK;
// Run the main event loop for
the
ORB.
orb->run
(ACE_ENV_SINGLE_ARG_PARAMETER);
ACE_TRY_CHECK
}
ACE_CATCHANY
{
ACE_PRINT_EXCEPTION
(ACE_ANY_EXCEPTION,
"server::main \n");
return 1;
}
ACE_ENDTRY;
return 0;
}
(Highlighted text is
manually added to the
generated .cpp file)
project(Static_CCM_App) : ciao_server, ciao_client,
rtcorba,
rtportableserver,
iortable, acexml {
includes += $(ACE_ROOT)/TAO/CIAO/tools/Assembly_Deployer
includes += $(ACE_ROOT)/TAO/CIAO/tools/static_configurator
libs += CIAO_XML_Helpers Static_Configurator
after += CIAO_XML_Helpers Static_Configurator
libs += BasicSP_stub BasicSP_svnt
after += BasicSP_stub BasicSP_svnt
libs += EC_exec
after += EC_exec
libs += EC_svnt EC_stub
after += EC_svnt EC_stub
libs += BMDevice_exec
after += BMDevice_exec
libs += BMDevice_svnt BMDevice_stub
after += BMDevice_svnt BMDevice_stub
libs += BMClosedED_exec
after += BMClosedED_exec
libs += BMClosedED_svnt BMClosedED_stub
after += BMClosedED_svnt BMClosedED_stub
libs += BMDisplay_exec
after += BMDisplay_exec
libs += BMDisplay_svnt BMDisplay_stub
after += BMDisplay_svnt BMDisplay_stub
Source_Files {
Static_CCM_App.cpp
}
IDL_Files {
}
}