##// END OF EJS Templates
Merge branch 'feature/KernelSciQlopCatalogu' into develop
trabillard -
r1160:6701a5941352 merge
parent child
Show More
@@ -11,17 +11,19
11
11
12 #include <Common/spimpl.h>
12 #include <Common/spimpl.h>
13
13
14 #include <memory>
15
16 class DBCatalogue;
17 class DBEvent;
18
14 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueController)
19 Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueController)
15
20
16 class DataSourceItem;
21 class DataSourceItem;
17 class Variable;
22 class Variable;
18
23
19 /**
24 /**
20 * @brief The CatalogueController class aims to make the link between SciQlop and its plugins.
25 * @brief The CatalogueController class aims to handle catalogues and event using the CatalogueAPI
21 * This is the intermediate class that SciQlop has to use in the way to connect a data source.
26 * library.
22 * Please first use register method to initialize a plugin specified by its metadata name (JSON
23 * plugin source) then others specifics method will be able to access it. You can load a data source
24 * driver plugin then create a data source.
25 */
27 */
26 class SCIQLOP_CORE_EXPORT CatalogueController : public QObject {
28 class SCIQLOP_CORE_EXPORT CatalogueController : public QObject {
27 Q_OBJECT
29 Q_OBJECT
@@ -29,12 +31,26 public:
29 explicit CatalogueController(QObject *parent = 0);
31 explicit CatalogueController(QObject *parent = 0);
30 virtual ~CatalogueController();
32 virtual ~CatalogueController();
31
33
32 signals:
34 // DB
33 /// Signal emitted when a variable is about to be deleted from SciQlop
35 QStringList getRepositories() const;
34 void variableAboutToBeDeleted(std::shared_ptr<Variable> variable);
36 void addDB(const QString &dbPath);
37 void saveDB(const QString &destinationPath, const QString &repository);
38
39 // Event
40 bool createEvent(const QString &name);
41 std::list<std::shared_ptr<DBEvent> > retrieveEvents(const QString &repository) const;
42 std::list<std::shared_ptr<DBEvent> > retrieveAllEvents() const;
43 void updateEvent(std::shared_ptr<DBEvent> event);
44 void trashEvent(std::shared_ptr<DBEvent> event);
45 void removeEvent(std::shared_ptr<DBEvent> event);
46 void restore(QUuid eventId);
47 void saveEvent(std::shared_ptr<DBEvent> event);
35
48
36 /// Signal emitted when a data acquisition is requested on a range for a variable
49 // Catalogue
37 void rangeChanged(std::shared_ptr<Variable> variable, const SqpRange &range);
50 bool createCatalogue(const QString &name, QVector<QUuid> eventList);
51 void getCatalogues(const QString &repository) const;
52 void removeEvent(QUuid catalogueId, const QString &repository);
53 void saveCatalogue(std::shared_ptr<DBEvent> event);
38
54
39 public slots:
55 public slots:
40 /// Manage init/end of the controller
56 /// Manage init/end of the controller
@@ -4,6 +4,13
4
4
5 #include <CatalogueDao.h>
5 #include <CatalogueDao.h>
6
6
7 #include <ComparaisonPredicate.h>
8 #include <CompoundPredicate.h>
9 #include <DBCatalogue.h>
10 #include <DBEvent.h>
11 #include <DBTag.h>
12 #include <IRequestPredicate.h>
13
7 #include <QMutex>
14 #include <QMutex>
8 #include <QThread>
15 #include <QThread>
9
16
@@ -12,10 +19,18
12
19
13 Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController")
20 Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController")
14
21
22 namespace {
23
24 static QString REPOSITORY_WORK_SUFFIX = QString{"Work"};
25
26 }
27
15 class CatalogueController::CatalogueControllerPrivate {
28 class CatalogueController::CatalogueControllerPrivate {
16 public:
29 public:
17 QMutex m_WorkingMutex;
30 QMutex m_WorkingMutex;
18 CatalogueDao m_CatalogueDao;
31 CatalogueDao m_CatalogueDao;
32
33 std::list<QString> m_RepositoryList;
19 };
34 };
20
35
21 CatalogueController::CatalogueController(QObject *parent)
36 CatalogueController::CatalogueController(QObject *parent)
@@ -32,12 +47,84 CatalogueController::~CatalogueController()
32 this->waitForFinish();
47 this->waitForFinish();
33 }
48 }
34
49
50 void CatalogueController::addDB(const QString &dbPath)
51 {
52 QDir dbDir(dbPath);
53 if (dbDir.exists()) {
54 auto dirName = dbDir.dirName();
55
56 if (std::find(impl->m_RepositoryList.cbegin(), impl->m_RepositoryList.cend(), dirName)
57 != impl->m_RepositoryList.cend()) {
58 qCCritical(LOG_CatalogueController())
59 << tr("Impossible to addDB that is already loaded");
60 }
61
62 if (!impl->m_CatalogueDao.addDB(dbPath, dirName)) {
63 qCCritical(LOG_CatalogueController())
64 << tr("Impossible to addDB %1 from %2 ").arg(dirName, dbPath);
65 }
66 else {
67 impl->m_RepositoryList.push_back(dirName);
68 }
69 }
70 else {
71 qCCritical(LOG_CatalogueController()) << tr("Impossible to addDB that not exists: ")
72 << dbPath;
73 }
74 }
75
76 void CatalogueController::saveDB(const QString &destinationPath, const QString &repository)
77 {
78 if (!impl->m_CatalogueDao.saveDB(destinationPath, repository)) {
79 qCCritical(LOG_CatalogueController())
80 << tr("Impossible to saveDB %1 from %2 ").arg(repository, destinationPath);
81 }
82 }
83
84 std::list<std::shared_ptr<DBEvent> >
85 CatalogueController::retrieveEvents(const QString &repository) const
86 {
87 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
88 auto events = impl->m_CatalogueDao.getEvents(repository);
89 for (auto event : events) {
90 eventsShared.push_back(std::make_shared<DBEvent>(event));
91 }
92 return eventsShared;
93 }
94
95 std::list<std::shared_ptr<DBEvent> > CatalogueController::retrieveAllEvents() const
96 {
97 auto eventsShared = std::list<std::shared_ptr<DBEvent> >{};
98 for (auto repository : impl->m_RepositoryList) {
99 eventsShared.splice(eventsShared.end(), retrieveEvents(repository));
100 }
101
102 return eventsShared;
103 }
104
35 void CatalogueController::initialize()
105 void CatalogueController::initialize()
36 {
106 {
37 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init")
107 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init")
38 << QThread::currentThread();
108 << QThread::currentThread();
39 impl->m_WorkingMutex.lock();
109 impl->m_WorkingMutex.lock();
40 impl->m_CatalogueDao.initialize();
110 impl->m_CatalogueDao.initialize();
111 auto defaultRepositoryLocation
112 = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
113
114 QDir defaultRepositoryLocationDir;
115 if (defaultRepositoryLocationDir.mkpath(defaultRepositoryLocation)) {
116 defaultRepositoryLocationDir.cd(defaultRepositoryLocation);
117 auto defaultRepository = defaultRepositoryLocationDir.absoluteFilePath(REPOSITORY_DEFAULT);
118 qCInfo(LOG_CatalogueController())
119 << tr("Persistant data loading from: ") << defaultRepository;
120 this->addDB(defaultRepository);
121 }
122 else {
123 qCWarning(LOG_CatalogueController())
124 << tr("Cannot load the persistent default repository from ")
125 << defaultRepositoryLocation;
126 }
127
41 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END");
128 qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END");
42 }
129 }
43
130
General Comments 3
Under Review
author

Auto status change to "Under Review"

Approved

Status change > Approved

You need to be logged in to leave comments. Login now