Example #1
0
static CosNotifyChannelAdmin::ConsumerAdmin_ptr
create_consumeradmin (CosNotifyChannelAdmin::EventChannel_ptr ec)
{
  CosNotifyChannelAdmin::AdminID adminid = 0;
  CosNotifyChannelAdmin::ConsumerAdmin_var admin =
    ec->new_for_consumers (CosNotifyChannelAdmin::AND_OP,
                           adminid);


  if (filter)
    {
      ACE_DEBUG((LM_DEBUG, "\nConsumer filter enabled.\n"));

      CosNotifyFilter::FilterFactory_var ffact =
          ec->default_filter_factory ();

      CosNotifyFilter::Filter_var filter =
          ffact->create_filter (GRAMMAR);

      CosNotifyFilter::ConstraintExpSeq constraint_list (1);
      constraint_list.length (1);

      constraint_list[0].event_types.length (0);
      constraint_list[0].constraint_expr =
                                 CORBA::string_dup ("type == 'even'");

      filter->add_constraints (constraint_list);

      admin->add_filter (filter.in ());
    }

  return CosNotifyChannelAdmin::ConsumerAdmin::_duplicate (admin.in ());
}
Example #2
0
static CosNotifyChannelAdmin::ConsumerAdmin_ptr
create_consumeradmin (CosNotifyChannelAdmin::EventChannel_ptr ec)
{
  CosNotifyChannelAdmin::AdminID adminid = 0;
  CosNotifyChannelAdmin::ConsumerAdmin_var admin =
    ec->new_for_consumers (CosNotifyChannelAdmin::OR_OP, adminid);

  return CosNotifyChannelAdmin::ConsumerAdmin::_duplicate (admin.in ());
}
Example #3
0
template <class SERVANT_TYPE> CosNotifyChannelAdmin::ConsumerAdmin_ptr
TAO_Notify_ProxySupplier_T<SERVANT_TYPE>::MyAdmin (void)
{
  CosNotifyChannelAdmin::ConsumerAdmin_var ret;

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

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

  return ret._retn ();
}
Example #4
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  int status = 0;
  try
  {
    Consumer_Client client;

    status = client.init (argc, argv);
    ACE_UNUSED_ARG(status);
    ACE_ASSERT(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);

    sig_var sig = sig::_narrow (object.in ());
    ACE_ASSERT(! CORBA::is_nil (sig.in ()));

    CosNotifyChannelAdmin::ConsumerAdmin_var admin =
      create_consumeradmin (ec.in ());
    ACE_ASSERT(!CORBA::is_nil (admin.in ()));

    create_consumers (admin.in (), &client);

    // Tell the supplier to go
    sig->go ();

    ACE_DEBUG((LM_DEBUG, "Consumer waiting for events...\n"));

    client.ORB_run( );

    ACE_DEBUG((LM_DEBUG, "Consumer done.\n"));
    consumer_1->disconnect();

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

  return status;
}
Example #5
0
bool
IdAssignment::default_consumer_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::ConsumerAdmin_var default_consumer_admin =
    ec->get_consumeradmin (0);

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

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

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

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

  return true;
}
Example #6
0
int ACE_TMAIN (int argc, ACE_TCHAR* argv[])
{
  int status = 0;
  try
    {
      Consumer_Client client;

      status = client.init (argc, argv);
      if (status != 0)
        ACE_ERROR_RETURN ((LM_ERROR, "Error: Client init failed.\n"),1);

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

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

      CosNotifyChannelAdmin::ConsumerAdmin_var admin =
        create_consumeradmin (ec.in ());

      if (CORBA::is_nil (admin.in ()))
        ACE_ERROR_RETURN ((LM_ERROR, "Error: nil ConsumerAdmin.\n"),1);

      create_consumers (admin.in (), &client);

      ACE_DEBUG ((LM_DEBUG, "\nConsumer waiting for events...\n"));

      sig->go ();
      ACE_Time_Value tv (5);
      orb->run (tv);

      ACE_DEBUG ((LM_DEBUG, "Consumer done.\n"));
    }
  catch (const CORBA::Exception& e)
    {
      e._tao_print_exception ("Consumer Error: ");
      status = 1;
    }

  return status;
}
Example #7
0
  virtual bool execute (const char* command)
  {
    if (ACE_OS::strcmp (command, TAO_NS_CONTROL_REMOVE_CONSUMERADMIN) == 0)
      {
        CosNotifyChannelAdmin::ConsumerAdmin_var admin =
          this->ec_->get_consumeradmin (this->id_);

        if (!CORBA::is_nil (admin.in ()))
          {
            admin->destroy ();
          }
      }
    else
      {
        return false;
      }

    return true;
  }
