Пример #1
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  static const int orb_threads = 5;
  static const int total_threads = 15;

  // It must be ensured that there are more total threads that there are
  // that are dedicated to running the ORB.
  ACE_ASSERT (total_threads > orb_threads);

  Worker worker (orb_threads);
  try
    {
      worker.orb_ =
        CORBA::ORB_init (argc, argv, "test");

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

      ACE_DEBUG ((LM_DEBUG,"using ior = %s\n",ior));

      CORBA::Object_var tmp = worker.orb_->string_to_object(ior);

      if (CORBA::is_nil (tmp.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR, "Invalid IOR.\n")
                            ,1);
        }
      worker.hello_ = Test::Hello::_narrow(tmp.in ());

      if (CORBA::is_nil (worker.hello_.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Nil Test::Hello reference <%s>\n",
                             ior),
                            1);
        }

//       bool x = worker.hello_->_non_existent();
//       ACE_DEBUG ((LM_DEBUG, "_non_existent returned %d\n",x));

      {
        // Set the Synch Scopes

        CORBA::Any scope_as_any;

        ACE_DEBUG ((LM_DEBUG, "(%P|%t) - Applying SYNC_NONE.\n"));
        scope_as_any <<= Messaging::SYNC_NONE;
        CORBA::PolicyList policies (1);
        policies.length (1);
        policies[0] =
          worker.orb_->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE,
                              scope_as_any);

        ACE_DEBUG ((LM_DEBUG,
                    "(%P|%t) - Applying Synch Scope at Object level.\n"));
        tmp = tmp->_set_policy_overrides (policies, CORBA::SET_OVERRIDE);
        policies[0]->destroy ();
      }

      worker.asynch_hello_ = Test::Hello::_narrow(tmp.in ());

      if (CORBA::is_nil (worker.asynch_hello_.in ())) {
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Nil Test::Hello reference <%s>\n",
                           ior),
                          1);
      }

      init_callback(worker);

    }
  catch (CORBA::Exception &ex)
    {
      ACE_ERROR ((LM_ERROR, "Exception caught: %s\"%s\"\n"
                  , ex._name(), ex._rep_id ()));
      return 1;
    }

  worker.activate (THR_NEW_LWP | THR_JOINABLE, total_threads);
  worker.wait();

  return 0;
}
Пример #2
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      parse_args (argc, argv);

      if (client_orb)
        {
          ACE_Argv_Type_Converter conv (argc, argv);
          // Client creates the orb.
          orb = CORBA::ORB_init (conv.get_argc (),
                                 conv.get_ASCII_argv (),
                                 OpenDDS::DCPS::DEFAULT_ORB_NAME);

          TheServiceParticipant->set_ORB(orb.in());

          // Client runs the orb.
          CORBA::Object_var obj =
            orb->resolve_initial_references ("RootPOA");

          poa = PortableServer::POA::_narrow (obj.in ());

          PortableServer::POAManager_var poa_manager =
            poa->the_POAManager ();

          poa_manager->activate ();

          orb_task = new ORB_Task (orb.in ());
          if (orb_task->activate (THR_NEW_LWP | THR_JOINABLE, 1) == -1)
            {
              ACE_ERROR ((LM_ERROR,
                          ACE_TEXT ("OPENDDS_DCPS_Service_Participant::get_domain_participant_factory, ")
                          ACE_TEXT ("Failed to activate the orb task.")));
              return 1;
            }

          dpf = TheParticipantFactory;
       }
      else
        {
          dpf = TheParticipantFactoryWithArgs(argc, argv);
          poa = TheServiceParticipant->the_poa();
        }


      int ret = run_domain_test ();
      TEST_CHECK (ret == 0);
      ACE_DEBUG((LM_DEBUG,
        ACE_TEXT("(%P|%t) main: ")
        ACE_TEXT("(ret == 0)")
        ACE_TEXT("\n")
      ));

      for (ssize_t i = 0; i < 6; i ++)
      {
        run_next_sample_test (i);
        run_next_send_sample_test (i);
        run_next_instance_sample_test (i);
      }

      if (client_orb)
        {
          orb->shutdown (0);
          orb_task->wait ();
        }

      TheTransportFactory->release();
      TheServiceParticipant->shutdown ();

      if (client_orb)
        {
          orb->destroy ();
        }

    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught:");
      return 1;
    }

  return 0;
}
Пример #3
0
void
Lorica::Proxy::configure(Config & config, 
			 const std::string &def_ior_file )
	throw (InitError)
{
	try {
		// This should be OK even if multiple copies of Proxy
		// get created as they all create the same ORB instance
		// and therefore the single ORB instance will get shutdown.
		Lorica::Proxy::this_ = this;

		std::auto_ptr<ACE_ARGV> arguments(config.get_orb_options());

		// Create proxy ORB.
		int argc = arguments->argc();
		if (Lorica_debug_level > 2) {
			ACE_DEBUG((LM_DEBUG,
				   ACE_TEXT("(%T) %N:%l - passing %d args to ORB_init:\n"), 
				   argc));

			for (int i = 0; i < argc; i++)
				ACE_DEBUG((LM_DEBUG, ACE_TEXT("%N:%l - %s\n"), arguments->argv()[i]));
		}
		orb_ = CORBA::ORB_init(argc, arguments->argv());

		// test if we have any security functionality
		ACE_Service_Repository * repo = 
			orb_->orb_core()->configuration()->
			current_service_repository();
		config.secure_available(repo->find("SSLIOP_Factory") == 0);

		int attempts = 3;
		CORBA::Object_var obj = CORBA::Object::_nil();
		resolve_again:
		try {
			obj = orb_->resolve_initial_references("RootPOA");
		}
		catch (CORBA::Exception & ex) {
			if (attempts--) {
				ACE_DEBUG((LM_INFO, ACE_TEXT("(%T) %N:%l - Exception trying to resolve initial references\n")));
				ACE_OS::sleep(10);
				goto resolve_again;
			}
			ACE_DEBUG((LM_ERROR, ACE_TEXT("(%T) %N:%l - %s\n"), ex._info().c_str()));
			throw InitError();
		}

		root_poa_ = PortableServer::POA::_narrow(obj.in());
		if (CORBA::is_nil(root_poa_.in())) {
			ACE_ERROR((LM_ERROR,
				   "(%T) %N:%l - could not get root POA\n"));
			throw InitError();
		}

		pmf_ = root_poa_->the_POAManagerFactory();
		if (CORBA::is_nil(pmf_.in())) {
			ACE_ERROR((LM_ERROR,
				   "(%T) %N:%l - could not get PMF\n"));
			throw InitError();
		}

		obj = orb_->resolve_initial_references("IORTable");
		iorTable_ = IORTable::Table::_narrow(obj.in());
		if (CORBA::is_nil(iorTable_.in())) {
			ACE_ERROR((LM_ERROR,
				   "(%T) %N:%l - could not get IORTable\n"));
			throw InitError();
		}

		CORBA::PolicyList policies;
		EndpointPolicy::EndpointList list;
		CORBA::Any policy_value;

		// Create external POA manager
		Config::Endpoints ex_points = config.get_endpoints(true);
		policies.length(1);
		list.length(ex_points.size());
		if (Lorica_debug_level > 2) {
			ACE_DEBUG((LM_DEBUG,
				   ACE_TEXT("(%T) %N:%l - setting up External POA manager with %d endpoints\n"),
				   ex_points.size()));
		}
		for (size_t count = 0; count < ex_points.size(); count++) {
			std::string inter = ex_points[count].hostname_;
			if (!ex_points[count].alias_.empty())
				inter = ex_points[count].alias_;

			list[count] = new IIOPEndpointValue_i(inter.c_str(),
							      ex_points[count].port_);
		}
		policy_value <<= list;
		policies[0] = orb_->create_policy(EndpointPolicy::ENDPOINT_POLICY_TYPE,
						  policy_value);
		outside_pm_ = pmf_->create_POAManager("OutsidePOAManager",
						      policies);

		// Create internal POA manager.
		Config::Endpoints in_points = config.get_endpoints(false);
		policies.length(1);
		list.length(in_points.size());
		if (Lorica_debug_level > 2) {
			ACE_DEBUG((LM_DEBUG,
				   ACE_TEXT("(%T) %N:%l - setting up Internal POA manager with %d endpoints\n"),
				   in_points.size()));
		}
		for (size_t count = 0; count < in_points.size(); count++) {
			std::string inter = in_points[count].hostname_;
			if (!in_points[count].alias_.empty())
				inter = in_points[count].alias_;

			list[count] = new IIOPEndpointValue_i(inter.c_str(),
							      in_points[count].port_);
		}
		policy_value <<= list;
		policies[0] = orb_->create_policy(EndpointPolicy::ENDPOINT_POLICY_TYPE,
						  policy_value);
		inside_pm_ = pmf_->create_POAManager("InsidePOAManager",
						     policies);

		if (Lorica_debug_level > 2) {
			ACE_DEBUG((LM_DEBUG,
				   ACE_TEXT("(%T) %N:%l - creating admin POA with internal POA manager\n")));
		}
		policies.length(0);
		admin_poa_ = root_poa_->create_POA("adminPOA",
						   inside_pm_.in(),
						   policies);

		try {
			ReferenceMapper_i *refMapper = new ReferenceMapper_i(orb_.in(),
									     iorTable_.in(),
									     config.secure_available());
			PortableServer::ServantBase_var refMapperServant = refMapper;

			PortableServer::ObjectId_var oid = admin_poa_->activate_object(refMapperServant.in());
			obj = admin_poa_->id_to_reference(oid.in());

			// refMapper->allow_insecure_access (obj.in());
		}
		catch (CORBA::Exception & ex) {
			ACE_DEBUG((LM_ERROR, ACE_TEXT("(%T) %N:%l - %s\n"), ex._info().c_str()));
			throw InitError();
		}

		ReferenceMapper_var refMapper_obj = ReferenceMapper::_narrow(obj.in());

		CORBA::String_var ior = 
			orb_->object_to_string(refMapper_obj.in());
		iorTable_->bind(Lorica::ReferenceMapper::IOR_TABLE_KEY,
				ior.in());

		this->ior_file_ = config.get_value("IOR_FILE", def_ior_file);

		FILE *output_file =
			ACE_OS::fopen (ACE_TEXT_CHAR_TO_TCHAR (this->ior_file_.c_str()), ACE_TEXT("w"));
		if (!output_file) {
			ACE_ERROR((LM_ERROR,
				   "(%T) %N:%l - cannot open output file for writing IOR: %s\n",
				   this->ior_file_.c_str()));
			throw InitError();
		}
		ACE_OS::fprintf(output_file, "%s", ior.in());
		ACE_OS::fclose(output_file);

		if (!setup_shutdown_handler()) {
			ACE_ERROR ((LM_ERROR,
				    "(%T) %N:%l - could not set up shutdown handler\n"));
			throw InitError();
		}

		// Initialize the mapper registry
		Lorica_MapperRegistry *mreg = 
			ACE_Dynamic_Service<Lorica_MapperRegistry>::instance
			(this->orb_->orb_core()->configuration(),"MapperRegistry");

		std::string ne_ids = config.null_eval_type_ids();
		if (!ne_ids.empty()) {
			if (Lorica_debug_level > 2) {
				ACE_DEBUG((LM_DEBUG,
					   ACE_TEXT("(%T) %N:%l - adding type ids for null ")
					   ACE_TEXT("evaluator: %s\n"),
					   ne_ids.c_str()));
			}

			size_t space = ne_ids.find(' ');
			size_t start = 0;
			while (space != std::string::npos) {
				mreg->add_null_mapper_type(ne_ids.substr(start,space - start));
				start = space+1;
				space = ne_ids.find(' ',start);
			}
			mreg->add_null_mapper_type(ne_ids.substr(start));
		} else if (config.null_eval_any()) {
			if (Lorica_debug_level > 2)
				ACE_DEBUG((LM_DEBUG,
					   ACE_TEXT("(%T) %N:%l - creating default null mapper\n")));
			mreg->create_default_null_mapper();
		}
		if (config.generic_evaluator()) {
			if (Lorica_debug_level > 0) {
				ACE_DEBUG((LM_DEBUG,
					   ACE_TEXT("(%T) %N:%l - loading generic evaluator\n")));
			}
#ifdef ACE_WIN32
			this->orb_->orb_core()->configuration()->process_directive
				(ACE_TEXT_ALWAYS_CHAR
				 (ACE_DYNAMIC_SERVICE_DIRECTIVE("Lorica_GenericLoader",
								"lorica_GenericEvaluator",
								"_make_Lorica_GenericLoader",
								"")
					 )
					);
#else
			Lorica::GenericMapper *gen_eval =
				new Lorica::GenericMapper(debug_, *mreg);
			mreg->add_proxy_mapper(gen_eval);
#endif
		}

		// add generic or other mappers...
		mreg->init_mappers(this->outside_pm_,
				   this->inside_pm_,
				   this->orb_,
				   config.secure_available());



		// last thing to do, put both POAs in the active state.
		outside_pm_->activate();
		inside_pm_->activate();

	}
	catch (CORBA::Exception & ex) {
		ACE_DEBUG((LM_ERROR, ACE_TEXT("(%T) %N:%l - %s\n"), ex._info().c_str()));
		throw InitError();
	}
	catch (...) {
		ACE_ERROR((LM_ERROR, "%N:%l - Caught an otherwise unknown exception\n"));
		throw InitError();
	}
}
Пример #4
0
void
TAO::PG_Object_Group::create_members (size_t count)
{
  // assume internals is locked
  // @@ what if factories were passed as criteria?

  CORBA::String_var factory_type;
  PortableGroup::FactoryInfos_var factories =
  this->factory_registry_->list_factories_by_role (
        role_.c_str(),
        factory_type.out ());

  CORBA::ULong factory_count = factories->length ();
  if (factory_count > 0)
    {
      CORBA::ULong factory_pos = 0;
      while (members_.current_size () < count && factory_pos < factory_count)
        {
          const PortableGroup::FactoryInfo & factory_info =
            (*factories)[factory_pos];
          const PortableGroup::Location & factory_location =
            factory_info.the_location;
          if (0 != this->members_.find (factory_location))
            {
              ///////////////////////////////////////////
              // If a factory refuses to create a replica
              // it's not fatal.
              try
                {
                  PortableGroup::GenericFactory::FactoryCreationId_var fcid;
                  CORBA::Object_var member =
                    factory_info.the_factory->create_object (
                      this->type_id_.in (),
                      factory_info.the_criteria,
                      fcid. out());

                  // convert the new member to a stringified IOR to avoid
                  // contamination with group info
                  CORBA::String_var member_ior_string =
                    orb_->object_to_string (member.in ());

                  PortableGroup::ObjectGroup_var new_reference =
                    this->add_member_to_iogr (member.in ());

                  // Convert new member back to a (non group) ior.
                  CORBA::Object_var member_ior =
                    this->orb_->string_to_object (member_ior_string.in ());

                  MemberInfo * info = 0;
                  ACE_NEW_THROW_EX (info, MemberInfo(
                                                     member_ior.in(),
                                                     factory_location,
                                                     factory_info.the_factory,
                                                     fcid.in ()),
                                    CORBA::NO_MEMORY());

                  if (this->members_.bind (factory_location, info) != 0)
                    {
                      throw CORBA::NO_MEMORY();
                    }
                  this->reference_ =
                    new_reference; // note var-to-var assignment does
                                   // a duplicate
                }
              catch (const CORBA::Exception&)
                {
                  // log, but otherwise ignore the errorf
                  if (TAO_debug_level > 0)
                    {
                      ORBSVCS_ERROR ((LM_ERROR,
                                  ACE_TEXT ("PG (%P|%t) Replica Factory ")
                                  ACE_TEXT ("@ %s refused create_object ")
                                  ACE_TEXT ("request for type %s\n"),
                                  static_cast<const char *> (factory_info.the_location[0].id),
                                  static_cast<const char *> (this->type_id_.in ())
                                  ));
                    }
                }
            }
        }

      if (this->increment_version ())
        {
          this->distribute_iogr ();
        }
    }
  else
    {
      throw PortableGroup::NoFactory();
    }
}
Пример #5
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{

    try
    {
        CORBA::ORB_var orb =
            CORBA::ORB_init (argc, argv);

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

        CORBA::Object_var poa_object =
            orb->resolve_initial_references ("RootPOA");

        if (CORBA::is_nil (poa_object.in ()))
            ACE_ERROR_RETURN ((LM_ERROR,
                               " (%P|%t) Unable to initialize the POA.\n"),
                              1);

        PortableServer::POA_var root_poa =
            PortableServer::POA::_narrow (poa_object.in ());

        PortableServer::POAManager_var poa_manager =
            root_poa->the_POAManager ();

        // Policies for the childPOA to be created.
        CORBA::PolicyList policies (1);
        policies.length (1);

        CORBA::Any pol;
        pol <<= BiDirPolicy::BOTH;
        policies[0] =
            orb->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE,
                                pol);

        // Create POA as child of RootPOA with the above policies.  This POA
        // will receive request in the same connection in which it sent
        // the request
        PortableServer::POA_var child_poa =
            root_poa->create_POA ("childPOA",
                                  poa_manager.in (),
                                  policies);

        // Creation of childPOA is over. Destroy the Policy objects.
        for (CORBA::ULong i = 0;
                i < policies.length ();
                ++i)
        {
            policies[i]->destroy ();
        }

        poa_manager->activate ();

        CORBA::Object_var object =
            orb->string_to_object (ior);

        Sender_var sender =
            Sender::_narrow (object.in ());

        if (CORBA::is_nil (sender.in ()))
        {
            ACE_ERROR_RETURN ((LM_ERROR,
                               "Object reference <%s> is nil.\n",
                               ior),
                              1);
        }


        Receiver_i *receiver;
        ACE_NEW_RETURN (receiver,
                        Receiver_i (),
                        -1);

        PortableServer::ServantBase_var owner_transfer (receiver);

        PortableServer::ObjectId_var id =
            root_poa->activate_object (receiver);

        CORBA::Object_var object_act = root_poa->id_to_reference (id.in ());

        Receiver_var receiver_obj =
            Receiver::_narrow (object_act.in ());

        // Send the calback object to the server
        sender->receiver_object (receiver_obj.in ());

        // Threads that will handle the call backs
        Client_Task client_task (orb.in (),
                                 ACE_Thread_Manager::instance ());

        if (client_task.activate (THR_NEW_LWP | THR_JOINABLE, 4, 1) == -1)
        {
            ACE_ERROR ((LM_ERROR, "Error activating client task\n"));
        }

        ACE_Thread_Manager::instance ()->wait ();

        CORBA::Long count =
            receiver->get_event_count ();

        ACE_DEBUG ((LM_DEBUG,
                    "(%P|%t) Number of events received.. [%d]\n",
                    count));

        root_poa->destroy (1,
                           1);
    }
    catch (const CORBA::Exception& ex)
    {
        ex._tao_print_exception ("Caught exception:");
        return 1;
    }

    return 0;
}
Пример #6
0
CORBA::ExtValueDef::ExtFullValueDescription *
TAO_ExtValueDef_i::describe_ext_value_i (
  )
{
  CORBA::ExtValueDef::ExtFullValueDescription *fv_desc = 0;
  ACE_NEW_RETURN (fv_desc,
                  CORBA::ExtValueDef::ExtFullValueDescription,
                  0);
  CORBA::ExtValueDef::ExtFullValueDescription_var retval = fv_desc;

  ACE_TString holder;
  this->repo_->config ()->get_string_value (this->section_key_,
                                            "name",
                                            holder);
  fv_desc->name = holder.fast_rep ();
  this->repo_->config ()->get_string_value  (this->section_key_,
                                             "id",
                                             holder);
  fv_desc->id = holder.fast_rep ();

  CORBA::ULong val = 0;

  this->repo_->config ()->get_integer_value (this->section_key_,
                                             "is_abstract",
                                             val);
  fv_desc->is_abstract = static_cast<CORBA::Boolean> (val);
  this->repo_->config ()->get_integer_value (this->section_key_,
                                             "is_custom",
                                             val);
  fv_desc->is_custom = static_cast<CORBA::Boolean> (val);
  this->repo_->config ()->get_string_value (this->section_key_,
                                            "container_id",
                                            holder);
  fv_desc->defined_in = holder.fast_rep ();
  this->repo_->config ()->get_string_value (this->section_key_,
                                            "version",
                                            holder);
  fv_desc->version = holder.fast_rep ();

  // Operations.

  fv_desc->operations.length (0);

  ACE_Configuration_Section_Key ops_key;
  int status =
    this->repo_->config ()->open_section (this->section_key_,
                                          "ops",
                                          0,
                                          ops_key);
  CORBA::ULong count = 0;
  CORBA::ULong param_count = 0;
  char *stringified = 0;
  CORBA::ULong i = 0;
  CORBA::ULong j = 0;
  TAO_IDLType_i *idl_type = 0;
  CORBA::Object_var obj;
  ACE_Configuration_Section_Key params_key, excepts_key, except_def_key;

  if (status == 0)
    {
      this->repo_->config ()->get_integer_value (ops_key,
                                                 "count",
                                                 count);
      fv_desc->operations.length (count);
      ACE_Configuration_Section_Key op_key, result_key, contexts_key;

      for (i = 0; i < count; ++i)
        {
          stringified = TAO_IFR_Service_Utils::int_to_string (i);
          this->repo_->config ()->open_section (ops_key,
                                                stringified,
                                                0,
                                                op_key);
          this->repo_->config ()->get_string_value (op_key,
                                                    "name",
                                                    holder);
          fv_desc->operations[i].name = holder.fast_rep ();
          this->repo_->config ()->get_string_value (op_key,
                                                    "id",
                                                    holder);
          fv_desc->operations[i].id = holder.fast_rep ();
          this->repo_->config ()->get_string_value (this->section_key_,
                                                    "id",
                                                    holder);
          fv_desc->operations[i].defined_in = holder.fast_rep ();
          this->repo_->config ()->get_string_value (op_key,
                                                    "result",
                                                    holder);
          idl_type =
            TAO_IFR_Service_Utils::path_to_idltype (holder,
                                                    this->repo_);
          fv_desc->operations[i].result =
            idl_type->type_i ();

          this->repo_->config ()->get_integer_value (op_key,
                                                     "mode",
                                                     val);
          fv_desc->operations[i].mode = static_cast<CORBA::OperationMode> (val);
          CORBA::TCKind kind =
            fv_desc->operations[i].result->kind ();

          if (fv_desc->operations[i].mode == CORBA::OP_ONEWAY
              && kind != CORBA::tk_void)
            {
              throw CORBA::BAD_PARAM (
                CORBA::OMGVMCID | 31,
                CORBA::COMPLETED_NO);
            }

          // Operation contexts.

          TAO_IFR_Strseq_Utils<CORBA::ContextIdSeq>::fill_string_seq (
              "contexts",
              this->repo_->config (),
              op_key,
              fv_desc->operations[i].contexts
            );

          // Operation parameters.

          fv_desc->operations[i].parameters.length (0);
          status =
            this->repo_->config ()->open_section (op_key,
                                                  "params",
                                                  0,
                                                  params_key);
          if (status == 0)
            {
              ACE_Configuration_Section_Key param_key;
              this->repo_->config ()->get_integer_value (params_key,
                                                        "count",
                                                        param_count);
              fv_desc->operations[i].parameters.length (param_count);

              for (j = 0; j < param_count; ++j)
                {
                  stringified = TAO_IFR_Service_Utils::int_to_string (j);
                  this->repo_->config ()->open_section (params_key,
                                                        stringified,
                                                        0,
                                                        param_key);
                  this->repo_->config ()->get_string_value (param_key,
                                                            "name",
                                                            holder);
                  fv_desc->operations[i].parameters[j].name =
                    holder.fast_rep ();
                  this->repo_->config ()->get_string_value (param_key,
                                                            "type_path",
                                                            holder);
                  idl_type =
                    TAO_IFR_Service_Utils::path_to_idltype (holder,
                                                            this->repo_);
                  fv_desc->operations[i].parameters[j].type =
                    idl_type->type_i ();

                  obj =
                    TAO_IFR_Service_Utils::path_to_ir_object (
                                               holder,
                                               this->repo_
                                             );

                  fv_desc->operations[i].parameters[j].type_def =
                    CORBA::IDLType::_narrow (obj.in ());

                  this->repo_->config ()->get_integer_value (param_key,
                                                             "mode",
                                                             val);
                  fv_desc->operations[i].parameters[j].mode =
                    static_cast<CORBA::ParameterMode> (val);
                }
            }

          // Operation exceptions.

          status =
            this->repo_->config ()->open_section (op_key,
                                                  "excepts",
                                                  0,
                                                  excepts_key);
          fv_desc->operations[i].exceptions.length (0);

          if (status == 0)
            {
              CORBA::ULong excep_count = 0;
              this->repo_->config ()->get_integer_value (excepts_key,
                                                         "count",
                                                         excep_count);
              fv_desc->operations[i].exceptions.length (excep_count);
              ACE_Configuration_Section_Key except_def_key;

              for (j = 0; j < excep_count; ++j)
                {
                  stringified = TAO_IFR_Service_Utils::int_to_string (j);
                  this->repo_->config ()->get_string_value (excepts_key,
                                                            stringified,
                                                            holder);

                  this->repo_->config ()->expand_path (
                                              this->repo_->root_key (),
                                              holder,
                                              except_def_key,
                                              0
                                            );
                  this->repo_->config ()->get_string_value (except_def_key,
                                                            "name",
                                                            holder);
                  fv_desc->operations[i].exceptions[j].name =
                    holder.fast_rep ();
                  this->repo_->config ()->get_string_value (except_def_key,
                                                            "id",
                                                            holder);
                  fv_desc->operations[i].exceptions[j].id =
                    holder.fast_rep ();
                  this->repo_->config ()->get_string_value (except_def_key,
                                                            "container_id",
                                                            holder);
                  fv_desc->operations[i].exceptions[j].defined_in =
                    holder.fast_rep ();
                  this->repo_->config ()->get_string_value (except_def_key,
                                                            "version",
                                                            holder);
                  fv_desc->operations[i].exceptions[j].version =
                    holder.fast_rep ();

                  TAO_ExceptionDef_i impl (this->repo_);
                  impl.section_key (except_def_key);
                  fv_desc->operations[i].exceptions[j].type =
                    impl.type_i ();
                }
            }
        }
    }

  // Attributes..

  fv_desc->attributes.length (0);

  ACE_Configuration_Section_Key attrs_key;
  status =
    this->repo_->config ()->open_section (this->section_key_,
                                          "attrs",
                                          0,
                                          attrs_key);
  if (status == 0)
    {
      this->repo_->config ()->get_integer_value (attrs_key,
                                                 "count",
                                                 count);
      fv_desc->attributes.length (count);
      ACE_Configuration_Section_Key attr_key, attr_def_key;

      for (i = 0; i < count; ++i)
        {
          stringified = TAO_IFR_Service_Utils::int_to_string (i);
          this->repo_->config ()->open_section (attrs_key,
                                                stringified,
                                                0,
                                                attr_key);
          this->repo_->config ()->get_string_value (attr_key,
                                                    "name",
                                                    holder);
          fv_desc->attributes[i].name = holder.fast_rep ();
          this->repo_->config ()->get_string_value (attr_key,
                                                    "id",
                                                    holder);
          fv_desc->attributes[i].id = holder.fast_rep ();
          this->repo_->config ()->get_string_value (attr_key,
                                                    "version",
                                                    holder);
          fv_desc->attributes[i].version = holder.fast_rep ();
          this->repo_->config ()->get_integer_value (attr_key,
                                                     "mode",
                                                     val);
          fv_desc->attributes[i].mode =
            static_cast<CORBA::AttributeMode> (val);
          this->repo_->config ()->get_string_value (attr_key,
                                                    "type_path",
                                                    holder);

          // Use the type path for 'defined_in' and 'type'.

          idl_type =
            TAO_IFR_Service_Utils::path_to_idltype (holder,
                                                    this->repo_);
          fv_desc->attributes[i].type =
            idl_type->type_i ();

          this->repo_->config ()->expand_path (this->repo_->root_key (),
                                               holder,
                                               attr_def_key,
                                               0);
          this->repo_->config ()->get_string_value (attr_def_key,
                                                    "container_id",
                                                    holder);
          fv_desc->attributes[i].defined_in = holder.fast_rep ();


          this->fill_exceptions (fv_desc->attributes[i].get_exceptions,
                                 attr_key,
                                 "get_excepts");


          this->fill_exceptions (fv_desc->attributes[i].put_exceptions,
                                 attr_key,
                                 "put_excepts");
        }
    }

  // Members..

  fv_desc->members.length (0);

  ACE_Configuration_Section_Key members_key;
  status =
    this->repo_->config ()->open_section (this->section_key_,
                                          "members",
                                          0,
                                          members_key);
  if (status == 0)
    {
      this->repo_->config ()->get_integer_value (members_key,
                                                 "count",
                                                 count);
      fv_desc->members.length (count);
      ACE_Configuration_Section_Key member_key, member_def_key;

      for (i = 0; i < count; ++i)
        {
          stringified = TAO_IFR_Service_Utils::int_to_string (i);
          this->repo_->config ()->open_section (members_key,
                                                stringified,
                                                0,
                                                member_key);
          this->repo_->config ()->get_string_value (member_key,
                                                    "name",
                                                    holder);
          fv_desc->members[i].name = holder.fast_rep ();
          this->repo_->config ()->get_string_value (member_key,
                                                    "id",
                                                    holder);
          fv_desc->members[i].id = holder.fast_rep ();
          this->repo_->config ()->get_string_value (member_key,
                                                    "container_id",
                                                    holder);
          fv_desc->members[i].defined_in = holder.fast_rep ();
          this->repo_->config ()->get_string_value (member_key,
                                                    "version",
                                                    holder);
          fv_desc->members[i].version = holder.fast_rep ();

          this->repo_->config ()->get_integer_value (member_key,
                                                     "access",
                                                     val);
          fv_desc->members[i].access =
            static_cast<CORBA::Visibility> (val);

          // Use type path for 'type' and 'type_def',

          this->repo_->config ()->get_string_value (member_key,
                                                    "type_path",
                                                    holder);
          idl_type =
            TAO_IFR_Service_Utils::path_to_idltype (holder,
                                                    this->repo_);
          fv_desc->members[i].type =
            idl_type->type_i ();

          obj =
            TAO_IFR_Service_Utils::path_to_ir_object (holder,
                                                      this->repo_);

          fv_desc->members[i].type_def =
            CORBA::IDLType::_narrow (obj.in ());
        }
    }

  // Initializers

  fv_desc->initializers.length (0);

  ACE_Configuration_Section_Key initializers_key;
  status =
    this->repo_->config ()->open_section (this->section_key_,
                                          "initializers",
                                          0,
                                          initializers_key);

  if (status == 0)
    {
      this->repo_->config ()->get_integer_value (initializers_key,
                                                 "count",
                                                 count);
      fv_desc->initializers.length (count);
      ACE_Configuration_Section_Key initializer_key,
                                    params_key,
                                    arg_key,
                                    excepts_key;

      for (i = 0; i < count; ++i)
        {
          stringified = TAO_IFR_Service_Utils::int_to_string (i);
          this->repo_->config ()->open_section (initializers_key,
                                                stringified,
                                                0,
                                                initializer_key);
          this->repo_->config ()->get_string_value (initializer_key,
                                                    "name",
                                                    holder);
          fv_desc->initializers[i].name = holder.fast_rep ();

          fv_desc->initializers[i].members.length (0);

          status =
            this->repo_->config ()->open_section (initializer_key,
                                                  "params",
                                                  0,
                                                  params_key);

          if (status == 0)
            {
              this->repo_->config ()->get_integer_value (params_key,
                                                         "count",
                                                         param_count);
              fv_desc->initializers[i].members.length (param_count);

              for (j = 0; j < param_count; ++j)
                {
                  stringified = TAO_IFR_Service_Utils::int_to_string (j);
                  this->repo_->config ()->open_section (params_key,
                                                        stringified,
                                                        0,
                                                        arg_key);
                  this->repo_->config ()->get_string_value (arg_key,
                                                            "arg_name",
                                                            holder);
                  fv_desc->initializers[i].members[j].name =
                    holder.fast_rep ();
                  this->repo_->config ()->get_string_value (arg_key,
                                                            "arg_path",
                                                            holder);
                  TAO_IDLType_i *impl =
                    TAO_IFR_Service_Utils::path_to_idltype (holder,
                                                             this->repo_);
                  fv_desc->initializers[i].members[j].type =
                    impl->type_i ();

                  obj =
                    TAO_IFR_Service_Utils::path_to_ir_object (
                                               holder,
                                               this->repo_
                                             );

                  fv_desc->initializers[i].members[j].type_def =
                    CORBA::IDLType::_narrow (obj.in ());
                }
            }

          this->fill_exceptions (fv_desc->initializers[i].exceptions,
                                 initializer_key,
                                 "excepts");
        }
    }

  TAO_IFR_Strseq_Utils<CORBA::RepositoryIdSeq>::fill_string_seq (
      "supported",
      this->repo_->config (),
      this->section_key_,
      fv_desc->supported_interfaces
    );

  TAO_IFR_Strseq_Utils<CORBA::RepositoryIdSeq>::fill_string_seq (
      "abstract_bases",
      this->repo_->config (),
      this->section_key_,
      fv_desc->abstract_base_values
    );

  this->repo_->config ()->get_integer_value (this->section_key_,
                                             "is_truncatable",
                                             val);
  fv_desc->is_truncatable = static_cast<CORBA::Boolean> (val);
  status =
    this->repo_->config ()->get_string_value (this->section_key_,
                                              "base_value",
                                              holder);

  if (status == 0)
    {
      ACE_Configuration_Section_Key base_key;
      this->repo_->config ()->expand_path (this->repo_->root_key (),
                                           holder,
                                           base_key,
                                           0);
      this->repo_->config ()->get_string_value (base_key,
                                                "id",
                                                holder);
    }

  // If status isn't 0, then holder will be empty anyway.
  fv_desc->base_value = holder.fast_rep ();
  fv_desc->type = this->type_i ();

  return retval._retn ();
}
Пример #7
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{

  try
    {
      // Initialize the ORB.
      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);

      // Obtain the RootPOA.
      CORBA::Object_var object =
        orb->resolve_initial_references ("RootPOA");

      // Narrow to POA.
      PortableServer::POA_var root_poa =
        PortableServer::POA::_narrow (object.in ());

      // Get the POAManager of the RootPOA.
      PortableServer::POAManager_var poa_manager =
        root_poa->the_POAManager ();

      // Policies for the new POA.
      CORBA::PolicyList policies (3);
      policies.length (3);

      // Request Processing Policy.
      policies[0] =
        root_poa->create_request_processing_policy (PortableServer::USE_DEFAULT_SERVANT);

      // Id Uniqueness Policy.
      policies[1] =
        root_poa->create_id_uniqueness_policy (PortableServer::MULTIPLE_ID);

      // Servant Retention Policy.
      policies[2] =
        root_poa->create_servant_retention_policy (PortableServer::NON_RETAIN);

      // Create POA to host default servant.
      ACE_CString name = "Default Servant";
      PortableServer::POA_var default_servant_poa =
        root_poa->create_POA (name.c_str (),
                              poa_manager.in (),
                              policies);

      // Destroy policies.
      for (CORBA::ULong i = 0;
           i < policies.length ();
           ++i)
        {
          CORBA::Policy_ptr policy = policies[i];
          policy->destroy ();
        }

      // Activate POA manager.
      poa_manager->activate ();

      test_reference_to_servant_active_object(root_poa.in ());

      // Test servant.
      test_i test;
      CORBA::ULong expected_refcount = 1;

      (void) test_get_servant_with_no_set (default_servant_poa.in());

      (void) test_get_servant_manager (default_servant_poa.in());

      (void) test_set_servant_manager (default_servant_poa.in());

      // Register default servant.
      default_servant_poa->set_servant (&test);
      expected_refcount++;

      // Create dummy id.
      PortableServer::ObjectId_var id =
        PortableServer::string_to_ObjectId ("id");

      // Create dummy object.
      object =
        default_servant_poa->create_reference ("IDL:test:1.0");

      // Invoke id_to_servant(). Should retrieve default servant.
      PortableServer::ServantBase_var servant =
        default_servant_poa->id_to_servant (id.in ());
      expected_refcount++;

      // Assert correctness.
      ACE_ASSERT (&test == servant.in());

      // Invoke reference_to_servant(). Should retrieve default servant.
      servant =
        default_servant_poa->reference_to_servant (object.in ());
      expected_refcount++;

      // Assert correctness.
      ACE_ASSERT (&test == servant.in());

      // Report success.
      ACE_DEBUG ((LM_DEBUG,
                  "Default_Servant test successful\n"));

      CORBA::ULong refcount =
        test._refcount_value ();

      ACE_UNUSED_ARG (refcount);
      ACE_UNUSED_ARG (expected_refcount);
      ACE_ASSERT (expected_refcount == refcount);

      // Destroy the ORB.
      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught");
      return -1;
    }

  return 0;
}
Пример #8
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv);

      CORBA::Object_var poa_object =
        orb->resolve_initial_references ("RootPOA");

      if (CORBA::is_nil (poa_object.in ()))
        ACE_ERROR_RETURN ((LM_ERROR,
                           " (%P|%t) Unable to initialize the POA.\n"),
                          1);

      PortableServer::POA_var root_poa =
        PortableServer::POA::_narrow (poa_object.in ());

      PortableServer::POAManager_var poa_manager =
        root_poa->the_POAManager ();

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

      Timeout_i timeout_i (orb.in ());

      PortableServer::ObjectId_var id =
        root_poa->activate_object (&timeout_i);

      CORBA::Object_var object = root_poa->id_to_reference (id.in ());

      TimeoutObj_var timeout_var =
        TimeoutObj::_narrow (object.in ());

      CORBA::String_var ior =
        orb->object_to_string (timeout_var.in ());

      ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ()));

      // If the ior_output_file exists, output the ior to it
      if (ior_output_file != 0)
        {
          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",
                               ior_output_file),
                              1);
          ACE_OS::fprintf (output_file, "%s", ior.in ());
          ACE_OS::fclose (output_file);
        }

      poa_manager->activate ();

      // Instantiate reply handler
      TimeoutHandler_i timeoutHandler_i;

      PortableServer::ObjectId_var idu =
        root_poa->activate_object (&timeoutHandler_i);

      CORBA::Object_var objectu = root_poa->id_to_reference (idu.in ());

      AMI_TimeoutObjHandler_var timeoutHandler_var =
        AMI_TimeoutObjHandler::_narrow (objectu.in ());

      // Instantiate client
      /*
      TimeoutClient* client = new TimeoutClient (orb,
                                                 timeout_var.in (),
                                                 timeoutHandler_var.in (),
                                                 &timeoutHandler_i);

      client->activate ();
      */

      orb->run ();


      ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));

      root_poa->destroy (1,  // ethernalize objects
                         0  // wait for completion
                        );

      orb->destroy ();

      //delete client;
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Caught exception:");
      return 1;
    }

  return 0;
}
Пример #9
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv);

      CORBA::Object_var poa_object =
        orb->resolve_initial_references("RootPOA");

      if (CORBA::is_nil (poa_object.in ()))
        ACE_ERROR_RETURN ((LM_ERROR,
                           " (%P|%t) Unable to initialize the POA.\n"),
                          1);

      PortableServer::POA_var root_poa =
        PortableServer::POA::_narrow (poa_object.in ());

      PortableServer::POAManager_var poa_manager =
        root_poa->the_POAManager ();

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

      // create, activate and initialize AMI reply handler
      Test_Reply_i test_i_rh_srv(orb.in (),
                                 max_count,
                                 mode_flag);
      PortableServer::ObjectId_var id =
        root_poa->activate_object (&test_i_rh_srv);

      CORBA::Object_var object = root_poa->id_to_reference (id.in ());

      A::AMI_TestHandler_var rh =
        A::AMI_TestHandler::_narrow (object.in ());

      test_i_rh_srv.test_handler ().set_reply_handler (rh.in ());

      // create and activate test servant
      Test_i test_i_srv (orb.in (), rh.in (), max_count, mode_flag);

      id = root_poa->activate_object (&test_i_srv);

      object = root_poa->id_to_reference (id.in ());

      A::Test_var test_var =
        A::Test::_narrow (object.in ());

      CORBA::String_var ior =
        orb->object_to_string (test_var.in ());

      ACE_DEBUG ((LM_DEBUG, "Servant activated\n"));

      // If the ior_output_file exists, output the ior to it
      if (ior_output_file != 0)
        {
          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",
                               ior_output_file),
                              1);
          ACE_OS::fprintf (output_file, "%s", ior.in ());
          ACE_OS::fclose (output_file);
        }

      poa_manager->activate ();

      A::Test_var opponent;
      do {
        if (mode_flag == A::RM_SLAVE)
          ACE_OS::sleep (ACE_Time_Value (0, 100));

        // get object reference for opponent
        object = orb->string_to_object (input_ior);
        opponent =  A::Test::_narrow (object.in ());
      } while (mode_flag == A::RM_SLAVE && CORBA::is_nil (opponent.in ()));

      if (CORBA::is_nil (opponent.in ()))
      {
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Cannot resolve opponent IOR: %s",
                           input_ior),
                           1);
      }

      // register opponent
      test_i_srv.set_opponent (opponent.in ());
      test_i_rh_srv.test_handler ().set_opponent (opponent.in ());

      // start the show
      if (mode_flag == A::RM_MASTER)
        test_i_rh_srv.test_handler ().start ();

      orb->run ();

      root_poa->destroy (1,  // ethernalize objects
                         0  // wait for completion
                        );

      orb->destroy ();

      ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Caught exception:");
      return 1;
    }

  return 0;
}
Пример #10
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  int priority =
    (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO)
     + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO)) / 2;
  priority = ACE_Sched_Params::next_priority (ACE_SCHED_FIFO,
                                                  priority);
  // Enable FIFO scheduling, e.g., RT scheduling class on Solaris.

  if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO,
                                              priority,
                                              ACE_SCOPE_PROCESS)) != 0)
    {
      if (ACE_OS::last_error () == EPERM)
        {
          ACE_DEBUG ((LM_DEBUG,
                      "server (%P|%t): user is not superuser, "
                      "test runs in time-shared class\n"));
        }
      else
        ACE_ERROR ((LM_ERROR,
                    "server (%P|%t): sched_params failed\n"));
    }

  try
    {
      ORBInitializer *initializer = 0;
      ACE_NEW_RETURN (initializer,
                      ORBInitializer,
                      -1);  // No exceptions yet!
      PortableInterceptor::ORBInitializer_var orb_initializer =
        initializer;

      PortableInterceptor::register_orb_initializer (orb_initializer.in ());

      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv);


      CORBA::Object_var poa_object =
        orb->resolve_initial_references ("RootPOA");

      if (CORBA::is_nil (poa_object.in ()))
        ACE_ERROR_RETURN ((LM_ERROR,
                           " (%P|%t) Unable to initialize the POA.\n"),
                          1);

      PortableServer::POA_var root_poa =
        PortableServer::POA::_narrow (poa_object.in ());

      PortableServer::POAManager_var poa_manager =
        root_poa->the_POAManager ();

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

      poa_manager->activate ();

      CORBA::Object_var lm_object =
        orb->resolve_initial_references ("LoadManager");

      CosLoadBalancing::LoadManager_var load_manager =
        CosLoadBalancing::LoadManager::_narrow (lm_object.in ());

      RPS_Monitor * monitor_servant;
      ACE_NEW_THROW_EX (monitor_servant,
                        RPS_Monitor (initializer->interceptor ()),
                        CORBA::NO_MEMORY ());

      PortableServer::ServantBase_var safe_monitor_servant (monitor_servant);

      CosLoadBalancing::LoadMonitor_var load_monitor =
        monitor_servant->_this ();

      PortableGroup::Location_var location =
        load_monitor->the_location ();

      CORBA::Object_var roundtrip =
        ::join_object_group (orb.in (),
                             load_manager.in (),
                             location.in ());

      TAO_LB_LoadAlert & alert_servant = initializer->load_alert ();

      CosLoadBalancing::LoadAlert_var load_alert =
        alert_servant._this ();


      CORBA::String_var ior =
        orb->object_to_string (roundtrip.in ());

      // If the ior_output_file exists, output the ior to it
      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",
                           ior_output_file),
                          1);
      ACE_OS::fprintf (output_file, "%s", ior.in ());
      ACE_OS::fclose (output_file);

      load_manager->register_load_monitor (location.in (),
                                           load_monitor.in ());

      load_manager->register_load_alert (location.in (),
                                         load_alert.in ());

      orb->run ();

      ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));

      root_poa->destroy (1, 1);

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught:");
      return 1;
    }

  return 0;
}
Пример #11
0
CORBA::Object_ptr
join_object_group (CORBA::ORB_ptr orb,
                   CosLoadBalancing::LoadManager_ptr lm,
                   const PortableGroup::Location & location)
{
  CORBA::Object_var ns_object =
    orb->resolve_initial_references ("NameService");

  CosNaming::NamingContext_var nc =
    CosNaming::NamingContext::_narrow (ns_object.in ());

  CosNaming::Name name (1);
  name.length (1);

  name[0].id = "RoundtripObjectGroup";
  name[0].kind = "Object Group";

  CORBA::Object_var group;

  try
    {
      group = nc->resolve (name);
    }
  catch (const CosNaming::NamingContext::NotFound& )
    {
      // Object group not created.  Create one.
      const char repository_id[] = "IDL:Test/Roundtrip:1.0";

      PortableGroup::Criteria criteria (1);
      criteria.length (1);

      PortableGroup::Property & property = criteria[0];
      property.nam.length (1);

      property.nam[0].id =
        CORBA::string_dup ("org.omg.PortableGroup.MembershipStyle");

      PortableGroup::MembershipStyleValue msv =
        PortableGroup::MEMB_APP_CTRL;
      property.val <<= msv;

      PortableGroup::GenericFactory::FactoryCreationId_var fcid;

      group = lm->create_object (repository_id,
                                 criteria,
                                 fcid.out ());

      try
        {
          nc->bind (name,
                    group.in ());

          PortableGroup::Properties props (1);
          props.length (1);
          props[0].nam.length (1);
          props[0].nam[0].id =
            CORBA::string_dup ("org.omg.CosLoadBalancing.StrategyInfo");

          CosLoadBalancing::StrategyInfo strategy_info;

          strategy_info.name = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(strategy));

          if (ACE_OS::strcasecmp (strategy, ACE_TEXT("LeastLoaded")) == 0
              && (!ACE::is_equal (reject_threshold, (CORBA::Float)0.0)
                  || !ACE::is_equal (critical_threshold, (CORBA::Float)0.0)
                  || !ACE::is_equal (dampening, (CORBA::Float)0.0)))
            {
              CORBA::ULong len = 1;

              PortableGroup::Properties & props =
                strategy_info.props;

              if (!ACE::is_equal (reject_threshold, (CORBA::Float)0.0))
                {
                  const CORBA::ULong i = len - 1;

                  props.length (len++);

                  props[i].nam.length (1);
                  props[i].nam[0].id =
                    CORBA::string_dup ("org.omg.CosLoadBalancing.Strategy.LeastLoaded.RejectThreshold");
                  props[i].val <<= reject_threshold;
                }

              if (!ACE::is_equal (critical_threshold, (CORBA::Float)0.0))
                {
                  const CORBA::ULong i = len - 1;

                  props.length (len++);

                  props[i].nam.length (1);
                  props[i].nam[0].id =
                    CORBA::string_dup ("org.omg.CosLoadBalancing.Strategy.LeastLoaded.CriticalThreshold");
                  props[i].val <<= critical_threshold;
                }

              if (!ACE::is_equal (dampening, (CORBA::Float)0.0))
                {
                  const CORBA::ULong i = len - 1;

                  props.length (len++);

                  props[i].nam.length (1);
                  props[i].nam[0].id =
                    CORBA::string_dup ("org.omg.CosLoadBalancing.Strategy.LeastLoaded.Dampening");
                  props[i].val <<= dampening;
                }

            }

          props[0].val <<= strategy_info;

          lm->set_default_properties (props);
        }
      catch (const CosNaming::NamingContext::AlreadyBound& )
        {
          // Somebody beat us to creating the object group.  Clean up
          // the one we created.
          lm->delete_object (fcid.in ());

          group = nc->resolve (name);
        }
    }

  Roundtrip * roundtrip_impl;
  ACE_NEW_THROW_EX (roundtrip_impl,
                    Roundtrip (orb),
                    CORBA::NO_MEMORY ());

  PortableServer::ServantBase_var owner_transfer (roundtrip_impl);

  Test::Roundtrip_var roundtrip =
    roundtrip_impl->_this ();

  group = lm->add_member (group.in (),
                          location,
                          roundtrip.in ());

  return group._retn ();
}
/** @cond
*/    
int main(int argc, char *argv[]) 
{
    //Checks command-line arguments
    if (argc < 2)
	{
	ACS_SHORT_LOG((LM_INFO, "Usage: %s <component name> <options>", argv[0]));
	return -1;
	}
    else
	{
	ACS_SHORT_LOG((LM_INFO, "Welcome to %s!", argv[0]));
	}
    
    //Creates and initialyses the SimpleClient object
    SimpleClient client;
    if (client.init(argc,argv) == 0)
	{
	ACE_DEBUG((LM_DEBUG,"Cannot init client"));
	return -1;
	}
    else
	{
	//Must log into manager before we can really do anything
	client.login();
	}
    
    try
	{
	//Gets from manager the reference to the requested component.
	//Pay special attention that this reference is just a generic
	//CORBA object at this point.
	ACS_SHORT_LOG((LM_INFO, "Looking for Object '%s' ", argv[1]));
        CORBA::Object_var obj =  client.getComponent(argv[1], 0 , true);
	
	//Get the stringified IOR of the component.  The IOR of CORBA objects
	//can be considered to be a unique "phone number" used to access CORBA
	//servants.
	ACS_SHORT_LOG((LM_INFO, "Getting stringified IOR"));
	CORBA::String_var mior = client.getORB()->object_to_string(obj.in());    
	
	//Print the IOR to standard out
	u_int result;         
	ACS_SHORT_LOG ((LM_INFO, "IOR for %s is: %s", argv[1], mior.in()));
	result = ACE_OS::printf ("%s", mior.in());
	}
    catch(maciErrType::CannotGetComponentExImpl &_ex)
	{
	_ex.log();
	return -1;
	}
    catch(...)
	{
	ACSErrTypeCommon::UnexpectedExceptionExImpl uex(__FILE__, __LINE__, 
							"main");
	
	uex.log();
	return -1;
	}

    //Normally you would not want to have separate try sections for releasing
    //the components and logging out from manager.  This is a very special case 
    //since we do not know ahead of time what will be released.  In other words,
    //argv[1] could technically be "manager" which would end up raising a 
    //no-permission exception.  To get around this just use separate try/catch 
    //sections and ignore no-permission exceptions.
    try
	{
	//All clients must cleanly release objects they activate!
	client.releaseComponent(argv[1]);
	}
    catch(maciErrType::CannotReleaseComponentExImpl &_ex)
	{
	_ex.log();
	return -1;
	}
    catch(...)
	{
	ACSErrTypeCommon::UnexpectedExceptionExImpl uex(__FILE__, __LINE__, 
							"main");
	uex.log();
	return -1;
	}
    
    try
	{
	if (client.logout() == 0)
	    {
	    ACS_SHORT_LOG ((LM_INFO, "Cannot logout"));
	    return -1;
	    }
	}
    catch(...)
	{
	ACS_SHORT_LOG((LM_ERROR, "Exception caught"));
	return -1;
	}    
    
    ACS_SHORT_LOG((LM_INFO,"The end!"));
    return 0;
}
Пример #13
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv);

      CORBA::Object_var poa_object =
        orb->resolve_initial_references ("RootPOA");

      if (CORBA::is_nil (poa_object.in ()))
        ACE_ERROR_RETURN ((LM_ERROR,
                           ACE_TEXT (" (%P|%t) Unable to initialize the POA.\n")),
                          1);

      PortableServer::POA_var root_poa =
        PortableServer::POA::_narrow (poa_object.in ());

      PortableServer::POAManager_var poa_manager =
        root_poa->the_POAManager ();

      // Policies for the childPOA to be created.
      CORBA::PolicyList policies (1);
      policies.length (1);

      CORBA::Any pol;
      pol <<= BiDirPolicy::BOTH;
      policies[0] =
        orb->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE,
                            pol);

      // Create POA as child of RootPOA with the above policies.  This POA
      // will receive request in the same connection in which it sent
      // the request
      PortableServer::POA_var child_poa =
        root_poa->create_POA ("childPOA",
                              poa_manager.in (),
                              policies);

      // Creation of childPOA is over. Destroy the Policy objects.
      for (CORBA::ULong i = 0;
           i < policies.length ();
           ++i)
        {
          policies[i]->destroy ();
        }

      poa_manager->activate ();

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

      CORBA::Object_var object =
        orb->string_to_object (ior);

      Simple_Server_var server =
        Simple_Server::_narrow (object.in ());

      if (CORBA::is_nil (server.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Object reference <%s> is nil\n",
                             ior),
                            1);
        }


      Callback_i *callback_impl = 0;
      callback_impl = new Callback_i (orb.in ());
      PortableServer::ServantBase_var safe (callback_impl);

      PortableServer::ObjectId_var id =
        PortableServer::string_to_ObjectId ("client_callback");

      child_poa->activate_object_with_id (id.in (),
                                          callback_impl);

      CORBA::Object_var callback_object =
        child_poa->id_to_reference (id.in ());

      Callback_var callback =
        Callback::_narrow (callback_object.in ());


      CORBA::String_var ior =
        orb->object_to_string (callback.in ());

      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("(%P|%t) Client callback activated as <%C>\n"), ior.in ()));

      // Send the calback object to the server
      server->callback_object (callback.in ());

      // This is a non-portable, but the only currently available way of
      // determining the number of currently open connections.
      size_t pre_call_connections =
        orb->orb_core ()->lane_resources ().transport_cache ().current_size ();

      // A  method to kickstart callbacks from the server
      CORBA::Long r =
        server->test_method (1);

      if (r != 0)
        {
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("(%P|%t) unexpected result = %d "),
                      r));
        }

      orb->run ();

      // This is a non-portable, but the only currently available way of
      // determining the number of currently open connections.
      size_t cur_connections =
        orb->orb_core()->lane_resources().transport_cache().current_size ();

      if (cur_connections > pre_call_connections)
        {
          ACE_ERROR ((LM_ERROR,
                      ACE_TEXT ("(%P|%t) Expected %d ")
                      ACE_TEXT ("connections in the transport cache, but found ")
                      ACE_TEXT ("%d instead.  Aborting.\n"),
                      pre_call_connections,
                      cur_connections));

          ACE_OS::abort ();
        }

      root_poa->destroy (1, 1);

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Caught exception:");
      return 1;
    }

  return 0;
}
Пример #14
0
int
ACE_TMAIN(int argc, ACE_TCHAR *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;

      MyInterfaceImpl *test_impl = 0;
      ACE_NEW_RETURN (test_impl,
                      MyInterfaceImpl (orb.in ()),
                      1);

      PortableServer::ServantBase_var owner_transfer(test_impl);

      PortableServer::ObjectId_var id =
        root_poa->activate_object (test_impl);

      CORBA::Object_var object = root_poa->id_to_reference (id.in ());

      MyInterface_var test_ref =
        MyInterface::_narrow (object.in ());

      CORBA::String_var ior =
        orb->object_to_string (test_ref.in ());

      // Output the IOR to the <ior_output_file>
      FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
      if (output_file != 0)
        {
          ACE_OS::fprintf (output_file, "%s", ior.in ());
          ACE_OS::fclose (output_file);
        }

      poa_manager->activate ();

      CORBA::Object_var table_object =
        orb->resolve_initial_references ("IORTable");

      IORTable::Table_var adapter =
        IORTable::Table::_narrow (table_object.in ());

      if (CORBA::is_nil (adapter.in ()))
        {
          ACE_ERROR ((LM_ERROR, "Nil IORTable\n"));
        }
      else
        {
          adapter->bind ("collocated_ior_bound_in_remote_iortable",
                         ACE_TEXT_ALWAYS_CHAR(client_ior));
        }

      orb->run ();

      ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));

      root_poa->destroy (1, 1);

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught:");
      return 1;
    }

  return 0;
}
Пример #15
0
int
ACE_TMAIN(int argc, ACE_TCHAR *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 ();

      // Make all oneways "reliable."
      {
        CORBA::Object_var manager_object =
          orb->resolve_initial_references("ORBPolicyManager");
        CORBA::PolicyManager_var policy_manager =
          CORBA::PolicyManager::_narrow(manager_object.in());

        if (CORBA::is_nil (policy_manager.in ()))
          ACE_ERROR_RETURN ((LM_ERROR,
                             " (%P|%t) Panic: nil PolicyManager\n"),
                            1);
        CORBA::Any policy_value;
        policy_value <<= Messaging::SYNC_WITH_SERVER;
        CORBA::PolicyList policies(1); policies.length(1);
        policies[0] =
          orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE,
                              policy_value);

        policy_manager->set_policy_overrides (policies,
                                              CORBA::ADD_OVERRIDE);

        policies[0]->destroy ();
      }

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

      Service *service_impl;
      ACE_NEW_RETURN (service_impl,
                      Service(orb.in ()),
                      1);
      PortableServer::ServantBase_var owner_transfer(service_impl);

      PortableServer::ObjectId_var id =
        root_poa->activate_object (service_impl);

      CORBA::Object_var object = root_poa->id_to_reference (id.in ());

      Test::Service_var service =
        Test::Service::_narrow (object.in ());

      CORBA::String_var ior =
        orb->object_to_string (service.in ());

      // If the ior_output_file exists, output the ior to it
      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",
                           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, "Event loop finished\n"));

      service_impl->dump_results ();

      root_poa->destroy (1, 1);

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught:");
      return 1;
    }

  return 0;
}
Пример #16
0
Messenger_i::Messenger_i (CORBA::ORB_ptr orb)
  : orb_ (CORBA::ORB::_duplicate (orb))
{

  CORBA::Object_var naming_obj =
    orb_->resolve_initial_references ("NameService");

  CosNaming::NamingContext_var naming_context =
    CosNaming::NamingContext::_narrow (naming_obj.in());

  CosNaming::Name name;
  name.length (1);
  name[0].id = CORBA::string_dup ("NotifyEventChannelFactory");

  CORBA::Object_var obj = naming_context->resolve (name);

  CosNotifyChannelAdmin::EventChannelFactory_var notify_factory =
    CosNotifyChannelAdmin::EventChannelFactory::_narrow (obj.in ());

  CosNotifyChannelAdmin::ChannelID id;
  CosNotification::QoSProperties initial_qos;
  CosNotification::AdminProperties initial_admin;

  CosNotifyChannelAdmin::EventChannel_var ec =
    notify_factory->create_channel (initial_qos,
                                    initial_admin,
                                    id);

  name[0].id = CORBA::string_dup ("MyEventChannel");

  naming_context->rebind (name, ec.in());

  CosNotifyChannelAdmin::AdminID adminid;
  CosNotifyChannelAdmin::InterFilterGroupOperator ifgop =
    CosNotifyChannelAdmin::OR_OP;

  CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin =
    ec->new_for_suppliers (ifgop, adminid);

  CosNotifyChannelAdmin::ProxyID supplieradmin_proxy_id;

  CosNotifyChannelAdmin::ProxyConsumer_var proxy_consumer =
    supplier_admin->obtain_notification_push_consumer(
                                 CosNotifyChannelAdmin::STRUCTURED_EVENT,
                                 supplieradmin_proxy_id);

  StructuredEventSupplier_i *servant =
    new StructuredEventSupplier_i(orb_.in());

  CORBA::Object_var poa_obj = orb_->resolve_initial_references ("RootPOA");
  PortableServer::POA_var poa = PortableServer::POA::_narrow (poa_obj.in ());
  PortableServer::POAManager_var mgr = poa->the_POAManager ();

  mgr->activate ();
  PortableServer::ObjectId_var objectId = poa->activate_object (servant);

  CORBA::Object_var supplier_obj = poa->id_to_reference (objectId.in ());

  CosNotifyComm::StructuredPushSupplier_var supplier =
    CosNotifyComm::StructuredPushSupplier::_narrow (supplier_obj.in ());

  consumer_proxy_ =
    CosNotifyChannelAdmin::StructuredProxyPushConsumer::_narrow (proxy_consumer.in());

  consumer_proxy_->
    connect_structured_push_supplier (supplier.in());
}
Пример #17
0
int
ACE_TMAIN (int argc, ACE_TCHAR* argv[])
{
  int status = 0;

#if defined (TAO_HAS_MONITOR_FRAMEWORK) && (TAO_HAS_MONITOR_FRAMEWORK == 1)

  try
    {
      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);

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

      CORBA::Object_var obj =
        orb->string_to_object (monitor_ior);
      CosNotification::NotificationServiceMonitorControl_var nsm =
        CosNotification::NotificationServiceMonitorControl::_narrow (obj.in ());

      if (CORBA::is_nil (nsm.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Monitor: Unable to locate the "
                             "Notification Service Monitor\n"),
                            1);
        }

      MonitorTestInterface_i* mti = 0;
      ACE_NEW_RETURN (mti, MonitorTestInterface_i (nsm.in ()), 1);
      PortableServer::ServantBase_var owner_transfer (mti);

      CORBA::Object_var poa_object =
        orb->resolve_initial_references("RootPOA");
      PortableServer::POA_var root_poa =
        PortableServer::POA::_narrow (poa_object.in ());

      PortableServer::ObjectId_var id = root_poa->activate_object (mti);
      CORBA::Object_var object = root_poa->id_to_reference (id.in ());

      MonitorTestInterface_var test =
        MonitorTestInterface::_narrow (object.in ());
      CORBA::String_var ior = orb->object_to_string (test.in ());

      // Test the case where there are no consumers or suppliers first
      // before we write out our IOR
      mti->running (MonitorTestInterface::NotifyService);

      FILE *output_file= ACE_OS::fopen (ACE_TEXT_ALWAYS_CHAR(ior_output_file), ACE_TEXT ("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);

      PortableServer::POAManager_var poa_manager =
        root_poa->the_POAManager ();
      poa_manager->activate ();

      orb->run ();
      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("test_monitor: ");
      status++;
    }

#else
  ACE_UNUSED_ARG (argc);
  ACE_UNUSED_ARG (argv);
#endif /* TAO_HAS_MONITOR_FRAMEWORK==1 */

  return status;
}
Пример #18
0
int
ACE_TMAIN(int argc, ACE_TCHAR *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 ());

      PortableServer::POAManager_var poa_manager =
        root_poa->the_POAManager ();

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

      server_i servant (orb.in ());

      PortableServer::ObjectId_var id =
        root_poa->activate_object (&servant);

      CORBA::Object_var object = root_poa->id_to_reference (id.in ());

      server_var server_object =
        server::_narrow (object.in ());

      CORBA::String_var ior =
        orb->object_to_string (server_object.in ());

      ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ()));

      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",
                           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, "event loop finished\n"));

      root_poa->destroy (1,
                         1);

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught:");
      return -1;
    }

  return 0;
}
Пример #19
0
CORBA::ExtInitializerSeq *
TAO_ExtValueDef_i::ext_initializers_i (
  )
{
  CORBA::ExtInitializerSeq *iseq = 0;
  ACE_NEW_RETURN (iseq,
                  CORBA::ExtInitializerSeq,
                  0);
  CORBA::ExtInitializerSeq_var retval = iseq;

  ACE_Configuration_Section_Key initializers_key;
  int status =
    this->repo_->config ()->open_section (this->section_key_,
                                          "initializers",
                                          0,
                                          initializers_key);

  if (status != 0)
    {
      iseq->length (0);
      return retval._retn ();
    }

  CORBA::ULong count = 0;
  this->repo_->config ()->get_integer_value (initializers_key,
                                             "count",
                                             count);
  iseq->length (count);
  char *stringified = 0;
  ACE_Configuration_Section_Key initializer_key, params_key, arg_key;
  ACE_TString holder;
  CORBA::ULong arg_count = 0;

  for (CORBA::ULong i = 0; i < count; ++i)
    {
      stringified = TAO_IFR_Service_Utils::int_to_string (i);
      this->repo_->config ()->open_section (initializers_key,
                                            stringified,
                                            0,
                                            initializer_key);
      this->repo_->config ()->get_string_value (initializer_key,
                                                "name",
                                                holder);
      retval[i].name = holder.fast_rep ();
      status =
        this->repo_->config ()->open_section (initializer_key,
                                              "params",
                                              0,
                                              params_key);

      if (status != 0)
        {
          retval[i].members.length (0);
          continue;
        }

      this->repo_->config ()->get_integer_value (params_key,
                                                 "count",
                                                 arg_count);
      retval[i].members.length (arg_count);
      CORBA::Object_var obj;

      for (CORBA::ULong j = 0; j < arg_count; ++j)
        {
          stringified = TAO_IFR_Service_Utils::int_to_string (j);
          this->repo_->config ()->open_section (params_key,
                                                stringified,
                                                0,
                                                arg_key);
          this->repo_->config ()->get_string_value (arg_key,
                                                    "arg_name",
                                                    holder);
          retval[i].members[j].name = holder.fast_rep ();
          this->repo_->config ()->get_string_value (arg_key,
                                                    "arg_path",
                                                    holder);
          TAO_IDLType_i *impl =
            TAO_IFR_Service_Utils::path_to_idltype (holder,
                                                    this->repo_);
          retval[i].members[j].type =
            impl->type_i ();

          obj =
            TAO_IFR_Service_Utils::path_to_ir_object (holder,
                                                      this->repo_);

          retval[i].members[j].type_def =
            CORBA::IDLType::_narrow (obj.in ());
        }

      this->fill_exceptions (retval[i].exceptions,
                             initializer_key,
                             "excepts");
    }

  return retval._retn ();
}
Пример #20
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      Server_ORBInitializer *temp_initializer = 0;
      ACE_NEW_RETURN (temp_initializer,
                      Server_ORBInitializer,
                      -1);  // No exceptions yet!
      PortableInterceptor::ORBInitializer_var orb_initializer =
        temp_initializer;

      PortableInterceptor::register_orb_initializer (orb_initializer.in ());

      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv, "Server ORB");

      CORBA::Object_var poa_object =
        orb->resolve_initial_references ("RootPOA");

      if (CORBA::is_nil (poa_object.in ()))
        ACE_ERROR_RETURN ((LM_ERROR,
                           " (%P|%t) Unable to initialize the POA.\n"),
                          1);

      PortableServer::POA_var root_poa =
        PortableServer::POA::_narrow (poa_object.in ());

      PortableServer::POAManager_var poa_manager =
        root_poa->the_POAManager ();

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

      test_i servant (orb.in ());

      PortableServer::ObjectId_var id =
        root_poa->activate_object (&servant);

      CORBA::Object_var object = root_poa->id_to_reference (id.in ());

      CORBA::Object_var obj = CORBA::Object::_narrow (object.in ());

      CORBA::String_var ior =
        orb->object_to_string (obj.in ());

      ACE_DEBUG ((LM_DEBUG,
                  "Servant:\n<%C>\n",
                  ior.in ()));

      poa_manager->activate ();

      // Write IOR to a file.
      FILE *output_file= ACE_OS::fopen (ior_file, "w");
      if (output_file == 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Cannot open output file <%s> for writing "
                           "IOR: %C",
                           ior_file,
                           ior.in ()),
                          1);
      ACE_OS::fprintf (output_file, "%s", ior.in ());
      ACE_OS::fclose (output_file);

      // Run the ORB event loop.
      orb->run ();

      root_poa->destroy (1, 1);

      orb->destroy ();

      ACE_DEBUG ((LM_DEBUG, "Event loop finished.\n"));
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Caught exception:");
      return -1;
    }

  return 0;
}
Пример #21
0
void
TAO::PG_Object_Group::create_member (
    const PortableGroup::Location & the_location,
    const char * type_id,
    const PortableGroup::Criteria & the_criteria)
{
  ACE_GUARD (TAO_SYNCH_MUTEX, guard, this->internals_);


  if (0 != this->members_.find (the_location))
    {
      // @@ what if factories were passed as criteria?

      CORBA::String_var factory_type;
      PortableGroup::FactoryInfos_var factories =
        this->factory_registry_->list_factories_by_role (
          role_.c_str(),
          factory_type.out ());

      // @@ what if factory_type != type_id != this->type_id_

      int created = 0; // bool
      CORBA::ULong factory_count = factories->length ();
      for (CORBA::ULong factory_pos = 0;
           ! created && factory_pos < factory_count;
           ++factory_pos)
        {
          const PortableGroup::FactoryInfo & factory_info =
            (*factories)[factory_pos];
          if (factory_info.the_location == the_location)
            {
              // @@ should we merge the_criteria with
              // factory_info.the_criteria?

              PortableGroup::GenericFactory::FactoryCreationId_var fcid;
              CORBA::Object_var member =
                factory_info.the_factory->create_object (
                  type_id,
                  the_criteria,
                  fcid. out());

              // convert the new member to a stringified IOR to avoid
              // contamination with group info
              CORBA::String_var member_ior_string =
                orb_->object_to_string (member.in ());

              PortableGroup::ObjectGroup_var new_reference =
                this->add_member_to_iogr (member.in ());

              // Convert new member back to a (non group) ior.
              CORBA::Object_var member_ior =
                this->orb_->string_to_object (member_ior_string.in ());

              MemberInfo * info = 0;
              ACE_NEW_THROW_EX (info, MemberInfo(
                                                 member_ior.in(),
                                                 the_location,
                                                 factory_info.the_factory,
                                                 fcid.in ()),
                                CORBA::NO_MEMORY());

              if (this->members_.bind (the_location, info) != 0)
                {
                  throw CORBA::NO_MEMORY();
                }

              this->reference_ = new_reference; // note var-to-var
                                                // assignment does a
                                                // duplicate
              if (this->increment_version ())
                {
                  this->distribute_iogr ();
                }
              created = 1;
            }
        }
      if (! created)
        {
          throw PortableGroup::NoFactory ();
        }
    }
  else
    {
      throw PortableGroup::MemberAlreadyPresent ();
    }
}
Пример #22
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  int ec = 0;
  try {
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

    int max_run = 0;
    int server_num = 0;
    int init_delay_secs = 0;
    const ACE_TCHAR *ior_file_name = ACE_TEXT ("");
    ACE_Get_Opt get_opts (argc, argv, ACE_TEXT ("d:m:n:o:?"));
    int c;

    while ((c = get_opts ()) != -1)
      switch (c)
        {
        case 'd':
          init_delay_secs = ACE_OS::atoi (get_opts.opt_arg ());
          break;
        case 'm':
          max_run = ACE_OS::atoi (get_opts.opt_arg ());
          break;
        case 'n':
          server_num = ACE_OS::atoi (get_opts.opt_arg ());
          break;
        case 'o':
          ior_file_name = get_opts.opt_arg ();
          break;
        case '?':
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("usage: %s ")
                      ACE_TEXT ("-d <seconds to delay before initializing POA> ")
                      ACE_TEXT ("-n Number of the server\n"),
                      argv[0]));
          return 1;
          break;
        }

    ACE_OS::sleep (init_delay_secs);

    CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
    PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj.in());

    PortableServer::POAManager_var mgr = root_poa->the_POAManager();

    ACE_CString poa_name = ACE_CString("TestObject_") + toStr (server_num);

    PortableServer::POA_var test_poa = createPOA(root_poa.in(), poa_name.c_str ());

    Test_i *impl = new Test_i(orb.in());
    PortableServer::Servant_var<Test_i> test_servant = impl;

    PortableServer::ObjectId_var object_id =
      PortableServer::string_to_ObjectId("test_object");

    //
    // Activate the servant with the test POA,
    // obtain its object reference, and get a
    // stringified IOR.
    //
    test_poa->activate_object_with_id(object_id.in(), test_servant.in());

    //
    // Create binding between "TestService" and
    // the test object reference in the IOR Table.
    // Use a TAO extension to get the non imrified poa
    // to avoid forwarding requests back to the ImR.

    TAO_Root_POA* tpoa = dynamic_cast<TAO_Root_POA*>(test_poa.in());
    obj = tpoa->id_to_reference_i(object_id.in(), false);
    CORBA::String_var test_ior = orb->object_to_string(obj.in());
    obj = orb->resolve_initial_references("IORTable");
    IORTable::Table_var table = IORTable::Table::_narrow(obj.in());
    table->bind(poa_name.c_str (), test_ior.in());

    if (ACE_OS::strlen (ior_file_name) > 0)
      {
        obj = test_poa->id_to_reference (object_id.in ());
        test_ior = orb->object_to_string (obj.in ());
        FILE *f = ACE_OS::fopen (ior_file_name, ACE_TEXT ("w"));
        ACE_OS::fprintf (f, "%s", test_ior.in ());
        ACE_OS::fclose (f);
      }

    //
    // This server is now ready to run.
    // This version does not create an IOR
    // file as demonstrated in the
    // Developer's Guide.  It assumes that
    // users create IORs for the client using
    // the tao_imr utility.
    //
    //
    // Stop discarding requests.
    //
    mgr->activate();

    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("Started Server <%C> pid = %d\n"),
                poa_name.c_str(), ACE_OS::getpid ()));

    ACE_CString pid_file = "server.pid";
    {
      ofstream out(pid_file.c_str (), ios_base::app);
      out << ACE_OS::getpid () << endl;
      out.close ();
    }
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("Server <%C> pid = %d closed pidfile\n"),
                poa_name.c_str(), ACE_OS::getpid ()));

    if (max_run > 0)
      {
        ACE_Time_Value tv (max_run,0);
        orb->run (tv);
      }
    else
      {
        orb->run ();
      }
    ec = impl->exit_code ();
    root_poa->destroy(1,1);
    orb->destroy();

    //    ACE_OS::unlink (pid_file.c_str ());

  }
  catch(const CORBA::Exception& ex) {
    ex._tao_print_exception (ACE_TEXT ("Server main()"));
    return 1;
  }

  return ec;
}
Пример #23
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv);

      CORBA::Object_var poa_object =
        orb->resolve_initial_references("RootPOA");

      if (CORBA::is_nil (poa_object.in ()))
        ACE_ERROR_RETURN ((LM_ERROR,
                           " (%P|%t) Unable to initialize the POA.\n"),
                          1);

      PortableServer::POA_var root_poa =
        PortableServer::POA::_narrow (poa_object.in ());

      PortableServer::POAManager_var poa_manager =
        root_poa->the_POAManager ();

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

      Sender_i *sender_impl;
      ACE_NEW_RETURN (sender_impl,
                      Sender_i (orb.in ()),
                      1);
      PortableServer::ServantBase_var receiver_owner_transfer(sender_impl);

      PortableServer::ObjectId_var id =
        root_poa->activate_object (sender_impl);

      CORBA::Object_var object = root_poa->id_to_reference (id.in ());

      Test::Sender_var sender =
        Test::Sender::_narrow (object.in ());

      CORBA::String_var ior =
        orb->object_to_string (sender.in ());

      // If the ior_output_file exists, output the ior to it
      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",
                           ior_output_file),
                              1);
      ACE_OS::fprintf (output_file, "%s", ior.in ());
      ACE_OS::fclose (output_file);

      poa_manager->activate ();

      Server_Task server_task (orb.in (),
                               ACE_Thread_Manager::instance ());

      if (server_task.activate (THR_NEW_LWP | THR_JOINABLE, 4, 1) == -1)
        {
          ACE_ERROR ((LM_ERROR, "Error activating server task\n"));
        }
      ACE_Thread_Manager::instance ()->wait ();

      ACE_DEBUG ((LM_DEBUG, "Now terminating test\n"));

      CORBA::ULong activeobjects = sender_impl->get_active_objects ();
      if (((number_of_oneways * activeobjects) !=
            sender_impl->get_number_received ()) && activeobjects != 0)
        {
          ACE_ERROR ((LM_ERROR, "Error, expected %d oneways, received %d\n",
                      number_of_oneways,
                      sender_impl->get_number_received()));
        }
      else
        {
          if (sender_impl->get_number_received () == 0)
            {
              ACE_ERROR ((LM_ERROR, "Error: Received no calls\n"));
            }
          else
            {
              ACE_DEBUG ((LM_DEBUG, "Corrected amount received\n"));
            }
        }

      root_poa->destroy (1, 1);

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught:");
      return 1;
    }

  return 0;
}
Пример #24
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{

  try
    {
      // Initialize the ORB first.
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv);

      CORBA::Object_var object =
        orb->resolve_initial_references ("RTORB");

      RTCORBA::RTORB_var rtorb =
        RTCORBA::RTORB::_narrow (object.in ());

      /*
       * The following code should be reenabled once the OMG spec has
       * been fixed such that a RTCORBA::PriorityModelPolicy can be
       * created by using the ORB::create_policy interface.
       *
      {
        RTCORBA::PriorityModelPolicy_var policy1 =
          rtorb->create_priority_model_policy (RTCORBA::CLIENT_PROPAGATED,
                                               RTCORBA::minPriority);

        CORBA::Any policy_value;
        policy_value <<= RTCORBA::CLIENT_PROPAGATED;
        policy_value <<= RTCORBA::minPriority;

        CORBA::Policy_var policy =
          orb->create_policy (RTCORBA::PRIORITY_MODEL_POLICY_TYPE,
                              policy_value);

        RTCORBA::PriorityModelPolicy_var policy2 =
          RTCORBA::PriorityModelPolicy::_narrow (policy.in ());

        ACE_ASSERT (policy1->priority_model () == policy2->priority_model ());
        ACE_ASSERT (policy1->server_priority () == policy2->server_priority ());
      }

      */

      {
        RTCORBA::ThreadpoolId poolid = 0;

        RTCORBA::ThreadpoolPolicy_var policy1 =
          rtorb->create_threadpool_policy (poolid);

        CORBA::Any policy_value;
        policy_value <<= poolid;

        CORBA::Policy_var policy =
          orb->create_policy (RTCORBA::THREADPOOL_POLICY_TYPE,
                              policy_value);

        RTCORBA::ThreadpoolPolicy_var policy2 =
          RTCORBA::ThreadpoolPolicy::_narrow (policy.in ());

        ACE_ASSERT (policy1->threadpool () == policy2->threadpool ());
      }

      {
        RTCORBA::ProtocolList empty_protocols;

        RTCORBA::ServerProtocolPolicy_var policy1 =
          rtorb->create_server_protocol_policy (empty_protocols);

        CORBA::Any policy_value;
        policy_value <<= empty_protocols;

        CORBA::Policy_var policy =
          orb->create_policy (RTCORBA::SERVER_PROTOCOL_POLICY_TYPE,
                              policy_value);

        RTCORBA::ServerProtocolPolicy_var policy2 =
          RTCORBA::ServerProtocolPolicy::_narrow (policy.in ());

        RTCORBA::ProtocolList_var protocols1 =
          policy1->protocols ();
        RTCORBA::ProtocolList_var protocols2 =
          policy2->protocols ();

        ACE_ASSERT (protocols1->length () == protocols2->length ());
      }

      {
        RTCORBA::ProtocolList empty_protocols;

        RTCORBA::ClientProtocolPolicy_var policy1 =
          rtorb->create_client_protocol_policy (empty_protocols);

        CORBA::Any policy_value;
        policy_value <<= empty_protocols;

        CORBA::Policy_var policy =
          orb->create_policy (RTCORBA::CLIENT_PROTOCOL_POLICY_TYPE,
                              policy_value);

        RTCORBA::ClientProtocolPolicy_var policy2 =
          RTCORBA::ClientProtocolPolicy::_narrow (policy.in ());

        RTCORBA::ProtocolList_var protocols1 =
          policy1->protocols ();
        RTCORBA::ProtocolList_var protocols2 =
          policy2->protocols ();

        ACE_ASSERT (protocols1->length () == protocols2->length ());
      }

      {
        RTCORBA::PrivateConnectionPolicy_var policy1 =
          rtorb->create_private_connection_policy ();

        CORBA::Any policy_value;

        CORBA::Policy_var policy =
          orb->create_policy (RTCORBA::PRIVATE_CONNECTION_POLICY_TYPE,
                              policy_value);

        RTCORBA::PrivateConnectionPolicy_var policy2 =
          RTCORBA::PrivateConnectionPolicy::_narrow (policy.in ());
      }

      {
        RTCORBA::PriorityBands empty_priority_bands;

        RTCORBA::PriorityBandedConnectionPolicy_var policy1 =
          rtorb->create_priority_banded_connection_policy (empty_priority_bands);

        CORBA::Any policy_value;
        policy_value <<= empty_priority_bands;

        CORBA::Policy_var policy =
          orb->create_policy (RTCORBA::PRIORITY_BANDED_CONNECTION_POLICY_TYPE,
                              policy_value);

        RTCORBA::PriorityBandedConnectionPolicy_var policy2 =
          RTCORBA::PriorityBandedConnectionPolicy::_narrow (policy.in ());

        RTCORBA::PriorityBands_var priority_bands1 =
          policy1->priority_bands ();
        RTCORBA::PriorityBands_var priority_bands2 =
          policy2->priority_bands ();

        ACE_ASSERT (priority_bands1->length () == priority_bands2->length ());
      }

      ACE_DEBUG ((LM_DEBUG,
                  "%s successful\n",
                  argv[0]));

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught");
      return -1;
    }

  return 0;
}
Пример #25
0
int
ACE_TMAIN (int argc,
      ACE_TCHAR *argv[])
{
  try
    {
      // Initialize the ORB first.
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv);

      CORBA::Object_var obj
        = orb->resolve_initial_references ("RootPOA");

      // Get the POA_var object from Object_var.
      PortableServer::POA_var root_poa =
        PortableServer::POA::_narrow (obj.in ());

      PortableServer::POAManager_var mgr
        = root_poa->the_POAManager ();

      mgr->activate ();

      // Initialize the AVStreams components.
      TAO_AV_CORE::instance ()->init (orb.in (),
                                      root_poa.in ());

      int result =
        parse_args (argc,
                    argv);

      if (result == -1)
        return -1;

      // Make sure we have a valid <output_file>
      output_file = ACE_OS::fopen (output_file_name,
                                   "w");
      if (output_file == 0)
        ACE_ERROR_RETURN ((LM_DEBUG,
                           "Cannot open output file %s\n",
                           output_file_name),
                          -1);

      else
        ACE_DEBUG ((LM_DEBUG,
                    "File Opened Successfully\n"));

      Receiver receiver;
      result =
        receiver.init (argc,
                       argv);

      if (result != 0)
        return result;

      orb->run ();

      // Hack for now....
      ACE_OS::sleep (1);

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("receiver::init");
      return -1;
    }

  ACE_OS::fclose (output_file);

  return 0;
}
Пример #26
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  CORBA::ORB_var orb;
  test_var server;
  RTScheduling::Scheduler_var safe_scheduler;

  try
    {
      try
        {

          orb = CORBA::ORB_init (argc, argv);

          if (parse_args (argc, argv) == -1)
            return (-1);

          CORBA::Object_var manager_obj = orb->resolve_initial_references ("RTSchedulerManager");

          TAO_RTScheduler_Manager_var manager = TAO_RTScheduler_Manager::_narrow (manager_obj.in ());

          TAO_Scheduler* scheduler = 0;
          ACE_NEW_RETURN (scheduler,
                          TAO_Scheduler (orb.in ()),
                          -1);
          safe_scheduler = scheduler;

          manager->rtscheduler (scheduler);


          CORBA::Object_var object =
            orb->string_to_object (ior.c_str ());

          server = test::_narrow (object.in ());

          if (CORBA::is_nil (server.in ()))
            {
              ACE_ERROR_RETURN ((LM_ERROR,
                                "ERROR: Object reference <%s> is nil\n",
                                ior.c_str ()),
                                1);
            }

          CORBA::Object_var current_obj = orb->resolve_initial_references ("RTScheduler_Current");

          RTScheduling::Current_var current = RTScheduling::Current::_narrow (current_obj.in ());

          const char * name = 0;
          CORBA::Policy_ptr sched_param = 0;
          CORBA::Policy_ptr implicit_sched_param = 0;

          current->begin_scheduling_segment (name,
                                            sched_param,
                                            implicit_sched_param);

          ACE_DEBUG ((LM_DEBUG,
                      "Making a one-way request\n"));
          server->one_way (ACE_TEXT_ALWAYS_CHAR(ior.c_str ()));

          ACE_DEBUG ((LM_DEBUG,
                      "Making a two-way request\n"));
          server->two_way (ACE_TEXT_ALWAYS_CHAR(ior.c_str ()));

          current->end_scheduling_segment (name);

        }
      catch (const CORBA::THREAD_CANCELLED& )
        {
          ACE_DEBUG ((LM_DEBUG,
            "Distributable Thread Cancelled - Expected Exception\n"));
          server->shutdown ();
        }
      catch (const CORBA::Exception& ex)
        {
          ex._tao_print_exception ("Caught exception:");

          return 0;
        }

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Caught unexpected exception:");

      return 1;
    }

  return 0;
}
Пример #27
0
int acslogErrorServer (char *szCmdLn){
  int  argc;
  char *argv[100];

  argc = argUnpack(szCmdLn, argv);
  argv[0] = " acslogErrorServer";
#else
  int acslogErrorServer (int argc, char *argv[]){
#endif // defined( MAKE_VXWORKS )

  CORBA::ORB_var orb;
  

  if (argc<2){
    ACE_OS::printf ("usage: acslogErrorServer <server_name> [destination_server_name] \n");
    return -1;
  }
  
  try
    {
      // Initialize the ORB
      ACS_DEBUG(" acslogErrorServer", "Initialising ORB ... ");
      orb = CORBA::ORB_init (argc, argv, 0);
      ACS_DEBUG ("acslogErrorServer", "ORB initialsed !");
    }
  catch( CORBA::Exception &ex )
    {
      ACE_PRINT_EXCEPTION (ex, "Failed to initalise ORB");
      return -1;
    }

  // create logging proxy
  ACS_DEBUG (" acslogErrorServer", "Creating logging proxy ... ");
  LoggingProxy *m_logger = new LoggingProxy(0, 0, 31, 0);
  LoggingProxy::init (m_logger);  
  ACS_DEBUG (" acslogErrorServer", "Logging proxy successfully created !");

  try
    {

      //Naming Service 
      ACS_DEBUG (" acslogErrorServer", "Resolving  Naming service ... ");
      ACE_CString nameService;
      nameService +="corbaloc::";
      nameService += ACSPorts::getIP();
      nameService += ":"; 
      nameService += ACSPorts::getNamingServicePort().c_str();
      nameService += "/"; 
      nameService += acscommon::NAMING_SERVICE_NAME;

      CORBA::Object_var naming_obj = orb->string_to_object(nameService.c_str());
      if (!CORBA::is_nil (naming_obj.in ()))
	{
	  CosNaming::NamingContext_var naming_context =
	    CosNaming::NamingContext::_narrow (naming_obj.in ());
	  ACS_DEBUG ("acslogErrorServer", "Naming Service resolved !");

	  CosNaming::Name name;
	  name.length(1);
	  name[0].id = CORBA::string_dup("Log");
	  CORBA::Object_var log_obj = naming_context->resolve(name);

	  if (!CORBA::is_nil (log_obj.in()))
	    {
	      Logging::AcsLogService_var logger = Logging::AcsLogService::_narrow(log_obj.in());
	      ACS_DEBUG ("acslogErrorServer", "Logging Service resolved !");

	      m_logger->setCentralizedLogger(logger.in());
	    }
	  else
	    {
	      ACS_DEBUG ("acslogErrorServer", "Failed to initialise the Logging Service!");
	    }

	}
      else
	{
	  ACS_DEBUG ("acslogErrorServer", "Failed to initialise the NameService!");
	}//if-else
    }
  catch( CORBA::Exception &ex )
    {
      ACE_PRINT_EXCEPTION(ex, "Failed to get and set the centralized logger");
    }

  try
    {
      //Get a reference to the RootPOA
      CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
      
      PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj.in());
      
   
      PortableServer::POAManager_var poa_manager = root_poa->the_POAManager();
      
      /* 
      CORBA::PolicyList policy_list;
      policy_list.length(5);
      policy_list[0] = root_poa->create_request_processing_policy (PortableServer::USE_DEFAULT_SERVANT);
     policy_list[1] =  root_poa->create_id_uniqueness_policy (PortableServer::MULTIPLE_ID);
      policy_list[2] = root_poa->create_id_assignment_policy(PortableServer::USER_ID); 
      policy_list[3] = root_poa->create_servant_retention_policy(PortableServer::NON_RETAIN); 
      policy_list[4] =  root_poa->create_lifespan_policy (PortableServer::PERSISTENT);
      printf("policies are created !\n");

      PortableServer::POA_var poa = root_poa->create_POA("cdbSrv", poa_manager.in(), policy_list);
      printf("Poa created !\n");

      for (CORBA::ULong i = 0; i < policy_list.length (); ++i) {
	CORBA::Policy_ptr policy = policy_list[i];
	policy->destroy ();
      }
      printf("Policies are destructed !\n");
      */


#ifdef MAKE_VXWORKS      
      ACSError::processName (szCmdLn);
#else 
      char *buf;
      ACE_OS::argv_to_string (argv, buf);
      ACSError::processName (buf);
      delete[] buf;
#endif      
      ACS_DEBUG ("acslogErrorServer", "Creating test object ...");
      ESTest_var dest;
      
      if (argc>2){
	ACS_DEBUG ("acslogErrorServer", "Getting object reference ... ");
	char refName[64];
	sprintf(refName, "file://%s.ior", argv[2]);
	CORBA::Object_var destObj = orb->string_to_object (refName);
	

	ACS_DEBUG ("acslogErrorServer", "Narrowing it .... ");
	dest = ESTest::_narrow (destObj.in());
      }//if

      ESTestImpl  esTest (dest.in(), argv[1]);
      ESTest_var testObj = esTest._this ();
      
           
      poa_manager->activate ();
      
      ACS_DEBUG ("acslogErrorServer","POA Manager -> activate");
      
      ACS_DEBUG_PARAM ("acslogErrorServer", "Writing ior to the file: %s .... ", argv[1]);
      char* ior =  orb->object_to_string (testObj.in());
      
      
      char fileName[64];
      sprintf(fileName, "%s.ior", argv[1]);
      FILE *output_file = ACE_OS::fopen (fileName, "w");
      if (output_file == 0) {
	ACS_SHORT_LOG ((LM_ERROR,
			   "Cannot open output files for writing IOR: ior.ior"));
	return  -1;
      }

      int result = ACE_OS::fprintf (output_file, "%s", ior);
      if (result < 0) {
	ACS_SHORT_LOG ((LM_ERROR,
			   "ACE_OS::fprintf failed while writing %s to ior.ior\n", ior));
	return  -1;
      }

      ACE_OS::fclose (output_file);
      
      ACS_DEBUG ("acslogErrorServer", "Waiting for requests ...");
      orb->run ();
      
      ACS_DEBUG ("acslogErrorServer", "ORB -> run");
    }
  catch( CORBA::Exception &ex )
    {
      ACE_PRINT_EXCEPTION (ex, "EXCEPTION CAUGHT");
      return -1;
    }
  
  return 0;
}//startErrorServer
ContainerInterfaceImpl::ContainerInterfaceImpl (CORBA::ORB_ptr orb, 
												PortableServer::POA_ptr root_poa, 
												ContainerType container_type,
												ComponentServerImpl* component_server,
												Components::Deployment::ComponentInstallation_ptr component_installer)
