ConstraintArbiter::ConstraintArbiter(ACE_Reactor &ar_,
					 DifferentialMotion_ptr _pMotion,
					 StructuredPushSupplier * _pSupplier) :
      pMotion_(DifferentialMotion::_duplicate(_pMotion)),
      pSupplier_(_pSupplier),
      reactor(ar_),
      timerId(-1),
      skipDebug_(0),
      skipMax_(4)
    {
      MIRO_LOG_CTOR("Miro::ConstraintArbiter");
      
      currentVelocity_.translation = 0;
      currentVelocity_.rotation = 0.;
      
      if (pSupplier_) {
	// Status Notify Event initialization
	notifyEvent_.header.fixed_header.event_type.domain_name =
	  CORBA::string_dup(pSupplier_->domainName().c_str());
        notifyEvent_.header.fixed_header.event_type.type_name =
	  CORBA::string_dup("ConstraintArbiter");
	
	// offer declaration
	CosNotification::EventTypeSeq offers;
	offers.length(1);
	offers[0] = notifyEvent_.header.fixed_header.event_type;
	
	StructuredPushSupplier::IndexVector v =
	  pSupplier_->addOffers(offers);
	
	offerIndex_ = v[0];
      }
    }
void
Notify_Structured_Push_Consumer::_connect (
                CosNotifyChannelAdmin::ConsumerAdmin_ptr consumer_admin)
{
  CosNotifyComm::StructuredPushConsumer_var objref = this->_this ();

  CosNotifyChannelAdmin::ProxySupplier_var proxysupplier =
    consumer_admin->obtain_notification_push_supplier (
      CosNotifyChannelAdmin::STRUCTURED_EVENT,
      proxy_id_);

  this->proxy_ =
    CosNotifyChannelAdmin::StructuredProxyPushSupplier::_narrow (
      proxysupplier.in ());

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

  CosNotification::EventTypeSeq added (1);
  CosNotification::EventTypeSeq removed (1);
  added.length (1);
  removed.length (1);

  added[0].domain_name = CORBA::string_dup ("*");
  added[0].type_name = CORBA::string_dup ("examples");

  removed[0].domain_name = CORBA::string_dup ("*");
  removed[0].type_name = CORBA::string_dup ("*");

  this->subscription_change (added, removed);

  // give ownership to POA
  this->_remove_ref ();
}
  EventHandler::EventHandler(Connection& _connection, 
			     Miro::StructuredPushSupplier& _supplier) :
    connection(_connection),
    supplier_(_supplier),
    buttonStatus(0x00),
    blinkOn(false)
  {
    DBG(cout << "Constructing B21Buttons::EventHandler" << endl);

    // init button states
    for (unsigned long i = 0; i < NUM_BUTTONS; ++i) {
      button[i].number = i;
      button[i].event = Miro::Button::ON_RELEASE;
      button[i].mode = Miro::B21Button::TOGGLE_OFF;
    }
    
    // Status Notify Event initialization
    notifyEvent.header.fixed_header.event_type.domain_name = 
      CORBA::string_dup(supplier_.domainName().c_str());
    notifyEvent.header.fixed_header.event_type.type_name = 
      CORBA::string_dup("Button");
    notifyEvent.header.fixed_header.event_name = CORBA::string_dup("");
    notifyEvent.header.variable_header.length(0);   // put nothing here
    notifyEvent.filterable_data.length(0);          // put nothing here
    
    CosNotification::EventTypeSeq offers;
    offers.length(1);
    offers[0] = notifyEvent.header.fixed_header.event_type;
    supplier_.addOffers(offers);
  }
  void FilterDistanceScan::init(Miro::Server& _server, FilterParameters const * _params){
  
     std::cout << "FilterDistanceScan" << std::endl;
     
     
     if(pSupplier_ == NULL){
        ec_ = _server.resolveName<EventChannel>("EventChannel");     
        pSupplier_ = new Miro::StructuredPushSupplier(ec_.in(), _server.namingContextName.c_str(), false);
          
     }
     
     if(pSupplier_ != NULL){      
       
       notifyEvent_.header.fixed_header.event_type.domain_name =
           CORBA::string_dup(pSupplier_->domainName().c_str());
       notifyEvent_.header.fixed_header.event_type.type_name =
          CORBA::string_dup("OmniDistance");
       notifyEvent_.header.fixed_header.event_name = CORBA::string_dup("");
       notifyEvent_.header.variable_header.length(0);   // put nothing here
       notifyEvent_.filterable_data.length(0);          // put nothing here

       CosNotification::EventTypeSeq offers;
       offers.length(1);
       offers[0] = notifyEvent_.header.fixed_header.event_type;
       pSupplier_->addOffers(offers);
       pSupplier_->connect();
       this->connect();

     }
     
    Super::init(_server, _params);

  
  }
