@@ -1,28 +1,33 | |||
|
1 | 1 | #ifndef SCIQLOP_AMDASERVER_H |
|
2 | 2 | #define SCIQLOP_AMDASERVER_H |
|
3 | 3 | |
|
4 | 4 | #include <QLoggingCategory> |
|
5 | 5 | |
|
6 | 6 | #include <memory> |
|
7 | 7 | |
|
8 | 8 | Q_DECLARE_LOGGING_CATEGORY(LOG_AmdaServer) |
|
9 | 9 | |
|
10 | // Directive used to determine the active AMDA server | |
|
11 | #ifndef SCIQLOP_AMDA_SERVER | |
|
12 | #define SCIQLOP_AMDA_SERVER "default" | |
|
13 | #endif | |
|
14 | ||
|
10 | 15 | /** |
|
11 | 16 | * @brief The AmdaServer class represents the server used to retrieve AMDA data (singleton). |
|
12 | 17 | * |
|
13 | 18 | * The server instance is initialized at compile time, as defined by the AMDA_SERVER value. |
|
14 | 19 | */ |
|
15 | 20 | class AmdaServer { |
|
16 | 21 | public: |
|
17 | 22 | /// @return the unique instance of the AMDA server |
|
18 | 23 | static AmdaServer &instance(); |
|
19 | 24 | |
|
20 | 25 | virtual ~AmdaServer() noexcept = default; |
|
21 | 26 | |
|
22 | 27 | /// @return the name of the server |
|
23 | 28 | virtual QString name() const = 0; |
|
24 | 29 | /// @return the url of the server (used to retrieve data) |
|
25 | 30 | virtual QString url() const = 0; |
|
26 | 31 | }; |
|
27 | 32 | |
|
28 | 33 | #endif // SCIQLOP_AMDASERVER_H |
@@ -1,26 +1,45 | |||
|
1 | 1 | #include "AmdaServer.h" |
|
2 | 2 | |
|
3 | 3 | Q_LOGGING_CATEGORY(LOG_AmdaServer, "AmdaServer") |
|
4 | 4 | |
|
5 | 5 | namespace { |
|
6 | 6 | |
|
7 | 7 | /// Default AMDA server |
|
8 | 8 | struct AmdaDefaultServer : public AmdaServer { |
|
9 | 9 | public: |
|
10 | 10 | QString name() const override { return QStringLiteral("AMDA (default)"); } |
|
11 | 11 | QString url() const override { return QStringLiteral("amda.irap.omp.eu"); } |
|
12 | 12 | }; |
|
13 | 13 | |
|
14 | 14 | /// Alternative AMDA server (tests) |
|
15 | 15 | struct AmdaTestServer : public AmdaServer { |
|
16 | 16 | public: |
|
17 | 17 | QString name() const override { return QStringLiteral("AMDA (test)"); } |
|
18 | 18 | QString url() const override { return QStringLiteral("amdatest.irap.omp.eu"); } |
|
19 | 19 | }; |
|
20 | 20 | |
|
21 | /// @return an AMDA server instance created from the name of the server passed in parameter. If the | |
|
22 | /// name does not match any known server, a default server instance is created | |
|
23 | std::unique_ptr<AmdaServer> createInstance(const QString &server) | |
|
24 | { | |
|
25 | if (server == QString{"amdatest"}) { | |
|
26 | return std::make_unique<AmdaTestServer>(); | |
|
27 | } | |
|
28 | else { | |
|
29 | if (server != QString{"default"}) { | |
|
30 | qCWarning(LOG_AmdaServer()) | |
|
31 | << QObject::tr("Unknown server '%1': default AMDA server will be used").arg(server); | |
|
32 | } | |
|
33 | ||
|
34 | return std::make_unique<AmdaDefaultServer>(); | |
|
35 | } | |
|
36 | } | |
|
37 | ||
|
21 | 38 | } // namespace |
|
22 | 39 | |
|
23 | 40 | AmdaServer &AmdaServer::instance() |
|
24 | 41 | { |
|
25 | /// @todo ALX | |
|
42 | // Creates instance depending on the SCIQLOP_AMDA_SERVER value at compile time | |
|
43 | static auto instance = createInstance(SCIQLOP_AMDA_SERVER); | |
|
44 | return *instance; | |
|
26 | 45 | } |
General Comments 0
You need to be logged in to leave comments.
Login now