Revision: 40873
http://brlcad.svn.sourceforge.net/brlcad/?rev=40873&view=rev
Author: davidloman
Date: 2010-09-29 20:05:47 +0000 (Wed, 29 Sep 2010)
Log Message:
-----------
Implement reading and writing objects to/from path with locking in place.
Modified Paths:
--------------
rt^3/trunk/include/FileDataSource.h
rt^3/trunk/src/GS/FileDataSource.cxx
Modified: rt^3/trunk/include/FileDataSource.h
===================================================================
--- rt^3/trunk/include/FileDataSource.h 2010-09-29 20:05:06 UTC (rev 40872)
+++ rt^3/trunk/include/FileDataSource.h 2010-09-29 20:05:47 UTC (rev 40873)
@@ -28,6 +28,8 @@
#include "IDataSource.h"
+#include <QtCore/QMutex>
+
class FileDataSource: public IDataSource {
public:
FileDataSource(QString repoPath);
@@ -44,6 +46,12 @@
private:
QString repoPath;
+ QMutex lockLock;
+ QList<QString> pathLocks;
+ bool hasPathLock(QString path);
+ void setPathLock(QString path);
+ void remPathLock(QString path);
+
};
#endif /* __FILEDATASOURCE_H__ */
Modified: rt^3/trunk/src/GS/FileDataSource.cxx
===================================================================
--- rt^3/trunk/src/GS/FileDataSource.cxx 2010-09-29 20:05:06 UTC (rev
40872)
+++ rt^3/trunk/src/GS/FileDataSource.cxx 2010-09-29 20:05:47 UTC (rev
40873)
@@ -25,40 +25,109 @@
#include "FileDataSource.h"
-FileDataSource::FileDataSource(QString repoPath):repoPath(repoPath)
-{
+#include <QtCore/QMutexLocker>
+#include <QtCore/QFile>
+
+FileDataSource::FileDataSource(QString repoPath) :
+ repoPath(repoPath) {
+
}
FileDataSource::~FileDataSource() {
}
-bool
-FileDataSource::lock(DbObject* obj, Account* a)
-{
+bool FileDataSource::lock(DbObject* obj, Account* a) {
}
-bool
-FileDataSource::hasLock(DbObject* obj, Account* a)
-{
+bool FileDataSource::hasLock(DbObject* obj, Account* a) {
}
-bool
-FileDataSource::unlock(DbObject* obj)
-{
+bool FileDataSource::unlock(DbObject* obj) {
}
DbObject*
-FileDataSource::getByPath(QString path)
-{
+FileDataSource::getByPath(QString path) {
+
+ //See if there is a file lock on this path
+ bool hasLock = this->hasPathLock(path);
+
+ //TODO failsafe this loop!
+ while (hasLock) {
+ GSThread::msleep(567);
+ hasLock = this->hasPathLock(path);
+ }
+
+ //lock it
+ this->setPathLock(path);
+
+ QFile f(this->repoPath + "/" + path);
+
+ if (f.exists()) {
+ QByteArray* data = new QByteArray(f.readAll());
+ DbObject* object = new DbObject(path, data);
+
+ f.close();
+
+ //unlock it
+ this->remPathLock(path);
+
+ return object;
+ }
+
+ f.close();
+
+ //unlock it
+ this->remPathLock(path);
+
+ return NULL;
}
+
DbObject*
-FileDataSource::getByID(QUuid id)
-{
+FileDataSource::getByID(QUuid id) {
+ return NULL;
}
-bool
-FileDataSource::putObject(DbObject* obj)
-{
+
+bool FileDataSource::putObject(DbObject* obj) {
+ QString path = obj->getPath();
+
+ //See if there is a file lock on this path
+ bool hasLock = this->hasPathLock(path);
+
+ //TODO failsafe this loop!
+ while (hasLock) {
+ GSThread::msleep(567);
+ hasLock = this->hasPathLock(path);
+ }
+
+ //lock it
+ this->setPathLock(path);
+
+ QFile f(this->repoPath + "/" + path);
+ f.write(*obj->getData());
+
+ f.close();
+
+ //unlock it
+ this->remPathLock(path);
+
+ return true;
}
+bool FileDataSource::hasPathLock(QString path) {
+ QMutexLocker(&this->lockLock);
+ return this->pathLocks.contains(path);
+}
+void FileDataSource::setPathLock(QString path) {
+ QMutexLocker(&this->lockLock);
+ if (!this->pathLocks.contains(path)) {
+ this->pathLocks.append(path);
+ }
+}
+
+void FileDataSource::remPathLock(QString path) {
+ QMutexLocker(&this->lockLock);
+ this->pathLocks.append(path);
+}
+
// Local Variables:
// tab-width: 8
// mode: C++
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing.
http://p.sf.net/sfu/novell-sfdev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits