1 /* 2 * Copyright (c) 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 FILEMANAGEMENT_DFS_SERVICE_SDK_ASSET_CALLBACK_MANAGER_H 17 #define FILEMANAGEMENT_DFS_SERVICE_SDK_ASSET_CALLBACK_MANAGER_H 18 19 #include <map> 20 #include <mutex> 21 #include <vector> 22 23 #include "asset/i_asset_recv_callback.h" 24 #include "asset/i_asset_send_callback.h" 25 #include "refbase.h" 26 27 namespace OHOS { 28 namespace Storage { 29 namespace DistributedFile { 30 31 class AssetCallbackManager { 32 public: 33 static AssetCallbackManager &GetInstance(); 34 35 void AddRecvCallback(const sptr<IAssetRecvCallback> &recvCallback); 36 void RemoveRecvCallback(const sptr<IAssetRecvCallback> &recvCallback); 37 void AddSendCallback(const std::string &taskId, const sptr<IAssetSendCallback> &sendCallback); 38 void RemoveSendCallback(const std::string &taskId); 39 40 void NotifyAssetRecvStart(const std::string &srcNetworkId, 41 const std::string &dstNetworkId, 42 const std::string &sessionId, 43 const std::string &dstBundleName); 44 void NotifyAssetRecvFinished(const std::string &srcNetworkId, 45 const sptr<AssetObj> &assetObj, 46 int32_t result); 47 void NotifyAssetSendResult(const std::string &taskId, 48 const sptr<AssetObj> &assetObj, 49 int32_t result); 50 51 private: 52 std::mutex recvCallbackListMutex_; 53 std::vector<sptr<IAssetRecvCallback>> recvCallbackList_; 54 std::mutex sendCallbackMapMutex_; 55 std::map<std::string, sptr<IAssetSendCallback>> sendCallbackMap_; 56 }; 57 58 } // namespace DistributedFile 59 } // namespace Storage 60 } // namespace OHOS 61 62 #endif // FILEMANAGEMENT_DFS_SERVICE_SDK_ASSET_CALLBACK_MANAGER_H 63