Exemplo n.º 1
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
  {
    // Initialize the ORB.
    CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);

    const ACE_TCHAR *ecname = ACE_TEXT ("EventService");
    for (int i = 0; argv[i] != 0; i++) {
      if (ACE_OS::strcmp (argv[i], ACE_TEXT ("-ecname")) == 0) {
        if (argv[i+1] != 0) {
          ecname = argv[i+1];
        } else {
    ACE_ERROR ((LM_ERROR,
          "Missing Event channel name\n"));
        }
      }
    }

    // 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 (ACE_TEXT_ALWAYS_CHAR (ecname));

    // Downcast the object reference to an EventChannel reference.
    RtecEventChannelAdmin::EventChannel_var ec =
      RtecEventChannelAdmin::EventChannel::_narrow(obj.in());
    if (CORBA::is_nil(ec.in())) {
      ACE_ERROR_RETURN ((LM_ERROR,
       "Could not narrow EchoEventChannel.\n"),
      1);
    }
    ACE_DEBUG ((LM_DEBUG,
    "EchoEventConsumerMain.cpp: Found the EchoEventChannel.\n"));

    // Obtain a reference to the consumer administration object.
    RtecEventChannelAdmin::ConsumerAdmin_var admin = ec->for_consumers();

    // Obtain a reference to the push supplier proxy.
    RtecEventChannelAdmin::ProxyPushSupplier_var supplier =
      admin->obtain_push_supplier();

    // Get the RootPOA.
    obj = orb->resolve_initial_references("RootPOA");
    PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in());

    // Instantiate an EchoEventConsumer_i servant.
    EchoEventConsumer_i servant(orb.in(), EVENT_LIMIT);

    // Register it with the RootPOA.
    PortableServer::ObjectId_var oid = poa->activate_object(&servant);
    CORBA::Object_var consumer_obj = poa->id_to_reference(oid.in());
    RtecEventComm::PushConsumer_var consumer =
      RtecEventComm::PushConsumer::_narrow(consumer_obj.in());

    // Connect as a consumer.
    ACE_ConsumerQOS_Factory qos;
    qos.start_disjunction_group ();
    qos.insert (MY_SOURCE_ID,   // Source ID
                MY_EVENT_TYPE,  // Event Type
                0);             // handle to the rt_info
    supplier->connect_push_consumer (consumer.in (),
                                     qos.get_ConsumerQOS ());

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

    ACE_DEBUG ((LM_DEBUG,
    "EchoEventConsumerMain.cpp: Ready to receive events...\n"));

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

    // If we have reached this, we must be shutting down...
    // Disconnect the ProxyPushSupplier.
    //supplier->disconnect_push_supplier();
    //supplier = RtecEventChannelAdmin::ProxyPushSupplier::_nil();
    //admin = RtecEventChannelAdmin::ConsumerAdmin::_nil();

    orb->destroy();

    return 0;

  }
  catch (const CORBA::Exception& exc)
  {
    ACE_ERROR ((LM_ERROR,
    "Caught CORBA::Exception\n%C (%C)\n",
    exc._name (),
    exc._rep_id () ));
  }

  return 1;
}
Exemplo n.º 2
0
int main(int argc,char *argv [])
{
  CORBA::ORB_ptr orb_ptr;
  try
  {
    /************************************************************************/
    /*            INICIALIZAMOS LA PARTE DEL ORB                            */
    /************************************************************************/
    int alt_argc = 0;
    char ** alt_argv;
    const char * orb_id="Test_TIDNotification";
    orb_ptr=CORBA::ORB_init(argc, argv, orb_id);
    if (!orb_ptr)
    {
      cerr<<"El ORB es null"<<endl;
      return -1;
    }

    CORBA::Object_ptr delegado_POA;
    PortableServer::POA_ptr rootPOA;
    try
    {
      delegado_POA = orb_ptr->resolve_initial_references("RootPOA");
    }
    catch ( CORBA::ORB::InvalidName ex )
    {
      ex._name();
      return -1;

    }
    rootPOA = PortableServer::_POAHelper::narrow( delegado_POA,true );
    PortableServer::POAManager_var poa_manager = rootPOA->the_POAManager();
    CORBA::PolicyList_var policies = NULL;
    policies = new CORBA::PolicyList(2);
    policies->length(2);
      // Valores cambiados
    (*policies)[0] = rootPOA->create_lifespan_policy
      ( PortableServer::PERSISTENT );
    (*policies)[1] = rootPOA->create_id_assignment_policy
      ( PortableServer::USER_ID );

    PortableServer::POA_var consumerPOA = rootPOA->create_POA("consumerPOA", poa_manager, *policies );
    
    /***********************************************************************/
    /*   OBTENEMOS LA FACTORIA DEL CANAL DE EVENTOS Y CREAMOS EL CANAL     */
    /**********************************************************************/

    CORBA::Object_ptr delegado_event_channel_factory;
    delegado_event_channel_factory=orb_ptr->string_to_object(argv[1]);
    CosNotifyChannelAdmin::EventChannelFactory_var factory;
    factory = CosNotifyChannelAdmin::EventChannelFactory::_narrow(delegado_event_channel_factory);
    if (CORBA::is_nil(factory)) { 
      cerr << "[server] ERROR: factoria nula " << endl;
      return -1; 
    } 
  
     CosNotifyChannelAdmin::EventChannel_var channel;
    //CosNotifyChannelAdmin::EventChannel_var channelv[10];


    CosNotification::QoSProperties initial_qos;
    CosNotification::AdminProperties initial_admin;
    CosNotifyChannelAdmin::ChannelID id;
    //CosNotifyChannelAdmin::ChannelID idv[10];



//     // Politicas Soportadas:

//     initial_qos.length(9);
//     initial_qos[0].name = CORBA::string_dup("OrderPolicy");
//     initial_qos[0].value <<= CosNotification::FifoOrder; // Any Fifo Priority Deadline

//     initial_qos[1].name = CORBA::string_dup("EventReliability");
//     initial_qos[1].value <<= CosNotification::BestEffort; // Persistent

//     initial_qos[2].name = CORBA::string_dup("ConnectionReliability");
//     initial_qos[2].value <<= CosNotification::BestEffort; // Persistent
    
//     initial_qos[3].name = CORBA::string_dup("Priority");
//     initial_qos[3].value <<= CosNotification::HighestPriority; // Highest, Default

//     initial_qos[4].name = CORBA::string_dup("StartTime");
//     initial_qos[4].value <<= *(new TimeBase::UtcT(
//                                   TIDorb::core::util::Time::currentTimeMillis(),
//                                   0,0,0));

//     initial_qos[5].name = CORBA::string_dup("StopTime");
//     initial_qos[5].value <<= *(new TimeBase::UtcT(
//                                   TIDorb::core::util::Time::currentTimeMillis(),
//                                   0,0,0));

//     initial_qos[6].name = CORBA::string_dup("Timeout");
//     initial_qos[6].value <<= (TimeBase::TimeT)TIDorb::core::util::Time::currentTimeMillis();

//     initial_qos[7].name = CORBA::string_dup("StartTimeSupported");
//     initial_qos[7].value <<= (CORBA::Boolean) 0;

//     initial_qos[8].name = CORBA::string_dup("StopTimeSupported");
//     initial_qos[8].value <<= (CORBA::Boolean) 1;

    //
    // Politicas de QoS no soportadas
    //

    // initial_qos[0].name = CORBA::string_dup("DiscardPolicy");
    // initial_qos[0].value <<= CosNotification::AnyOrder; // Any Fifo Priority Deadline

    // initial_qos[7].name = CORBA::string_dup("MaximumBatchSize");
    // initial_qos[7].value <<= (CORBA::Long) 20;

    // initial_qos[0].name = CORBA::string_dup("PacingInterval");
    // initial_qos[0].value <<= (TimeBase::TimeT)TIDorb::core::util::Time::currentTimeMillis();

    // initial_qos[9].name = CORBA::string_dup("MaxEventsPerConsumer");
    // initial_qos[9].value <<= (CORBA::Long) 20;


    try { 
      // Crear el canal
      channel = factory->get_event_channel(0);

//       for(int i=0; i < 10; i++){
//         channelv[i] = factory->create_channel(initial_qos, initial_admin, idv[i]);
//       }
    } catch (CosNotifyChannelAdmin::ChannelNotFound &ex) { 
      cerr << "[server_consumer] CosNotifyChannelAdmin::ChannelNotFound: " << ex._name(); 
      return -1; 
    }
    /**************************************************************************/
    /*              OBTENEMOS EL CONSUMERADMIN POR DEFECTO                    */
    /**************************************************************************/
    CosNotifyChannelAdmin::ConsumerAdmin_ptr consumerAdmin;
    consumerAdmin = channel->default_consumer_admin();
   
    //Metemos los filtros en el consumer admin
    CosNotifyFilter::Filter* filter_II = create_filter(channel,"GSyC","test","$domain_name != 'GSyC'");
    //consumerAdmin->add_filter(filter_II);
    //CosNotifyFilter::Filter* filter_III = create_filter(channel,"GSyC","test","$.remainder_of_boy.campo_uno != 1");
    //consumerAdmin->add_filter(filter_III);
   /**************************************************************************/
   /*         OBTENEMOS EL PROXYSUPPLIER APARTIR DEL CONSUMERADMIN           */
   /**************************************************************************/
    //TODO_MORFEO: add new filters
    CosNotifyChannelAdmin::ProxySupplier_ptr proxySupplier;
    CosNotifyChannelAdmin::ProxyID proxySupplierID = 1;
    proxySupplier = 
      consumerAdmin->obtain_notification_push_supplier(CosNotifyChannelAdmin::ANY_EVENT,
                                                      proxySupplierID);

                                                      

   /**************************************************************************/
   /*       OBTENEMOS EL PROXYPUSHSUPPLIER APARTIR DEL CONSUMERADMIN         */
   /**************************************************************************/
    CosNotifyChannelAdmin::StructuredProxyPushSupplier_ptr proxyPushSupplier;
    
    proxyPushSupplier = CosNotifyChannelAdmin::StructuredProxyPushSupplier::_narrow(proxySupplier);



    /**************************************************************************/
    /*            INSTANCIAMOS LOS PROXYS Y LOS ACTIVAMOS EN EL POA           */
    /**************************************************************************/
    my_push_consumer * my_consumer = new my_push_consumer(orb_ptr,proxyPushSupplier);
    PortableServer::ObjectId_ptr consumer_objectID = PortableServer::string_to_ObjectId("My_Consumer:1.0");
    consumerPOA->activate_object_with_id(*consumer_objectID,my_consumer);
    poa_manager->activate();
    CORBA::Object_ptr obj_consumer = consumerPOA->id_to_reference(*consumer_objectID);
    CosNotifyComm::StructuredPushConsumer_ptr my_pushConsumer = CosNotifyComm::StructuredPushConsumer::_narrow(obj_consumer);


    /***********************************************************************/
    /*                CONECTAMOS EL PUSHSUPPLIER Y EL PUSHCONSUMER         */
    /***********************************************************************/
    proxyPushSupplier->connect_structured_push_consumer(my_pushConsumer);


    orb_ptr->run();
 
    
  }
  catch (CORBA::Exception & e)
  {
    cerr<<"[Test_Filter] unknown error"<< typeid(e).name() << e._name();
   return -1;
   
  }

}
Exemplo n.º 3
0
int
Gateway::run (int argc, ACE_TCHAR* argv[])
{
    TAO_EC_Gateway_IIOP_Factory::init_svcs ();

    try
    {
        // First parse our command line options
        if (this->parse_args(argc, argv) != 0)
        {
            return -1;
        }

        // ORB initialization boiler plate...
        CORBA::ORB_var orb =
            CORBA::ORB_init (argc, argv);

        CORBA::Object_var object =
            orb->resolve_initial_references ("RootPOA");
        PortableServer::POA_var poa =
            PortableServer::POA::_narrow (object.in ());
        PortableServer::POAManager_var poa_manager =
            poa->the_POAManager ();
        poa_manager->activate ();

        // Obtain the event channel from 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,
                               " (%P|%t) Unable to get the Naming Service.\n"),
                              1);

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

        CosNaming::Name supplierecname (1);
        supplierecname.length (1);
        supplierecname[0].id = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(supplierec));

        CORBA::Object_var supplierec_obj =
            naming_context->resolve (supplierecname);

        CosNaming::Name consumerecname (1);
        consumerecname.length (1);
        consumerecname[0].id = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(consumerec));

        CORBA::Object_var consumerec_obj =
            naming_context->resolve (consumerecname);

        RtecEventChannelAdmin::EventChannel_var supplier_event_channel =
            RtecEventChannelAdmin::EventChannel::_narrow (supplierec_obj.in ());

        if (CORBA::is_nil (supplier_event_channel.in ()))
            ACE_ERROR_RETURN ((LM_ERROR,
                               " (%P|%t) Unable to get the supplier event channel.\n"),
                              1);

        RtecEventChannelAdmin::EventChannel_var consumer_event_channel =
            RtecEventChannelAdmin::EventChannel::_narrow (consumerec_obj.in ());

        if (CORBA::is_nil (consumer_event_channel.in ()))
            ACE_ERROR_RETURN ((LM_ERROR,
                               " (%P|%t) Unable to get the consumer event channel.\n"),
                              1);

        TAO_EC_Gateway_IIOP gateway;

        gateway.init(supplier_event_channel.in(), consumer_event_channel.in());

        PortableServer::ObjectId_var gateway_oid =
            poa->activate_object(&gateway);

        CORBA::Object_var gateway_obj =
            poa->id_to_reference(gateway_oid.in());

        RtecEventChannelAdmin::Observer_var obs =
            RtecEventChannelAdmin::Observer::_narrow(gateway_obj.in());

        RtecEventChannelAdmin::Observer_Handle local_ec_obs_handle =
            consumer_event_channel->append_observer (obs.in ());

        // Wait for events, using work_pending()/perform_work() may help
        // or using another thread, this example is too simple for that.
        orb->run ();

        consumer_event_channel->remove_observer (local_ec_obs_handle);

        poa->deactivate_object (gateway_oid.in ());

        // Destroy the POA
        poa->destroy (1, 0);
    }
    catch (const CORBA::Exception& ex)
    {
        ex._tao_print_exception ("Gateway::run");
        return 1;
    }

    return 0;
}
Exemplo n.º 4
0
int
Collocation_Test::init (int argc, ACE_TCHAR *argv[])
{
  // Initialize the ORB.
  this->orb_ = CORBA::ORB_init (argc, argv);

  int result = this->parse_args (argc, argv);
  if (result != 0)
    return result;

  // Get an Object reference to RootPOA.
  CORBA::Object_var obj =
    this->orb_->resolve_initial_references ("RootPOA");

  // Narrow the Object reference to a POA reference
  this->root_poa_ =
    PortableServer::POA::_narrow (obj.in ());

  // Get the POAManager of RootPOA
  this->poa_manager_ =
    this->root_poa_->the_POAManager ();

  // Create our own child POA
  // Empty sequence means all default policies
  int nPolicies = 0;
  CORBA::PolicyList policies;

  policies.length(1);
  policies[nPolicies++] =
    this->root_poa_->create_implicit_activation_policy(PortableServer::IMPLICIT_ACTIVATION);

  obj = this->root_poa_->create_POA("child", this->poa_manager_.in(), policies);
  PortableServer::POA_var childPOA = PortableServer::POA::_narrow (obj.in ());

  // Destroy the Policy objects (before we may exit as a result of failures)
  for (CORBA::ULong i = 0; i < policies.length(); ++i)
    {
      policies[i]->destroy();
    }

  // Activate the diamond servant and its base classes under childPOA.
  PortableServer::ObjectId_var id =
    childPOA->activate_object (&this->top_servant_);

//    // We only care about the most derived class here.
//    this->diamond_obj_ = this->diamond_servant_._this ();

  id =
    childPOA->activate_object (&this->diamond_servant_);

  // We only care about the most derived class here.
  this->diamond_obj_ = childPOA->id_to_reference (id.in ());

  id =
    childPOA->activate_object (&this->left_servant_);

  id =
    childPOA->activate_object (&this->right_servant_);


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

  ACE_DEBUG ((LM_DEBUG, "Diamond Servant activated:\n %C\n",
              str.in()));

  return 0;


}
Exemplo n.º 5
0
int
Task::svc (void)
{
    try
    {
        CORBA::Object_var object =
            this->orb_->resolve_initial_references ("RTORB");

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

        object =
            this->orb_->resolve_initial_references ("RootPOA");

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

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

        CORBA::PolicyList policies;

        int result =
            get_priority_bands ("server",
                                bands_file,
                                rt_orb.in (),
                                policies,
                                debug);
        if (result != 0)
            return result;

        result =
            get_priority_lanes ("server",
                                lanes_file,
                                rt_orb.in (),
                                stacksize,
                                static_threads,
                                dynamic_threads,
                                allow_request_buffering,
                                max_buffered_requests,
                                max_request_buffer_size,
                                allow_borrowing,
                                policies,
                                debug);
        if (result != 0)
            return result;

        CORBA::Policy_var priority_model_policy =
            rt_orb->create_priority_model_policy (RTCORBA::CLIENT_PROPAGATED,
                    0);

        // Implicit_activation policy.
        CORBA::Policy_var implicit_activation_policy =
            root_poa->create_implicit_activation_policy (PortableServer::IMPLICIT_ACTIVATION);

        policies.length (policies.length () + 1);
        policies[policies.length () - 1] =
            priority_model_policy;

        policies.length (policies.length () + 1);
        policies[policies.length () - 1] =
            implicit_activation_policy;

        PortableServer::POA_var poa =
            root_poa->create_POA ("child",
                                  poa_manager.in (),
                                  policies);

        test_i *servant = 0;
        ACE_NEW_THROW_EX (servant,
                          test_i (this->orb_.in (),
                                  poa.in ()),
                          CORBA::NO_MEMORY ());

        PortableServer::ServantBase_var safe_servant (servant);

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

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

        test_var test =
            test::_narrow (object_act.in ());

        write_iors_to_file (test.in (),
                            this->orb_.in (),
                            ior);

        poa_manager->activate ();

        this->orb_->run ();

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

    return 0;
}
Exemplo n.º 6
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());
}
Exemplo n.º 7
0
Messenger_i::Messenger_i (CORBA::ORB_ptr orb)
: orb_ (CORBA::ORB::_duplicate(orb))