Example #8
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;
}
Example #9
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();

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

    poa_manager->activate();

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

    //Instanciating the Consumer
    CosNotifyComm::StructuredPushConsumer_var spc =
      CosNotifyComm::StructuredPushConsumer::_nil();

    CosNotifyCommImpl::StructuredPushConsumer *pImpl_spc = new CosNotifyCommImpl::StructuredPushConsumer;
    spc = pImpl_spc->_this();

    //Obtain a Consumer Admin
    CosNotifyChannelAdmin::AdminID adminid = 0;
    CosNotifyChannelAdmin::ConsumerAdmin_var ca =
      ec->new_for_consumers (CosNotifyChannelAdmin::AND_OP, adminid);

    if( ca.in() == CosNotifyChannelAdmin::ConsumerAdmin::_nil() ){
      std::cerr << "ca is nil!" << std::endl;
      return 1;
    }

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

    CosNotifyChannelAdmin::ProxySupplier_var proxySupplier_obj;
    try
    {
      proxySupplier_obj = ca->obtain_notification_push_supplier(ctype, proxy_id);
    }
    catch(CosNotifyChannelAdmin::AdminLimitExceeded err)
    {
      std::cerr << "CosNotifyChannelAdmin::AdminLimitExceeded Exception!" << std::endl;
      throw;
    }

    CosNotifyChannelAdmin::StructuredProxyPushSupplier_var pps =
      CosNotifyChannelAdmin::StructuredProxyPushSupplier::_narrow(proxySupplier_obj.in());


    //Attaching a filter to pps
    CosNotifyFilter::FilterFactory_var dff =
      ec->default_filter_factory();

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

    CosNotifyFilter::Filter_var filter = dff->create_filter("EXTENDED_TCL");

    CosNotification::EventTypeSeq event_types(1);
    event_types.length(2);

    event_types[0].domain_name = CORBA::string_dup("DomainA");
    event_types[0].type_name = CORBA::string_dup("TypeA");
    event_types[1].domain_name = CORBA::string_dup("DomainB");
    event_types[1].type_name = CORBA::string_dup("TypeB");

    CosNotifyFilter::ConstraintExpSeq constraints(1);
    constraints.length(1);

    constraints[0].event_types = event_types;
    constraints[0].constraint_expr = CORBA::string_dup(
      "");

    filter->add_constraints(constraints);

    pps->add_filter(filter.in());

    std::cout << "Attached a filter to ProxyPushSupplier" << std::endl;
    std::cout << "The filter's event_types[0].domain_name=" <<  event_types[0].domain_name << std::endl;
    std::cout << "The filter's event_types[0].type_name=" <<  event_types[0].type_name << std::endl;
    std::cout << "The filter's event_types[1].domain_name=" <<  event_types[1].domain_name << std::endl;
    std::cout << "The filter's event_types[1].type_name=" <<  event_types[1].type_name << std::endl;


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


    ACE_Time_Value tv (runtime);
    orb->run (tv);
    ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Consumer done.\n")));

    if (pImpl_spc->received_events ())
    {
      //Consumer should not receive any events as it's filtered with event type.
      std::cerr << "Test failed - received test events." << std::endl;
      return 1;
    }
    else
    {
      std::cerr << "Test passed - did not receive test events as expected." << std::endl;
    }
  }
  catch(...)
  {
    std::cerr << "Consumer: Some exceptions was caught!" << std::endl;
    return 1;
  }


  return 0;
}
Example #10
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
  {
    Consumer_Client client;

    int status = client.init (argc, argv);
    ACE_ASSERT(status == 0);
    ACE_UNUSED_ARG(status);

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

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

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

    CosNotifyChannelAdmin::ConsumerAdmin_var admin =
      create_consumeradmin (ec.in ());

    if (filter)
    {
      CosNotifyFilter::FilterFactory_var ffact =
        ec->default_filter_factory ();

      CosNotifyFilter::Filter_var filter =
        ffact->create_filter ("TCL");

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

      CosNotifyFilter::ConstraintExpSeq constraint_list (1);
      constraint_list.length(1);

      constraint_list[0].event_types.length (0);
      constraint_list[0].constraint_expr = CORBA::string_dup(ACE_TEXT_ALWAYS_CHAR (constraintString));

      filter->add_constraints (constraint_list);

      admin->add_filter(filter.in());
    }

    ACE_ASSERT (!CORBA::is_nil (admin.in ()));
    create_consumers(admin.in (), &client);

    // Tell the supplier to go
    sig->go ();

    client.ORB_run( );
    ACE_DEBUG((LM_DEBUG, "Consumer done.\n"));

    sig->done ();

    return 0;

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

  return 1;
}
Example #11
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  int status = 0;
  try
    {
      Consumer_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);

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

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

          CosNotifyChannelAdmin::ConsumerAdmin_var admin =
            ec->default_consumer_admin();

          CosNotifyFilter::Filter_var filter =
            create_proxyFilter (ec.in());

          if (!CORBA::is_nil (admin.in ()))
            {
              create_consumers (admin.in (), &client, filter.in());

              // Tell the supplier to go
              sig->go ();

              ACE_Time_Value tv(10, 0);
              client.ORB_run(tv);
              ACE_DEBUG((LM_DEBUG, "Consumer done.\n"));

              sig->done ();

              ACE_DEBUG((LM_DEBUG, "Expected %d message(s) and received %d message(s).\n",
                expect_fail == 1 ? 0 : 1, consumer_1->messages_received()));

              if (1 == expect_fail)
                status = consumer_1->messages_received() == 0 ? 0 : 1;
              else
                status = consumer_1->messages_received() == 1 ? 0 : 1;

              ACE_DEBUG((LM_DEBUG, "Test status is %s.\n", status == 1 ? "fail" : "pass"));

            }
        }
    }
  catch (const CORBA::Exception& e)
    {
      e._tao_print_exception ("Error: Consumer exception: ");
      status = 1;
    }

  return status;
}
Example #12
0
int main(int argc, char* argv[]){

  char aux1[1000];


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

    CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
    PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj);
    PortableServer::POAManager_var manager = root_poa->the_POAManager();


    //
    // Obtain NamincContext reference ...
    //
    CORBA::Object_var naming_context_object;
    CosNaming::NamingContext_ptr naming_context;
    try {
       naming_context_object = 
         orb->string_to_object("corbaloc:iiop:[email protected]:2809/NameService");
       naming_context =
          CosNaming::NamingContext::_narrow (naming_context_object.in ());
    } catch (...) {
       cerr << "Error: cannot obtain naming service initial reference" << endl;
       throw; 
    }

    //
    // Crea un POA para el supplier: PERSISTENT LifespanPolicy, USER_ID policy
    // 

    PortableServer::LifespanPolicy_var lifespan =
      root_poa->create_lifespan_policy(PortableServer::PERSISTENT);
    
    PortableServer::IdAssignmentPolicy_var idAssignment =
      root_poa->create_id_assignment_policy(PortableServer::USER_ID);
    
    CORBA::PolicyList policies(2);  
    policies.length(2);
    policies[0] = PortableServer::IdAssignmentPolicy::_duplicate(idAssignment);
    policies[1] = PortableServer::LifespanPolicy::_duplicate(lifespan);
    
    PortableServer::POA_var consumer_poa =
      root_poa->create_POA("consumerPOA", manager.in(), policies);

    PortableServer::POAManager_var consumer_poa_manager = 
      consumer_poa->the_POAManager();

    idAssignment->destroy();
    lifespan->destroy();

    // Activa el POAManager
    manager->activate();


    //
    // Crea y activa el servant del consumer
    // 

    PortableServer::ObjectId_var oid = 
      PortableServer::string_to_ObjectId("MyConsumer");

    MyConsumerImpl servant_consumer;

    try{
      consumer_poa->activate_object_with_id(oid.in(), &servant_consumer);
    }
    catch(...){
      cerr << "[supplier] ERROR: activating servant_supplier " << endl;
    }
    CORBA::Object_var consumer_obj = consumer_poa->id_to_reference(oid.in());


    CosEventComm::PushConsumer_var consumer =
      CosEventComm::PushConsumer::_narrow(consumer_obj);


    //
    // Recoge la referencia al canal
    //
    // readChannelIOR();
    // obj = orb->string_to_object(ChannelIOR);
    CosNaming::NamingContext_var naming_context_notif = NULL;
    CosNaming::Name name_notif(2);
    name_notif.length (2);
    name_notif[0].id = CORBA::string_dup ("MyNotif");
    name_notif[0].kind = CORBA::string_dup ("");
    name_notif[1].id = CORBA::string_dup ("channel");
    name_notif[1].kind = CORBA::string_dup ("");
    obj = naming_context->resolve(name_notif);

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


    // 
    // Obtenemos el manager 
    // 
    CosNotifyChannelAdmin::ConsumerAdmin_var consumerAdmin;
    CosNotifyChannelAdmin::AdminID adminid;
    
    try{
      consumerAdmin = channel->default_consumer_admin();   
    }
    catch(CORBA::Exception &ce){
      fprintf(stderr,"(%s)%i CORBA::Exception - %s\n",
              __FILE__,__LINE__,ce._name());
    }
    catch(...){
      fprintf(stderr,"(%s)%i - Unexpected exception!",
              __FILE__,__LINE__);
    }


    //
    // Obtenemos el proxy
    // 
    CosNotifyChannelAdmin::ProxyPushSupplier_var pushSupplier;
    CosNotifyChannelAdmin::ProxyID proxy_id;
    CosNotifyChannelAdmin::ClientType ctype = CosNotifyChannelAdmin::ANY_EVENT;

    try{
      CosNotifyChannelAdmin::ProxySupplier_var obj =
        consumerAdmin->obtain_notification_push_supplier(ctype, proxy_id);
      
      pushSupplier = CosNotifyChannelAdmin::ProxyPushSupplier::_narrow(obj);
      
      // Conecta proxy
      pushSupplier->connect_any_push_consumer(consumer);

    }
    catch(CosEventChannelAdmin::AlreadyConnected &ac){
      fprintf(stderr,"(%s)%i CosEventChannelAdmin::AlreadyConnected\n",
              __FILE__,__LINE__);
    }
    catch(CORBA::SystemException& se){
      fprintf(stderr,"(%s)%i CORBA::SystemException\n",
              __FILE__,__LINE__);
    }
    catch(CosNotifyChannelAdmin::AdminLimitExceeded err){
      fprintf(stderr,"(%s)%i CosNotifyChannelAdmin::AdminLimitExceeded\n",
              __FILE__,__LINE__);
    }
    catch(CORBA::Exception &ce){
      fprintf(stderr,"(%s)%i CORBA::Exception - %s\n",
              __FILE__,__LINE__,ce._name());
    }
    catch(...){
      fprintf(stderr,"Unexpected exception!\n");
    }

