diff options
author | nshankar <nshankar@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2006-11-02 23:43:32 +0000 |
---|---|---|
committer | nshankar <nshankar@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2006-11-02 23:43:32 +0000 |
commit | f9d7e808f3f044fec2a1777b0463c8d10316962f (patch) | |
tree | cdb125a8aa89b2f9b01d9d9c399ce94a60c561f1 | |
parent | 5d3e8be7ff8baa99a3efc0fb50462bc04103c370 (diff) | |
download | ATCD-f9d7e808f3f044fec2a1777b0463c8d10316962f.tar.gz |
Thu Nov 2 23:41:56 UTC 2006 Nishanth Shankaran <nshankar@nospam.com>
-rw-r--r-- | ChangeLog | 10 | ||||
-rw-r--r-- | SA_POP/server/Driver.cpp | 170 | ||||
-rw-r--r-- | SA_POP/server/Driver.h | 65 | ||||
-rw-r--r-- | SA_POP/server/Driver.idl | 21 | ||||
-rw-r--r-- | SA_POP/server/Driver.mpc | 82 | ||||
-rw-r--r-- | SA_POP/server/client.cpp | 81 | ||||
-rw-r--r-- | SA_POP/server/server.cpp | 108 |
7 files changed, 537 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog index 37d0747a87b..191dcaa2853 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Thu Nov 2 23:41:56 UTC 2006 Nishanth Shankaran <nshankar@nospam.com> + + * SA_POP/server: + * SA_POP/server/Driver.h: + * SA_POP/server/Driver.idl: + * SA_POP/server/Driver.cpp: + * SA_POP/server/Driver.mpc: + * SA_POP/server/client.cpp: + * SA_POP/server/server.cpp: Added the "driver server". + Thu Nov 2 17:48:07 UTC 2006 Nishanth Shankaran <nshanka@nospam.com> * Controller/Component/Poller.cpp: Fixed compiler warnings. diff --git a/SA_POP/server/Driver.cpp b/SA_POP/server/Driver.cpp new file mode 100644 index 00000000000..501924b9941 --- /dev/null +++ b/SA_POP/server/Driver.cpp @@ -0,0 +1,170 @@ +#include "Driver.h" + +namespace CIAO +{ + namespace RACE + { + + namespace SA_POP + { + Driver_i::Driver_i (CORBA::ORB_ptr orb) + : orb_ (CORBA::ORB::_duplicate (orb)), + iia_name_ ("RACE::InteractiveInput") + { + } + + Driver_i::~Driver_i (void) + { + } + + int + Driver_i::init (const char *RM_name) + { + try + { + // Resolve naming service + CORBA::Object_var ns_tmp = + this->orb_->resolve_initial_references ("NameService"); + ::CosNaming::NamingContext_var ns = + ::CosNaming::NamingContext::_narrow (ns_tmp.in ()); + ::CosNaming::Name ns_name; + CORBA::ULong i = 0; + ACE_Tokenizer tok (this->iia_name_.rep ()); + tok.delimiter_replace (':', 0); + tok.delimiter_replace ('/', 0); + char *name_element = 0; + while ((name_element = tok.next ()) != 0) + { + ns_name.length (ns_name.length () + 1); + ns_name[i].id = CORBA::string_dup (name_element); + ++i; + } + + /// now try to resolve the reference to the IIA. + CORBA::Object_var iia_tmp = ns->resolve (ns_name); + this->iia_ = + ::CIAO::RACE::Interactive_Input_Adapter::_narrow (iia_tmp.in ()); + + // Now initialize the plan generator. + // this->plan_gen_.init (this->orb_, true, RM_name); + return 0; + } + catch (CORBA::Exception &ex) + { + ACE_PRINT_EXCEPTION (ex, "Error in initializing the driver!\n"); + return -1; + } + } + + + void + Driver_i::deploy_plan (const char * plan_uri) + throw (::CORBA::SystemException) + { + try + { + // Create deploy input event and populate it. + CIAO::RACE::Deploy_Input_var input = new OBV_CIAO::RACE::Deploy_Input; + input->plan_uri (plan_uri); + input->command (::CIAO::RACE::DEPLOY); + + // Now push the event to the IIA. + this->iia_->get_consumer_deployment ()->push_Deploy_Input (input.in ()); + + } + catch (CORBA::Exception &ex) + { + ACE_PRINT_EXCEPTION (ex, "Exception caught in Driver::deploy_plan"); + } + } + + void + Driver_i::deploy_goal (const ::CIAO::RACE::GoalStructure &) + throw (::CORBA::SystemException) + { + } + + int + Driver_i::convert (::CIAO::RACE::OperationalString &op_string, + ::Deployment::DeploymentPlan &plan) + { + // Populate the label, UUID, connections, and info property fields of + // the deployment plan. + plan.label = op_string.name; + plan.UUID = op_string.UUID; + plan.connection = op_string.dataLinks; + plan.infoProperty = op_string.properties; + + // Now, populate the instance, implementation, and artifact fields of + // the deployment plan using the plan generator. + int position; + for (CORBA::ULong itr = 0; itr < op_string.instances.length (); ++itr) + { + + ::CIAO::RACE::InstanceDescription op_instance = op_string.instances [itr]; + if (this->plan_gen_.generate_plan + (plan, + op_instance.suggestedImpl.in (), + position)) + { + ::Deployment::InstanceDeploymentDescription instance; + instance.name = op_instance.name; + + // @@ This is a temporaty hack. Later on we must be using the + // simple bin packer do perform the node assignment. + if (strcmp ("IDL:SPACE/Ground_Station:1.0", + op_instance.suggestedImpl.in ()) == 0) + { + instance.node = CORBA::string_dup ("ground"); + } + else + { + instance.node = CORBA::string_dup ("space"); + } + + instance.implementationRef = position; + instance.configProperty = op_instance.configProperty; + CORBA::ULong cur_len = plan.instance.length (); + plan.instance.length (cur_len+1); + plan.instance [cur_len] = instance; + + } + else + { + ACE_ERROR ((LM_ERROR, "Given suggested type is not available " + "in the Repoman!!\n Bailing out....\n")); + return -1; + } + } + return 0; + } + + int + Driver_i::deploy_plan (::Deployment::DeploymentPlan &plan) + { + try + { + // Create a metadata event and populate it. + CIAO::RACE::Metadata_var metadata = new OBV_CIAO::RACE::Metadata; + metadata->command (::CIAO::RACE::DEPLOY); + metadata->plan (plan); + + // Now push the event to the IIA. + this->iia_->get_consumer_meta_data ()->push_Metadata (metadata.in ()); + } + catch (CORBA::Exception &ex) + { + ACE_PRINT_EXCEPTION (ex, "Exception caught\n"); + return -1; + } + + catch (...) + { + ACE_ERROR ((LM_ERROR, "(%P|%t) Driver_i: Unknown exception\n")); + return -1; + } + return 0; + } + } + } +} diff --git a/SA_POP/server/Driver.h b/SA_POP/server/Driver.h new file mode 100644 index 00000000000..ad626a0d34d --- /dev/null +++ b/SA_POP/server/Driver.h @@ -0,0 +1,65 @@ +#ifndef DRIVER_H_ +#define DRIVER_H_ + +#include "DriverS.h" +#include "Input_Adapters/Interactive_Input_Adapter/Interactive_Input_AdapterC.h" +#include "ace/OS.h" +#include "ace/SString.h" +#include "orbsvcs/CosNamingC.h" +#include "RACE/common/OpStringC.h" +#include "Plan_Generator_Impl.h" +namespace CIAO +{ + namespace RACE + { + + namespace SA_POP + { + + class Driver_i + : public virtual POA_CIAO::RACE::SA_POP::Driver + { + public: + // Constructor + Driver_i (CORBA::ORB_ptr orb); + + // Destructor + virtual ~Driver_i (void); + + virtual + int init (const char *RM_name); + + virtual + void deploy_plan (const char * plan_uri) + throw (::CORBA::SystemException); + + virtual + void deploy_goal (const ::CIAO::RACE::GoalStructure & goal) + throw (::CORBA::SystemException); + + protected: + virtual int convert (::CIAO::RACE::OperationalString &op_string, + ::Deployment::DeploymentPlan &plan); + + virtual int deploy_plan (::Deployment::DeploymentPlan &plan); + + + private: + + // Pointer to the ORB. + CORBA::ORB_var orb_; + + // Naming context of the interactive input adapter. + ACE_TString iia_name_; + + // Pointer to the interactive input adapter. + ::CIAO::RACE::Interactive_Input_Adapter_var iia_; + + // Plan generator object. + ::CIAO::Plan_Generator::Plan_Generator_i plan_gen_; + }; + } + } +} + +#endif /* DRIVER_H_ */ diff --git a/SA_POP/server/Driver.idl b/SA_POP/server/Driver.idl new file mode 100644 index 00000000000..a4a6cc17315 --- /dev/null +++ b/SA_POP/server/Driver.idl @@ -0,0 +1,21 @@ +#include "common/OpString.idl" + +module CIAO +{ + module RACE + { + module SA_POP + { + interface Driver + { + // Deploy the given fully populated deployment plan. + oneway void deploy_plan (in string plan_uri); + + // Generate and deploy a deployment plan that achieves the + // specified goal. + oneway void deploy_goal (in ::CIAO::RACE::GoalStructure goal); + }; + + }; + }; +}; diff --git a/SA_POP/server/Driver.mpc b/SA_POP/server/Driver.mpc new file mode 100644 index 00000000000..cda776c32d5 --- /dev/null +++ b/SA_POP/server/Driver.mpc @@ -0,0 +1,82 @@ +project(Driver_stub): taolib_with_idl, ciao_race_default { + + after += OpString_stub + libs += OpString_stub + + IDL_Files { + + Driver.idl + } + + Header_Files { + DriverC.h + } + + Inline_Files { + DriverC.inl + } + + Source_Files { + DriverC.cpp + } +} + +project(Driver_svnt): taolib_with_idl, ciao_race_default { + + after += Driver_stub + libs += OpString_stub \ + Driver_stub + + IDL_Files { + + Driver.idl + } + + Header_Files { + DriverS.h + } + + Inline_Files { + DriverS.inl + } + + Source_Files { + DriverS.cpp + } +} + +project(Server): ciao_component_dnc, ciao_race_component, taoexe, ciao_plan_generator { + + exename = server + after += Driver_svnt + libs += OpString_stub \ + Driver_stub \ + Driver_svnt \ + Interactive_Input_Adapter_stub + + IDL_Files { + } + + Header_Files { + Driver.h + } + + Source_Files { + Driver.cpp + server.cpp + } +} + +project(client): taoclient, ciao_race_component, ciao_component_dnc { + + exename = client + after += Driver_stub + libs += Driver_stub + + IDL_Files { + } + + Source_Files { + client.cpp + } +} diff --git a/SA_POP/server/client.cpp b/SA_POP/server/client.cpp new file mode 100644 index 00000000000..a72eef2f6a2 --- /dev/null +++ b/SA_POP/server/client.cpp @@ -0,0 +1,81 @@ +#include "DriverC.h" +#include "ace/Get_Opt.h" + +const char *ior = "file://server.ior"; +const char *plan = 0; + +int +parse_args (int argc, char *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "k:d:"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'k': + ior = get_opts.opt_arg (); + break; + + case 'd': + plan = get_opts.opt_arg (); + break; + + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s " + "-k <ior> " + "-d <deployment plan uri> " + "\n", + argv [0]), + -1); + } + if (plan != 0) + { + // Indicates sucessful parsing of the command line + return 0; + } + + else + { + ACE_ERROR ((LM_ERROR, "URI of the deployment plan is necessary!\n")); + return -1; + } +} + +int +main (int argc, char *argv[]) +{ + try + { + CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, ""); + + if (parse_args (argc, argv) != 0) + { + return 1; + } + + CORBA::Object_var tmp = + orb->string_to_object(ior); + + ::CIAO::RACE::SA_POP::Driver_var driver = + ::CIAO::RACE::SA_POP::Driver::_narrow(tmp.in ()); + + if (CORBA::is_nil (driver.in ())) + { + ACE_ERROR_RETURN ((LM_DEBUG, + "Nil Driver reference <%s>\n", ior), 1); + } + + driver->deploy_plan (plan); + + orb->destroy (); + } + catch (CORBA::Exception &ex) + { + ACE_PRINT_EXCEPTION (ex, "Exception caught:"); + return 1; + } + return 0; +} diff --git a/SA_POP/server/server.cpp b/SA_POP/server/server.cpp new file mode 100644 index 00000000000..18556df7b2e --- /dev/null +++ b/SA_POP/server/server.cpp @@ -0,0 +1,108 @@ +#include "Driver.h" +#include "ace/Get_Opt.h" +#include "ace/OS_NS_stdio.h" + +const char *ior_output_file = "server.ior"; +const char *rm_name = "RM"; + +int +parse_args (int argc, char *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "o:r:"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'o': + ior_output_file = get_opts.opt_arg (); + break; + + case 'r': + rm_name = get_opts.opt_arg (); + break; + + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s " + "-o <iorfile> " + "-r <repoman name>" + "\n", + argv [0]), + -1); + } + // Indicates sucessful parsing of the command line + return 0; +} + +int +main (int argc, char *argv[]) +{ + try + { + CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, ""); + + CORBA::Object_var poa_object = + orb->resolve_initial_references("RootPOA"); + + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (poa_object.in ()); + + if (CORBA::is_nil (root_poa.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + " (%P|%t) Panic: nil RootPOA\n"), + 1); + + PortableServer::POAManager_var poa_manager = + root_poa->the_POAManager (); + + if (parse_args (argc, argv) != 0) + { + return 1; + } + + ::CIAO::RACE::SA_POP::Driver_i *driver_impl; + ACE_NEW_RETURN (driver_impl, + ::CIAO::RACE::SA_POP::Driver_i (orb.in ()), 1); + + if (driver_impl->init (rm_name) != 0) + { + return -1; + + } + + PortableServer::ServantBase_var owner_transfer(driver_impl); + + ::CIAO::RACE::SA_POP::Driver_var driver = driver_impl->_this (); + + CORBA::String_var ior = + orb->object_to_string (driver.in ()); + + // Output the IOR to the <ior_output_file> + FILE *output_file= ACE_OS::fopen (ior_output_file, "w"); + if (output_file == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot open output file for writing IOR: %s\n", + ior_output_file), + 1); + ACE_OS::fprintf (output_file, "%s", ior.in ()); + ACE_OS::fclose (output_file); + + poa_manager->activate (); + + orb->run (); + + ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); + + root_poa->destroy (1, 1); + + orb->destroy (); + } + catch (CORBA::Exception &ex) + { + ACE_PRINT_EXCEPTION (ex, "Exception caught:"); + return 1; + } + return 0; +} |