CosEventChannelAdmin::EventChannel_ptr createEventChannel (const std::string& name)
{
    TRACE_ENTER(EventChannelSupport);

    CosLifeCycle::GenericFactory_var factory = getEventChannelFactory();
    if (CORBA::is_nil(factory)) {
        LOG_WARN(EventChannelSupport, "Event channel " << name << " not created");
        TRACE_EXIT(EventChannelSupport);
        return CosEventChannelAdmin::EventChannel::_nil();
    }

    CosLifeCycle::Key key;
    key.length(1);
    key[0].id = "EventChannel";
    key[0].kind = "object interface";

    std::string insName = name;
    CosLifeCycle::Criteria criteria;
    criteria.length(1);
    criteria[0].name = "InsName";
    criteria[0].value <<= insName.c_str();

    CosEventChannelAdmin::EventChannel_var eventChannel;

    LOG_TRACE(EventChannelSupport, "Creating event channel " << name);
    try {
        CORBA::Object_var obj = factory->create_object(key, criteria);
        eventChannel = CosEventChannelAdmin::EventChannel::_narrow(obj);
    } catch (const CosLifeCycle::InvalidCriteria&) {
        LOG_WARN(EventChannelSupport, "Invalid Criteria for creating event channel " << name);
    } catch (const CORBA::Exception& ex) {
        LOG_WARN(EventChannelSupport, "CORBA " << ex._name() << " exception creating event channel " << name);
    }

    TRACE_EXIT(EventChannelSupport);
    return eventChannel._retn();
}
Пример #2
0
int
Quoter_Client::init (int argc, ACE_TCHAR **argv)
{
  this->argc_ = argc;
  int i;

  // Make a copy of argv since ORB_init will change it.
  this->argv_ = new ACE_TCHAR *[argc];

  for (i = 0; i < argc; i++)
    this->argv_[i] = argv[i];

  try
    {
      // Retrieve the ORB.
      this->orb_ = CORBA::ORB_init (this->argc_,
                                    this->argv_,
                                    "internet");

      // Parse command line and verify parameters.
      if (this->parse_args () == -1)
        return -1;

      int naming_result = this->init_naming_service ();
      if (naming_result == -1)
        return naming_result;

      if (this->debug_level_ >= 2)
        ACE_DEBUG ((LM_DEBUG, "Quoter Client: Factory received OK\n"));

      // using the Quoter Generic Factory
      CosLifeCycle::Key genericFactoryName (1);  // max = 1
      genericFactoryName.length(1);
      genericFactoryName[0].id = CORBA::string_dup ("Quoter_Factory");

      // The final factory

      CosLifeCycle::Criteria criteria(1);
      criteria.length (1);
      criteria[0].name = CORBA::string_dup ("filter");
      criteria[0].value <<= CORBA::string_dup ("name=='Quoter_Generic_Factory'");
      // used to find the last generic factory in the chain

      CORBA::Object_var quoterObject_var =
        this->generic_Factory_var_->create_object (genericFactoryName,
                                                   criteria);

      this->quoter_var_ = Stock::Quoter::_narrow (quoterObject_var.in());

      if (this->debug_level_ >= 2)
        ACE_DEBUG ((LM_DEBUG, "Quoter Client: Quoter Created\n"));

      if (CORBA::is_nil (this->quoter_var_.in()))
      {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "null quoter objref returned by factory\n"),
                            -1);
      }
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("Quoter::init");
      return -1;
    }

  return 0;
}
Пример #3
0
int
Quoter_Client::init_naming_service (void)
{
  const char *exception_message = "Null Message";

  try
    {
      // Resolve the Naming Service
      CORBA::Object_var naming_obj =
        orb_->resolve_initial_references ("NameService");

      if (CORBA::is_nil (naming_obj.in ()))
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Unable to resolve the Name Service.\n"),
                          -1);

      exception_message = "While narrowing the naming context";
      CosNaming::NamingContext_var naming_context =
        CosNaming::NamingContext::_narrow (naming_obj.in ());

      if (this->debug_level_ >= 2)
        ACE_DEBUG ((LM_DEBUG, "Quoter Client: Have a proper reference to the Naming Service.\n"));

      CosNaming::Name quoterFactoryFinderName (2);
      quoterFactoryFinderName.length (2);
      quoterFactoryFinderName[0].id = CORBA::string_dup ("IDL_Quoter");
      quoterFactoryFinderName[1].id = CORBA::string_dup ("Quoter_Factory_Finder");

      if (this->debug_level_ >= 2)
        ACE_DEBUG ((LM_DEBUG, "Quoter Client: Trying to resolve the Quoter Factory Finder!\n"));

      exception_message = "While resolving the factory finder";
      CORBA::Object_var factory_obj =
        naming_context->resolve (quoterFactoryFinderName);

      if (this->debug_level_ >= 2)
        ACE_DEBUG ((LM_DEBUG, "Quoter Client: Resolved the Quoter Factory Finder!\n"));

      exception_message = "While narrowing the factory finder";
      factory_Finder_var_ =
        Stock::Quoter_Factory_Finder::_narrow (factory_obj.in ());

      if (CORBA::is_nil (factory_Finder_var_.in ()))
        ACE_ERROR_RETURN ((LM_ERROR,
                           " could not resolve quoter factory in Naming service\n"),
                          -1);

      if (this->debug_level_ >= 2)
        ACE_DEBUG ((LM_DEBUG, "Quoter Client: Have a proper reference to the Quoter Factory Finder.\n"));

      // The name of the Quoter Generic Factory
      CosLifeCycle::Key factoryName (2);  // max = 2

      if (this->useLifeCycleService_ == 1)
      {
        // use the LifeCycle Service
        factoryName.length(1);
        factoryName[0].id = CORBA::string_dup ("Life_Cycle_Service");
      }
      else
      {
        // use a Generic Factory
        factoryName.length(2);
        factoryName[0].id = CORBA::string_dup ("IDL_Quoter");
        factoryName[1].id = CORBA::string_dup ("Quoter_Generic_Factory");
      }

      if (this->debug_level_ >= 2)
        ACE_DEBUG ((LM_DEBUG, "Quoter Client: Trying to get a reference of a factory.\n"));

      // Find an appropriate factory over there.
      exception_message = "While finding factories";
      CosLifeCycle::Factories *factories_ptr =
          factory_Finder_var_->find_factories (factoryName);

      if (factories_ptr == 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Did not get a Generic Quoter Factory.\n"),
                          -1);

      if (this->debug_level_ >= 2)
        ACE_DEBUG ((LM_DEBUG, "Quoter Client: Got a proper reference of a factory.\n"));


      // Get the first object reference to a factory.
      CORBA::Object_var quoter_FactoryObj_var;

      if (factories_ptr->length () >= 1)
        {
          // everything is ok, at least one factory is there
          CosLifeCycle::Factory_ptr factory = (*factories_ptr)[0];
          quoter_FactoryObj_var = factory;
        }
      else
        ACE_ERROR_RETURN ((LM_ERROR,
                           "No Factory received.\n"),
                          -1);

      // Narrow it to a Quoter Generic Factory
      exception_message = "While narrowing the factory";
      generic_Factory_var_ =
        CosLifeCycle::GenericFactory::_narrow (quoter_FactoryObj_var.in ());

      if (CORBA::is_nil (this->generic_Factory_var_.in ()))
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Factory received is not valid.\n"),
                          -1);

      if (this->debug_level_ >= 2)
        ACE_DEBUG ((LM_DEBUG, "Quoter Client: Have a proper reference to the Quoter Factory.\n"));
    }
  catch (const CosLifeCycle::NoFactory& excpt)
    {
      ACE_ERROR ((LM_ERROR, "Quoter_Client::run - %C\n", exception_message));
      excpt._tao_print_exception (
        "Quoter::init_naming_service: No Factory available!");
    }
  catch (const CORBA::Exception& ex)
    {
      ACE_ERROR ((LM_ERROR, "Quoter_Client::init_naming_service - %C\n", exception_message));
      ex._tao_print_exception ("Quoter::init_naming_service");
      return -1;
    }

  return 0;
}