{
  try
  {
    CORBA::Object_var poa_obj = orb->resolve_initial_references("RootPOA");
    PortableServer::POA_var poa = PortableServer::POA::_narrow(poa_obj.in());

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

    if (CORBA::is_nil(naming_obj.in())) {
      std::cerr << "Unable to find naming service" << std::endl;
    }

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


    //
    //  Create an instance of TAO's notification event channel
    //

    CosNotifyChannelAdmin::EventChannelFactory_var notify_factory =
      TAO_Notify_EventChannelFactory_i::create(poa.in());

    if (CORBA::is_nil (notify_factory.in ())) {
      std::cerr << "Unable to create the notify event channel" << std::endl;
      return;
    }

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

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

    if (CORBA::is_nil (ec.in())) {
      std::cerr << "Unable to create event channel" << std::endl;
      return;
    }


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

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

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

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

    if (CORBA::is_nil (supplier_admin.in())) {
      std::cerr << "Unable to find supplier admin" << std::endl;
    }

    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());

    PortableServer::ObjectId_var oid = poa->activate_object(servant);
    CORBA::Object_var supplier_obj = poa->id_to_reference(oid.in());
    CosNotifyComm::StructuredPushSupplier_var supplier =
      CosNotifyComm::StructuredPushSupplier::_narrow(supplier_obj.in());

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

    if (CORBA::is_nil (consumer_proxy_.in())) {
      std::cerr << "Unable to find structured proxy push consumer" << std::endl;
    }

    consumer_proxy_->connect_structured_push_supplier(supplier.in());

  }
  catch(const CORBA::Exception& ex) {
    std::cerr << ex << std::endl;
  }

}
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
  {
    // Initialize the EC Factory so we can customize the EC
    TAO_EC_Default_Factory::init_svcs ();

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

    const ACE_TCHAR *ecname = ACE_TEXT ("EventService");
    const ACE_TCHAR *address = ACE_TEXT ("localhost");
    const ACE_TCHAR *iorfile = 0;
    u_short port = 12345;
    u_short listenport = 12345;

    int mcast = 1;

    for (int i = 0; argv[i] != 0; i++)
      {
        if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-ecname")) == 0)
          {
            if (argv[i+1] != 0)
                ecname = argv[++i];
            else
              ACE_ERROR_RETURN ((LM_ERROR,  "Missing Event channel name\n"),0);
          }
        else if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-address")) == 0)
          {
            if (argv[i+1] != 0)
              address = argv[++i];
            else
              ACE_ERROR_RETURN ((LM_ERROR, "Missing address\n"),0);
          }
        else if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-port")) == 0)
          {
            if (argv[i+1] != 0)
              port = ACE_OS::atoi(argv[++i]);
            else
              ACE_ERROR_RETURN ((LM_ERROR, "Missing port\n"),0);
          }
        else if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-listenport")) == 0)
          {
            if (argv[i+1] != 0)
              listenport = ACE_OS::atoi(argv[++i]);
            else
              ACE_ERROR_RETURN ((LM_ERROR, "Missing port\n"), 0);
          }
        else if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-iorfile")) == 0)
          {
            if (argv[i+1] != 0)
              iorfile = argv[++i];
             else
              ACE_ERROR_RETURN ((LM_ERROR, "Missing ior file\n"), 0);
          }
        else if (ACE_OS::strcasecmp(argv[i], ACE_TEXT ("-udp")) == 0)
          mcast = 0;
      }

    // Get the POA
    CORBA::Object_var tmpobj = orb->resolve_initial_references ("RootPOA");
    PortableServer::POA_var poa = PortableServer::POA::_narrow (tmpobj.in ());
    PortableServer::POAManager_var poa_manager = poa->the_POAManager ();
    poa_manager->activate ();

    // Create a local event channel and register it
    TAO_EC_Event_Channel_Attributes attributes (poa.in (), poa.in ());
    TAO_EC_Event_Channel ec_impl (attributes);
    ec_impl.activate ();
    PortableServer::ObjectId_var oid = poa->activate_object(&ec_impl);
    tmpobj = poa->id_to_reference(oid.in());
    RtecEventChannelAdmin::EventChannel_var ec =
      RtecEventChannelAdmin::EventChannel::_narrow(tmpobj.in());

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

    // Bind the Event Channel using Naming Services
    CosNaming::Name_var name =
      root_context->to_name (ACE_TEXT_ALWAYS_CHAR (ecname));
    root_context->rebind(name.in(), ec.in());

    // Get a proxy push consumer from the EventChannel.
    RtecEventChannelAdmin::SupplierAdmin_var admin = ec->for_suppliers();
    RtecEventChannelAdmin::ProxyPushConsumer_var consumer =
      admin->obtain_push_consumer();

    // Instantiate an EchoEventSupplier_i servant.
    EchoEventSupplier_i servant(orb.in());

    // Register it with the RootPOA.
    oid = poa->activate_object(&servant);
    tmpobj = poa->id_to_reference(oid.in());
    RtecEventComm::PushSupplier_var supplier =
      RtecEventComm::PushSupplier::_narrow(tmpobj.in());

    // Connect to the EC.
    ACE_SupplierQOS_Factory qos;
    qos.insert (MY_SOURCE_ID, MY_EVENT_TYPE, 0, 1);
    consumer->connect_push_supplier (supplier.in (), qos.get_SupplierQOS ());

    // Initialize the address server with the desired address. This will
    // be used by the sender object and the multicast receiver only if
    // one is not otherwise available via the naming service.
    ACE_INET_Addr send_addr (port, address);
    SimpleAddressServer addr_srv_impl (send_addr);

    // Create an instance of the addr server for local use

    PortableServer::ObjectId_var addr_srv_oid =
      poa->activate_object(&addr_srv_impl);
    tmpobj =
      poa->id_to_reference(addr_srv_oid.in());

    RtecUDPAdmin::AddrServer_var addr_srv =
      RtecUDPAdmin::AddrServer::_narrow(tmpobj.in());

    // Create and initialize the sender object
    PortableServer::Servant_var<TAO_ECG_UDP_Sender> sender =
                                TAO_ECG_UDP_Sender::create();
    TAO_ECG_UDP_Out_Endpoint endpoint;
    // need to be explicit about the address type when built with
    // IPv6 support, otherwise SOCK_DGram::open defaults to ipv6 when
    // given a sap_any address. This causes trouble on at least solaris
    // and windows, or at most on not-linux.
    if (endpoint.dgram ().open (ACE_Addr::sap_any,
                                send_addr.get_type()) == -1)
      {
        ACE_ERROR_RETURN ((LM_ERROR,
                           "Cannot open send endpoint\n"),
                          1);
      }

   // TAO_ECG_UDP_Sender::init() takes a TAO_ECG_Refcounted_Endpoint.
    // If we don't clone our endpoint and pass &endpoint, the sender will
    // attempt to delete endpoint during shutdown.
    TAO_ECG_Refcounted_Endpoint clone (new TAO_ECG_UDP_Out_Endpoint (endpoint));
    sender->init (ec.in (), addr_srv.in (), clone);

    // Setup the subscription and connect to the EC
    ACE_ConsumerQOS_Factory cons_qos_fact;
    cons_qos_fact.start_disjunction_group ();
    cons_qos_fact.insert (ACE_ES_EVENT_SOURCE_ANY, ACE_ES_EVENT_ANY, 0);
    RtecEventChannelAdmin::ConsumerQOS sub = cons_qos_fact.get_ConsumerQOS ();
    sender->connect (sub);

    // Create and initialize the receiver
    PortableServer::Servant_var<TAO_ECG_UDP_Receiver> receiver =
                                      TAO_ECG_UDP_Receiver::create();

    // TAO_ECG_UDP_Receiver::init() takes a TAO_ECG_Refcounted_Endpoint.
    // If we don't clone our endpoint and pass &endpoint, the receiver will
    // attempt to delete endpoint during shutdown.
    TAO_ECG_Refcounted_Endpoint clone2 (new TAO_ECG_UDP_Out_Endpoint (endpoint));
    receiver->init (ec.in (), clone2, addr_srv.in ());

    // Setup the registration and connect to the event channel
    ACE_SupplierQOS_Factory supp_qos_fact;
    supp_qos_fact.insert (MY_SOURCE_ID, MY_EVENT_TYPE, 0, 1);
    RtecEventChannelAdmin::SupplierQOS pub = supp_qos_fact.get_SupplierQOS ();
    receiver->connect (pub);

    // Create the appropriate event handler and register it with the reactor
    auto_ptr<ACE_Event_Handler> eh;
    if (mcast) {
      auto_ptr<TAO_ECG_Mcast_EH> mcast_eh(new TAO_ECG_Mcast_EH (receiver.in()));
      mcast_eh->reactor (orb->orb_core ()->reactor ());
      mcast_eh->open (ec.in());
      ACE_auto_ptr_reset(eh,mcast_eh.release());
      //eh.reset(mcast_eh.release());
    } else {
      auto_ptr<TAO_ECG_UDP_EH> udp_eh (new TAO_ECG_UDP_EH (receiver.in()));
      udp_eh->reactor (orb->orb_core ()->reactor ());
      ACE_INET_Addr local_addr (listenport);
      if (udp_eh->open (local_addr) == -1)
        ACE_ERROR ((LM_ERROR,"Cannot open EH\n"));

      ACE_auto_ptr_reset(eh,udp_eh.release());
      //eh.reset(udp_eh.release());
    }

    // Create an event (just a string in this case).

    // Create an event set for one event
    RtecEventComm::EventSet event (1);
    event.length (1);

    // Initialize event header.
    event[0].header.source = MY_SOURCE_ID;
    event[0].header.ttl = 1;
    event[0].header.type = MY_EVENT_TYPE;

#if !defined (TAO_LACKS_EVENT_CHANNEL_ANY)
    // Initialize data fields in event.
    const CORBA::String_var eventData =
      CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR (ecname));

    event[0].data.any_value <<= eventData;
