Beispiel #1
0
static CosNotifyChannelAdmin::SupplierAdmin_ptr
create_supplieradmin (CosNotifyChannelAdmin::EventChannel_ptr ec)
{
  CosNotifyChannelAdmin::AdminID adminid = 0;
  CosNotifyChannelAdmin::SupplierAdmin_var admin =
    ec->new_for_suppliers (CosNotifyChannelAdmin::AND_OP, adminid);

  return CosNotifyChannelAdmin::SupplierAdmin::_duplicate (admin.in ());
}
template <class SERVANT_TYPE> CosNotifyChannelAdmin::SupplierAdmin_ptr
TAO_Notify_ProxyConsumer_T<SERVANT_TYPE>::MyAdmin (void)
{
    CosNotifyChannelAdmin::SupplierAdmin_var ret;

    CORBA::Object_var object = this->supplier_admin().ref ();

    ret = CosNotifyChannelAdmin::SupplierAdmin::_narrow (object.in ());

    return ret._retn ();
}
Beispiel #3
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  int status = 0;
  try
    {
      Supplier_Client client;
      status = client.init (argc, argv);

      if (status == 0)
        {
          CosNotifyChannelAdmin::EventChannel_var ec =
            client.create_event_channel ("MyEventChannel", 1);

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

          MonitorTestInterface_var sig =
            MonitorTestInterface::_narrow (object.in ());

          if (CORBA::is_nil (sig.in ()))
            ACE_ERROR_RETURN ((LM_ERROR, "Error: Structured Supplier: Narrow to MonitorTestInterface failed.\n"),1);
          CosNotifyChannelAdmin::SupplierAdmin_var admin =
            create_supplieradmin (ec.in ());
          if (!CORBA::is_nil (admin.in ()))
            {
              create_suppliers (admin.in (), client.root_poa ());

              sig->running (MonitorTestInterface::Supplier);
              ACE_DEBUG ((LM_DEBUG,
                          "1 supplier sending %d events...\n", max_events));
              for (int i = 0; i < max_events; ++i)
              {
                ACE_DEBUG ((LM_DEBUG, "+"));
                SendEvent (i);
              }
              ACE_DEBUG ((LM_DEBUG,
                          "\nSupplier sent %d events.\n", max_events));
              sig->finished (MonitorTestInterface::Supplier);
              supplier_1->disconnect ();
            }
        }
    }
  catch (const CORBA::Exception& e)
    {
      e._tao_print_exception ("Supplier Error: ");
      status = 1;
    }

  return status;
}
  virtual bool execute (const char* command) {
    if (ACE_OS::strcmp (command, TAO_NS_CONTROL_REMOVE_SUPPLIERADMIN) == 0)
      {
        CosNotifyChannelAdmin::SupplierAdmin_var admin =
          this->ec_->get_supplieradmin (this->id_);
        if (!CORBA::is_nil (admin.in ()))
          admin->destroy ();
      }
    else
      {
        return false;
      }

    return true;
  }
