void
StatisticsFilter::LoadChannelSets( const Context& ioContext ) const
{
  typedef ChannelSetSource::ChannelSet ChannelSet;
  typedef map<string, ChannelSet> ChannelSetContainer;
  ChannelSetContainer sets;
  const SignalProperties& Input = ioContext.signal->Properties();

  const ParamRef& ChannelSets = Parameter( "ChannelSets" );
  for( int i = 0; i < ChannelSets->NumRows(); ++i )
  {
    string name = ChannelSets->RowLabels()[i],
           definition;
    for( int j = 0; j < ChannelSets->NumColumns(); ++j )
      definition += string( ChannelSets( i, j ) ) + " ";
    istringstream iss( definition );
    string entry;
    ChannelSet channelSet;
    while( iss >> ws >> entry )
    {
      if( sets.find( entry ) != sets.end() )
      { // A channel list with that name exists, copy it.
        for( size_t i = 0; i < sets[entry].size(); ++i )
          channelSet.push_back( sets[entry][i] );
      }
      else
      {
        IndexList s( entry, Input.ChannelLabels(), Input.ChannelUnit() );
        string errors = s.Errors();
        if( errors.empty() && s.Empty() )
          errors = "entry \"" + entry + "\" does not match any channel";
        if( errors.empty() )
          for( int i = 0; i < s.Size(); ++i )
            channelSet.push_back( static_cast<int>( s[i] ) );
        else
          bcierr << "Channel set \"" << name << "\": " << errors;
      }
    }
    if( channelSet.empty() )
      bcierr << "Empty channel set \"" << name << "\"" << endl;
    else
      sets[name] = channelSet;
  }
  for( ChannelSetContainer::const_iterator i = sets.begin(); i != sets.end(); ++i )
    ioContext.sources->Add( new ChannelSetSource( i->first, i->second ) );
}
예제 #2
0
static int try_send_request()
{
	if (g_limit > 0 && g_sent_count >= g_limit)
	{
		stop_serv();
		return 0;
	}
	uint64 now = get_current_monotonic_millis();

	if (g_tp10ms > 0 && g_count_in_10msperiod >= g_tp10ms)
	{

		if (g_period_task_id == -1)
		{
			if (g_count_in_1speriod >= g_options.tps)
			{
				uint64 delay_1s = 0;
				if (now >= g_1s_transc_start_time + 1000)
				{
					delay_1s = 0;
				} else
				{
					delay_1s = (g_1s_transc_start_time + 1000) - now;
				}
				g_period_task_id = g_serv->GetTimer().ScheduleHeapTask(
						make_fun_runnable(start_1s_period_task, true), delay_1s,
						-1);
			} else
			{
				uint64 delay_10ms = 0;
				if (now >= g_10ms_transc_start_time + 10)
				{
					delay_10ms = 0;
				} else
				{
					delay_10ms = (g_10ms_transc_start_time + 10) - now;
				}
				g_period_task_id = g_serv->GetTimer().ScheduleHeapTask(
						make_fun_runnable(start_10ms_period_task, true),
						delay_10ms, -1);
			}
		}

		return 0;
	}
	if (!g_ready_channels.empty())
	{
		ChannelSet::iterator it = g_ready_channels.begin();
		HttpClientHandler* client = *it;
		client->m_request_sent = true;
		Buffer& data = get_request_data();
		client->m_client->Write(data);
		data.SetReadIndex(0);
		g_ready_channels.erase(it);
		g_count_in_10msperiod++;
		g_sent_count++;
		g_ratio_sent_req++;
		g_count_in_1speriod++;
		return 1;
	} else
	{
		if (g_all_channels.size() < g_options.concurrentConns)
		{
			http_client_connect(g_options.host.c_str(), g_options.port);
		}
	}
	return 0;
}