1 /* 2 * Copyright (c) 2024-2025 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_ABILITY_CONNECTION_MANAGER_DISTRIBUTED_CLIENT_H 17 #define OHOS_ABILITY_CONNECTION_MANAGER_DISTRIBUTED_CLIENT_H 18 19 20 #include <string> 21 22 #include "ability_connection_info.h" 23 #include "ability_connection_session.h" 24 #include "iremote_object.h" 25 #include "system_ability_status_change_stub.h" 26 #include <mutex> 27 #include <condition_variable> 28 29 namespace OHOS { 30 namespace DistributedCollab { 31 class DistributedClient { 32 public: 33 DistributedClient() = default; 34 ~DistributedClient(); 35 36 int32_t CollabMission(int32_t sessionId, const std::string& serverSocketName, 37 const AbilityConnectionSessionInfo& sessionInfo, const ConnectOption& options, const std::string& token); 38 int32_t NotifyPrepareResult(const std::string& token, int32_t result, int32_t sessionId, 39 const std::string& serverSocketName); 40 int32_t NotifyCloseCollabSession(const std::string& token); 41 int32_t NotifyRejectReason(const std::string& token, const std::string& reason); 42 int32_t GetPeerVersion(int32_t sessionId, const std::string& peerDeviceId, const std::string dmsServerToken); 43 bool GetWifiStatus(); 44 45 enum { 46 COLLAB_MESSION = 330, 47 NOTIFY_PREPARE_RESULT = 331, 48 NOTIFY_REJECT_REASON = 332, 49 BNOTIFY_CLOSE_COLLAB_SESSION = 333, 50 GET_SINK_COLLAB_VERSION = 335, 51 GET_WIFI_STATUS = 336, 52 }; 53 private: 54 sptr<IRemoteObject> GetDmsProxy(); 55 56 private: 57 std::mutex mtx_; 58 std::condition_variable cv_; 59 bool callbackReceived_ = false; 60 sptr<ISystemAbilityStatusChange> listener_ = nullptr; 61 class SystemAbilityStatusChangeListener : public SystemAbilityStatusChangeStub { 62 public: SystemAbilityStatusChangeListener(DistributedClient * client)63 explicit SystemAbilityStatusChangeListener(DistributedClient* client): client_(client) {} 64 void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 65 void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; 66 private: 67 DistributedClient* client_ = nullptr; 68 }; 69 }; 70 } // namespace AAFwk 71 } // namespace OHOS 72 #endif