コード例 #1
0
int main(int argc, char* argv[])
{
	if (argc < 2)
	{
		std::cout << "Usage: gpudb-api-example http://172.30.70.6:9191\n";
		exit(1);
	}

	std::string host(argv[1]);
	std::cout << "Connecting to GPUdb host: '" << host << "'\n";

	gpudb::GPUdb gpudb(host, gpudb::GPUdb::Options().setThreadCount(4));
	std::map<std::string, std::string> options;

	// Get the version information
	std::cout << "GPUdb C++ Client Version: " << gpudb.getApiVersion() << std::endl;

	// Create some test data

	std::vector<gpudb::Type::Column> columns;
	std::vector<std::string> pk;
	pk.push_back("primary_key");
	std::vector<gpudb::GenericRecord> data;

	columns.push_back(gpudb::Type::Column("A", gpudb::Type::Column::INT, pk));
	gpudb::Type aType = gpudb::Type("JoinTestA", columns);
	gpudb.createTable("JoinTestA", aType.create(gpudb), options);

	for (int ii = 0; ii < 10; ii++) {
		gpudb::GenericRecord aRecord(aType);
		aRecord.asInt("A") = ii;
		data.push_back(aRecord);
	}

    gpudb.insertRecords("JoinTestA", data, options);

    columns.clear();
    columns.push_back(gpudb::Type::Column("B", gpudb::Type::Column::INT, pk));
    gpudb::Type bType = gpudb::Type("JoinTestB", columns);
    gpudb.createTable("JoinTestB", bType.create(gpudb), options);

	data.clear();

	for (int ii = 0; ii < 20; ii++) {
		gpudb::GenericRecord bRecord(bType);
		bRecord.asInt("B") = ii;
		data.push_back(bRecord);
	}
    gpudb.insertRecords("JoinTestB", data, options);

    std::vector<std::string> joinTables;
    joinTables.push_back("JoinTestA");
    joinTables.push_back("JoinTestB");
    std::vector<std::string> aliases;
    aliases.push_back("A");
    aliases.push_back("B");
    std::vector<std::string> expressions;
    gpudb.createJoinTable("JoinTestC", joinTables, aliases, "A.A = B.B", expressions, options);

    std::vector<std::string> columnNames;
    columnNames.push_back("A.A");
    columnNames.push_back("B.B");
    gpudb::GetRecordsByColumnResponse grbcResponse = gpudb.getRecordsByColumn("JoinTestC", columnNames, 0, 10, options);

    for (size_t i = 0; i < grbcResponse.data.size(); ++i)
    {
        gpudb::GenericRecord& record = grbcResponse.data[i];
        std::cout << record.asInt("A.A")
                << " " << record.asInt("B.B")
                << std::endl;
    }

    gpudb.clearTable("JoinTestA", "", options);
    gpudb.clearTable("JoinTestB", "", options);

    return 0;
}
コード例 #2
0
ファイル: igclogger.cpp プロジェクト: Exadios/Cumulus
/** This slot is called by the calculator if a new flight sample is ready to
 *  make a log entry on a predefined interval into the IGC file.
 */
void IgcLogger::slotMakeFixEntry()
{
  if ( _logMode == off || calculator->samplelist.count() == 0 )
    {
      // make sure logger is not off and and entries are in the sample list
      return;
    }

  const FlightSample &lastfix = calculator->samplelist.at(0);

  // check if we have to log a new B-Record
  if ( ! lastLoggedBRecord->isNull() &&
         lastLoggedBRecord->addSecs( _bRecordInterval ) > lastfix.time.time() )
    {
      // write K-Record, if needed
      writeKRecord( lastfix.time.time() );
      return;
    }

  *lastLoggedBRecord = lastfix.time.time();

  QString bRecord( "B" + formatTime(lastfix.time.time()) + formatPosition(lastfix.position) + "A" +
                   formatAltitude(lastfix.STDAltitude) + formatAltitude(lastfix.GNSSAltitude) +
                   QString("%1").arg(GpsNmea::gps->getLastSatInfo().fixAccuracy, 3, 10, QChar('0')) +
                   QString("%1").arg(GpsNmea::gps->getLastSatInfo().satsInUse, 2, 10, QChar('0')) );

  if ( _logMode == standby &&
       ( calculator->moving() == false ||
         _flightMode == Calculator::unknown ||
         _flightMode == Calculator::standstill ) )
    {
      // save B and F record and time in backtrack, if we are not in move
      QString fRecord = "F" +
                         formatTime( lastfix.time.time() ) +
                         GpsNmea::gps->getLastSatInfo().constellation;
      QStringList list;
      list << bRecord << fRecord << QTime::currentTime ().toString("hhmmss");
      _backtrack.add( list );

      // qDebug( "Backtrack add: backtrack.size=%d", _backtrack.size() );

      // Set last F recording time from the oldest log entry. Looks a little bit
      // tricky but should work so. ;-)
      *lastLoggedFRecord = QTime::fromString( _backtrack.last().at(2), "hhmmss" );
      return;
    }

  if( isLogFileOpen() )
    {
      if( _logMode == standby || _backtrack.size() > 0 )
        {
          // There is a special case. The user can switch on the logger via toggle L
          // but the logger was before in state standby and the backtrack contains
          // entries. Such entries must be written out in the new opened log file
          // before start with normal logging. Otherwise the first B record is missing.
          _logMode = on;

          // set start date and time of logging
          startLogging = QDateTime::currentDateTime();

          emit takeoffTime( startLogging );

          // If log mode was before in standby we have to write out the backtrack entries.
          if( _backtrack.size() > 0 )
            {
              if( _backtrack.last().at( 0 ).startsWith( "B" ) )
                {
                  // The backtrack contains at the last position a B record but IGC log
                  // should start with a F record. Therefore we take the corresponding
                  // F record from the stored string list.
                  _stream << _backtrack.last().at( 1 ) << "\r\n";
                }

              for( int i = _backtrack.count() - 1; i >= 0; i-- )
                {
                  // qDebug( "backtrack %d: %s, %s", i,
                  // _backtrack.at(i).at(0).toLatin1().data(),
                  // _backtrack.at(i).at(1).toLatin1().data() );

                  _stream << _backtrack.at(i).at(0) << "\r\n";
                }

              _backtrack.clear(); // make sure we aren't leaving old data behind.
            }
          else
            {
              // If backtrack contains no entries we must write out a F record at first
              makeSatConstEntry( lastfix.time.time() );
            }
        }

      /*
      qDebug("F-TimeCheck: time=%s, elapsed=%dms",
              lastLoggedFRecord->toString("hh:mm:ss").toLatin1().data(),
              lastLoggedFRecord->elapsed());
      */

      // Check if F record has to be written
      if( lastLoggedFRecord->elapsed() >= 5*60*1000 )
        {
          // According to the IGC specification after 5 minutes a F record has
          // to be logged. So we will do now.
          makeSatConstEntry( lastfix.time.time() );
        }

      _stream << bRecord << "\r\n";

      // write K-Record
      writeKRecord( lastfix.time.time() );

      emit madeEntry();
    }
}