//=================== DESTROYER =============================
StatisticsCollector::~StatisticsCollector() {

    if(isSubscribed("arrival",listener)){
        unsubscribe("arrival", listener);
    }

    if(isSubscribed("arrivalTime",listener)){
        unsubscribe("arrivalTime", listener);
    }
}
void StatisticsCollector::finish(){
    this->arrivalPercentage.recordAs("arrivalPercentage");
    this->arrivalTime.recordAs("arrivalTime");

    if(isSubscribed("arrival",listener)){
            unsubscribe("arrival", listener);
        }

    if(isSubscribed("arrivalTime",listener)){
        unsubscribe("arrivalTime", listener);
    }
}
Example #3
0
void EventManager::subscribe(LuaScriptRunner *subscriber, EventType eventType, ScriptContext context, bool failSilently)
{
   // First, see if we're already subscribed
   if(isSubscribed(subscriber, eventType) || isPendingSubscribed(subscriber, eventType))
      return;

   lua_State *L = LuaScriptRunner::getL();

   // Make sure the script has the proper event listener
   bool ok = LuaScriptRunner::loadFunction(L, subscriber->getScriptId(), eventDefs[eventType].function);     // -- function

   if(!ok)
   {
      if(!failSilently)
         logprintf(LogConsumer::LogError, "Error subscribing to %s event: couldn't find handler function.  Unsubscribing.", 
                                          eventDefs[eventType].name);
      lua_pop(L, -1);    // Remove function from stack    

      return;
   }

   removeFromPendingUnsubscribeList(subscriber, eventType);

   Subscription s;
   s.subscriber = subscriber;
   s.context = context;

   pendingSubscriptions[eventType].push_back(s);
   anyPending = true;

   lua_pop(L, -1);    // Remove function from stack                                  -- <<empty stack>>
}
void ProcessVariable::unsubscribe(Guard &guard)
{
    guard.check(__FILE__, __LINE__, mutex);
    // See comments in stop(): this->id is already 0, state==INIT.
    if (isSubscribed(guard))
    {
#ifdef CHECK_EVID
        void *user = peek_evid_userptr(ev_id);
        LOG_ASSERT(user == this);
#endif
        evid _ev_id = ev_id;
        ev_id = 0;
        GuardRelease release(__FILE__, __LINE__, guard);
        {
            Guard ctx_guard(__FILE__, __LINE__, ctx);
            LOG_ASSERT(ctx.isAttached(ctx_guard));
        }
        try
        {
            ca_clear_subscription(_ev_id);
        }
        catch (std::exception &e)
        {
            LOG_MSG("ProcessVariable::unsubscribe(%s): %s\n",
                    getName().c_str(), e.what());
        }
        catch (...)
        {
            LOG_MSG("ProcessVariable::unsubscribe(%s): Unknown Exception\n",
                    getName().c_str());
        }    
    }    
}
  void PrimitiveShapeClassifier::configCallback(Config& config, uint32_t level)
  {
    boost::mutex::scoped_lock lock(mutex_);
    min_points_num_ = config.min_points_num;

    sac_max_iterations_ = config.sac_max_iterations;
    sac_distance_threshold_ = config.sac_distance_threshold;
    if (config.sac_radius_limit_min < config.sac_radius_limit_max) {
      sac_radius_limit_min_ = config.sac_radius_limit_min;
      sac_radius_limit_max_ = config.sac_radius_limit_max;
    } else {
      config.sac_radius_limit_min = sac_radius_limit_min_;
      config.sac_radius_limit_max = sac_radius_limit_max_;
    }

    box_threshold_ = config.box_threshold;
    circle_threshold_ = config.circle_threshold;

    if (queue_size_ = config.queue_size) {
      queue_size_ = config.queue_size;
      if (isSubscribed()) {
        unsubscribe();
        subscribe();
      }
    }
  }