#else
    // Use the octet sequence payload instead
    char *tmpstr = const_cast<char *>(ACE_TEXT_ALWAYS_CHAR (ecname));
    size_t len = ACE_OS::strlen(tmpstr) +1;
    event[0].data.payload.replace (
      len,
      len,
      reinterpret_cast<CORBA::Octet *> (tmpstr));
#endif  /* !TAO_LACKS_EVENT_CHANNEL_ANY */

    if (iorfile != 0) {
      CORBA::String_var str = orb->object_to_string( ec.in() );
      std::ofstream iorFile( ACE_TEXT_ALWAYS_CHAR(iorfile) );
      iorFile << str.in() << std::endl;
      iorFile.close();
    }
    ACE_DEBUG ((LM_DEBUG,
    "Starting main loop\n"));

    const int EVENT_DELAY_MS = 1000;

    while (1) {
      consumer->push (event);

      ACE_Time_Value tv(0, 1000 * EVENT_DELAY_MS);
      orb->run(tv);
    }

    orb->destroy();
    return 0;
  }
  catch (CORBA::Exception& exc)
  {
    ACE_ERROR ((LM_ERROR,
    "Caught CORBA::Exception\n%C (%C)\n",
    exc._name (),
    exc._rep_id () ));
  }
  return 1;
}