Пример #5
0
void
TAO_Notify_ThreadPool_Consumer::connect (void)
{
  // Activate the consumer with the default_POA_
  CosNotifyComm::StructuredPushConsumer_var objref = this->_this ();

  CosNotifyChannelAdmin::ProxySupplier_var proxysupplier;

  if (this->proxy_supplier_thread_count_ != 0)
    {
      // Narrow to the extended interface.
      NotifyExt::ConsumerAdmin_var admin_ext = NotifyExt::ConsumerAdmin::_narrow (this->admin_.in ());

      NotifyExt::ThreadPoolParams tp_params = { NotifyExt::CLIENT_PROPAGATED, 0,
                                                0, static_cast<CORBA::ULong> (this->proxy_supplier_thread_count_),
                                                0, 0, 0, 0, 0 };

      CosNotification::QoSProperties qos (1);
      qos.length (1);
      qos[0].name = CORBA::string_dup (NotifyExt::ThreadPool);
      qos[0].value <<= tp_params;

      // Obtain the proxy. The QoS is applied to the POA in which the Proxy is hosted.
      proxysupplier = admin_ext->obtain_notification_push_supplier_with_qos (CosNotifyChannelAdmin::STRUCTURED_EVENT
                                                                                   , proxy_supplier_id_, qos);
    }
  else
    {
      proxysupplier = this->admin_->obtain_notification_push_supplier (CosNotifyChannelAdmin::STRUCTURED_EVENT
                                                                       , proxy_supplier_id_);
    }

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

  // narrow
  this->proxy_supplier_ =
    CosNotifyChannelAdmin::StructuredProxyPushSupplier::_narrow (proxysupplier.in ());

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

  this->proxy_supplier_->connect_structured_push_consumer (objref.in ());

  // Call subscription_change to inform the supplier that this consumer is available.
  CosNotification::EventTypeSeq added (1);
  CosNotification::EventTypeSeq removed;

  added.length (1);
  added[0].domain_name = CORBA::string_dup ("TEST_DOMAIN");

  /* We generate a unique Id for the consumer type so that the supplier can distinguish between the consumers.*/
  char type[BUFSIZ];
  ACE_OS::sprintf (type, "TEST_TYPE_%d", this->proxy_supplier_id_);

  added[0].type_name = CORBA::string_dup (type);

  this->proxy_supplier_->subscription_change (added, removed);

  ACE_DEBUG ((LM_DEBUG, "(%P,%t) Created Consumer %d with %d threads at the ProxySupplier\n", proxy_supplier_id_,
              this->proxy_supplier_thread_count_));
}
Пример #6
0
void
TAO_Notify_Tests_Options_Parser::execute (CosNotification::EventTypeSeq& added, CosNotification::EventTypeSeq& removed, ACE_Arg_Shifter& arg_shifter)
{
    const ACE_TCHAR* current_arg = 0;

    while (arg_shifter.is_anything_left ())
    {
        current_arg = arg_shifter.get_current ();
        arg_shifter.consume_arg ();

        if (current_arg[0] == '+')
        {
            // create 1 more space.
            int seq_ln =  added.length ();
            added.length (seq_ln + 1);

            added[seq_ln].domain_name = CORBA::string_dup ("*");
            added[seq_ln].type_name = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(++current_arg)); // Skip the '+' sign.
        }
        else if (current_arg[0] == '-')
        {
            // create 1 more space.
            int seq_ln =  removed.length ();
            removed.length (seq_ln + 1);

            removed[seq_ln].domain_name = CORBA::string_dup ("*");
            removed[seq_ln].type_name = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(++current_arg)); // Skip the '-' sign.
        }
    }
}
  RangeSensorDispatcher::RangeSensorDispatcher(const ScanDescriptionIDL& _description,
					       StructuredPushSupplier * _supplier) :
    supplier_(_supplier),
    mutex_(),
    cond_(mutex_),
    notifyEvent_(1),
    eventPending_(1, false)
  {
    if (supplier_) {
      if (_description.scanType == RangeSensor::GROUPWISE) {
	notifyEvent_.resize(_description.group.length());
	eventPending_.resize(_description.group.length(), false);
      }

      for (unsigned int i = 0; i < notifyEvent_.size(); ++i) {
	// Notify Event initialization
	notifyEvent_[i].header.fixed_header.event_type.domain_name =
	  CORBA::string_dup(supplier_->domainName().c_str());
	notifyEvent_[i].header.fixed_header.event_type.type_name =
	  CORBA::string_dup(_description.eventName);
	notifyEvent_[i].header.fixed_header.event_name = CORBA::string_dup("");
	notifyEvent_[i].header.variable_header.length(0);   // put nothing here
	notifyEvent_[i].filterable_data.length(0);          // put nothing here
      }

      // offer declaration
      CosNotification::EventTypeSeq offers;
      offers.length(1);
      offers[0] = notifyEvent_[0].header.fixed_header.event_type;
      supplier_->addOffers(offers);
    }
  }
    void offer_change(CosNotification::EventTypeSeq const& added,
		      CosNotification::EventTypeSeq const& removed)
      throw(CosNotifyComm::InvalidEventType)
    {
      cerr << endl << endl << "offer_change() called" << endl;

      if (added.length() > 0) {
	cout << "added: " << endl;
	for (CORBA::ULong i = 0; i < added.length(); ++i) {
	  cout << "  domain name: "
	       << added[i].domain_name 
	       << "    "
	       << "type name: "
	       << added[i].type_name << endl;
	}
      }
      if (removed.length() > 0) {
	cout << "removed: " << endl;
	for (CORBA::ULong i = 0; i < removed.length(); ++i) {
	  cout << "  domain name: "
	       << removed[i].domain_name 
	       << "    "
	       << "type name: "
	       << removed[i].type_name << endl;
	}
      }
    }
