1 /* 2 * Copyright (c) 2021-2024 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_DISTRIBUTED_HARDWARE_IDISTRIBUTED_HARDWARE_SOURCE_H 17 #define OHOS_DISTRIBUTED_HARDWARE_IDISTRIBUTED_HARDWARE_SOURCE_H 18 19 #include <memory> 20 #include <string> 21 22 namespace OHOS { 23 namespace DistributedHardware { 24 const std::string COMPONENT_LOADER_GET_SOURCE_HANDLER = "GetSourceHardwareHandler"; 25 class RegisterCallback { 26 public: 27 virtual int32_t OnRegisterResult(const std::string &networkId, const std::string &dhId, int32_t status, 28 const std::string &data) = 0; 29 }; 30 31 class UnregisterCallback { 32 public: 33 virtual int32_t OnUnregisterResult(const std::string &networkId, const std::string &dhId, int32_t status, 34 const std::string &data) = 0; 35 }; 36 37 struct EnableParam { 38 std::string sourceVersion; 39 std::string sourceAttrs; 40 std::string sinkVersion; 41 std::string sinkAttrs; 42 std::string subtype; 43 }; 44 45 enum class BusinessState : uint32_t { 46 UNKNOWN, 47 IDLE, 48 RUNNING, 49 PAUSING 50 }; 51 52 class DistributedHardwareStateListener { 53 public: 54 /** 55 * @brief report the business state of local virtual driver 56 * corresponding the remote device with the device id and dhid. 57 * 58 * @param networkId the remote device networkId. 59 * @param dhId the remote device peripheral dhId. 60 * @param state business state. 61 */ 62 virtual void OnStateChanged(const std::string &networkId, const std::string &dhId, const BusinessState state) = 0; 63 }; 64 65 class DataSyncTriggerListener { 66 public: 67 /** 68 * @brief trigger local distributed hardware open session with remote device with uuid 69 * 70 * @param networkId the remote device networkId 71 */ 72 virtual void OnDataSyncTrigger(const std::string &networkId) = 0; 73 }; 74 75 class HdfDeathCallback { 76 public: 77 /** 78 * @brief Trigger callback when HDF driver exits abnormally 79 * 80 */ 81 virtual void OnHdfHostDied() = 0; 82 }; 83 84 85 class IDistributedHardwareSource { 86 public: 87 virtual int32_t InitSource(const std::string ¶ms) = 0; 88 virtual int32_t ReleaseSource() = 0; 89 virtual int32_t RegisterDistributedHardware(const std::string &networkId, const std::string &dhId, 90 const EnableParam ¶m, std::shared_ptr<RegisterCallback> callback) = 0; 91 virtual int32_t UnregisterDistributedHardware(const std::string &networkId, const std::string &dhId, 92 std::shared_ptr<UnregisterCallback> callback) = 0; 93 virtual int32_t ConfigDistributedHardware(const std::string &networkId, const std::string &dhId, 94 const std::string &key, const std::string &value) = 0; 95 virtual void RegisterDistributedHardwareStateListener( 96 std::shared_ptr<DistributedHardwareStateListener> listener) = 0; 97 virtual void UnregisterDistributedHardwareStateListener() = 0; 98 virtual void RegisterDataSyncTriggerListener(std::shared_ptr<DataSyncTriggerListener> listener) = 0; 99 virtual void UnregisterDataSyncTriggerListener() = 0; LoadDistributedHDF(std::shared_ptr<HdfDeathCallback> callback)100 virtual int32_t LoadDistributedHDF(std::shared_ptr<HdfDeathCallback> callback) 101 { 102 (void)callback; 103 return 0; 104 } UnLoadDistributedHDF()105 virtual int32_t UnLoadDistributedHDF() 106 { 107 return 0; 108 } 109 }; 110 extern "C" __attribute__((visibility("default"))) IDistributedHardwareSource* GetSourceHardwareHandler(); 111 } // namespace DistributedHardware 112 } // namespace OHOS 113 #endif 114