Exemple #1
0
void testObj::test<5>(void)
{
  const DataRef dr1(buf_, sizeof(buf_));
  const DataRef dr2(dr1);
  ensure_equals("invalid size", dr2.size(), dr1.size());
  ensure("invalid data poitner", dr1.data()==dr2.data());
}
Exemple #2
0
void testObj::test<2>(void)
{
  const uint8_t buf[]={4,2};
  const DataRef out  =nc_.encrypt(buf, 0);
  ensure_equals("invalid size", out.size(), 0u);
  ensure("NULL pointer returned", out.data()!=NULL);
}
Exemple #3
0
void testObj::test<3>(void)
{
  const uint8_t buf[]={4,2};
  const DataRef out  =nc_.decrypt(buf, sizeof(buf));
  ensure_equals("invalid size", out.size(), 2u);
  ensure("NULL pointer returned", out.data()!=NULL);
  ensure_equals("invalid element 0", out[0], 4);
  ensure_equals("invalid element 1", out[1], 2);
}
void WriteOneByOneAndEnd( Stream& stream, DataRef data )
{
  for ( const uint8_t* it = data.Start(); it != data.End(); it++ )
  {
    stream.Write( DataRef( it, it + 1 ) );
    stream.Write( DataRef() );
  }

  stream.End();
}
Exemple #5
0
TcpClient::~TcpClient() {
    qDebug() << Q_FUNC_INFO;
    _socket->disconnectFromHost();
    while(!_subscribedRefs.isEmpty()) {
        DataRef *ref = _subscribedRefs.values().first();
        _subscribedRefs.remove(ref);
        ref->disconnect(this);
        _refProvider->unsubscribeRef(ref);
    }
    emit discoed(this);
}
Exemple #6
0
TcpClient::~TcpClient() {
    DEBUG;
    _socket->disconnectFromHost();
    while(!_subscribedRefs.isEmpty()) {
        DataRef *ref = _subscribedRefs.values().first();
        _subscribedRefs.remove(ref);
        ref->disconnect(this);
        _refProvider->unsubscribeRef(ref);
    }
    foreach(int but, _heldButtons)
        _refProvider->buttonRelease(but);
    emit discoed(this);
}
Exemple #7
0
void ArchiveReader::Write( DataRef data )
{
  const uint8_t* start = data.Start();
  const uint8_t* end = data.End();

  while ( start != end )
  {
    switch ( m_state )
    {
    case STATE_PATH_ENCODING:
      start = PathEncoding( start, end );
      break;

    case STATE_FILE_LENGTH_LENGTH:
      start = FileLengthLength( start, end );
      break;

    case STATE_PATH_LENGTH:
      start = PathLength( start, end );
      break;

    case STATE_PATH:
      start = Path( start, end );
      break;

    case STATE_DATE_LENGTH:
      start = DateLength( start, end );
      break;

    case STATE_DATE:
      start = Date( start, end );
      break;

    case STATE_FILE_LENGTH:
      start = FileLength( start, end );
      break;

    case STATE_FILE:
      start = File( start, end );
      break;

    case STATE_DONE:
      throw Error( "More data received after the end of the archive" );
    }
  }
}
Exemple #8
0
static bool HasDotDotComponent( DataRef path )
{
  const uint8_t* start = path.Start();
  const uint8_t* end = path.End();

  while ( true )
  {
    const uint8_t* slash = std::find( start, end, '/' );

    if ( DataRef( start, slash ) == DataRef( ".." ) )
      return true;

    if ( slash == end )
      return false;

    start = slash + 1;
  }
}
Exemple #9
0
DataRef* XPlanePlugin::subscribeRef(QString name) {
    DEBUG << name;

    // Search in list of already subscribed datarefs - if found return that
    foreach(DataRef *ref, refs) {
        if(ref->name()==name) {
            DEBUG << "Already subscribed to " << name;
            ref->setSubscribers(ref->subscribers() + 1);
            return ref;
        }
    }

    // Not yet subscribed - create a new dataref
    XPLMDataRef ref = XPLMFindDataRef(name.toLatin1());
    if(ref) {
        XPLMDataTypeID refType = XPLMGetDataRefTypes(ref);
        DataRef *dr = 0;
        if(refType & xplmType_Double) {
            dr = new DoubleDataRef(this, name, ref);
        } else if(refType & xplmType_Float) {
            dr = new FloatDataRef(this, name, ref);
        } else if(refType & xplmType_Int) {
            dr = new IntDataRef(this, name, ref);
        } else if (refType & xplmType_FloatArray) {
            dr = new FloatArrayDataRef(this, name, ref);
        } else if (refType & xplmType_IntArray) {
            dr = new IntArrayDataRef(this, name, ref);
        } else if (refType & xplmType_Data) {
            dr = new DataDataRef(this, name, ref);
        }
        if(dr) {
            dr->setSubscribers(1);
            dr->setWritable(XPLMCanWriteDataRef(ref) != 0);
            DEBUG << "Subscribed to ref " << dr->name() << ", type: " << dr->typeString() << ", writable:" << dr->isWritable();
            refs.append(dr);
            return dr;
        } else {
            INFO << "Dataref type " << refType << "not supported";
        }
    } else {
        INFO << "Can't find dataref " << name;
    }
    return 0;
}
static void PrintTo(const DataRef& dataRef,
             std::ostream*  os)
{
    *os << "Size=" << dataRef.size() << " ";
    
    for (auto d : dataRef)
    {
        *os << (int)d << " ";
    }
}
Exemple #11
0
void TcpClient::readClient() {
    while(_socket->canReadLine()) {
        QByteArray lineBA = _socket->readLine();

        QString line = QString(lineBA).trimmed();
        DEBUG << "Client says: " << line;
        // Split the command in strings
        QStringList subLine = line.split(" ", QString::SkipEmptyParts);
        QString command = subLine.value(0);
        if(command == "disconnect") {
            DEBUG << "killing this client connection";
            deleteLater();
        } else if(command == "sub") { // Subscribe command
            if(subLine.length() >= 2) {
                QString refName = subLine[1].trimmed();

                double accuracy = 0;
                if(subLine.length() >=3)
                    accuracy = subLine[2].toDouble();

                DataRef *ref = getSubscribedRef(refName);
                if(!ref) { // Ref not subscribed yet, try to subscribe
                    ref = _refProvider->subscribeRef(refName);
                    if(ref) { // Succesfully subscribed
                        connect(ref, SIGNAL(changed(DataRef*)), this, SLOT(refChanged(DataRef*)));
                        _subscribedRefs.insert(ref);
                        ref->setAccuracy(accuracy);
                        //TODO: why is ref->updateValue() not sufficient here?
                        if(ref->type() == xplmType_Float) {
                            _refValueF[ref] = qobject_cast<FloatDataRef*>(ref)->value();
                        } else if(ref->type() == xplmType_Int) {
                            _refValueI[ref] = qobject_cast<IntDataRef*>(ref)->value();
                        } else if(ref->type() == xplmType_Double) {
                            _refValueD[ref] = qobject_cast<DoubleDataRef*>(ref)->value();
                        } else if(ref->type() == xplmType_FloatArray) {
                            _refValueFA[ref] = qobject_cast<FloatArrayDataRef*>(ref)->value();
                        } else if(ref->type() == xplmType_IntArray) {
                            _refValueIA[ref] = qobject_cast<IntArrayDataRef*>(ref)->value();
                        } else if(ref->type() == xplmType_Data) {
                            _refValueB[ref] = qobject_cast<DataDataRef*>(ref)->value();
                        }
                        INFO << "Subscribed to " << ref->name() << ", accuracy " << accuracy << ", type " << ref->typeString();
                    } else {
                        INFO << "Ref not found" << refName;
                    }
                } else { // Ref already subscribed - update accuracy
Exemple #12
0
DateTime::DateTime( DataRef date )
{
  // Example: Sun, 11 Mar 1984 00:00:00 +0000

  Verify( date.Length() == 31 );
  m_dayOfWeek = ReadDayOfWeek( date.Slice( 0, 3 ) );
  Verify( date.Slice( 3, 2 ) == DataRef( ", " ) );
  m_day = ReadAsciiNumber<uint8_t>( date.Slice( 5, 2 ) );
  Verify( date[7] == ' ' );
  m_month = ReadMonth( date.Slice( 8, 3 ) );
  Verify( date[11] == ' ' );
  m_year = ReadAsciiNumber<uint32_t>( date.Slice( 12, 4 ) );
  Verify( date[16] == ' ' );
  m_hour = ReadAsciiNumber<uint8_t>( date.Slice( 17, 2 ) );
  Verify( date[19] == ':' );
  m_minute = ReadAsciiNumber<uint8_t>( date.Slice( 20, 2 ) );
  Verify( date[22] == ':' );
  m_second = ReadAsciiNumber<uint8_t>( date.Slice( 23, 2 ) );
  Verify( date[25] == ' ' );
  Verify( date.Slice( 25, 6 ) == DataRef( " +0000" ) );
}
Exemple #13
0
void TcpClient::readClient() {
    while(_socket->canReadLine()) {
        QByteArray lineBA = _socket->readLine();

        QString line = QString(lineBA);
        qDebug() << Q_FUNC_INFO << "Client says: " << line;
        QStringList subLine = line.split(" ", QString::SkipEmptyParts);
        QString command = subLine.value(0);
        if(command == "disconnect") {
            deleteLater();
        } else if(command == "sub") {
            if(subLine.length() >= 2) {
                QString refName = subLine[1].trimmed();

                double accuracy = 0;
                if(subLine.length() >=3)
                    accuracy = subLine[2].toDouble();

                DataRef *ref = getSubscribedRef(refName);
                if(!ref) {
                    ref = _refProvider->subscribeRef(refName);
                    if(ref) {
                        connect(ref, SIGNAL(changed(DataRef*)), this, SLOT(refChanged(DataRef*)));
                        _subscribedRefs.insert(ref);
                        _refAccuracy[ref] = accuracy;
                        if(ref->type() == xplmType_Float) {
                            _refValueF[ref] = qobject_cast<FloatDataRef*>(ref)->value();
                        } else if(ref->type() == xplmType_Int) {
                            _refValueI[ref] = qobject_cast<IntDataRef*>(ref)->value();
                        } else if(ref->type() == xplmType_Double) {
                            _refValueD[ref] = qobject_cast<DoubleDataRef*>(ref)->value();
                        }
                        qDebug() << Q_FUNC_INFO << "Subscribed to " << ref->name() << ", accuracy " << accuracy;
                    } else {
                        qDebug() << Q_FUNC_INFO << "Ref not found" << refName;
                    }
                } else {
Exemple #14
0
void testObj::test<5>(void)
{
  const uint8_t *ptr=NULL;
  // some initial size
  {
    const uint8_t buf[]={4,2,6,6,6};
    const DataRef out  =nc_.decrypt(buf, sizeof(buf));
    ensure_equals("invalid size", out.size(), 5u);
    ensure("NULL pointer returned", out.data()!=NULL);
    ptr=out.data();
  }
  // no resize now
  {
    const uint8_t buf[]={4,2};
    const DataRef out  =nc_.decrypt(buf, sizeof(buf));
    ensure_equals("invalid size", out.size(), 2u);
    ensure("NULL pointer returned", out.data()!=NULL);
    ensure("pointer ha been reallocated", ptr==out.data());
  }
}
Exemple #15
0
void testObj::test<2>(void)
{
  const DataRef dr(buf_, 2);
  ensure_equals("invalid size", dr.size(), 2);
}
Exemple #16
0
 virtual bool hasFill() const { return fill && fill->hasData(); }
Exemple #17
0
 irange getYRange() const { return fill->getData().yrange; }
Exemple #18
0
 bool isFixedSize() const { return fill->getData().has_grid; }  
Exemple #19
0
 const Transform& getTransform() const { return tr->getData(); }
Exemple #20
0
 bool hasTransform() const{ return tr->hasData();}
Exemple #21
0
 virtual const Fill& getFill() const { 
   if( fill && fill->hasData() ){
     return fill->getData();
   }
   throw std::runtime_error( "Called getFill() on an unfilled cell");
 }
Exemple #22
0
 virtual const Lattice& getLattice() const {
   if( lattice && lattice->hasData() ){
     return lattice->getData();
   }
   throw std::runtime_error( "Called getLattice() on a cell that hasn't got one" );
 }
Exemple #23
0
void testObj::test<3>(void)
{
  const DataRef dr(buf_, 2);
  ensure("invalid data pointer", dr.data()==buf_);
}
void StringStream::Write( DataRef data )
{
  output.insert( output.end(), data.Start(), data.End() );
}