Esempio n. 1
0
  QStringList Preferences::Keys() const
  {
    QMutexLocker scopedMutex(&m_Mutex);
    AssertValid_unlocked();

    return m_Properties.keys();
  }
Esempio n. 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);
 }
Esempio n. 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)));
 }
Esempio n. 4
0
 void Preferences::Clear()
 {
   {
     QMutexLocker scopedMutex(&m_Mutex);
     AssertValid_unlocked();
     m_Properties.clear();
   }
   this->SetDirty(true);
 }
Esempio n. 5
0
 void Preferences::SetDirty( bool _Dirty )
 {
   {
     QMutexLocker scopedMutex(&m_Mutex);
     m_Dirty = _Dirty;
   }
   if(_Dirty)
   {
     this->OnChanged.Send(this);
   }
 }
Esempio n. 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;
 }
Esempio n. 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;
  }
Esempio n. 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));
   }
 }
Esempio n. 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;
  }
Esempio n. 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);
  }
Esempio n. 11
0
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();
}
Esempio n. 12
0
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_;
}
Esempio n. 13
0
 Preferences::ChildrenList Preferences::GetChildren() const
 {
   QMutexLocker scopedMutex(&m_Mutex);
   return m_Children;
 }
Esempio n. 14
0
 Preferences::PropertyMap Preferences::GetProperties() const
 {
   QMutexLocker scopedMutex(&m_Mutex);
   return m_Properties;
 }
Esempio n. 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;
 }
Esempio n. 16
0
 bool Preferences::IsRemoved() const
 {
   QMutexLocker scopedMutex(&m_Mutex);
   return m_Removed;
 }
Esempio n. 17
0
 void Preferences::SetRemoved( bool _Removed )
 {
   QMutexLocker scopedMutex(&m_Mutex);
   this->SetRemoved_unlocked(_Removed);
 }
Esempio n. 18
0
 bool Preferences::Has(const QString& key ) const
 {
   QMutexLocker scopedMutex(&m_Mutex);
   return this->Has_unlocked(key);
 }
Esempio n. 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;
 }
Esempio n. 20
0
 IPreferences::Pointer Preferences::Parent() const
 {
   QMutexLocker scopedMutex(&m_Mutex);
   AssertValid_unlocked();
   return IPreferences::Pointer(m_Parent);
 }
Esempio n. 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;
 }
Esempio n. 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;
 }
Esempio n. 23
0
 void Preferences::PutByteArray(const QString& key, const QByteArray& value)
 {
   QMutexLocker scopedMutex(&m_Mutex);
   AssertValid_unlocked();
   this->Put(key, value.toBase64().data());
 }
Esempio n. 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;
 }
Esempio n. 25
0
 IPreferences::Pointer Preferences::Node(const QString& path)
 {
   QMutexLocker scopedMutex(&m_Mutex);
   return this->Node_unlocked(path);
 }