//     // 
//     // Guarda la referencia en el Servicio de Nombres
//     // 

//     CosNaming::NamingContext_var naming_context_notif = NULL;
//     CosNaming::Name name_notif(1);
//     name_notif.length (1);
//     name_notif[0].id = CORBA::string_dup ("MyNotif");
//     name_notif[0].kind = CORBA::string_dup ("");

//     naming_context_notif = naming_context->bind_new_context(name_notif);

//     CosNaming::Name name_consumer(1);
//     name_consumer.length (1);
//     name_consumer[0].id = CORBA::string_dup ("consumer");
//     name_consumer[0].kind = CORBA::string_dup ("");
//     naming_context_notif->bind(name_consumer, consumer_obj);



    cerr << "[consumer] Esperando eventos.... " << endl;


    orb->run();  

    cerr << "[consumer] disconnect .... " << endl;
//     supplier->disconnect_push_supplier();
//     consumeradmin->destroy();

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



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

}
Example #13
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  int status = 0;

  try
    {
      Consumer_Client client;
      status = client.init (argc, argv);

      if (status != 0)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Error: Client init failed.\n"),
                            1);
        }

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

#ifdef TEST_QOS_MAX_QUEUE_LENGTH
      ACE_OS::printf ("%s: setting max queue length to 1000\n", argv[0]);
      CosNotification::AdminProperties properties(1);
      properties.length(1);
      properties[0].name = CORBA::string_dup (CosNotification::MaxQueueLength);
      properties[0].value <<= 1000;
      ec->set_admin(properties);
