| 1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. | 
|---|---|
| 2 | // | 
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later | 
| 4 | |
| 5 | #include "framework.h" | 
| 6 | #include "backtrace/backtrace.h" | 
| 7 | #include "framework/log/frameworklog.h" | 
| 8 | #include "framework/lifecycle/lifecycle.h" | 
| 9 | |
| 10 | DPF_BEGIN_NAMESPACE | 
| 11 | |
| 12 | class FrameworkPrivate | 
| 13 | { | 
| 14 | friend class Framework; | 
| 15 | Framework *const q; | 
| 16 | // Plugin lifeCycle manager. | 
| 17 | QScopedPointer<LifeCycle> lifeCycle; | 
| 18 | bool bInitialized = false; | 
| 19 | |
| 20 | explicit FrameworkPrivate(Framework *dd); | 
| 21 | }; | 
| 22 | |
| 23 | FrameworkPrivate::FrameworkPrivate(Framework *dd) | 
| 24 | : q(dd) | 
| 25 | { | 
| 26 | |
| 27 | } | 
| 28 | |
| 29 | /*! | 
| 30 | * \brief Get framework instance. | 
| 31 | * \return | 
| 32 | */ | 
| 33 | Framework &Framework::instance() | 
| 34 | { | 
| 35 | static Framework ins; | 
| 36 | return ins; | 
| 37 | } | 
| 38 | |
| 39 | |
| 40 | /*! | 
| 41 | * \brief Framework inner modules will be initialized | 
| 42 | * when it invoked,same for plugins. | 
| 43 | * \return | 
| 44 | */ | 
| 45 | bool Framework::initialize() | 
| 46 | { | 
| 47 | if (d->bInitialized) { | 
| 48 | qDebug() << "Frame work has been initialized!"; | 
| 49 | return true; | 
| 50 | } | 
| 51 | #ifndef NO_BACKTRACE | 
| 52 | backtrace::initbacktrace(); | 
| 53 | #endif | 
| 54 | FrameworkLog::initialize(); | 
| 55 | |
| 56 | // It will be true after all inner moudules initialized | 
| 57 | // successfully. | 
| 58 | d->bInitialized = true; | 
| 59 | |
| 60 | return true; | 
| 61 | } | 
| 62 | |
| 63 | |
| 64 | /*! | 
| 65 | * \brief Start framework after initialized. | 
| 66 | * \return | 
| 67 | */ | 
| 68 | bool Framework::start() | 
| 69 | { | 
| 70 | // TODO(anyone):Start plugin after initialized, | 
| 71 | // thus plugin logic will be run | 
| 72 | return true; | 
| 73 | } | 
| 74 | |
| 75 | /*! | 
| 76 | * \brief Get plugin life cycle manager | 
| 77 | * \return | 
| 78 | */ | 
| 79 | const LifeCycle &Framework::lifeCycle() const | 
| 80 | { | 
| 81 | return *d->lifeCycle; | 
| 82 | } | 
| 83 | |
| 84 | /*! | 
| 85 | * \brief Get plugin service context | 
| 86 | * \return | 
| 87 | */ | 
| 88 | PluginServiceContext &Framework::serviceContext() const | 
| 89 | { | 
| 90 | return PluginServiceContext::instance(); | 
| 91 | } | 
| 92 | |
| 93 | /*! | 
| 94 | * \brief Get event proxy | 
| 95 | * \return | 
| 96 | */ | 
| 97 | EventCallProxy &Framework::eventProxy() const | 
| 98 | { | 
| 99 | return EventCallProxy::instance(); | 
| 100 | } | 
| 101 | |
| 102 | Framework::Framework() : | 
| 103 | d(new FrameworkPrivate(this)) | 
| 104 | { | 
| 105 | d->lifeCycle.reset(new LifeCycle()); | 
| 106 | } | 
| 107 | |
| 108 | DPF_END_NAMESPACE | 
| 109 | 