Beispiel #5
0
bool
IdAssignment::default_supplier_admin_test (CosNotifyChannelAdmin::ChannelID channel_id)
{
  CosNotifyChannelAdmin::EventChannel_var ec =
    this->notify_factory_->get_event_channel (channel_id);

  if (CORBA::is_nil (ec.in ()))
    {
      ACE_ERROR((LM_ERROR,
                 " (%P|%t) Unable to find event channel\n"));
      return false;
    }

  CosNotifyChannelAdmin::SupplierAdmin_var default_supplier_admin =
    ec->get_supplieradmin (0);

  if (CORBA::is_nil (default_supplier_admin.in()))
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                  " (%P|%t) Unable to create default supplier admin\n"),
                  false);
    }

  CosNotifyChannelAdmin::SupplierAdmin_var def = ec->default_supplier_admin ();
  if (CORBA::is_nil (default_supplier_admin.in()))
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                  " (%P|%t) Unable to get default supplier admin\n"),
                  false);
    }

  if (! default_supplier_admin->_is_equivalent(def.in ()))
    {
      ACE_ERROR_RETURN ((LM_ERROR,
        " (%P|%t) failed for default supplier admin checking\n"),
        false);
    }

  if (TAO_debug_level)
    ACE_DEBUG ((LM_DEBUG,
                "passed default supplier admin test.\n"));

  return true;
}
Beispiel #6
0
int
ACE_TMAIN (int argc, ACE_TCHAR* argv[])
{
#if defined (TAO_HAS_MONITOR_FRAMEWORK) && (TAO_HAS_MONITOR_FRAMEWORK == 1)

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

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

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

      TAO_Notify_Service* notify_service =
        TAO_Notify_Service::load_default ();

      if (notify_service == 0)
        {
          error ("Unable to load the Notify Service");
        }

      notify_service->init_service (orb.in ());
      ACE_OS::sleep (1);

      const ACE_CString ecf_name ("MonitoringEventChannelFactory");
      CosNotifyChannelAdmin::EventChannelFactory_var ecf =
         notify_service->create (poa.in (), ecf_name.c_str ());
      NotifyMonitoringExt::EventChannelFactory_var monitor_ec_factory =
        NotifyMonitoringExt::EventChannelFactory::_narrow (ecf.in ());

      if (CORBA::is_nil (monitor_ec_factory.in ()))
        {
         error ("Unable to create the Monitoring Event Channel Factory");
        }

      CosNotification::QoSProperties qos_prop;
      CosNotification::AdminProperties admin_prop;
      CosNotifyChannelAdmin::ChannelID id;
      const ACE_CString ec_name ("test1");

      CosNotifyChannelAdmin::EventChannel_var ec =
        monitor_ec_factory->create_named_channel (qos_prop,
                                                  admin_prop,
                                                  id,
                                                  ec_name.c_str ());
      NotifyMonitoringExt::EventChannel_var mec =
        NotifyMonitoringExt::EventChannel::_narrow (ec.in ());

      if (CORBA::is_nil (mec.in ()))
        {
          error ("Unable to narrow the event channel");
        }

      try
        {
          CosNotifyChannelAdmin::ChannelID fake_id;
          CosNotifyChannelAdmin::EventChannel_var fake =
            monitor_ec_factory->create_named_channel (qos_prop,
                                                      admin_prop,
                                                      fake_id,
                                                      "test1");
          error ("Expected a NotifyMonitoringExt::"
                 "NameAlreadyUsed exception");
        }
      catch (const NotifyMonitoringExt::NameAlreadyUsed&)
        {
          // This is expected.
        }

      Monitor_Point_Registry* instance = Monitor_Point_Registry::instance ();
      ACE_CString stat_name =
        ecf_name
        + "/"
        + ACE_CString (NotifyMonitoringExt::InactiveEventChannelCount);

      Monitor_Base* stat = instance->get (stat_name);

      if (stat == 0)
        {
          error ("Could not find InactiveEventChannelCount statistic");
        }

      stat->update ();
      double count = stat->last_sample ();

      if (!ACE::is_equal (count, 1.0))
        {
          error ("Invalid inactive event channel count");
        }

      stat_name =
        ecf_name
        + "/"
        + ACE_CString (NotifyMonitoringExt::ActiveEventChannelCount);

      stat = instance->get (stat_name);

      if (stat == 0)
        {
          error ("Could not find ActiveEventChannelCount statistic");
        }

      stat->update ();
      count = stat->last_sample ();

      if (!ACE::is_equal (count, 0.0))
        {
          error ("Invalid active event channel count");
        }

      stat_name =
        ecf_name
        + "/"
        + ACE_CString (NotifyMonitoringExt::InactiveEventChannelNames);

      stat = instance->get (stat_name);

      if (stat == 0)
        {
          error ("Could not find InactiveEventChannels statistic");
        }

      stat->update ();
      Monitor_Control_Types::NameList list = stat->get_list ();

      if (list.size () != 1)
        {
          error ("Invalid inactive event channel list");
        }

      ACE_CString full_ec_name (ecf_name + "/" + ec_name);

      if (list[0] != full_ec_name)
        {
          error ("Wrong event channel name");
        }

      CosNotifyChannelAdmin::AdminID aid;
      CosNotifyChannelAdmin::SupplierAdmin_var admin =
        mec->named_new_for_suppliers (CosNotifyChannelAdmin::AND_OP,
                                      aid,
                                      "TestSupplierAdmin");

      try
        {
          admin =
            mec->named_new_for_suppliers (CosNotifyChannelAdmin::AND_OP,
                                          aid,
                                          "TestSupplierAdmin");

          error ("Expected a SupplierAdmin "
                 "NotifyMonitoringExt::NameAlreadyUsed exception");
        }
      catch (const NotifyMonitoringExt::NameAlreadyUsed&)
        {
          // This is expected.
        };

      // We should be able to create another one with the same name.
      admin->destroy ();
      admin =
        mec->named_new_for_suppliers (CosNotifyChannelAdmin::AND_OP,
                                      aid,
                                      "TestSupplierAdmin");

      NotifyMonitoringExt::SupplierAdmin_var madmin =
        NotifyMonitoringExt::SupplierAdmin::_narrow (admin.in ());

      if (CORBA::is_nil (madmin.in ()))
        {
          error ("Could not narrow the supplier admin");
        }

      CosNotifyChannelAdmin::ProxyID pid;
      CosNotifyChannelAdmin::ProxyConsumer_var conproxy =
        madmin->obtain_named_notification_push_consumer (
          CosNotifyChannelAdmin::STRUCTURED_EVENT,
          pid,
          "supplier");

      try
        {
          CosNotifyChannelAdmin::ProxyConsumer_var fake =
            madmin->obtain_named_notification_push_consumer
            (CosNotifyChannelAdmin::STRUCTURED_EVENT, pid, "supplier");

          error ("Expected a ProxyConsumer "
                 "NotifyMonitoringExt::NameAlreadyUsed exception");
        }
      catch (const NotifyMonitoringExt::NameAlreadyUsed&)
        {
          // This is expected.
        }

      stat_name =
        ecf_name
        + "/"
        + ec_name
        + "/"
        + ACE_CString (NotifyMonitoringExt::EventChannelSupplierCount);

      stat = instance->get (stat_name);

      if (stat == 0)
        {
          error ("Could not find the event channel suppliers statistic");
        }

      stat->update ();
      count = stat->last_sample ();

      if (!ACE::is_equal (count, 1.0))
        {
          error ("Invalid supplier count");
        }

      CosNotifyChannelAdmin::StructuredProxyPushConsumer_var push_conproxy =
        CosNotifyChannelAdmin::StructuredProxyPushConsumer::_narrow (
          conproxy.in ());
      ACE_ASSERT (!CORBA::is_nil (push_conproxy.in ()));
      push_conproxy->disconnect_structured_push_consumer ();

      try
        {
          CosNotifyChannelAdmin::ProxyConsumer_var fake =
            madmin->obtain_named_notification_push_consumer (
              CosNotifyChannelAdmin::STRUCTURED_EVENT,
              pid,
              "supplier");
        }
      catch (const NotifyMonitoringExt::NameAlreadyUsed&)
        {
          error ("Unexpected ProxyConsumer "
                 "NotifyMonitoringExt::NameAlreadyUsed exception");
        }

      CosNotifyChannelAdmin::ConsumerAdmin_var cadmin =
        mec->named_new_for_consumers (CosNotifyChannelAdmin::AND_OP,
                                      aid,
                                      "TestConsumerAdmin");

      try
        {
          cadmin =
            mec->named_new_for_consumers (CosNotifyChannelAdmin::AND_OP,
                                          aid,
                                          "TestConsumerAdmin");

          error ("Expected a ConsumerAdmin "
                 "NotifyMonitoringExt::NameAlreadyUsed exception");
        }
      catch (const NotifyMonitoringExt::NameAlreadyUsed&)
        {
          // This is expected.
        };

      // We should be able to create another one with the same name
      cadmin->destroy ();
      cadmin =
        mec->named_new_for_consumers (CosNotifyChannelAdmin::AND_OP,
                                      aid,
                                      "TestConsumerAdmin");

      NotifyMonitoringExt::ConsumerAdmin_var mcadmin =
        NotifyMonitoringExt::ConsumerAdmin::_narrow (cadmin.in ());

      if (CORBA::is_nil (mcadmin.in ()))
        {
          error ("Could not narrow the consumer admin");
        }

      CosNotifyChannelAdmin::ProxySupplier_var supproxy =
        mcadmin->obtain_named_notification_push_supplier (
          CosNotifyChannelAdmin::STRUCTURED_EVENT,
          pid,
          "consumer");

      try
        {
          CosNotifyChannelAdmin::ProxySupplier_var fake =
            mcadmin->obtain_named_notification_push_supplier (
              CosNotifyChannelAdmin::STRUCTURED_EVENT,
              pid,
              "consumer");

          error ("Expected a ProxySupplier "
                 "NotifyMonitoringExt::NameAlreadyUsed exception");
        }
      catch (const NotifyMonitoringExt::NameAlreadyUsed&)
        {
          // This is expected.
        }

      stat_name =
        ecf_name
        + "/"
        + ec_name
        + "/"
        + ACE_CString (NotifyMonitoringExt::EventChannelConsumerCount);

      stat = instance->get (stat_name);

      if (stat == 0)
        {
          error ("Could not find the event channel consumers statistic");
        }

      stat->update ();
      count = stat->last_sample ();

      if (!ACE::is_equal (count, 1.0))
        {
          error ("Invalid consumer count");
        }

      CosNotifyChannelAdmin::StructuredProxyPushSupplier_var push_supproxy =
        CosNotifyChannelAdmin::StructuredProxyPushSupplier::_narrow (
          supproxy.in());
      ACE_ASSERT (!CORBA::is_nil (push_supproxy.in ()));
      push_supproxy->disconnect_structured_push_supplier ();

      try
        {
          CosNotifyChannelAdmin::ProxySupplier_var fake =
            mcadmin->obtain_named_notification_push_supplier (
              CosNotifyChannelAdmin::STRUCTURED_EVENT,
              pid,
              "consumer");
        }
      catch (const NotifyMonitoringExt::NameAlreadyUsed&)
        {
          error ("Unexpected ProxySupplier "
                 "NotifyMonitoringExt::NameAlreadyUsed exception");
        }

      TAO_MonitorManager::shutdown ();
      orb->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("MonitorControlExt: ");
    }
  catch (...)
    {
      error ("Caught an unexpected exception type");
    }
