Exemple #1
0
void
FactoryClient::find_channel (const char* channel_id)
{
  try
    {
      ACE_DEBUG ((LM_DEBUG,
                  "trying to find the Channel \"%s \"\n",
                  channel_id));

      CosEventChannelAdmin::EventChannel_var channel =
        this->factory_->find (channel_id);


      CORBA::String_var str =
        orb_->object_to_string (channel.in ());

      ACE_DEBUG ((LM_DEBUG,
              "Find returned - %s\n",
                  str.in ()));

      this->find_channel_id (channel.in ());
    }
  catch (const CORBA::UserException& ue)
    {
      ue._tao_print_exception ("User Exception in findchannel: ");
    }
  catch (const CORBA::SystemException& se)
    {
      se._tao_print_exception ("System Exception in findchannel: ");
    }
}
Exemple #2
0
CosEventChannelAdmin::EventChannel_ptr
FactoryClient::create_channel (const char *channel_id,
                            CosEventChannelFactory::ChannelFactory_ptr factory)
{
  ACE_DEBUG ((LM_DEBUG,
              "Trying to create channel %s\n", channel_id));

  CosEventChannelAdmin::EventChannel_var ec =
    CosEventChannelAdmin::EventChannel::_nil ();

  try
    {
      ec = factory->create (channel_id,
                            this->use_naming_service);

      ACE_ASSERT (!CORBA::is_nil (ec.in ()));

      ACE_DEBUG ((LM_DEBUG,
                  "Created Cos Event Channel \"%s \"\n",
                  channel_id));
    }
 catch (const CORBA::UserException& ue)
   {
     ue._tao_print_exception ("User Exception in createChannel: ");
     return CosEventChannelAdmin::EventChannel::_nil ();
   }
  catch (const CORBA::SystemException& se)
    {
      se._tao_print_exception ("System Exception in createChannel: ");
      return CosEventChannelAdmin::EventChannel::_nil ();
    }

  return ec._retn ();
}
CosEventChannelAdmin::ProxyPullSupplier_ptr VOmniORBHelper::
eventGetProxyPullSupplier(const char* program, const char* object,
			  int telescopenumber)
{
  CosEventChannelAdmin::EventChannel_var channel =
    nsGetNarrowedObject<CosEventChannelAdmin::EventChannel>(program,object,
							    telescopenumber);
  CosEventChannelAdmin::ConsumerAdmin_var consumer_admin =
    channel->for_consumers();
  return consumer_admin->obtain_pull_supplier();
}
Exemple #4
0
int ACE_TMAIN (int argc, ACE_TCHAR* argv[])
{
  try {
    // First initialize the ORB, that will remove some arguments...
    CORBA::ORB_var orb =
      CORBA::ORB_init (argc, argv);
    CORBA::Object_var poa_object =
      orb->resolve_initial_references ("RootPOA");
    PortableServer::POA_var poa =
      PortableServer::POA::_narrow (poa_object.in ());
    PortableServer::POAManager_var poa_manager =
      poa->the_POAManager ();
    poa_manager->activate ();

    CORBA::Object_var naming_context_object =
      orb->resolve_initial_references ("NameService");
    CosNaming::NamingContext_var naming_context =
      CosNaming::NamingContext::_narrow (naming_context_object.in ());

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

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

    // Now downcast the object reference to the appropriate type
    CosEventChannelAdmin::EventChannel_var ec =
      CosEventChannelAdmin::EventChannel::_narrow (ec_object.in ());

    Stock_Consumer stock_consumer_i;
    stock_consumer_i.connect (ec.in ());

    orb->run ();

    stock_consumer_i.disconnect ();

    poa->destroy (1, 1);
    orb->destroy ();
  }
  catch (CORBA::Exception &) {
    cerr << "CORBA exception raised!" << endl;
  }
  return 0;
}
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();
}
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
  {
    // Initialize the ORB.
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

    // Find the Naming Service.
    CORBA::Object_var obj = orb->resolve_initial_references("NameService");
    CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(obj.in());

    // Find the EchoEventChannel.
    obj = root_context->resolve_str("CosEventService");

    // Downcast the object reference to an EventChannel reference.
    CosEventChannelAdmin::EventChannel_var echoEC =
      CosEventChannelAdmin::EventChannel::_narrow(obj.in());
    if (CORBA::is_nil(echoEC.in())) {
      std::cerr << "Could not narrow EchoEventChannel." << std::endl;
      return 1;
    }
    std::cout << "Found the EchoEventChannel." << std::endl;

    // Get a ConsumerAdmin object from the EventChannel.
    CosEventChannelAdmin::ConsumerAdmin_var consumerAdmin =
      echoEC->for_consumers();

    // Get a ProxyPushSupplier from the ConsumerAdmin.
    CosEventChannelAdmin::ProxyPushSupplier_var supplier =
      consumerAdmin->obtain_push_supplier();

    // Instantiate an EchoEventConsumer_i servant.
    PortableServer::Servant_var<EchoEventConsumer_i> servant =
      new EchoEventConsumer_i(orb.in(), supplier.in(), EVENTS_TILL_SHUTDOWN);

    // Register it with the RootPOA.
    obj = orb->resolve_initial_references("RootPOA");
    PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in());
    PortableServer::ObjectId_var oid = poa->activate_object(servant.in());
    CORBA::Object_var consumer_obj = poa->id_to_reference(oid.in());
    CosEventComm::PushConsumer_var consumer =
      CosEventComm::PushConsumer::_narrow(consumer_obj.in());

    // Connect to the ProxyPushSupplier, passing our PushConsumer object
    // reference to it.
    supplier->connect_push_consumer(consumer.in());

    // Activate the POA via its POAManager.
    PortableServer::POAManager_var poa_manager = poa->the_POAManager();
    poa_manager->activate();

    std::cout << "Ready to receive events..." << std::endl;

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

    // If we have reached this, we must be shutting down...
    orb->destroy();

    std::cout << "Test complete." << std::endl;

    return 0;
  }
  catch(const CORBA::Exception& ex)
  {
    std::cerr << "Consumer: Caught CORBA::Exception:  " << ex << std::endl;
  }

  return 1;
}
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
    {
      // Initialize the ORB.
      CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
      CORBA::ORB_var s_orb;

      // Find the Naming Service.
      CORBA::Object_var obj = orb->resolve_initial_references ("NameService");
      CosNaming::NamingContextExt_var root_context =
        CosNaming::NamingContextExt::_narrow (obj.in ());

      obj = root_context->resolve_str ("CosEventService");

      // Downcast the object reference to an EventChannel reference.
      CosEventChannelAdmin::EventChannel_var ec =
        CosEventChannelAdmin::EventChannel::_narrow (obj.in ());
      if (CORBA::is_nil (ec.in ()))
        {
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("Could not narrow the EventChannel.\n")));
          return 1;
        }
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Found the EventChannel.\n")));

      bool consumer = false;
      bool supplier = false;
      bool hang = false;
      for (int i=1; i < argc; ++i)
        {
          if (0 == ACE_OS::strcasecmp (argv[i], ACE_TEXT ("-consumer")))
            consumer = true;
          else if (0 == ACE_OS::strcasecmp (argv[i], ACE_TEXT ("-supplier")))
            supplier = true;
          else if (0 == ACE_OS::strcasecmp (argv[i], ACE_TEXT ("-hang")))
            hang = true;
        }

      TestEventConsumer_i servant (orb.in (), hang);

      if (consumer)
        {
          // Register it with the RootPOA.
          obj = orb->resolve_initial_references ("RootPOA");
          PortableServer::POA_var poa =
            PortableServer::POA::_narrow (obj.in ());
          PortableServer::ObjectId_var oid = poa->activate_object (&servant);
          CORBA::Object_var consumer_obj = poa->id_to_reference (oid.in ());
          CosEventComm::PushConsumer_var consumer =
            CosEventComm::PushConsumer::_narrow (consumer_obj.in ());

          // Get a ConsumerAdmin object from the EventChannel.
          CosEventChannelAdmin::ConsumerAdmin_var consumerAdmin =
            ec->for_consumers ();

          // Get a ProxyPushSupplier from the ConsumerAdmin.
          CosEventChannelAdmin::ProxyPushSupplier_var supplier =
            consumerAdmin->obtain_push_supplier ();

          // Connect to the ProxyPushSupplier, passing our PushConsumer object
          // reference to it.
          supplier->connect_push_consumer (consumer.in ());
          ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Consumer connected\n")));

          // Activate the POA via its POAManager.
          PortableServer::POAManager_var poa_manager = poa->the_POAManager ();
          poa_manager->activate ();
          servant.activate ();
        }

      ACE_Auto_Ptr<SupplierTask> pST;
      if (supplier)
        {
          // The supplier will use its own ORB.
          CORBA::String_var ec_str = orb->object_to_string (ec.in ());

          int no_args = 0;
          ACE_TCHAR **no_argv = 0;
          s_orb = CORBA::ORB_init (no_args, no_argv,
                                   "Supplier_pure_client_ORB");

          CORBA::Object_var s_ec_obj = s_orb->string_to_object (ec_str.in ());

          CosEventChannelAdmin::EventChannel_var s_ec =
            CosEventChannelAdmin::EventChannel::_narrow (s_ec_obj.in ());

          // Get a SupplierAdmin object from the EventChannel.
          CosEventChannelAdmin::SupplierAdmin_var supplierAdmin =
            s_ec->for_suppliers ();

          // Get a ProxyPushConsumer from the SupplierAdmin.
          CosEventChannelAdmin::ProxyPushConsumer_var consumer =
            supplierAdmin->obtain_push_consumer ();

          // Connect to the ProxyPushConsumer as a PushSupplier
          // (passing a nil PushSupplier object reference to it because
          // we don't care to be notified about disconnects).
          consumer->connect_push_supplier
            (CosEventComm::PushSupplier::_nil ());

          SupplierTask *tmp = 0;
          ACE_NEW_RETURN (tmp, SupplierTask (consumer.in (), s_orb.in ()), -1);
          pST.reset (tmp);
          pST->activate ();
        }

      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Ready to receive events...\n")));

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

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

      if (!CORBA::is_nil (s_orb.in ()))
        {
          s_orb->destroy ();
        }

      orb->destroy ();
      return 0;
    }
  catch (CORBA::Exception &ex)
    {
      ex._tao_print_exception (
        ACE_TEXT (
          "TimeoutTest: Caught CORBA::Exception:"));
    }

  return 1;
}