Пример #9
0
void
Updates::add_type (CosNotification::EventTypeSeq& type_seq, const char* type)
{
  // Make space.
  int index = type_seq.length ();
  type_seq.length (index + 1);

  type_seq[index].domain_name =  CORBA::string_dup (type);
  type_seq[index].type_name = CORBA::string_dup (type);
}
  void
  StructuredPushConsumer::setSingleSubscription(std::string const& _domain,
      std::string const& _type)
  {
    CosNotification::EventTypeSeq subscriptions;
    subscriptions.length(1);
    subscriptions[0].domain_name = CORBA::string_dup(_domain.c_str());
    subscriptions[0].type_name = CORBA::string_dup(_type.c_str());

    setSubscriptions(subscriptions);
  }
  /**
   * The consumer will register the subscriptions at its event consumer admin.
   * The admin will make sure, the notification channel suppliers are informed
   * about new subscription. That way, suppliers can query whether the events they
   * offer are currently subscribed by any supplier.
   *
   * Internally the consumer keeps track of the events offered by suppliers.
   * A user of the consumer can query at the consumer for each subscribed event,
   * wheter it is offered by any supplier or not. This way an event sink
   * can determine whether the demanded information is produced by the system.
   *
   * For efficient querying of offer/subscription matches, this method returns a
   * vector containing a handle for each added subscription. This handle can be used
   * for efficient querying of the availability of suppliers for a
   * particular event type vie the offered method.
   */
  StructuredPushConsumer::IndexVector
  StructuredPushConsumer::addSubscriptons(CosNotification::EventTypeSeq const& _added)
  {
    Guard guard(connectedMutex_);

    CORBA::ULong subscriptionsLen = subscriptions_.length();
    CORBA::ULong addedLen = _added.length();
    CORBA::ULong newSubscriptionsLen = subscriptionsLen;

    // assigned indexes
    IndexVector indexes(addedLen);

    // actually added events
    CosNotification::EventTypeSeq added;
    // dummy: allway empty
    CosNotification::EventTypeSeq removed;

    // enlarge the offers vector by the maximum required size
    subscriptions_.length(subscriptionsLen + addedLen);
    added.length(addedLen);

    for (unsigned int i = 0; i < addedLen; ++i) {
      unsigned int j = 0;
      for (; j < subscriptionsLen; ++j) {
        // search whether already offered
        if (strcmp(subscriptions_[j].type_name, _added[i].type_name) == 0 &&
              strcmp(subscriptions_[j].domain_name, _added[i].domain_name) == 0) {
          indexes[i] = j;
          break;
        }
      }

      // add new offer to list of offers
      if (j == subscriptionsLen) {
        subscriptions_[newSubscriptionsLen] = _added[i];
        added[newSubscriptionsLen - subscriptionsLen] = _added[i];
        indexes[i] = newSubscriptionsLen;
        ++newSubscriptionsLen;
      }
    }
    // resize offers vector to actual size
    subscriptions_.length(newSubscriptionsLen);
    added.length(newSubscriptionsLen - subscriptionsLen);

    initiateSubscriptionChange(added, removed);

    return indexes;
  }
