Beispiel #1
0
  QStringList Preferences::Keys() const
  {
    QMutexLocker scopedMutex(&m_Mutex);
    AssertValid_unlocked();

    return m_Properties.keys();
  }
Beispiel #2
0
 void Preferences::Remove(const QString& key)
 {
   QMutexLocker scopedMutex(&m_Mutex);
   AssertValid_unlocked();
   PropertyMap::iterator it = m_Properties.find(key);
   if(it != m_Properties.end())
     m_Properties.erase(it);
 }
Beispiel #3
0
 void Preferences::RemoveNode()
 {
   QMutexLocker scopedMutex(&m_Mutex);
   AssertValid_unlocked();
   this->SetRemoved_unlocked(true);
   m_Parent->m_Children.erase(std::find(m_Parent->m_Children.begin(), m_Parent->m_Children.end(),
     Preferences::Pointer(this)));
 }
Beispiel #4
0
 void Preferences::Clear()
 {
   {
     QMutexLocker scopedMutex(&m_Mutex);
     AssertValid_unlocked();
     m_Properties.clear();
   }
   this->SetDirty(true);
 }
Beispiel #5
0
 void Preferences::SetDirty( bool _Dirty )
 {
   {
     QMutexLocker scopedMutex(&m_Mutex);
     m_Dirty = _Dirty;
   }
   if(_Dirty)
   {
     this->OnChanged.Send(this);
   }
 }
Beispiel #6
0
 QStringList Preferences::ChildrenNames() const
 {
   QMutexLocker scopedMutex(&m_Mutex);
   AssertValid_unlocked();
   QStringList names;
   for (ChildrenList::const_iterator it = m_Children.begin()
     ; it != m_Children.end(); ++it)
   {
     names.push_back((*it)->Name());
   }
   return names;
 }
Beispiel #7
0
  bool Preferences::NodeExists(const QString& path) const
  {
    QString pathName = path;

    QMutexLocker scopedMutex(&m_Mutex);
    AssertValid_unlocked();
    AssertPath_unlocked(pathName);

    bool nodeExists = false;

    // absolute path
    if(pathName[0] == '/')
    {
      pathName = pathName.mid(1);
      // call root with this relative path
      return m_Root->NodeExists(pathName);
    }
    // relative path
    else
    {
      // check if pathName contains anymore names
      QString name = pathName;

      // create new child nodes as long as there are names in the path
      int pos = pathName.indexOf("/");
      // cut from the beginning
      if(pos != -1)
      {
        name = pathName.left(pos);
        pathName = pathName.mid(pos+1);
      }

      // now check if node exists->if not: make new
      for (ChildrenList::const_iterator it = m_Children.begin()
        ; it != m_Children.end(); it++)
      {
        // node found
        if((*it)->Name() == name)
        {
          // call recursively if more names on the path exist
          if(pos != -1)
            nodeExists = (*it)->NodeExists(pathName);
          else
            nodeExists = true;
          break;
        }
      }
    }

    return nodeExists;
  }
Beispiel #8
0
 void Preferences::Put(const QString& key, const QString& value)
 {
   QString oldValue;
   {
     QMutexLocker scopedMutex(&m_Mutex);
     AssertValid_unlocked();
     oldValue = m_Properties[key];
     m_Properties[key] = value;
   }
   if (oldValue != value)
   {
     this->SetDirty(true);
     this->OnPropertyChanged(ChangeEvent(this, key, oldValue, value));
   }
 }
Beispiel #9
0
  bool Preferences::IsDirty() const
  {
    QMutexLocker scopedMutex(&m_Mutex);

    bool dirty = m_Dirty;
    for (ChildrenList::const_iterator it = m_Children.begin()
      ; it != m_Children.end(); ++it)
    {
      // break condition: if one node is dirty the whole tree is dirty
      if(dirty)
        break;
      else
        dirty = (*it)->IsDirty();
    }

    return dirty;
  }
Beispiel #10
0
  void Preferences::Flush()
  {
    {
      QMutexLocker scopedMutex(&m_Mutex);
      AssertValid_unlocked();
    }

    m_Storage->Flush(this);

    // if something is written, make the tree undirty
    // there is a race condition here: after flushing, another thread
    // could modify this object before we can set dirty to false,
    // but we cannot hold a lock before flushing because the operation
    // will call other methods on this object, which would lead
    // to a recursive lock.
    this->SetDirty(false);
  }
