• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_ACE_UI_SERVICE_MANAGER_SERVICE_H
17 #define OHOS_ACE_UI_SERVICE_MANAGER_SERVICE_H
18 
19 #include <memory>
20 #include <singleton.h>
21 #include <thread_ex.h>
22 #include <unordered_map>
23 
24 #include "element_name.h"
25 #include "event_handler.h"
26 #include "event_runner.h"
27 #include "hilog_wrapper.h"
28 #include "iremote_object.h"
29 
30 #include "system_ability.h"
31 #include "ui_service_mgr_stub.h"
32 
33 namespace OHOS {
34 namespace Ace {
35 using EventRunner = OHOS::AppExecFwk::EventRunner;
36 using EventHandler = OHOS::AppExecFwk::EventHandler;
37 enum class UIServiceRunningState { STATE_NOT_START, STATE_RUNNING };
38 
39 class UIMgrService : public SystemAbility,
40                           public UIServiceMgrStub,
41                           public std::enable_shared_from_this<UIMgrService> {
42     DECLARE_DELAYED_SINGLETON(UIMgrService)
43     DECLEAR_SYSTEM_ABILITY(UIMgrService)
44 public:
45     void OnStart() override;
46     void OnStop() override;
47     UIServiceRunningState QueryServiceState() const;
48 
49     int32_t RegisterCallBack(const AAFwk::Want& want, const sptr<IUIService>& uiService) override;
50     int32_t UnregisterCallBack(const AAFwk::Want& want) override;
51     int32_t Push(const AAFwk::Want& want, const std::string& name, const std::string& jsonPath,
52         const std::string& data, const std::string& extraData) override;
53 
54     int32_t Request(const AAFwk::Want& want, const std::string& name, const std::string& data) override;
55     int32_t ReturnRequest(const AAFwk::Want& want, const std::string& source, const std::string& data,
56         const std::string& extraData) override;
57 
58     int32_t Dump(int32_t fd, const std::vector<std::u16string>& args) override;
59 
60 private:
61     bool Init();
62     bool CheckCallBackFromMap(const std::string& key);
63     int32_t HandleRegister(const AAFwk::Want& want,  const sptr<IUIService>& uiService);
64     int32_t HandleUnregister(const AAFwk::Want& want);
65 
66     std::string GetCallBackKeyStr(const AAFwk::Want& want);
67     std::shared_ptr<EventRunner> eventLoop_;
68     std::shared_ptr<EventHandler> handler_;
69     UIServiceRunningState state_;
70 
71     std::map<std::string, sptr<IUIService>> callbackMap_;
72     std::recursive_mutex uiMutex_;
73 };
74 }  // namespace Ace
75 }  // namespace OHOS
76 #endif  // OHOS_AAFWK_UI_SERVICE_MANAGER_SERVICE_H
77