QStringList Preferences::Keys() const { QMutexLocker scopedMutex(&m_Mutex); AssertValid_unlocked(); return m_Properties.keys(); }
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); }
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))); }
void Preferences::Clear() { { QMutexLocker scopedMutex(&m_Mutex); AssertValid_unlocked(); m_Properties.clear(); } this->SetDirty(true); }
void Preferences::SetDirty( bool _Dirty ) { { QMutexLocker scopedMutex(&m_Mutex); m_Dirty = _Dirty; } if(_Dirty) { this->OnChanged.Send(this); } }
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; }
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; }
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)); } }
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; }
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_; }
Preferences::ChildrenList Preferences::GetChildren() const { QMutexLocker scopedMutex(&m_Mutex); return m_Children; }
Preferences::PropertyMap Preferences::GetProperties() const { QMutexLocker scopedMutex(&m_Mutex); return m_Properties; }
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; }
bool Preferences::IsRemoved() const { QMutexLocker scopedMutex(&m_Mutex); return m_Removed; }
void Preferences::SetRemoved( bool _Removed ) { QMutexLocker scopedMutex(&m_Mutex); this->SetRemoved_unlocked(_Removed); }
bool Preferences::Has(const QString& key ) const { QMutexLocker scopedMutex(&m_Mutex); return this->Has_unlocked(key); }
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; }
IPreferences::Pointer Preferences::Parent() const { QMutexLocker scopedMutex(&m_Mutex); AssertValid_unlocked(); return IPreferences::Pointer(m_Parent); }
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; }
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; }
void Preferences::PutByteArray(const QString& key, const QByteArray& value) { QMutexLocker scopedMutex(&m_Mutex); AssertValid_unlocked(); this->Put(key, value.toBase64().data()); }
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; }
IPreferences::Pointer Preferences::Node(const QString& path) { QMutexLocker scopedMutex(&m_Mutex); return this->Node_unlocked(path); }