1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
---|---|
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #ifndef BUILDERSERVICE_H |
6 | #define BUILDERSERVICE_H |
7 | |
8 | #include "buildergenerator.h" |
9 | #include "builderglobals.h" |
10 | #include "builderinterface.h" |
11 | #include <framework/framework.h> |
12 | |
13 | namespace dpfservice { |
14 | |
15 | class BuilderService final : public dpf::PluginService, |
16 | dpf::AutoServiceRegister<BuilderService>, |
17 | dpf::QtClassFactory<BuilderGenerator>, |
18 | dpf::QtClassManager<BuilderGenerator> |
19 | { |
20 | Q_OBJECT |
21 | Q_DISABLE_COPY(BuilderService) |
22 | public: |
23 | explicit BuilderService(QObject *parent = nullptr) |
24 | : dpf::PluginService (parent) |
25 | { |
26 | |
27 | } |
28 | |
29 | static QString name() |
30 | { |
31 | return "org.deepin.service.BuilderService"; |
32 | } |
33 | |
34 | template<class T> |
35 | bool regClass(const QString &name, QString *error= nullptr) { |
36 | return dpf::QtClassFactory<BuilderGenerator>::regClass<T>(name, error); |
37 | } |
38 | |
39 | template<class T> |
40 | T* create(const QString &name, QString *error = nullptr) { |
41 | auto value = dpf::QtClassManager<BuilderGenerator>::value(name); |
42 | if (!value) { |
43 | value = dpf::QtClassFactory<BuilderGenerator>::create(name); |
44 | dpf::QtClassManager<BuilderGenerator>::append(name, value, error); |
45 | } |
46 | return dynamic_cast<T*>(value); |
47 | } |
48 | |
49 | BuilderInterface interface; |
50 | }; |
51 | |
52 | } // namespace dpfservice |
53 | #endif // BUILDERSERVICE_H |
54 |