: orb_ (CORBA::ORB::_duplicate (orb)),
  root_poa_ (PortableServer::POA::_duplicate (root_poa)),
  container_type_ (container_type),
  component_server_ (component_server),
  component_installer_ (Components::Deployment::ComponentInstallation::_duplicate (component_installer))
{
	event_queue_thread_ = 0;
	event_queue_stopping_ = false ;

	component_server_->_add_ref();

	// Retrieve config values
	if (Qedo::ConfigurationReader::instance()->lookup_config_value ("/Events/EventDispatchingStrategy") == "asynchronous")
	{
		event_communication_mode_ = EVENT_COMMUNICATION_ASYNCHRONOUS;
	}
	else
	{
		event_communication_mode_ = EVENT_COMMUNICATION_SYNCHRONOUS;
	}

	//
	// get home finder
	//
	home_finder_ = Qedo_Components::HomeFinder::_nil();
	CORBA::Object_var obj;

    try
    {
        obj = orb->resolve_initial_references("ComponentHomeFinder");
    }
    catch (const CORBA::ORB::InvalidName&)
    {

        DEBUG_OUT("ContainerInterfaceImpl: No HomeFinder");
		// Since problem with MICO Initializer a new try directly over the name service
		//return;

		CosNaming::NamingContext_var nameService;

		try
		{
			std::string ns = Qedo::ConfigurationReader::instance()->lookup_config_value( "/General/NameService" );

			if( !ns.empty() )
			{
				obj = orb_->string_to_object( ns.c_str() );
				DEBUG_OUT2( "ContainerInterfaceImpl:: NameService is ", ns );
			}
			//
			// try to get naming service from orb
			//
			else
			{
				obj = orb_->resolve_initial_references( "NameService" );
			}
	}
		catch (const CORBA::ORB::InvalidName&)
		{
			std::cerr << "ContainerInterfaceImpl: Can't resolve NameService" << std::endl;
		}

		if (CORBA::is_nil(obj.in()))
		{
			std::cerr << "ContainerInterfaceImpl: NameService is a nil object reference" << std::endl;
		}

		try
		{
			nameService = CosNaming::NamingContext::_narrow(obj.in());
		}
		catch (CORBA::SystemException&)
		{
			std::cerr << "ContainerInterfaceImpl: ORB knows NameService, but I cannot contact it" << std::endl;
		}

		//
		// Resolve the HomeFinder
		//
		CosNaming::Name aName;
	    aName.length(2);
		aName[0].id = CORBA::string_dup("Qedo");
		aName[0].kind = CORBA::string_dup("");
		aName[1].id = CORBA::string_dup("HomeFinder");
		aName[1].kind = CORBA::string_dup("");

		try
		{
			obj = nameService->resolve(aName);
		}
		catch (CosNaming::NamingContext::InvalidName&)
		{
			obj = CORBA::Object::_nil();
		}
		catch (CosNaming::NamingContext::NotFound&)
		{
			obj = CORBA::Object::_nil();
		}
		catch (CORBA::SystemException&)
		{
			obj = CORBA::Object::_nil();
		}

    }
    if (CORBA::is_nil(obj.in())) {
        DEBUG_OUT("ContainerInterfaceImpl: No HomeFinder");
    }

	try
	{
		home_finder_ = Qedo_Components::HomeFinder::_narrow(obj.in());
	}
	catch (const CORBA::SystemException&)
	{
		DEBUG_OUT("ContainerInterfaceImpl: No HomeFinder");
	}
    if (CORBA::is_nil(home_finder_.in())) {
        DEBUG_OUT("ContainerInterfaceImpl: No HomeFinder");
    }

	// Start global event dispatcher thread
	if (event_communication_mode_ == EVENT_COMMUNICATION_ASYNCHRONOUS)
		event_queue_thread_ = qedo_startDetachedThread (event_dispatcher_thread, this);
}
Пример #29
0
int
ACE_TMAIN(int argc, ACE_TCHAR *argv[])
{
  try
    {
      ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - ORB_init\n"));
      CORBA::ORB_var orb =
        CORBA::ORB_init (argc, argv);

      ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - Obtain RootPOA\n"));
      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 ();

      ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - parse args\n"));
      if (parse_args (argc, argv) != 0)
        return 1;

      ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - init hello\n"));
      Hello *hello_impl = 0;
      ACE_NEW_RETURN (hello_impl,
                      Hello (orb.in ()),
                      1);
      PortableServer::ServantBase_var owner_transfer(hello_impl);

      PortableServer::ObjectId_var id =
        root_poa->activate_object (hello_impl);

      CORBA::Object_var object = root_poa->id_to_reference (id.in ());

      Test::Hello_var hello = Test::Hello::_narrow (object.in ());

      CORBA::String_var ior = orb->object_to_string (hello.in ());

      ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - Create the forwarding loop\n"));
      CORBA::Object_var iorTableObj =
            orb->resolve_initial_references ("IORTable");

      IORTable::Table_var iorTable
          = IORTable::Table::_narrow (iorTableObj.in ());

      // We are using this test with ObjRefStyle == URL ... or at
      // least we better be. The IOR is therefore a corbaloc
      ACE_CString full_corbaloc (ior.in (), 0, 1);

      // Create a corbaloc for an IOR table binding that points to
      // itself. Acessing this will  make the server reply with LOCATION_FORWARD
      // indefinitely.

      ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - Corbaloc is\n  \"%C\"\n", full_corbaloc.c_str()));
      // Get the endpoint info only...
      CORBA::ULong first_slash = full_corbaloc.find ("/", 0);
      ACE_CString forward_forever = full_corbaloc.substring (0,
                                                             first_slash);

      // .. add the string we are going to bind against and then bind
      forward_forever += "/hello";
      iorTable->bind("hello", forward_forever.c_str ());

      ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - Forward forever is\n  \"%C\"\n", forward_forever.c_str()));
      // Output the IORs
      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);

      output_file = ACE_OS::fopen (ior_output_file2, "w");
      if (output_file == 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Cannot open output file for writing IOR: %s\n",
                           ior_output_file2),
                           1);
      ACE_OS::fprintf (output_file, "%s", forward_forever.c_str ());
      ACE_OS::fclose (output_file);

      poa_manager->activate ();

      ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - orb->run()\n"));
      orb->run ();

      ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));

      root_poa->destroy (1, 1);

      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Exception caught:");
      return 1;
    }

  return 0;
}
Пример #30
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  Demo::ATC_Test_var test;
  CORBA::ORB_var orb;
  try
    {
      orb = CORBA::ORB_init (argc, argv);

      if (parse_args (argc, argv) == -1)
        {
          return -1;
        }
      CORBA::Object_var obj =
        orb->string_to_object (ACE_TEXT_ALWAYS_CHAR (ior_str));
      if  (CORBA::is_nil (obj.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             ACE_TEXT ("%P could not get ATC_Test IOR.\n")),
                            -1);
        }

      test = Demo::ATC_Test::_narrow (obj.in ());
      if  (CORBA::is_nil (test.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             ACE_TEXT ("%P narrow failed.\n")),
                            -1);
        }
    }
  catch  (CORBA::Exception& ex)
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         ACE_TEXT ("%P initialization caught %s.\n"), ex._name()),
                        -1);
    }

  CORBA::Any any;
  CORBA::String_var str;

  // union tests
  try
    {
      unionWithBar1 (any);
      str = test->do_union (any);
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%P Union test 1 returned %s\n"), str.in()));

      unionWithBar2 (any);
      str = test->do_union (any);
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%P Union test 2 returned %s\n"), str.in()));

      unionWithDefaultBar (any);
      str = test->do_union (any);
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%P Union test 3 returned %s\n"), str.in()));
    }
  catch  (CORBA::Exception& ex)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("%P Union test caught %s.\n"), ex._name()));
    }

  // valuetype tests
  try
    {
      Demo_BaseValueImpl* foo1 = new Demo_BaseValueImpl();
      foo1->str(CORBA::string_dup("BaseValue 1"));

      Demo_BaseValueImpl* foo2 = new Demo_BaseValueImpl();
      foo2->str(CORBA::string_dup("BaseValue 2"));

      Demo_NestedValueImpl* bar = new Demo_NestedValueImpl();
      bar->foo1(foo1);
      bar->foo2(foo2);

      any <<= bar;

      str = test->do_value (any);
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("%P Valuetype test returned %s\n"),
                  str.in()));
    }
  catch  (CORBA::Exception& ex)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("%P Valuetype test caught %s.\n"), ex._name()));
    }

  // struct tests
  try
    {

      Demo::BaseStruct foo1;
      foo1.str = CORBA::string_dup("BaseStruct 1");

      Demo::BaseStruct foo2;
      foo2.str = CORBA::string_dup("BaseStruct 2");

      Demo::BaseStruct foo3;
      foo3.str = CORBA::string_dup("BaseStruct 3");

      Demo::NestedStruct bar;
      bar.foo1 = foo1;
      bar.foo2 = foo2;
      bar.foo3 = foo3;

      Demo::BaseStruct innerBaseStruct1;
      innerBaseStruct1.str = CORBA::string_dup("Inner BaseStruct 1");

      Demo::BaseStruct innerBaseStruct2;
      innerBaseStruct2.str = CORBA::string_dup("Inner BaseStruct 2");

      Demo::BaseStruct innerBaseStruct3;
      innerBaseStruct3.str = CORBA::string_dup("Inner BaseStruct 3");

      Demo::NestedStruct innerBar;
      innerBar.foo1 = innerBaseStruct1;
      innerBar.foo2 = innerBaseStruct2;
      innerBar.foo3 = innerBaseStruct3;

      Demo::NestedSeq bars;
      bars.length(1);
      bars[0] = innerBar;

      bar.bars = bars;

      any <<= bar;

      str = test->do_struct (any);
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("%P struct test returned %s\n"),
                  str.in()));
    }
  catch  (CORBA::Exception& ex)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("%P struct test caught %s.\n"), ex._name()));
    }

  test->shutdown ();

  return 0;
}