Auto status change to "Under Review"
@@ -1,51 +1,67 | |||
|
1 | 1 | #ifndef SCIQLOP_CATALOGUECONTROLLER_H |
|
2 | 2 | #define SCIQLOP_CATALOGUECONTROLLER_H |
|
3 | 3 | |
|
4 | 4 | #include "CoreGlobal.h" |
|
5 | 5 | |
|
6 | 6 | #include <Data/SqpRange.h> |
|
7 | 7 | |
|
8 | 8 | #include <QLoggingCategory> |
|
9 | 9 | #include <QObject> |
|
10 | 10 | #include <QUuid> |
|
11 | 11 | |
|
12 | 12 | #include <Common/spimpl.h> |
|
13 | 13 | |
|
14 | #include <memory> | |
|
15 | ||
|
16 | class DBCatalogue; | |
|
17 | class DBEvent; | |
|
18 | ||
|
14 | 19 | Q_DECLARE_LOGGING_CATEGORY(LOG_CatalogueController) |
|
15 | 20 | |
|
16 | 21 | class DataSourceItem; |
|
17 | 22 | class Variable; |
|
18 | 23 | |
|
19 | 24 | /** |
|
20 |
* @brief The CatalogueController class aims to |
|
|
21 | * This is the intermediate class that SciQlop has to use in the way to connect a data source. | |
|
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 | * @brief The CatalogueController class aims to handle catalogues and event using the CatalogueAPI | |
|
26 | * library. | |
|
25 | 27 | */ |
|
26 | 28 | class SCIQLOP_CORE_EXPORT CatalogueController : public QObject { |
|
27 | 29 | Q_OBJECT |
|
28 | 30 | public: |
|
29 | 31 | explicit CatalogueController(QObject *parent = 0); |
|
30 | 32 | virtual ~CatalogueController(); |
|
31 | 33 | |
|
32 | signals: | |
|
33 | /// Signal emitted when a variable is about to be deleted from SciQlop | |
|
34 | void variableAboutToBeDeleted(std::shared_ptr<Variable> variable); | |
|
34 | // DB | |
|
35 | QStringList getRepositories() const; | |
|
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 | |
|
37 | void rangeChanged(std::shared_ptr<Variable> variable, const SqpRange &range); | |
|
49 | // Catalogue | |
|
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 | 55 | public slots: |
|
40 | 56 | /// Manage init/end of the controller |
|
41 | 57 | void initialize(); |
|
42 | 58 | void finalize(); |
|
43 | 59 | |
|
44 | 60 | private: |
|
45 | 61 | void waitForFinish(); |
|
46 | 62 | |
|
47 | 63 | class CatalogueControllerPrivate; |
|
48 | 64 | spimpl::unique_impl_ptr<CatalogueControllerPrivate> impl; |
|
49 | 65 | }; |
|
50 | 66 | |
|
51 | 67 | #endif // SCIQLOP_CATALOGUECONTROLLER_H |
@@ -1,52 +1,131 | |||
|
1 | 1 | #include <Catalogue/CatalogueController.h> |
|
2 | 2 | |
|
3 | 3 | #include <Variable/Variable.h> |
|
4 | 4 | |
|
5 | 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 | 14 | #include <QMutex> |
|
8 | 15 | #include <QThread> |
|
9 | 16 | |
|
10 | 17 | #include <QDir> |
|
11 | 18 | #include <QStandardPaths> |
|
12 | 19 | |
|
13 | 20 | Q_LOGGING_CATEGORY(LOG_CatalogueController, "CatalogueController") |
|
14 | 21 | |
|
22 | namespace { | |
|
23 | ||
|
24 | static QString REPOSITORY_WORK_SUFFIX = QString{"Work"}; | |
|
25 | ||
|
26 | } | |
|
27 | ||
|
15 | 28 | class CatalogueController::CatalogueControllerPrivate { |
|
16 | 29 | public: |
|
17 | 30 | QMutex m_WorkingMutex; |
|
18 | 31 | CatalogueDao m_CatalogueDao; |
|
32 | ||
|
33 | std::list<QString> m_RepositoryList; | |
|
19 | 34 | }; |
|
20 | 35 | |
|
21 | 36 | CatalogueController::CatalogueController(QObject *parent) |
|
22 | 37 | : impl{spimpl::make_unique_impl<CatalogueControllerPrivate>()} |
|
23 | 38 | { |
|
24 | 39 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController construction") |
|
25 | 40 | << QThread::currentThread(); |
|
26 | 41 | } |
|
27 | 42 | |
|
28 | 43 | CatalogueController::~CatalogueController() |
|
29 | 44 | { |
|
30 | 45 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController destruction") |
|
31 | 46 | << QThread::currentThread(); |
|
32 | 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 | { | |
|
68 | impl->m_RepositoryList << dirName; | |
|
69 | } | |
|
70 | } | |
|
71 | else { | |
|
72 | qCCritical(LOG_CatalogueController()) << tr("Impossible to addDB that not exists: ") | |
|
73 | << dbPath; | |
|
74 | } | |
|
75 | } | |
|
76 | ||
|
77 | void CatalogueController::saveDB(const QString &destinationPath, const QString &repository) | |
|
78 | { | |
|
79 | if (!impl->m_CatalogueDao.saveDB(destinationPath, repository)) { | |
|
80 | qCCritical(LOG_CatalogueController()) | |
|
81 | << tr("Impossible to saveDB %1 from %2 ").arg(repository, destinationPath); | |
|
82 | } | |
|
83 | } | |
|
84 | ||
|
85 | std::list<std::shared_ptr<DBEvent> > | |
|
86 | CatalogueController::retrieveEvents(const QString &repository) const | |
|
87 | { | |
|
88 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; | |
|
89 | auto events = impl->m_CatalogueDao.getEvents(repository); | |
|
90 | for (auto event : events) { | |
|
91 | eventsShared.push_back(std::make_shared<DBEvent>(event)); | |
|
92 | } | |
|
93 | return eventsShared; | |
|
94 | } | |
|
95 | ||
|
96 | std::list<std::shared_ptr<DBEvent> > CatalogueController::retrieveAllEvents() const | |
|
97 | { | |
|
98 | auto eventsShared = std::list<std::shared_ptr<DBEvent> >{}; | |
|
99 | for (auto repository : impl->m_RepositoryList) { | |
|
100 | eventsShared.splice(eventsShared.end(), retrieveEvents(repository)); | |
|
101 | } | |
|
102 | ||
|
103 | return eventsShared; | |
|
104 | } | |
|
105 | ||
|
35 | 106 | void CatalogueController::initialize() |
|
36 | 107 | { |
|
37 | 108 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController init") |
|
38 | 109 | << QThread::currentThread(); |
|
39 | 110 | impl->m_WorkingMutex.lock(); |
|
40 | 111 | impl->m_CatalogueDao.initialize(); |
|
41 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END"); | |
|
112 | auto defaultRepository = QString("%1/%2").arg( | |
|
113 | QStandardPaths::displayName(QStandardPaths::AppDataLocation), REPOSITORY_DEFAULT); | |
|
114 | QDir defaultRepositoryDir(defaultRepository); | |
|
115 | if (defaultRepositoryDir.exists()) { | |
|
116 | qCInfo(LOG_CatalogueController()) << tr("Persistant data loading from: ") | |
|
117 | << defaultRepository; | |
|
118 | this->addDB(defaultRepository); | |
|
119 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END"); | |
|
120 | } | |
|
42 | 121 | } |
|
43 | 122 | |
|
44 | 123 | void CatalogueController::finalize() |
|
45 | 124 | { |
|
46 | 125 | impl->m_WorkingMutex.unlock(); |
|
47 | 126 | } |
|
48 | 127 | |
|
49 | 128 | void CatalogueController::waitForFinish() |
|
50 | 129 | { |
|
51 | 130 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
52 | 131 | } |
General Comments 3
Status change > Approved
You need to be logged in to leave comments.
Login now