void
Notify_Structured_Push_Consumer::_connect (
                CosNotifyChannelAdmin::ConsumerAdmin_ptr consumer_admin)
{
#ifdef TEST_QOS_MAX_EVENTS_PER_CONSUMER
  CosNotification::QoSProperties properties (8);
  properties.length (2);
  CORBA::ULong idx = 0;
  properties[idx].name = CORBA::string_dup (CosNotification::DiscardPolicy);
  properties[idx].value <<= this->CosNotification::FifoOrder;
  idx += 1;
  properties[idx].name = CORBA::string_dup (CosNotification::MaxEventsPerConsumer);
  properties[idx].value <<= 500;
  idx += 1;
  ACE_OS::printf("Setting %d::%d QoS properties in Admin.\n", (int)idx, (int)properties.length());
  consumer_admin->set_qos (properties);
#endif // TEST_QOS_MAX_EVENTS_PER_CONSUMER

  CosNotifyComm::StructuredPushConsumer_var objref = this->_this ();

  CosNotifyChannelAdmin::ProxySupplier_var proxysupplier =
    consumer_admin->obtain_notification_push_supplier (
      CosNotifyChannelAdmin::STRUCTURED_EVENT,
      proxy_id_);

  this->proxy_ =
    CosNotifyChannelAdmin::StructuredProxyPushSupplier::_narrow (
      proxysupplier.in ());

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

  CosNotification::EventTypeSeq added (1);
  CosNotification::EventTypeSeq removed (1);
  added.length (1);
  removed.length (1);

  added[0].domain_name = CORBA::string_dup ("*");
  added[0].type_name = CORBA::string_dup ("examples");

  removed[0].domain_name = CORBA::string_dup ("*");
  removed[0].type_name = CORBA::string_dup ("*");

  this->subscription_change (added, removed);

  // give ownership to POA
  this->_remove_ref ();
}
Пример #13
0
void
Updates::print_event_types (const CosNotification::EventTypeSeq &types)
{
  for (CORBA::ULong i = 0; i < types.length (); ++i)
    {
      ACE_DEBUG ((LM_DEBUG, "(%s, %s)\n", types[i].domain_name.in (), types[i].type_name. in()));
    }
}
 void
 subscription_change(CosNotification::EventTypeSeq const& added,
                     CosNotification::EventTypeSeq const& removed)
 throw()
 {
     for (CORBA::ULong i = 0; i < added.length(); ++i) {
         cout << "subscription_change() - added:   domain name="
              << added[i].domain_name
              << " type name="
              << added[i].type_name << endl;
     }
     for (CORBA::ULong i = 0; i < removed.length(); ++i) {
         cout << "subscription_change() - removed: domain name="
              << removed[i].domain_name
              << " type name="
              << removed[i].type_name << endl;
     }
 }
Пример #15
0
void
Updates::types_changed (const CosNotification::EventTypeSeq & added,
                        const CosNotification::EventTypeSeq & removed)
{
  if (TAO_debug_level)
    {
      ACE_DEBUG ((LM_DEBUG, "Added Types..\n"));
      this->print_event_types (added);

      ACE_DEBUG ((LM_DEBUG, "Removed Types..\n"));
      this->print_event_types (removed);
    }

  ACE_GUARD (TAO_SYNCH_MUTEX, mon, this->lock_);

  this->added_count_ += added.length ();
  this->removed_count_ += removed.length ();
}
Пример #16
0
void
TAO_Notify_EventTypeSeq::remove_seq (const CosNotification::EventTypeSeq& event_type_seq)
{
    TAO_Notify_EventType event_type;

    for (CORBA::ULong i = 0; i < event_type_seq.length (); ++i)
    {
        event_type = event_type_seq[i];
        inherited::remove (event_type);
    }
}
  OdometryDispatcher::OdometryDispatcher(StructuredPushSupplier * _supplier,
					 bool _rawPositionEvents) :
    supplier_(_supplier),
    rawPositionEvents_(_rawPositionEvents),
    mutex_(),
    cond_(mutex_)
  {
    if (supplier_) {
      // Status Notify Event initialization
      notifyEvent_.header.fixed_header.event_type.domain_name = 
	CORBA::string_dup(supplier_->domainName().c_str());
      notifyEvent_.header.fixed_header.event_type.type_name = 
	CORBA::string_dup("Odometry");
      notifyEvent_.header.fixed_header.event_name = CORBA::string_dup("");
      notifyEvent_.header.variable_header.length(0);   // put nothing here
      notifyEvent_.filterable_data.length(0);          // put nothing here

      if (rawPositionEvents_) {
	// Status Notify Raw Event initialization
	notifyRawEvent_.header.fixed_header.event_type.domain_name = 
	  CORBA::string_dup(supplier_->domainName().c_str());
	notifyRawEvent_.header.fixed_header.event_type.type_name = 
	  CORBA::string_dup("RawPosition");
	notifyRawEvent_.header.fixed_header.event_name = CORBA::string_dup("");
	notifyRawEvent_.header.variable_header.length(0);   // put nothing here
	notifyRawEvent_.filterable_data.length(0);          // put nothing here
      }

      CosNotification::EventTypeSeq offers;
      offers.length((rawPositionEvents_)? 2 : 1);
      offers[0] = notifyEvent_.header.fixed_header.event_type;
      if (rawPositionEvents_) {
	offers[1] = notifyRawEvent_.header.fixed_header.event_type;
      }
      StructuredPushSupplier::IndexVector eventId = supplier_->addOffers(offers);

      for (unsigned int i = 0; i < eventId.size(); ++i) {
	eventId_[i] = eventId[i];
      }
    }
  }
  CompassDispatcher::CompassDispatcher(StructuredPushSupplier * _supplier) :
    supplier_(_supplier),
    mutex_(),
    cond_(mutex_)
  {
    if (supplier_) {
      // Status Notify Event initialization
      notifyEvent_.header.fixed_header.event_type.domain_name = 
	CORBA::string_dup(supplier_->domainName().c_str());
      notifyEvent_.header.fixed_header.event_type.type_name = 
	CORBA::string_dup("Compass");
      notifyEvent_.header.fixed_header.event_name = CORBA::string_dup("");
      notifyEvent_.header.variable_header.length(0);   // put nothing here
      notifyEvent_.filterable_data.length(0);          // put nothing here

      CosNotification::EventTypeSeq offers;
      offers.length(1);
      offers[0] = notifyEvent_.header.fixed_header.event_type;
      supplier_->addOffers(offers);
    }
  }