void PpapiDeviceInfo::gotDeviceId(int32_t result, const pp::Var& deviceId)
{
    assert(isMainThread());
    ScopedMutex scopedMutex(mutex_);
    string rawDeviceIdStr;
    if (result == PP_OK && deviceId.is_string())
        rawDeviceIdStr = deviceId.AsString();
    // Google says the device ID from PPAPI, when supported, will always be 64
    // chars: a string with the text value of the numerical ID. Clamp or extend
    // the actual received value to this length.
    const string::size_type SPEC_SIZE = 64;
    rawDeviceIdStr.resize(SPEC_SIZE, '0');
    // Now convert the text numerical ID to a binary value
    deviceIdBin_ = hexTextToBin(rawDeviceIdStr);
    assert(deviceIdBin_.size() == 32);
    // We are now initialized
    condVar_.signal();
}
vector<uint8_t> PpapiDeviceInfo::getBinaryDeviceId()
{
    assert(!isMainThread());
    // We get initialized by the PPAPI callback requested in the ctor. Block
    // here until that happens. Once the callback occurs, or we time out waiting
    // for it, we are forever after initialized.
    ScopedMutex scopedMutex(mutex_);
    if (deviceIdBin_.empty())
    {
        static const uint64_t timeoutMs(8000);    // 8s timeout
        ConditionVariable::Error err = ConditionVariable::OK;
        while (deviceIdBin_.empty())
        {
            err = condVar_.wait(mutex_, timeoutMs);
            if (err != ConditionVariable::OK)
                break;
        }
    }
    return deviceIdBin_;
}
Beispiel #13
0
 Preferences::ChildrenList Preferences::GetChildren() const
 {
   QMutexLocker scopedMutex(&m_Mutex);
   return m_Children;
 }
Beispiel #14
0
 Preferences::PropertyMap Preferences::GetProperties() const
 {
   QMutexLocker scopedMutex(&m_Mutex);
   return m_Properties;
 }
Beispiel #15
0
 bool Preferences::GetBool(const QString& key, bool def) const
 {
   QMutexLocker scopedMutex(&m_Mutex);
   AssertValid_unlocked();
   return this->Has_unlocked(key) ? (m_Properties[key] == "true" ? true: false) : def;
 }
Beispiel #16
0
 bool Preferences::IsRemoved() const
 {
   QMutexLocker scopedMutex(&m_Mutex);
   return m_Removed;
 }
Beispiel #17
0
 void Preferences::SetRemoved( bool _Removed )
 {
   QMutexLocker scopedMutex(&m_Mutex);
   this->SetRemoved_unlocked(_Removed);
 }
Beispiel #18
0
 bool Preferences::Has(const QString& key ) const
 {
   QMutexLocker scopedMutex(&m_Mutex);
   return this->Has_unlocked(key);
 }
Beispiel #19
0
 QByteArray Preferences::GetByteArray(const QString& key, const QByteArray& def) const
 {
   QMutexLocker scopedMutex(&m_Mutex);
   AssertValid_unlocked();
   return this->Has_unlocked(key) ? QByteArray::fromBase64(m_Properties[key].toLatin1()) : def;
 }
Beispiel #20
0
 IPreferences::Pointer Preferences::Parent() const
 {
   QMutexLocker scopedMutex(&m_Mutex);
   AssertValid_unlocked();
   return IPreferences::Pointer(m_Parent);
 }
Beispiel #21
0
 double Preferences::GetDouble(const QString& key, double def) const
 {
   QMutexLocker scopedMutex(&m_Mutex);
   AssertValid_unlocked();
   return this->Has_unlocked(key) ? m_Properties[key].toDouble() : def;
 }
Beispiel #22
0
 float Preferences::GetFloat(const QString& key, float def) const
 {
   QMutexLocker scopedMutex(&m_Mutex);
   AssertValid_unlocked();
   return this->Has_unlocked(key) ? m_Properties[key].toFloat() : def;
 }
Beispiel #23
0
 void Preferences::PutByteArray(const QString& key, const QByteArray& value)
 {
   QMutexLocker scopedMutex(&m_Mutex);
   AssertValid_unlocked();
   this->Put(key, value.toBase64().data());
 }
Beispiel #24
0
 long Preferences::GetLong(const QString& key, long def) const
 {
   QMutexLocker scopedMutex(&m_Mutex);
   AssertValid_unlocked();
   return this->Has_unlocked(key) ? m_Properties[key].toLong() : def;
 }
Beispiel #25
0
 IPreferences::Pointer Preferences::Node(const QString& path)
 {
   QMutexLocker scopedMutex(&m_Mutex);
   return this->Node_unlocked(path);
 }