Ejemplo n.º 1
0
CosNotifyFilter::FilterID
ExtendedFilter::add_filter (CosNotifyFilter::FilterAdmin_ptr filter_admin)
{
  // setup a filter at the filter admin
  CosNotifyFilter::Filter_var filter =
    this->ffact_->create_filter ("ETCL");

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

  const char* test_filter_string = "A > B";

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

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

  filter->add_constraints (constraint_list);

  CosNotifyFilter::FilterID id = filter_admin->add_filter (filter.in ());

  // Print the ID
  if (TAO_debug_level)
    ACE_DEBUG ((LM_DEBUG, "Added Filter %d\n", id));

  return id;
}
Ejemplo n.º 2
0
void Consumer::setAntennaName(std::string antennaName) {
    //If the antenna name is already set, do nothing
    if (this->antennaName.compare("") != 0)
        return;
    this->antennaName = antennaName;
    if (antennaName.compare("") != 0) {
        std::cout << "Adding filter" << std::endl;
        CosNotifyFilter::FilterFactory_var filter_factory =
                notifyChannel_m->default_filter_factory();
        CosNotifyFilter::Filter_var filter = filter_factory->create_filter(
                "ETCL");
        if (CORBA::is_nil(filter)) {
            ACS_SHORT_LOG(
                    (LM_ERROR,"Consumer::createConsumer failed for the '%s' channel due the filter cannot be created!", channelName_mp));
        }
        CosNotifyFilter::ConstraintExpSeq constraint_list;
        constraint_list.length(1);
        constraint_list[0].event_types.length(0);
        std::string filter_expr = "$antenna_name == '" + antennaName + "'";
        std::cout << filter_expr << std::endl;
        constraint_list[0].constraint_expr = CORBA::string_dup(
                filter_expr.c_str());
        filter->add_constraints(constraint_list);
        proxySupplier_m->add_filter(filter.in());
    }
}
Ejemplo n.º 3
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 ());
}
Ejemplo n.º 4
0
void
Notify_Push_Supplier::_connect (
                CosNotifyChannelAdmin::SupplierAdmin_ptr supplier_admin,
                CosNotifyChannelAdmin::EventChannel_ptr notify_channel,
                bool useFilter)
{
  CosNotifyComm::StructuredPushSupplier_var objref =
    this->_this ();

  CosNotifyChannelAdmin::ProxyConsumer_var proxyconsumer =
    supplier_admin->obtain_notification_push_consumer (
      CosNotifyChannelAdmin::STRUCTURED_EVENT,
      proxy_id_);

  if (useFilter)
    {
      CosNotifyFilter::FilterFactory_var ffact =
        notify_channel->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 ("group != 0");

      filter->add_constraints (constraint_list);

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

  this->proxy_ =
    CosNotifyChannelAdmin::StructuredProxyPushConsumer::_narrow (
      proxyconsumer.in ());

  this->proxy_->connect_structured_push_supplier (objref.in ());

  // give ownership to POA
  this->_remove_ref ();
}
Ejemplo n.º 5
0
void
TAO_Notify_Tests_Filter_Command::handle_create_filter (void)
{
  CosNotifyFilter::FilterFactory_var ff;

  LOOKUP_MANAGER->resolve (ff , this->factory_.c_str ());

  CosNotifyFilter::Filter_var filter =
    ff->create_filter ("ETCL");

  LOOKUP_MANAGER->_register (filter.in(), this->name_.c_str ());
}
Ejemplo n.º 6
0
void
TAO_Notify_Tests_Filter_Command::handle_add_filter (void)
{
  CosNotifyFilter::Filter_var filter;

  LOOKUP_MANAGER->resolve (filter , this->name_.c_str ());

  CosNotifyFilter::FilterAdmin_var filter_admin;

  LOOKUP_MANAGER->resolve (filter_admin , this->factory_.c_str ());

  filter_admin->add_filter (filter.in ());
}
Ejemplo n.º 7
0
/**
 * register this object
 */
int StubBatchConsumer::init (CORBA::ORB_ptr orb, ::FT::FaultNotifier_var & notifier)
{
  int result = 0;
  this->orb_ = CORBA::ORB::_duplicate (orb);
  this->notifier_ = notifier;
  this->identity_ = "StubBatchConsumer";


  // Use the ROOT POA for now
  CORBA::Object_var poa_object =
    this->orb_->resolve_initial_references (TAO_OBJID_ROOTPOA);

  if (CORBA::is_nil (poa_object.in ()))
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT (" (%P|%t) Unable to initialize the POA.\n")),
                      -1);

  // Get the POA .
  this->poa_ = PortableServer::POA::_narrow (poa_object.in ());


  if (CORBA::is_nil(this->poa_.in ()))
  {
    ACE_ERROR_RETURN ((LM_ERROR,
                       ACE_TEXT (" (%P|%t) Unable to narrow the POA.\n")),
                      -1);
  }

  PortableServer::POAManager_var poa_manager =
    this->poa_->the_POAManager ();

  poa_manager->activate ();

  // Register with the POA.

  this->object_id_ = this->poa_->activate_object (this);

  // find my identity as an object

  CORBA::Object_var this_obj =
    this->poa_->id_to_reference (object_id_.in ());

  CosNotifyFilter::Filter_var filter = CosNotifyFilter::Filter::_nil();

  this->consumer_id_ = notifier->connect_sequence_fault_consumer(
    CosNotifyComm::SequencePushConsumer::_narrow(this_obj.in ()),
    filter.in ());

  return result;
}
Ejemplo n.º 8
0
TAO_Notify::Topology_Object*
TAO_Notify_FilterAdmin::load_child (const ACE_CString &type, CORBA::Long id,
  const TAO_Notify::NVPList& attrs)
{
  if (type == "filter")
  {
   TAO_Notify_Object::ID mapid = 0;
   attrs.load("MapId", mapid);

   TAO_Notify_FilterFactory* factory = ec_->default_filter_factory_servant ();
   CosNotifyFilter::Filter_var filter = factory->get_filter (mapid);

    if (! CORBA::is_nil(filter.in()))
    {
      this->filter_ids_.set_last_used(id);
      if (this->filter_list_.bind (id, filter) != 0)
        throw CORBA::INTERNAL ();
    }
  }
  return this;
}
Ejemplo n.º 9
0
static CosNotifyFilter::Filter_ptr
create_proxyFilter (CosNotifyChannelAdmin::EventChannel_ptr ec)
{
  CosNotifyFilter::FilterFactory_var ffact =
    ec->default_filter_factory ();

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

  if(!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 ("$.domain_name == 'domain1'");

    filter->add_constraints (constraint_list);
    }
  return filter._retn();
}
Ejemplo n.º 10
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;
}
Ejemplo n.º 11
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;
}
Ejemplo n.º 12
0
//-----------------------------------------------------------------------------
int Consumer::addFilter(const char* type_name,
		    const char* filterString)
{
    ACS_TRACE("Consumer::addFilter");
    
    try
	{
	//Create a temporary filter factory
	CosNotifyFilter::FilterFactory_var filterFactory = notifyChannel_m->default_filter_factory();
	if(CORBA::is_nil(filterFactory.in()) == true)
	    {
	    CORBAProblemExImpl err = CORBAProblemExImpl(__FILE__,__LINE__,"nc::Consumer::addFilter");
	    throw err.getCORBAProblemEx();
	    }
	
	//Create a filter
	CosNotifyFilter::Filter_var filter = 0;
	filter = filterFactory->create_filter(getFilterLanguage());
	if(filter.in() == 0)
	    {
	    CORBAProblemExImpl err = CORBAProblemExImpl(__FILE__,__LINE__,"nc::Consumer::addFilter");
	    throw err.getCORBAProblemEx();
	    }
	
	//Create the constraint expression sequence
	CosNotifyFilter::ConstraintExpSeq cexp(1);
	cexp.length(1);
	cexp[0].event_types.length(1);
	cexp[0].event_types[0].domain_name = getChannelDomain();
	cexp[0].event_types[0].type_name   = CORBA::string_dup(type_name);
	cexp[0].constraint_expr            = CORBA::string_dup(filterString);
	
	try
	    {
	    filter->add_constraints(cexp);
	    }
	catch(CosNotifyFilter::InvalidConstraint e)
	    {
	    if (filter.in() != 0)
		{
		filter->destroy();
		filter = 0;
		}
	    
	    ACS_SHORT_LOG((LM_ERROR,"Consumer::addFilter failed for the '%s' channel, '%s' event type, and '%s' filter!",
			   channelName_mp, type_name, filterString));
	    CORBAProblemExImpl err = CORBAProblemExImpl(__FILE__,__LINE__,"nc::Consumer::addFilter");
	    throw err.getCORBAProblemEx();
	    }
	
	return proxySupplier_m->add_filter(filter._retn());
	}
    catch(CORBAProblemEx)
	{
	ACS_SHORT_LOG((LM_TRACE,"Consumer::addFilter failed for the '%s' channel, '%s' event type, and '%s' filter with a nil pointer!",
		       channelName_mp, type_name, filterString));
	throw;
	}
    catch(...)
	{
	ACS_SHORT_LOG((LM_ERROR,"Consumer::addFilter failed for the '%s' channel, '%s' event type, and '%s' filter!",
		       channelName_mp, type_name, filterString));
	CORBAProblemExImpl err = CORBAProblemExImpl(__FILE__,__LINE__,"nc::Consumer::addFilter");
	throw err.getCORBAProblemEx();
	}
}
Ejemplo n.º 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)
        {
          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;
}
Ejemplo n.º 14
0
void
ExtendedFilter::run_filter_test (CosNotifyFilter::FilterAdmin_ptr filter_admin)
{
  if (TAO_debug_level)
    ACE_DEBUG ((LM_DEBUG, "Narrowing CosNotifyFilterExt::FilterFactory\n"));

  CosNotifyFilterExt::FilterFactory_var extffact =
      CosNotifyFilterExt::FilterFactory::_narrow(ffact_.in());
  ACE_ASSERT (!CORBA::is_nil (extffact.in ()));

  if (TAO_debug_level)
    ACE_DEBUG ((LM_DEBUG, "Getting  ec2 FilterFactory\n"));
   CosNotifyFilter::FilterFactory_var  ffact2 = ec2_->default_filter_factory ();

  if (TAO_debug_level)
    ACE_DEBUG ((LM_DEBUG, "Narrowing CosNotifyFilterExt::FilterFactory\n"));
  CosNotifyFilterExt::FilterFactory_var extffact2 =
      CosNotifyFilterExt::FilterFactory::_narrow(ffact2.in());
  ACE_ASSERT (!CORBA::is_nil (extffact2.in ()));

  if (TAO_debug_level)
    ACE_DEBUG ((LM_DEBUG, "Adding a filter\n"));

  CosNotifyFilter::FilterID id_1 = this->add_filter (filter_admin);

  this->verify_filter_count (filter_admin, 1);

  if (TAO_debug_level)
    {
      ACE_DEBUG ((LM_DEBUG, "Calling print_filters\n"));
      this->print_filters (filter_admin);
    }

  if (TAO_debug_level)
    ACE_DEBUG ((LM_DEBUG, "Calling CosNotifyFilterExt::FilterFactory::get_filter\n"));

  CosNotifyFilter::Filter_var filter = extffact->get_filter (id_1);
  ACE_ASSERT (!CORBA::is_nil (filter.in ()));

  if (TAO_debug_level)
    ACE_DEBUG ((LM_DEBUG, "Calling CosNotifyFilterExt::FilterFactory::get_filterid\n"));

  CosNotifyFilter::FilterID id_dup = extffact->get_filterid (filter.in());
  ACE_ASSERT (id_dup == id_1);
#if defined (ACE_NDEBUG)
  ACE_UNUSED_ARG (id_dup );
#endif

  if (TAO_debug_level)
    ACE_DEBUG ((LM_DEBUG, "Calling CosNotifyFilterExt::FilterFactory::get_filterid of non existent filter\n"));

  bool id_lookup_failed = false;
  try {
    CosNotifyFilter::FilterID id_ne = extffact2->get_filterid (filter.in());
    ACE_UNUSED_ARG (id_ne );
  } catch (const CORBA::INTERNAL& ) {
    id_lookup_failed = true;
    }
  ACE_ASSERT (id_lookup_failed );
#if defined (ACE_NDEBUG)
  ACE_UNUSED_ARG (id_lookup_failed );
#endif

  if (TAO_debug_level)
    ACE_DEBUG ((LM_DEBUG, "Calling remove_filter\n"));

  // remove the filter.
  filter_admin->remove_filter (id_1);

  this->verify_filter_count (filter_admin, 0);

  if (TAO_debug_level)
    {
      ACE_DEBUG ((LM_DEBUG, "Calling print_filters\n"));
      this->print_filters (filter_admin);
    }

  if (TAO_debug_level)
    ACE_DEBUG ((LM_DEBUG, "Calling remove_all_filters\n"));

  filter_admin->remove_all_filters ();

  if (TAO_debug_level)
    {
      ACE_DEBUG ((LM_DEBUG, "Calling print_filters\n"));
      this->print_filters (filter_admin);
    }

  // Make sure all filters are removed -
  this->verify_filter_count (filter_admin, 0);

  if (TAO_debug_level)
    ACE_DEBUG ((LM_DEBUG, "Calling CosNotifyFilterExt::FilterFactory::remove_filter\n"));

  extffact->remove_filter(filter.in());
  filter = CosNotifyFilter::Filter::_nil ();

  if (TAO_debug_level)
    ACE_DEBUG ((LM_DEBUG, "Calling CosNotifyFilterExt::FilterFactory::get_filter of removed filter\n"));

  filter = extffact->get_filter (id_1);
  ACE_ASSERT (CORBA::is_nil (filter.in ()));

  ACE_DEBUG ((LM_DEBUG, "ExtendedFilters test has run successfully\n"));
}
Ejemplo n.º 15
0
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
  {
    Consumer_Client client;

    int status = client.init (argc, argv);
    if (status != 0)
    {
      ACE_ERROR((LM_ERROR, "Error: Unable to init consumer.\n"));
      return 1;
    }

    CosNotifyChannelAdmin::EventChannel_var ec =
      client.create_event_channel ("Struct_Multi_Filter", 1);

    CosNotifyChannelAdmin::AdminID adminid = 0;
    CosNotifyChannelAdmin::ConsumerAdmin_var consumer_admin =
      ec->new_for_consumers ((consumerFilter == OrOp
      ? CosNotifyChannelAdmin::OR_OP : CosNotifyChannelAdmin::AND_OP),
      adminid);

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

    if (consumerFilter != None)
    {
      CosNotifyFilter::FilterFactory_var ffact =
        ec->default_filter_factory ();

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

      if (CORBA::is_nil (filter.in ()))
      {
        ACE_ERROR ((LM_ERROR,
          " (%P|%t) Consumer unable to initialize filter.\n"));
        return 1;
      }

      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 != 1");

      filter->add_constraints (constraint_list);

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

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

    create_consumer (consumer_admin.in (), ec.in (), &client);

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

    sig->go ();

    client.ORB_run( );

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

    sig->done();

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

  return 1;
}
Ejemplo n.º 16
0
void
FilterClient::verify_filter (CosNotifyFilter::FilterAdmin_var& admin,
                             const char* constraint_expr,
                             const char* mod_constraint_expr)
{
  ACE_UNUSED_ARG (constraint_expr);
  // only used to validate assert, which is
  // compiled out for nondebug builds.
  const CosNotifyFilter::FilterIDSeq_var ids
    = admin->get_all_filters ();

  ACE_ASSERT (ids->length () == 1);

  CosNotifyFilter::Filter_var filter
    = admin->get_filter (ids[0]);

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

  CosNotifyFilter::ConstraintInfoSeq_var infos
    = filter->get_all_constraints();

  ACE_ASSERT (infos->length () == 2);

  u_int index = 0;

  for (index = 0; index < infos->length (); ++ index)
  {
    CosNotifyFilter::ConstraintID id = infos[index].constraint_id;
    ACE_UNUSED_ARG (id);
    // only used to validate assert, which is
    // compiled out for nondebug builds.
    ACE_ASSERT (id != 0);
    ACE_ASSERT (ACE_OS::strcmp (infos[index].constraint_expression.constraint_expr.in (), constraint_expr) == 0);

    CosNotification::EventTypeSeq& events = infos[index].constraint_expression.event_types;
    ACE_UNUSED_ARG (events);
    // only used to validate assert, which is
    // compiled out for nondebug builds.
    ACE_ASSERT (events.length () == 1);

    ACE_ASSERT (ACE_OS::strcmp (events[0].domain_name.in (), DOMAIN_NAME) == 0);
    ACE_ASSERT (ACE_OS::strcmp (events[0].type_name.in (), TYPE_NAME) == 0);
  }

  if (modify_constraint_)
  {
    CosNotifyFilter::ConstraintIDSeq_var ids = new CosNotifyFilter::ConstraintIDSeq (2);
    ids->length (2);
    for (index = 0; index < infos->length (); ++ index)
    {
      ids[index] = infos[index].constraint_id;
      ACE_DEBUG ((LM_DEBUG,
      ACE_TEXT ("(%P|%t)modify constraint %d \n"), ids[index]));

      infos[index].constraint_expression.constraint_expr
        = CORBA::string_dup (mod_constraint_expr);
    }

    filter->modify_constraints (ids.in (), infos.in());
  }
}