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 Query rtg id and other info provided by concurrent task service. 52 * 53 * @param queryItem Information of the corresponding query module. 54 * @param queryRs Indicates the context info of the query message. 55 */ 56 void QueryInterval(int queryItem, IntervalReply& queryRs); 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 ddlReply Indicates the setStatus of rate. 63 * @param mapPayload Indicates the context info of the frame rate data. 64 */ 65 void QueryDeadline(int queryItem, DeadlineReply& ddlReply, 66 const std::unordered_map<pid_t, uint32_t>& mapPayload); 67 68 /** 69 * @brief Receive game scene info provided by rss. 70 * 71 * @param queryItem Information of the corresponding query module. 72 * @param ddlReply Indicates the setStatus. 73 * @param mapPayload Indicates the context info of game. 74 */ 75 void QueryDeadline(int queryItem, DeadlineReply& ddlReply, 76 const std::unordered_map<std::string, std::string>& mapPayload); 77 78 /** 79 * @brief Report auth request data to the concurrent task service. 80 * 81 * @param mapPayload Indicates the context info of the auth request data. 82 */ 83 void RequestAuth(const std::unordered_map<std::string, std::string>& mapPayload); 84 /** 85 * @brief Stop remote object and reset ConcurrentTaskClient. 86 */ 87 void StopRemoteObject(); 88 89 protected: 90 ConcurrentTaskClient() = default; 91 virtual ~ConcurrentTaskClient() = default; 92 93 private: 94 class ConcurrentTaskDeathRecipient : public IRemoteObject::DeathRecipient { 95 public: 96 explicit ConcurrentTaskDeathRecipient(ConcurrentTaskClient& concurrentTaskClient); 97 98 ~ConcurrentTaskDeathRecipient() override; 99 100 void OnRemoteDied(const wptr<IRemoteObject>& object) override; 101 102 private: 103 ConcurrentTaskClient& concurrentTaskClient_; 104 }; 105 ErrCode TryConnect(); 106 107 std::mutex mutex_; 108 sptr<ConcurrentTaskDeathRecipient> recipient_; 109 sptr<IRemoteObject> remoteObject_; 110 sptr<IConcurrentTaskService> clientService_; 111 DISALLOW_COPY_AND_MOVE(ConcurrentTaskClient); 112 }; 113 } // namespace ConcurrentTask 114 } // namespace OHOS 115 116 #endif // CONCURRENT_TASK_SERVICE_INTERFACES_INNERAPI_ConcurrentTask_CLIENT_INCLUDE_CONCURRENT_TASK_CLIENT_H 117