Example #6
0
void MainWindow::formChannelList(){

    if (m_availableChannelsQuery->getChannels().size() == 0 ) return;
    else
    {
        m_availableChannels = m_availableChannelsQuery->getChannels();
    }

    m_subscribedChannels = m_subscribedChannelsQuery->getChannels();

    QListWidget * listWidget = ui->channelsListWidget;
    QListWidget * subscribedListWidget = ui->subscribedListWidget;

    // Tab - channels
    while(listWidget->count()>0)
    {
      listWidget->takeItem(0);
    }

    foreach (Channel s, m_availableChannels){
        QListWidgetItem * item = new QListWidgetItem(s.getName());
        if (isSubscribed(s.getName())){
            item->setBackgroundColor(Qt::lightGray);
        }

        listWidget->addItem(item);
    }
/// Creates a SymmetryOperation object from its identifier.
SymmetryOperation
SymmetryOperationFactoryImpl::createSymOp(const std::string &identifier) {
  if (!isSubscribed(identifier)) {
    subscribeSymOp(identifier);
  }

  return SymmetryOperation(m_prototypes[identifier]);
}
Example #8
0
void EventManager::unsubscribe(LuaScriptRunner *subscriber, EventType eventType)
{
   if((isSubscribed(subscriber, eventType) || isPendingSubscribed(subscriber, eventType)) && !isPendingUnsubscribed(subscriber, eventType))
   {
      removeFromPendingSubscribeList(subscriber, eventType);

      pendingUnsubscriptions[eventType].push_back(subscriber);
      anyPending = true;
   }
}
Example #9
0
void PointGroupFactoryImpl::subscribePointGroup(
    const std::string &hmSymbol, const std::string &generatorString,
    const std::string &description) {
  if (isSubscribed(hmSymbol)) {
    throw std::invalid_argument(
        "Point group with this symbol is already registered.");
  }

  PointGroupGenerator_sptr generator = boost::make_shared<PointGroupGenerator>(
      hmSymbol, generatorString, description);

  subscribe(generator);
}
Example #10
0
void MainWindow::onChannelsListChanged(int index){


    qDebug() << index;

    if (index<0) return ;

    if (isSubscribed(index)){
        ui->channelActionButton->setText("Unsubscribe");
    }else{
        ui->channelActionButton->setText("Subscribe");
    }


}
Example #11
0
void MainWindow::onChannelButtonPressed()
{
    if (m_session.isValid()){
        int index = ui->channelsListWidget->currentRow();
        if (index < 0) return;

        QString channelName = ui->channelsListWidget->item(index)->text();
        Channel channel(channelName);

        if (isSubscribed(index)){
            //do unsubscribe
            m_unsubscribeChannelQuery->setQuery(channel,m_session);
            m_unsubscribeChannelQuery->doRequest();
        }else{
            //do subscribe
            m_subscribeChannelQuery->setQuery(channel,m_session);
            m_subscribeChannelQuery->doRequest();
        }
    }
}
Example #12
0
bool ListJobs::v_caseMessage( af::Msg * msg)
{
	switch( msg->type())
	{
	case af::Msg::TJobsList:
	{
		if( updateItems( msg) && (af::Environment::VISOR() == false))
		{
			getUserJobsOrder();
		}
		if( false == isSubscribed() )
		{
			if( af::Environment::VISOR() == false )
			{
				m_view->scrollToBottom();
			}
			subscribe();
		}

		calcTotals();

		break;
	}
	case af::Msg::TUserJobsOrder:
	{
		af::MCGeneral ids( msg);
		if( ids.getId() == MonitorHost::getUid())
			sortMatch( ids.getList());
		break;
	}

	default:
		return false;
	}

	return true;
}
void ProcessVariable::subscribe(Guard &guard)
{
    guard.check(__FILE__, __LINE__, mutex);
    if (dbr_type == 0)
        throw GenericException(__FILE__, __LINE__,
                               "Cannot subscribe to %s, never connected",
                               getName().c_str());
    // Prevent multiple subscriptions
    if (isSubscribed(guard))
        return;
    // While we were unlocked, a disconnect or stop() could have happend,
    // in which case we need to bail out.
    if (id == 0 || state != CONNECTED)
    {
        LOG_MSG("'%s': Skipped subscription, state %s, id 0x%lu.\n",
                getName().c_str(),  getStateStr(guard), (unsigned long) id);
        return;
    }
    chid     _id    = id;
    evid     _ev_id = 0;
    DbrType  _type  = dbr_type;
    DbrCount _count = dbr_count;
    {   // Release around CA call??
        // --  GuardRelease release(__FILE__, __LINE__, guard);
        // Right now, could a stop() and ca_clear_channel(id) happen,
        // so that ca_create_subscription() uses an invalid id?
        //
        // Task A, CAC client:
        // control_callback, pvConnected, subscribe
        //
        // Task B, Engine or HTTPD:
        // stop, clear_channel
        //
        // LockTest.cpp indicates that the clear_channel() will wait
        // for the CAC library to leabe the control_callback.
        // So even though we unlock the ProcessVariable and somebody
        // could invoke stop() and set id=0, we have the copied _id,
        // and the ca_clear_channel(id) won't happen until we leave
        // the control_callback.
        // This of course only handles the use case of the engine
        // where subscribe is invoked from control_callback & pvConnected.
        // to be on the safe side, we keep the guard and prevent a stop(),
        // until we find a deadlock that forces us to reconsider....
        {
            int status;
            try
            {
                status = ca_create_subscription(_type, _count, _id,
                                                DBE_LOG | DBE_ALARM,
                                                value_callback, this, &_ev_id);
            }
            catch (std::exception &e)
            {
                LOG_MSG("ProcessVariable::subscribe(%s): %s\n",
                        getName().c_str(), e.what());
            }
            catch (...)
            {
                LOG_MSG("ProcessVariable::subscribe(%s): Unknown Exception\n",
                        getName().c_str());
            } 
            if (status != ECA_NORMAL)
            {
                LOG_MSG("%s: ca_create_subscription failed: %s\n",
                        getName().c_str(), ca_message(status));
                return;
            }
            Guard ctx_guard(__FILE__, __LINE__, ctx);
            ctx.requestFlush(ctx_guard);
        }
    }
    ev_id = _ev_id;
    LOG_ASSERT(ev_id != 0);
#ifdef CHECK_EVID
    void *user = peek_evid_userptr(ev_id);
    LOG_ASSERT(user == this);
#endif
}
    libember::glow::GlowStreamCollection* StreamConverter::create(libember::glow::GlowStreamCollection* root, gadget::StreamManager const& manager)
    {
        typedef std::vector<gadget::Parameter*> ParameterCollection;
        std::map<int, std::unique_ptr<ParameterCollection> > dic;

        {
            auto it = std::begin(manager);
            auto const last= std::end(manager);
            for (; it != last; ++it)
            {
                auto& parameter = *it;
                auto const identifier = parameter->streamIdentifier();

                if (dic.find(identifier) == std::end(dic))
                {
                    dic[identifier] = std::unique_ptr<ParameterCollection>(new ParameterCollection());
                }

                dic[identifier]->push_back(parameter);
            }
        }

        {
            for(auto& pair : dic)
            {
                auto& streams = *pair.second;
                auto const identifier = pair.first;
                auto const size = streams.size();

                if (size == 1 && streams.front()->hasStreamDescriptor() == false)
                {
                    auto parameter = streams.front();
                    if (parameter->isSubscribed() && parameter->isDirty())
                    {
                        auto entry = SingleStreamEntryFactory::create(parameter);
                        root->insert(entry);
                    }
                }
                else if (size >= 1)
                {
                    auto const first = std::begin(streams);
                    auto const last = std::end(streams);
                    auto const result = std::max_element(first, last, [](decltype(*first) max, decltype(*first) cur) -> bool
                    {
                        if (max->hasStreamDescriptor() && cur->hasStreamDescriptor())
                        {
                            return cur->streamDescriptor()->offset() > max->streamDescriptor()->offset();
                        }
                        else if (max->hasStreamDescriptor())
                        {
                            return false;
                        }
                        else if (cur->hasStreamDescriptor())
                        {
                            return true;
                        }

                        return false;
                    });

                    auto const isSubscribed = std::any_of(first, last, [](decltype(*first) stream) -> bool
                    {
                        return stream->isSubscribed() && stream->isDirty();
                    });

                    if (result != last && isSubscribed)
                    {
                        auto descriptor = (*result)->streamDescriptor();
                        auto const format = descriptor->format();
                        auto const offset = descriptor->offset();
                        auto const size = offset + format.size();

                        auto buffer = std::vector<unsigned char>(size, 0x00);
                        for(auto parameter : streams)
                        {
                            encode(parameter, std::begin(buffer), std::end(buffer));
                            parameter->clearDirtyState();
                        }

                        root->insert(identifier, std::begin(buffer), std::end(buffer));
                    }
                }
            }
        }

        return root;
    }
/// Unsubscribes a symmetry operation from the factory
void SymmetryOperationFactoryImpl::unsubscribeSymOp(
    const std::string &identifier) {
  if (isSubscribed(identifier)) {
    m_prototypes.erase(identifier);
  }
}
/// Subscribes symmetry operation into factory, using the supplied alias as key.
void SymmetryOperationFactoryImpl::subscribe(
    const std::string &alias, const SymmetryOperation &prototype) {
  if (!isSubscribed(alias)) {
    m_prototypes.insert(std::make_pair(alias, prototype));
  }
}
Example #17
0
bool MainWindow::isSubscribed(int index)
{
    QString channelName = ui->channelsListWidget->item(index)->text();
    return isSubscribed(channelName);
}