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