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,139 | |||
|
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 | 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 | 105 | void CatalogueController::initialize() |
|
36 | 106 | { |
|
37 | 107 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController init") |
|
38 | 108 | << QThread::currentThread(); |
|
39 | 109 | impl->m_WorkingMutex.lock(); |
|
40 | 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 | 128 | qCDebug(LOG_CatalogueController()) << tr("CatalogueController init END"); |
|
42 | 129 | } |
|
43 | 130 | |
|
44 | 131 | void CatalogueController::finalize() |
|
45 | 132 | { |
|
46 | 133 | impl->m_WorkingMutex.unlock(); |
|
47 | 134 | } |
|
48 | 135 | |
|
49 | 136 | void CatalogueController::waitForFinish() |
|
50 | 137 | { |
|
51 | 138 | QMutexLocker locker{&impl->m_WorkingMutex}; |
|
52 | 139 | } |
General Comments 3
Status change > Approved
You need to be logged in to leave comments.
Login now