• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 CONCURRENT_TASK_SERVICE_INTERFACES_INNERAPI_CONCURRENT_TASK_CLIENT_INCLUDE_CONCURRENT_TASK_CLIENT_H
17 #define CONCURRENT_TASK_SERVICE_INTERFACES_INNERAPI_CONCURRENT_TASK_CLIENT_INCLUDE_CONCURRENT_TASK_CLIENT_H
18 
19 #include <unordered_map>
20 #include "iremote_object.h"
21 #include "iconcurrent_task_service.h"
22 #include "concurrent_task_service_ipc_interface_code.h"
23 
24 namespace OHOS {
25 namespace ConcurrentTask {
26 /*
27  * this class wrapped the functions of IConcurrentTaskService,effect is the same.
28  * but through ConcurrentTaskClient, you don't need to get IConcurrentTaskService from samgr,
29  * just use the functions is ok.
30  */
31 
32 class ConcurrentTaskClient {
33 public:
34     /**
35      * @brief Only need one client connect to ConcurrentTaskService, singleton pattern.
36      *
37      * @return Returns the only one implement of ConcurrentTaskClient.
38      */
39     static ConcurrentTaskClient& GetInstance();
40 
41     /**
42      * @brief Report scene data to the concurrent task service through inter-process communication.
43      *
44      * @param resType Indicates the resource type, default is 0.
45      * @param value Indicates the uid of module of report scene module.
46      * @param mapPayload Indicates the context info of the scene data.
47      */
48     void ReportData(uint32_t resType, int64_t value, const std::unordered_map<std::string, std::string>& mapPayload);
49 
50     /**
51      * @brief Report scene info to the concurrent task service through inter-process communication.
52      *
53      * @param type Indicates the resource type, default is 0.
54      * @param mapPayload Indicates the context info of the scene data.
55      */
56     void ReportSceneInfo(uint32_t type, const std::unordered_map<std::string, std::string>& mapPayload);
57 
58     /**
59      * @brief Query rtg id and other info provided by concurrent task service.
60      *
61      * @param queryItem Information of the corresponding query module.
62      * @param queryRs Indicates the context info of the query message.
63      */
64     void QueryInterval(int queryItem, IntervalReply& queryRs);
65 
66     /**
67      * @brief Query rtg id and other info provided by concurrent task service.
68      *
69      * @param queryItem Information of the corresponding query module.
70      * @param ddlReply Indicates the setStatus of rate.
71      * @param mapPayload Indicates the context info of the frame rate data.
72      */
73     void QueryDeadline(int queryItem, DeadlineReply& ddlReply,
74                        const std::unordered_map<pid_t, uint32_t>& mapPayload);
75 
76     /**
77      * @brief Receive game scene info provided by rss.
78      *
79      * @param queryItem Information of the corresponding query module.
80      * @param ddlReply Indicates the setStatus.
81      * @param mapPayload Indicates the context info of game.
82      */
83     void QueryDeadline(int queryItem, DeadlineReply& ddlReply,
84         const std::unordered_map<std::string, std::string>& mapPayload);
85 
86     /**
87      * @brief Report auth request data to the concurrent task service.
88      *
89      * @param mapPayload Indicates the context info of the auth request data.
90      */
91     void RequestAuth(const std::unordered_map<std::string, std::string>& mapPayload);
92     /**
93      * @brief Stop remote object and reset ConcurrentTaskClient.
94      */
95     void StopRemoteObject();
96 
97 protected:
98     ConcurrentTaskClient() = default;
99     virtual ~ConcurrentTaskClient() = default;
100 
101 private:
102     class ConcurrentTaskDeathRecipient : public IRemoteObject::DeathRecipient {
103     public:
104         explicit ConcurrentTaskDeathRecipient(ConcurrentTaskClient& concurrentTaskClient);
105 
106         ~ConcurrentTaskDeathRecipient() override;
107 
108         void OnRemoteDied(const wptr<IRemoteObject>& object) override;
109 
110     private:
111         ConcurrentTaskClient& concurrentTaskClient_;
112     };
113     ErrCode TryConnect();
114 
115     std::mutex mutex_;
116     sptr<ConcurrentTaskDeathRecipient> recipient_;
117     sptr<IRemoteObject> remoteObject_;
118     sptr<IConcurrentTaskService> clientService_;
119     DISALLOW_COPY_AND_MOVE(ConcurrentTaskClient);
120 };
121 } // namespace ConcurrentTask
122 } // namespace OHOS
123 
124 #endif // CONCURRENT_TASK_SERVICE_INTERFACES_INNERAPI_ConcurrentTask_CLIENT_INCLUDE_CONCURRENT_TASK_CLIENT_H
125