#endif //TEST_QOS_MAX_QUEUE_LENGTH

      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: Narrow failed.\n"),
                            1);
        }

      CosNotifyChannelAdmin::ConsumerAdmin_var admin =
        create_consumeradmin (ec.in ());

      if (CORBA::is_nil (admin.in ()))
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Error: nil ConsumerAdmin.\n"),
                            1);
        }

      create_consumers (admin.in (), &client);

      sig->running (MonitorTestInterface::Consumer);

      ACE_DEBUG ((LM_DEBUG, "\nConsumer waiting for events...\n"));

      FILE* ready_file = ACE_OS::fopen (ACE_TEXT_ALWAYS_CHAR(ready_output_file), "w");

      if (ready_file == 0)
        {
          ACE_ERROR_RETURN ((LM_ERROR,
                             "Cannot open ready file for writing\n"),
                            1);
        }

      ACE_OS::fprintf (ready_file, "ready\n");
      ACE_OS::fclose (ready_file);

      client.ORB_run ();
#ifdef PAUSE_ON_EXIT
      _cputs( "All events received. Still connected.\n");
      _cputs( "Hit a key to exit consumer: " );
      _getch();
#endif // PAUSE_ON_EXIT
      ACE_DEBUG ((LM_DEBUG, "Consumer done.\n"));
      consumer_1->disconnect ();

      ec->destroy ();

      sig->finished (MonitorTestInterface::Consumer);
    }
  catch (const CORBA::Exception& e)
    {
      e._tao_print_exception ("Consumer Error: ");
      status = 1;
    }

  return status;
}
Example #14
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  int status = 0;
  try
    {
      Consumer_Client client;

      status = client.init (argc, argv);

      if (status == 0)
        {
          // If we are filtering, we will get half as many as originally
          // expected
          if (filter)
            {
              expected /= 2;
            }

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

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

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

          CosNotifyChannelAdmin::ConsumerAdmin_var admin =
            create_consumeradmin (ec.in ());

          if (!CORBA::is_nil (admin.in ()))
            {
              create_consumers(admin.in (), &client);

              // Tell the supplier to go
              sig->go ();

              client.ORB_run();

              ACE_DEBUG((LM_DEBUG, "Consumer done.\n"));

              sig->done ();
            }
        }
    }
  catch (const CORBA::Exception& e)
    {
      e._tao_print_exception ("Error: Consumer exception: ");
      status = 1;
    }

  return status;
}