/**
 * @param _pMotion a pointer to the motion interface
 * @param _pSupplier a pointer to a StructuredPushSupplier for
 *   emitting arbitration events for debugging.
 */
MotionArbiter::MotionArbiter(Motion_ptr _pMotion,
                             StructuredPushSupplier * _pSupplier) :
    pMotion_(Motion::_duplicate(_pMotion)),
    pSupplier_(_pSupplier)
{
    currentVelocity_.translation = 0;
    currentVelocity_.rotation = 0.;

    if (pSupplier_) {
        // Status Notify Event initialization
        notifyEvent.header.fixed_header.event_type.domain_name =
            CORBA::string_dup(pSupplier_->domainName().c_str());
        notifyEvent.header.fixed_header.event_type.type_name =
            CORBA::string_dup("ArbitrateChange");

        CosNotification::EventTypeSeq offers;
        offers.length(1);
        offers[0] = notifyEvent.header.fixed_header.event_type;
        pSupplier_->addOffers(offers);
    }
}
Пример #20
0
void
TAO_Notify_EventTypeSeq::populate (CosNotification::EventTypeSeq& event_type_seq) const
{
    event_type_seq.length (static_cast<CORBA::ULong> (this->size ()));

    inherited::CONST_ITERATOR iter (*this);

    TAO_Notify_EventType* event_type = 0;

    CORBA::ULong i = 0;
    for (iter.first (); iter.next (event_type); iter.advance (), ++i)
        event_type_seq[i] = event_type->native ();
}
StallImpl::StallImpl(BaseConnection * _connection,
                     Miro::StructuredPushSupplier * _pSupplier) :
    connection_(_connection),
    pSupplier(_pSupplier)
{
    MIRO_LOG_CTOR("Sparrow::StallImpl");

    // Stall Notify Event initialization
    if (pSupplier) {
        notifyEvent.header.fixed_header.event_type.domain_name =
            CORBA::string_dup(pSupplier->domainName().c_str());
        notifyEvent.header.fixed_header.event_type.type_name =
            CORBA::string_dup("Stall");
        notifyEvent.header.fixed_header.event_name = CORBA::string_dup("");
        notifyEvent.header.variable_header.length(0);   // put nothing here
        notifyEvent.filterable_data.length(0);          // put nothing here

        CosNotification::EventTypeSeq offers;
        offers.length(1);
        offers[0] = notifyEvent.header.fixed_header.event_type;
        pSupplier->addOffers(offers);
    }
}
Пример #22
0
void
TAO_Notify_Lanes_Supplier::subscription_change (const CosNotification::EventTypeSeq & added,
                                      const CosNotification::EventTypeSeq & /*removed */
                                      )
{
  ACE_GUARD (TAO_SYNCH_MUTEX, mon, this->lock_);

  // Count the number of consumers connect and signal the supplier thread when the expected count have connected.
  if (added.length () > 0)
    {
      if (++this->consumer_count_ == this->expected_consumer_count_)
        this->consumers_connected_.signal ();
    }
}
Пример #23
0
static void
create_suppliers (CosNotifyChannelAdmin::SupplierAdmin_ptr admin,
                  PortableServer::POA_ptr poa)
{
  // startup the supplier
  ACE_NEW_THROW_EX (supplier_1,
    TAO_Notify_Tests_StructuredPushSupplier (),
    CORBA::NO_MEMORY ());

  supplier_1->init (poa);
  supplier_1->connect (admin);

  CosNotification::EventTypeSeq added (1);
  CosNotification::EventTypeSeq removed (1);
  added.length (1);
  removed.length (1);
  added[0].domain_name = CORBA::string_dup ("DOC_TAO");
  added[0].type_name = CORBA::string_dup ("examples");

  removed[0].domain_name = CORBA::string_dup ("*");
  removed[0].type_name = CORBA::string_dup ("*");

  supplier_1->offer_change (added, removed);
}
Пример #24
0
void
TAO_Notify_EventTypeSeq::populate_no_special (CosNotification::EventTypeSeq& event_type_seq) const
{
    // If the special exists in us, don't include it.
    const TAO_Notify_EventType& special = TAO_Notify_EventType::special ();

    if (this->find (special) == 0)
    {
        event_type_seq.length (static_cast<CORBA::ULong> (this->size () - 1));
    }
    else
        event_type_seq.length (static_cast<CORBA::ULong> (this->size ()));

    inherited::CONST_ITERATOR iter (*this);

    TAO_Notify_EventType* event_type = 0;

    CORBA::ULong i = 0;
    for (iter.first (); iter.next (event_type); iter.advance (), ++i)
    {
        if (event_type->is_special () == 0) // if its not the special event type.
            event_type_seq[i] = event_type->native ();
    }
}
Пример #25
0
void
TAO_Notify_ThreadPool_Supplier::subscription_change (const CosNotification::EventTypeSeq & added,
                                      const CosNotification::EventTypeSeq & /*removed */
                                      )
{
  ACE_GUARD (TAO_SYNCH_MUTEX, mon, this->lock_);

  // Count the number of consumers connect and signal the supplier thread when the expected count have connected.
  // Only 1 consumer connects at a time.
  if (added.length () > 0)
    {
      // Set the domain and type nams in the event's fixed header.
      this->event_[consumer_count_].header.fixed_header.event_type.domain_name = CORBA::string_dup(added[0].domain_name);
      this->event_[consumer_count_].header.fixed_header.event_type.type_name = CORBA::string_dup(added[0].type_name);

      ++this->consumer_count_;

      ACE_DEBUG ((LM_DEBUG, "(%P,%t) Received Type %d: (%s)\n", this->consumer_count_, added[0].type_name.in ()));

      if (this->consumer_count_ == this->expected_consumer_count_)
        this->consumers_connected_.signal ();
    }
}
Пример #26
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
  {
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

    CORBA::Object_var poa_object =
      orb->resolve_initial_references("RootPOA");

    if (CORBA::is_nil (poa_object.in())) {
      std::cerr << "Unable to initialize the POA." << std::endl;
      return 1;
    }

    PortableServer::POA_var poa =
    PortableServer::POA::_narrow(poa_object.in());

    // Activate POA manager
    PortableServer::POAManager_var mgr = poa->the_POAManager();
    mgr->activate();

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

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

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

    CosNaming::Name name(1);

    name.length (1);
    name[0].id = CORBA::string_dup("MyEventChannel");
    CORBA::Object_var ecObj = naming_context->resolve(name);

    CosNotifyChannelAdmin::EventChannel_var ec =
      CosNotifyChannelAdmin::EventChannel::_narrow(ecObj.in());

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

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

    CosNotifyChannelAdmin::ConsumerAdmin_var consumer_admin =
      ec->new_for_consumers(ifgop,
      adminid);

    if (CORBA::is_nil (consumer_admin.in())) {
      std::cerr << "Unable to find consumer admin" << std::endl;
      return 1;
    }

    PortableServer::Servant_var<StructuredEventConsumer_i> servant =
      new StructuredEventConsumer_i(orb.in());

    CosNotifyComm::StructuredPushConsumer_var consumer = servant->_this();

    CosNotifyChannelAdmin::ProxyID consumeradmin_proxy_id;

    CosNotifyChannelAdmin::ProxySupplier_var proxy_supplier =
      consumer_admin->obtain_notification_push_supplier(
          CosNotifyChannelAdmin::STRUCTURED_EVENT,
          consumeradmin_proxy_id);

    // The proxy that we are connected to.
    CosNotifyChannelAdmin::StructuredProxyPushSupplier_var supplier_proxy;
    supplier_proxy = CosNotifyChannelAdmin::StructuredProxyPushSupplier::
      _narrow(proxy_supplier.in());

    if (CORBA::is_nil (supplier_proxy.in())) {
      std::cerr << "Unable to create structured push supplier proxy" << std::endl;
      return 1;
    }

    supplier_proxy->connect_structured_push_consumer(consumer.in());
    CosNotification::EventTypeSeq added (1);
    CosNotification::EventTypeSeq removed (1);
    added.length (1);
    removed.length (1);

    added[0].domain_name = CORBA::string_dup ("OCI_TAO");
    added[0].type_name = CORBA::string_dup ("examples");

    removed[0].domain_name = CORBA::string_dup ("*");
    removed[0].type_name = CORBA::string_dup ("*");

    supplier_proxy->subscription_change(added, removed);

    orb->run();
   }
   catch(const CORBA::Exception& ex)
    {
      std::cerr << "MessengerConsumer:: Caught exception: " << ex << std::endl;
      return 1;
    }
   std::cerr << "MessengerConsumer: success" << std::endl;
   return 0;
}
Пример #27
0
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
  try
  {
    CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);

    CORBA::Object_var obj = orb->resolve_initial_references("NameService");

    CosNaming::NamingContextExt_var naming_context =
      CosNaming::NamingContextExt::_narrow(obj.in());

    obj = naming_context->resolve_str("MyEventChannel");
    CosNotifyChannelAdmin::EventChannel_var ec =
      CosNotifyChannelAdmin::EventChannel::_narrow(obj.in());

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

    CosNotifyChannelAdmin::ConsumerAdmin_var consumer_admin =
      ec->new_for_consumers(ifgop,
      adminid);

    obj = orb->resolve_initial_references("RootPOA");

    PortableServer::POA_var poa = PortableServer::POA::_narrow (obj.in());

    PortableServer::Servant_var<EventSequenceConsumer_i> servant =
      new EventSequenceConsumer_i(orb.in());

    PortableServer::ObjectId_var objectId = poa->activate_object(servant.in());

    obj = poa->id_to_reference (objectId.in());
    CosNotifyComm::SequencePushConsumer_var consumer =
      CosNotifyComm::SequencePushConsumer::_narrow(obj.in());

    CosNotifyChannelAdmin::ProxyID consumeradmin_proxy_id;

    CosNotifyChannelAdmin::ProxySupplier_var proxy_supplier =
      consumer_admin->obtain_notification_push_supplier(
      CosNotifyChannelAdmin::SEQUENCE_EVENT,
          consumeradmin_proxy_id);

    CosNotifyChannelAdmin::SequenceProxyPushSupplier_var supplier_proxy =
      CosNotifyChannelAdmin::SequenceProxyPushSupplier::_narrow(proxy_supplier.in());

    supplier_proxy->connect_sequence_push_consumer(consumer.in());

    CosNotification::EventTypeSeq added (1);
    CosNotification::EventTypeSeq removed (1);
    added.length (1);
    removed.length (1);

    added[0].domain_name = CORBA::string_dup ("OCI_TAO");
    added[0].type_name = CORBA::string_dup ("examples");

    removed[0].domain_name = CORBA::string_dup ("*");
    removed[0].type_name = CORBA::string_dup ("*");

    supplier_proxy->subscription_change(added, removed);

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

    poa_manager->activate();

    orb->run();

    orb->destroy();

    return 0;
  }
  catch(const CORBA::Exception& ex)
  {
    std::cerr << "Caught exception: " << ex << std::endl;
  }
  return 1;
}
Пример #28
0
Messenger_i::Messenger_i (CORBA::ORB_ptr orb)
              : orb_(CORBA::ORB::_duplicate(orb))
{
  CORBA::Object_var poa_object =
    orb_->resolve_initial_references("RootPOA");

  if (CORBA::is_nil (poa_object.in())) {
    std::cerr << "Unable to initialize the POA." << std::endl;
  }

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

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

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

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

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

  CosNotifyChannelAdmin::EventChannelFactory_var notify_factory =
    CosNotifyChannelAdmin::EventChannelFactory::_narrow(obj.in());

  if (CORBA::is_nil(notify_factory.in())) {
    std::cerr << "Unable to find notify factory" << std::endl;
  }

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

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

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

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

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

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

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

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

  CosNotifyChannelAdmin::ProxyID supplieradmin_proxy_id;

  CosNotifyChannelAdmin::ProxyConsumer_var proxy_consumer =
    supplier_admin->obtain_notification_push_consumer(
         CosNotifyChannelAdmin::STRUCTURED_EVENT,
         supplieradmin_proxy_id);

  StructuredEventSupplier_i *servant =
    new StructuredEventSupplier_i(orb_.in());

  CosNotifyComm::StructuredPushSupplier_var supplier =
    servant->_this();

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

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

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


  CosNotification::EventTypeSeq added (1);
  CosNotification::EventTypeSeq removed (1);
  added.length (1);
  removed.length (1);
  added[0].domain_name = CORBA::string_dup ("OCI_TAO");
  added[0].type_name = CORBA::string_dup ("examples");

  removed[0].domain_name = CORBA::string_dup ("*");
  removed[0].type_name = CORBA::string_dup ("*");

  s_proxy_consumer_->offer_change(added, removed);
}
int main(int argc, char * argv[])
{
  Miro::Log::init(argc, argv);

  Miro::Server server(argc, argv);

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

  // The event channel
  CosNotifyChannelAdmin::EventChannel_var ec =
    server.resolveName<CosNotifyChannelAdmin::EventChannel>(channelName);

  //----------------------------------------------------------------------------
  // creating a notification service supplier admin

  // The group operator between admin-proxy's.
  CosNotifyChannelAdmin::InterFilterGroupOperator ifgop =
    CosNotifyChannelAdmin::OR_OP;
  // The id of the created adin.
  CosNotifyChannelAdmin::AdminID admin_id;
  // The supplier admin used by supplier.
  CosNotifyChannelAdmin::ConsumerAdmin_var consumer_admin;

  consumer_admin = ec->new_for_consumers(ifgop, admin_id);

  //----------------------------------------------------------------------------
  // create a notification service proxy consumer, to send events to

  // Initial qos specified to the factory when creating the EC.
  CosNotification::QoSProperties initial_qos;
  // Initial admin props specified to the factory when creating the EC.
  CosNotification::AdminProperties initial_admin;
  // This proxy's id.
  CosNotifyChannelAdmin::ProxyID proxy_id;
  // The proxy that we are connected to.
  CosNotifyChannelAdmin::StructuredProxyPushSupplier_var proxy_supplier;


  CORBA::Object_var obj;
  obj = consumer_admin->
        obtain_notification_push_supplier(CosNotifyChannelAdmin::STRUCTURED_EVENT,
                                          proxy_id);
  assert(!CORBA::is_nil(obj));

  // narrow
  proxy_supplier =
    CosNotifyChannelAdmin::StructuredProxyPushSupplier::_narrow(obj);

  //----------------------------------------------------------------------------
  // offer/subscription management

  // don't call us on offer changes
  CosNotification::EventTypeSeq_var events =
    proxy_supplier->
    obtain_offered_types(CosNotifyChannelAdmin::ALL_NOW_UPDATES_OFF);

  // tell about the events we gonna subscribe
  CosNotification::EventTypeSeq added;
  CosNotification::EventTypeSeq removed;

  added.length(1);
  added[0].domain_name = Miro::RobotParameters::instance()->namingContextName.c_str();
  added[0].type_name = eventName.c_str();
  // remove default subscription
  removed.length(1);
  removed[0].domain_name = string("*").c_str();
  removed[0].type_name = string("*").c_str();
  consumer_admin->subscription_change(added, removed);

  //----------------------------------------------------------------------------
  // create and connect a supplier class

  class MyConsumer : public POA_CosNotifyComm::StructuredPushConsumer {
  public:
    MyConsumer() :
        anyPrinter(printName,
                   printType,
                   printLength,
                   printEnums,
                   printTc,
                   printId,
		   maxSeqLen)
    {}

    virtual
    void
    push_structured_event(CosNotification::StructuredEvent const& event)
    throw()
    {
      anyPrinter.print(cout, event.remainder_of_body);
      cout << endl;
    }

    virtual
    void
    offer_change(const CosNotification::EventTypeSeq&, const CosNotification::EventTypeSeq&)
    throw()
    {}

    void disconnect_structured_push_consumer() throw()
    {
      cerr << "disconnect_structured_push_consumer() called" << endl;
    }
  private:
    Miro::AnyPrinter anyPrinter;
  };

  MyConsumer * consumer = new MyConsumer();

  // activate supplier with poa
  server.activate(consumer);

  CosNotifyComm::StructuredPushConsumer_var objref = consumer->_this();
  // connect
  proxy_supplier->connect_structured_push_consumer(objref);


  cout << "entering event loop" << endl;

  //----------------------------------------------------------------------------
  // receiving events
  server.run(1);

  proxy_supplier->disconnect_structured_push_supplier();
  consumer_admin->destroy();

  return 0;
}
  /**
   *
   * This will overwrite all previously set or added subscriptions.
   *
   * The consumer will register the subscriptions at its event consumer admin.
   * The admin will make sure, the notification channel suppliers are informed
   * about new subscriptions. That way, suppliers can query whether events it
   * offers are currently subscribed by any consumer.
   *
   * Internally the consumer keeps track of the events offered by suppliers.
   * A user of the consumer can query at the consumer for each subscribed event,
   * whether it is offered by any supplier or not. This way an event sink
   * can determine whether the demanded information is produced by the system.
   *
   * For efficiency, offer/subscription matches can be queried by the index,
   * they apeared within the orgument vector of this method.
   *
   * @param offers The vector of new subscirptions.
   */
  void
  StructuredPushConsumer::setSubscriptions(CosNotification::EventTypeSeq const& _newSubscriptions,
      bool _subscribe)
  {
    Guard guard(connectedMutex_);

    CORBA::ULong offersLen = subscriptions_.length();
    CORBA::ULong newOffersLen = _newSubscriptions.length();

    // actually added events
    CosNotification::EventTypeSeq added;
    // dummy: always empty
    CosNotification::EventTypeSeq removed;

    CORBA::ULong addedIndex = 0;
    CORBA::ULong removedIndex = 0;

    // enlarge the offers vector by the maximum required size
    added.length(newOffersLen);
    removed.length(offersLen);

    for (unsigned int i = 0; i < newOffersLen; ++i) {
      unsigned int j;
      for (j = 0; j < offersLen; ++j) {
        // search whether already offered
        if (strcmp(_newSubscriptions[i].type_name, subscriptions_[j].type_name) == 0 &&
              strcmp(_newSubscriptions[i].domain_name, subscriptions_[j].domain_name) == 0) {
          break;
        }
      }

      // add new offer to list of added offers
      if (j == offersLen) {
        added[addedIndex] = _newSubscriptions[i];
        ++addedIndex;
      }
    }

    for (unsigned int i = 0; i < offersLen; ++i) {
      unsigned int j;
      for (j = 0; j < newOffersLen; ++j) {
        // search whether still offered
        if (strcmp(subscriptions_[i].type_name, _newSubscriptions[j].type_name) == 0 &&
              strcmp(subscriptions_[i].domain_name, _newSubscriptions[j].domain_name) == 0) {
          break;
        }
      }

      // add odl offer to list of removed offers
      if (j == newOffersLen) {
        removed[removedIndex] = subscriptions_[i];
        ++removedIndex;
      }
    }

    // resize offers vector to actual size
    added.length(addedIndex);
    removed.length(removedIndex);

    // overwrite offers vector
    subscriptions_ = _newSubscriptions;

    // do the offers change and performe bookkeeping
    initiateSubscriptionChange(added, removed);

    subscribed_ = _subscribe;
  }