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 OHOS_DM_PUBLISH_MANAGER_H 17 #define OHOS_DM_PUBLISH_MANAGER_H 18 19 #include <queue> 20 21 #include "dm_publish_info.h" 22 #include "device_manager_service_listener.h" 23 #include "dm_timer.h" 24 #include "softbus_connector.h" 25 #include "softbus_publish_callback.h" 26 27 namespace OHOS { 28 namespace DistributedHardware { 29 typedef struct DmPublishContext { 30 std::string pkgName; 31 DmPublishInfo publishInfo; 32 } DmPublishContext; 33 34 class DmPublishManager final : public ISoftbusPublishCallback, 35 public std::enable_shared_from_this<DmPublishManager> { 36 public: 37 DmPublishManager(std::shared_ptr<SoftbusConnector> softbusConnector, 38 std::shared_ptr<IDeviceManagerServiceListener> listener); 39 ~DmPublishManager(); 40 41 /** 42 * @tc.name: DmPublishManager::PublishDeviceDiscovery 43 * @tc.desc: Publish Device Discovery of the Dm Publish Manager 44 * @tc.type: FUNC 45 */ 46 int32_t PublishDeviceDiscovery(const std::string &pkgName, const DmPublishInfo &publishInfo); 47 48 /** 49 * @tc.name: DmPublishManager::UnPublishDeviceDiscovery 50 * @tc.desc: UnPublish Device Discovery of the Dm Discovery Manager 51 * @tc.type: FUNC 52 */ 53 int32_t UnPublishDeviceDiscovery(const std::string &pkgName, int32_t publishId); 54 55 /** 56 * @tc.name: DmPublishManager::OnPublishResult 57 * @tc.desc: OnPublish Result of the Dm Discovery Manager 58 * @tc.type: FUNC 59 */ 60 void OnPublishResult(const std::string &pkgName, int32_t publishId, int32_t publishResult); 61 62 /** 63 * @tc.name: DmPublishManager::HandlePublishDiscoveryTimeout 64 * @tc.desc: Handle Publish Timeout of the Dm OnPublish Manager 65 * @tc.type: FUNC 66 */ 67 void HandlePublishTimeout(std::string name); 68 private: 69 void CfgPublishTimer(); 70 int32_t CheckPublishQueue(const std::string &pkgName); 71 72 private: 73 std::shared_ptr<SoftbusConnector> softbusConnector_; 74 std::shared_ptr<IDeviceManagerServiceListener> listener_; 75 std::queue<std::string> publishQueue_; 76 std::map<std::string, DmPublishContext> publishContextMap_; 77 std::shared_ptr<DmTimer> timer_; 78 std::mutex locks_; 79 }; 80 } // namespace DistributedHardware 81 } // namespace OHOS 82 #endif // OHOS_DM_PUBLISH_MANAGER_H 83