• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 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 NotifyAssetRecvProgress(const std::string &srcNetworkId,
45                                  const sptr<AssetObj> &assetObj,
46                                  uint64_t total,
47                                  uint64_t processed);
48     void NotifyAssetRecvFinished(const std::string &srcNetworkId,
49                                  const sptr<AssetObj> &assetObj,
50                                  int32_t result);
51     void NotifyAssetSendResult(const std::string &taskId,
52                                const sptr<AssetObj> &assetObj,
53                                int32_t result);
54 
55 private:
56     std::mutex recvCallbackListMutex_;
57     std::vector<sptr<IAssetRecvCallback>> recvCallbackList_;
58     std::mutex sendCallbackMapMutex_;
59     std::map<std::string, sptr<IAssetSendCallback>> sendCallbackMap_;
60 };
61 
62 } // namespace DistributedFile
63 } // namespace Storage
64 } // namespace OHOS
65 
66 #endif // FILEMANAGEMENT_DFS_SERVICE_SDK_ASSET_CALLBACK_MANAGER_H
67