#else /* ACE_HAS_MONITOR_FRAMEWORK==1 */
  ACE_UNUSED_ARG (argc);
  ACE_UNUSED_ARG (argv);
#endif /* TAO_HAS_MONITOR_FRAMEWORK==1 */

  return 0;
}
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
    int status = 0;
    ACE_Auto_Ptr< sig_i > sig_impl;
    try
    {
        Supplier_Client client;
        status = client.init (argc, argv);

        if (status == 0)
        {
            CosNotifyChannelAdmin::EventChannel_var ec =
                client.create_event_channel ("MyEventChannel", 0);

            if (use_deadline_ordering)
            {
                CosNotification::QoSProperties qos (1);
                qos.length (1);
                qos[0].name = CORBA::string_dup (CosNotification::OrderPolicy);
                qos[0].value <<= (CORBA::Short)CosNotification::DeadlineOrder;
                ec->set_qos (qos);
            }

            sig_impl.reset( new sig_i( client.orb() ) );
            sig_var sig = sig_impl->_this ();

            // If the ior_output_file exists, output the ior to it
            if (ior_output_file != 0)
            {
                CORBA::String_var ior =
                    client.orb ()->object_to_string (sig.in ());

                FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
                ACE_ASSERT (output_file != 0);
                ACE_OS::fprintf (output_file, "%s", ior.in ());
                ACE_OS::fclose (output_file);
            }

            CosNotifyChannelAdmin::SupplierAdmin_var admin =
                create_supplieradmin (ec.in ());
            ACE_ASSERT(!CORBA::is_nil (admin.in ()));

            create_suppliers (admin.in (), client.root_poa ());

            sig_impl->wait_for_startup();

            ACE_DEBUG((LM_DEBUG, "1 supplier sending %d events...\n", num_events));
            for (int i = 0; i < num_events; ++i)
            {
                ACE_DEBUG((LM_DEBUG, "+"));
                SendEvent (i + 1);
            }
            ACE_DEBUG((LM_DEBUG, "\nSupplier sent %d events.\n", num_events));

            sig_impl->wait_for_completion();

            ACE_OS::unlink (ior_output_file);

            supplier_1->disconnect();

            ec->destroy();
        }
    }
    catch (const CORBA::Exception& e)
    {
        e._tao_print_exception ("Error: ");
        status = 1;
    }

    return status;
}
Beispiel #8
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
  {
    PortableServer::POAManager_var poa_manager;

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

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

    poa_manager = root_poa->the_POAManager();

    poa_manager->activate();

    /*Get event_channel*/
    std::cout << "Create event_channel now"  << std::endl;
    CosNotifyChannelAdmin::EventChannel_var ec = get_event_channel(orb.in());

    //Instanciating the Supplier
    CosNotifyComm::StructuredPushSupplier_var sps =
      CosNotifyComm::StructuredPushSupplier::_nil();


    CosNotifyCommImpl::StructuredPushSupplier *pImpl_sps = new CosNotifyCommImpl::StructuredPushSupplier;
    sps = pImpl_sps->_this();

    //Obtain a Supplier Admin
    CosNotifyChannelAdmin::SupplierAdmin_var sa = ec->default_supplier_admin();
    if( sa.in() == CosNotifyChannelAdmin::SupplierAdmin::_nil() ){
      std::cerr << "sa is nil!" << std::endl;
      return 1;
    }

    //Obtain a Proxy Consumer
    CosNotifyChannelAdmin::ProxyID proxy_id;
    CosNotifyChannelAdmin::ClientType ctype = CosNotifyChannelAdmin::STRUCTURED_EVENT;

    CosNotifyChannelAdmin::ProxyConsumer_var proxyCon_obj;
    try
    {
      proxyCon_obj = sa->obtain_notification_push_consumer(ctype, proxy_id);
    }
    catch(CosNotifyChannelAdmin::AdminLimitExceeded err)
    {
      std::cerr << "CosNotifyChannelAdmin::AdminLimitExceeded Exception!" << std::endl;
      throw;
    }

    CosNotifyChannelAdmin::StructuredProxyPushConsumer_var ppc =
      CosNotifyChannelAdmin::StructuredProxyPushConsumer::_narrow(proxyCon_obj.in());

    //Connecting a Supplier to a Proxy Consumer
    try
    {
      ppc->connect_structured_push_supplier(sps.in());
    }
    catch (CosEventChannelAdmin::AlreadyConnected ac)
    {
      std::cerr << "CosEventChannelAdmin::AlreadyConnected" << std::endl;
      throw;
    }
    catch (CORBA::SystemException& se)
    {
      std::cerr << "System exception occurred during connect: " <<
        se << std::endl;
      throw;
    }


    //Demo::demo_send_heart_beat(ppc);
    //Send a Demo Notification

    CosNotification::StructuredEvent event;

    event.header.fixed_header.event_type.domain_name =
      CORBA::string_dup("Test_domain");
    event.header.fixed_header.event_type.type_name =
      CORBA::string_dup("Test_type_name");

    event.header.variable_header.length(0);
    event.remainder_of_body <<= "";

    std::cout << "Sending a demo event...," << std::endl;
    std::cout << "event.header.fixed_header.event_type.domain_name = "
      << event.header.fixed_header.event_type.domain_name
      << std::endl;
    std::cout << "event.header.fixed_header.event_type.type_name = "
      << event.header.fixed_header.event_type.type_name
      << std::endl;


    try{
      ppc->push_structured_event(event);
    }
    catch (CORBA::SystemException& se)
    {
      std::cerr << "System exception occurred during push: "
        << se << std::endl;
      throw;
    }
    catch (CORBA::Exception&)
    {
      std::cerr << "Unknown exception occurred during push" << std::endl;
      throw;
    }

    try{
      ppc->disconnect_structured_push_consumer();
    }
    catch(CORBA::Exception&)
    {
      std::cerr << "Disconnect fail!" << std::endl;
    }

    orb->shutdown();
    ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Supplier done.\n")));
  }
  catch(...)
  {
    std::cerr << "Supplier: Some exceptions was caught!" << std::endl;
    return 1;
  }


  return 0;
}
Beispiel #9
0
int main(int argc, char* argv[]) {

  char aux1[1000];
  time_t seconds;

  signal(SIGINT, TerminarEjecucion);

  time(&seconds);
  srand((unsigned int) seconds);

  try {

    // Inicializacion del ORB 
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv, "");

    // Recoge la referencia al canal
    cin >> aux1;   
    CORBA::Object_var obj = orb->string_to_object(aux1);

    // Obtiene el canal
    CosNotifyChannelAdmin::EventChannel_var channel;
    channel = CosNotifyChannelAdmin::EventChannel::_narrow(obj);
    if (CORBA::is_nil(channel)) { 
      cerr << "[supplier2] ERROR: canal nulo " << endl;
      return -1; 
    } 

    // Obtiene el SupplierAdmin
    CosNotifyChannelAdmin::AdminID id;
    _supplier_admin = 
      channel->new_for_suppliers(CosNotifyChannelAdmin::AND_OP, id);
    cerr << "[supplier2] SupplierAdminId = " << id << endl;


    CosNotifyChannelAdmin::ProxyID proxy_id;
    CosNotifyChannelAdmin::ProxyConsumer_var proxy_consumer = 
      _supplier_admin->obtain_notification_push_consumer(
                                          CosNotifyChannelAdmin::STRUCTURED_EVENT,
                                          proxy_id);
    cerr << "[supplier2] ProxyId = " << proxy_id << endl;


    // Obtiene el StructuredProxyPushConsumer
    _consumer = 
      CosNotifyChannelAdmin::StructuredProxyPushConsumer::_narrow(proxy_consumer);

    try{
      CosNotifyComm::StructuredPushSupplier_var supplier = 
        CosNotifyComm::StructuredPushSupplier::_nil();
      _consumer->connect_structured_push_supplier(supplier);
      if (_consumer == NULL)  cerr << "[supplier2] consumer NULO 5" << endl;

    } catch (CORBA::Exception& exc) {
      cerr << "[supplier2] Exception in _consumer->connect_push_supplier(...)";
      cerr << exc << endl;
    } catch (...) {
      cerr << "[supplier2] Unknowed exception ";
      cerr << "in _consumer->connect_push_supplier(...)";
    }



#ifdef _TAO
    sleep(1);
#elif defined _TIDORB
    TIDThr::Thread::sleep(1000); // 1 ''
#endif

    cerr << "[supplier2] Crea un structured event" << flush << endl;

    try{
        
      CosNotification::StructuredEvent* event = NULL;
      int rnd = 0;
        
      for(int i=0; i < 200; i++) {

        rnd = rand();

        TimeBase::UtcT current_utc = TIDorb::core::util::Time::currentUtcT();
        TimeBase::UtcT future_utc  = TIDorb::core::util::Time::currentUtcT();
        TimeBase::UtcT pass_utc    = TIDorb::core::util::Time::currentUtcT();
        future_utc.time += (5 * 10000000); // now + 5 ''
        pass_utc.time   -= (5 * 10000000); // now - 5 ''



        // Rellenamos la informacion del evento   
        event = new CosNotification::StructuredEvent();
        event->header.fixed_header.event_name = 
          (rnd % 2) ? CORBA::string_dup("event_name") : CORBA::string_dup("other");
        event->header.fixed_header.event_type.domain_name = 
          (rnd % 2) ? CORBA::string_dup("domain_name") : CORBA::string_dup("other");
        event->header.fixed_header.event_type.type_name  = 
          (rnd % 2) ? CORBA::string_dup("type_name") : CORBA::string_dup("other");

        event->header.variable_header.length(5); 
        event->header.variable_header[0].name = CORBA::string_dup("EventReliability");
        event->header.variable_header[0].value <<= (CORBA::Short) 0;
        event->header.variable_header[1].name = CORBA::string_dup("Priority");
        event->header.variable_header[1].value <<= (CORBA::Short) 0;
        event->header.variable_header[2].name = CORBA::string_dup("StartTime");
        event->header.variable_header[2].value <<= current_utc;
        event->header.variable_header[3].name = CORBA::string_dup("StopTime");
        event->header.variable_header[3].value <<= pass_utc;
        event->header.variable_header[4].name = CORBA::string_dup("Timeout");
        event->header.variable_header[4].value <<= (TimeBase::TimeT) 0;

        event->filterable_data.length(2);
        event->filterable_data[0].name = CORBA::string_dup("int");
        event->filterable_data[0].value <<= ( rnd * 1000 ) ;
        event->filterable_data[1].name = CORBA::string_dup("string");
        event->filterable_data[1].value <<= ( (rnd % 2) ? 
                                              (const char*)"greater" : 
                                              (const char*)"smaller" );
        event->remainder_of_body <<= (const char*) "remainder_of_body";
        CORBA::Long my_long;
        event->filterable_data[0].value >>= my_long;


        cout << "Enviando mensage " << my_long;
        cout << ": " << event->header.fixed_header.event_type.domain_name << ", ";
        cout << event->header.fixed_header.event_type.type_name << endl; 
          
          
        // Envia el evento
        _consumer->push_structured_event(*event);


        delete event;
        event = NULL;
      } // for
      
      cerr << "[supplier2] Desconectando... " << flush << endl;
      _consumer->disconnect_structured_push_consumer();      

    } catch(...){
      cerr << "[supplier2] Excepcion " << endl;
    }
    _supplier_admin->destroy();    

    cerr << "[supplier2] Terminando" << flush << endl;
    orb->shutdown(true);
    orb->destroy();


  } catch(CORBA::Exception& exc) {
    cerr << "[supplier2] Excepcion: " << exc << endl;
    return 1;
  }

}
Beispiel #10
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
    int status = 0;
    ACE_Auto_Ptr< sig_i > sig_impl;
    try
    {
        Supplier_Client client;
        status = client.init (argc, argv);

        if (status == 0)
        {
            static const char* ec_name = "MyEventChannel";
            CosNotifyChannelAdmin::EventChannel_var ec =
                client.create_event_channel (ec_name, 0);

            static const int max = 20;
            int count = 0;
            while(ACE_OS::access(ACE_TEXT_ALWAYS_CHAR(notify2ior), R_OK) == -1 && count < max)
            {
                ACE_OS::sleep (1);
                count++;
            }
            if (count >= max)
            {
                ACE_ERROR_RETURN ((LM_ERROR,
                                   "ERROR: Timed out waiting for the "
                                   "second notify service\n"),
                                  1);
            }
            ACE_OS::sleep (2);

            // Due to the way that connections are handled, we need to
            // perform the new event channel creation twice to flush out
            // the connection to the first notification service
            try
            {
                ec = client.create_event_channel (ec_name, 0);
            }
            catch (const CORBA::TRANSIENT&)
            {
            }
            catch (const CORBA::COMM_FAILURE&)
            {
            }

            ec = client.create_event_channel (ec_name, 0);

            CORBA::ORB_ptr orb = client.orb ();

            // Activate the signaler with the POA
            sig_impl.reset( new sig_i( orb ) );
            sig_var sig = sig_impl->_this ();

            CORBA::String_var ior =
                orb->object_to_string (sig.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 %s for "
                                       "writing IOR: %C",
                                       ior_output_file,
                                       ior.in ()),
                                      1);
                ACE_OS::fprintf (output_file, "%s", ior.in ());
                ACE_OS::fclose (output_file);
            }

            CosNotifyChannelAdmin::SupplierAdmin_var admin =
                create_supplieradmin (ec.in ());
            if (!CORBA::is_nil (admin.in ()))
            {
                create_suppliers (admin.in (), client.root_poa ());

                sig_impl->wait_for_startup();

                ACE_DEBUG((LM_DEBUG, "1 supplier sending %d events...\n", max_events));
                for (int i = 0; i < max_events; ++i)
                {
                    ACE_DEBUG((LM_DEBUG, "+"));
                    SendEvent (i);
                }
                ACE_DEBUG((LM_DEBUG, "\nSupplier sent %d events.\n", max_events));

                sig_impl->wait_for_completion();

                ACE_OS::unlink (ior_output_file);

                supplier_1->disconnect();

                ec->destroy();
            }
        }
    }
    catch (const CORBA::Exception& e)
    {
        e._tao_print_exception ("Error: ");
        status = 1;
    }

    return status;
}
Beispiel #11
0
int ACE_TMAIN (int argc, ACE_TCHAR* argv[])
{
  int status = 0;
  try
    {
      Supplier_Client client;
      status = client.init (argc, argv);

      if (status == 0)
        {
          CosNotifyChannelAdmin::EventChannel_var ec =
            client.create_event_channel ("MyEventChannel", 0);

          CORBA::ORB_ptr orb = client.orb ();

          sig_i* sig_impl;
          ACE_NEW_RETURN (sig_impl, sig_i (orb), 1);
          PortableServer::ServantBase_var owner_transfer(sig_impl);

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

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

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

          sig_var sig = sig::_narrow (object.in ());

          CORBA::String_var ior = orb->object_to_string (sig.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);
            }

          CosNotifyChannelAdmin::SupplierAdmin_var admin =
            create_supplieradmin (ec.in ());
          if (!CORBA::is_nil (admin.in ()))
            {
              create_suppliers (admin.in (), client.root_poa ());

              sig_impl->wait_for_startup();

              ACE_DEBUG ((LM_DEBUG,
                          "1 supplier sending %d events...\n", max_events));
              for (int i = 0; i < max_events; ++i)
              {
                ACE_DEBUG ((LM_DEBUG, "+"));
                SendEvent (i);
              }
              ACE_DEBUG ((LM_DEBUG,
                          "\nSupplier sent %d events.\n", max_events));

              ACE_OS::unlink (ior_output_file);
              supplier_1->disconnect ();

              ec->destroy ();
            }
        }
    }
  catch (const CORBA::Exception& e)
    {
      e._tao_print_exception ("Supplier Error: ");
      status = 1;
    }

  return status;
}
Beispiel #12
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  ACE_Auto_Ptr< sig_i > sig_impl;
  try
  {
    Notify_Test_Client client;
    int status = client.init (argc, argv);
    ACE_UNUSED_ARG(status);
    ACE_ASSERT(status == 0);

    CosNotifyChannelAdmin::EventChannel_var ec =
      client.create_event_channel ("MyEventChannel", 0);

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

    CORBA::ORB_ptr orb = client.orb ();

    sig_impl.reset( new sig_i( orb ) );
    sig_var sig = sig_impl->_this ();

    CosNotifyChannelAdmin::SupplierAdmin_var admin =
      create_supplieradmin (ec.in ());
    ACE_ASSERT(! CORBA::is_nil (admin.in ()));

    create_supplier (admin.in (), client.root_poa ());

    if (ior_file != 0)
    {
      CORBA::String_var ior =
        client.orb ()->object_to_string (sig.in ());

      FILE *output_file= ACE_OS::fopen (ACE_TEXT_ALWAYS_CHAR(ior_file), "w");
      ACE_ASSERT (output_file != 0);
      ACE_OS::fprintf (output_file, "%s", ior.in ());
      ACE_OS::fclose (output_file);
    }

    ACE_DEBUG((LM_DEBUG, "Supplier ready...\n"));

    sig_impl->wait_for_startup();

    ACE_DEBUG((LM_DEBUG, "Supplier sending %d events...\n", num_events));
    for (int i = 0; i < num_events; ++i)
    {
      ACE_DEBUG((LM_DEBUG, "+"));
      send_event (i);
    }
    ACE_DEBUG((LM_DEBUG, "\nSupplier sent %d events.\n", num_events));

    sig_impl->wait_for_completion();

    ACE_OS::unlink (ior_file);

    ec->destroy();

    return 0;
  }
  catch (const CORBA::Exception& e)
  {
    e._tao_print_exception ("Error: Supplier: ");
  }

  return 1;
}
Beispiel #13
0
int
ACE_TMAIN (int argc, ACE_TCHAR* argv[])
{
  int status = 0;
  ACE_Auto_Ptr<sig_i> sig_impl;
  try
    {
      Supplier_Client client;
      ACE_Argv_Type_Converter argcon (argc, argv);
      status = client.init (argcon.get_argc (), argcon.get_TCHAR_argv ());

      if (status == 0)
        {
          CosNotifyChannelAdmin::EventChannel_var ec =
            client.create_event_channel ("MyEventChannel", 0);

          sig_impl.reset (new sig_i (client.orb ()));
          sig_var sig = sig_impl->_this ();

          // If the ior_output_file exists, output the ior to it
          if (ior_output_file != 0)
            {
              CORBA::String_var ior =
                client.orb ()->object_to_string (sig.in ());

              FILE *output_file= ACE_OS::fopen (ior_output_file, ACE_TEXT ("w"));
              ACE_ASSERT (output_file != 0);
              ACE_OS::fprintf (output_file, "%s", ior.in ());
              ACE_OS::fclose (output_file);
            }

          CosNotifyChannelAdmin::SupplierAdmin_var admin =
            create_supplieradmin (ec.in ());
          ACE_ASSERT (!CORBA::is_nil (admin.in ()));

          create_suppliers (admin.in (), client.root_poa ());

          sig_impl->wait_for_startup ();

          // If this is changed, you should update max_events
          // found in Notify_Push_Consumer.cpp
          int batch_size = 4;
          int num_events = 80 / batch_size;
          ACE_DEBUG ((LM_DEBUG,
                      "1 supplier sending %d batches of %d events...\n",
                      num_events, batch_size));
          CosNotification::EventBatch events;
          events.length(batch_size);
          for (int i = 0; i < num_events; ++i)
            {
              supplier_1->send_events (events);
            }
          ACE_DEBUG ((LM_DEBUG, "\nSupplier sent %d events.\n", num_events));

          sig_impl->wait_for_completion ();

          ACE_OS::unlink (ior_output_file);

          supplier_1->disconnect ();

          ec->destroy ();
        }
    }
  catch (const CORBA::Exception& e)
  {
    e._tao_print_exception ("Error: ");
    status = 1;
  }

  return status;
}
Beispiel #14
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  ACE_Auto_Ptr< sig_i > sig_impl;
  int status = 0;
  try
  {
    Supplier_Client client;

    status = client.init (argc, argv);

    if (status == 0)
    {
      CosNotifyChannelAdmin::EventChannel_var ec =
        client.create_event_channel ("MyEventChannel", 0);

      CORBA::ORB_ptr orb = client.orb ();

      sig_impl.reset( new sig_i( orb ) );
      sig_var sig = sig_impl->_this ();

      CORBA::String_var ior =
        orb->object_to_string (sig.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 %s for "
          "writing IOR: %C",
          ior_output_file,
          ior.in ()),
          1);
        ACE_OS::fprintf (output_file, "%s", ior.in ());
        ACE_OS::fclose (output_file);
      }

      CosNotifyChannelAdmin::SupplierAdmin_var admin =
        create_supplieradmin (ec.in ());
      if (!CORBA::is_nil (admin.in ()))
      {
        create_suppliers(admin.in (), client.root_poa ());

        sig_impl->wait_for_startup();

        ACE_DEBUG((LM_DEBUG, " 1 supplier sending %d batches of %d events...\n", num_batches, PER_BATCH));
        for (int i = 0; i < num_batches; ++i)
        {
          ACE_DEBUG((LM_DEBUG, "+"));
          SendEvents (i);
        }
        ACE_DEBUG((LM_DEBUG, "\nSupplier waiting for consumer completion...\n"));

        sig_impl->wait_for_completion();

        ACE_DEBUG((LM_DEBUG, "\nSupplier finished.\n"));

        ACE_OS::unlink (ior_output_file);

        ec->destroy();
      }
    }
  }
  catch (const CORBA::Exception& e)
  {
    e._tao_print_exception ("Error: Supplier exception: ");
    status = 1;
  }

  return status;
}
Beispiel #15
0
void TerminarEjecucion (int){
  cerr << "CTRL-C recibido: Terminado ejecucion..." << endl;
  _consumer->disconnect_structured_push_consumer(); 
  _supplier_admin->destroy();    
  exit(0);
}
Beispiel #16
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  ACE_Auto_Ptr< sig_i > sig_impl;
  try
  {
    Supplier_Client client;
    int status = client.init (argc, argv);
    ACE_UNUSED_ARG(status);
    ACE_ASSERT(status == 0);

    CosNotifyChannelAdmin::EventChannel_var ec =
      client.create_event_channel ("MyEventChannel", 0);

    CosNotification::QoSProperties qos (1);
    qos.length (1);
    qos[0].name = CORBA::string_dup (CosNotification::OrderPolicy);
    qos[0].value <<= order_policy;
    ec->set_qos (qos);

    CORBA::ORB_ptr orb = client.orb ();

    sig_impl.reset( new sig_i( orb ) );
    sig_var sig = sig_impl->_this ();

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

    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 %s for "
        "writing IOR: %C",
        ior_output_file,
        ior.in ()),
        1);
      ACE_OS::fprintf (output_file, "%s", ior.in ());
      ACE_OS::fclose (output_file);
    }

    CosNotifyChannelAdmin::SupplierAdmin_var admin =
      create_supplieradmin (ec.in ());
    ACE_ASSERT(!CORBA::is_nil (admin.in ()));
    create_suppliers (admin.in (), client.root_poa ());

    sig_impl->wait_for_startup();

    ACE_DEBUG((LM_DEBUG, "1 supplier sending %d events...\n", num_events));
    for (int i = 0; i < num_events / BATCH_SIZE; ++i)
    {
      ACE_DEBUG((LM_DEBUG, "+"));
      SendBatch (i);
    }
    ACE_DEBUG((LM_DEBUG, "\nSupplier sent %d events.\n", num_events));

    sig_impl->wait_for_completion();

    ACE_OS::unlink (ior_output_file);

    supplier_1->disconnect();

    ec->destroy();

    return 0;
  }
  catch (const CORBA::Exception& e)
  {
    e._tao_print_exception ("Error: ");
  }

  return 1;
}
Beispiel #17
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
    ACE_Auto_Ptr< sig_i > sig_impl;
    try
    {
        Consumer_Client client;
        int status = client.init (argc, argv);
        ACE_UNUSED_ARG(status);
        ACE_ASSERT(status == 0);

        CosNotifyChannelAdmin::EventChannel_var ec =
            client.create_event_channel ("MyEventChannel", 0);

        CORBA::ORB_ptr orb = client.orb ();

        sig_impl.reset( new sig_i( orb ) );
        sig_var sig = sig_impl->_this ();

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

        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 %s for "
                                   "writing IOR: %C",
                                   ior_output_file,
                                   ior.in ()),
                                  1);
            ACE_OS::fprintf (output_file, "%s", ior.in ());
            ACE_OS::fclose (output_file);
        }

        CosNotifyChannelAdmin::SupplierAdmin_var admin =
            create_supplieradmin (ec.in ());
        ACE_ASSERT(!CORBA::is_nil (admin.in ()));
        create_suppliers (admin.in (), &client);

        sig_impl->wait_for_startup();

        ACE_DEBUG((LM_DEBUG, "%i supplier(s) sending %d events...\n", supplier_count, event_count));
        for (int i = 0; i < event_count; ++i)
        {
            ACE_DEBUG((LM_DEBUG, "+"));
            SendEvent (i);
        }
        ACE_DEBUG((LM_DEBUG, "\nEach Supplier sent %d events.\n", event_count));

        sig_impl->wait_for_completion();

        ACE_OS::unlink (ior_output_file);

        disconnect_suppliers();

        ec->destroy();

        return 0;
    }
    catch (const CORBA::Exception& e)
    {
        e._tao_print_exception ("Error: ");
    }

    return 1;
}