1 /*
2 * Copyright (c) 2023 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 #include "ipc/download_asset_callback_manager.h"
16
17 #include <cinttypes>
18
19 #include "utils_log.h"
20
21 namespace OHOS::FileManagement::CloudSync {
22 using namespace std;
23
GetInstance()24 DownloadAssetCallbackManager &DownloadAssetCallbackManager::GetInstance()
25 {
26 static DownloadAssetCallbackManager instance;
27 return instance;
28 }
29
AddCallback(const sptr<IDownloadAssetCallback> & callback)30 void DownloadAssetCallbackManager::AddCallback(const sptr<IDownloadAssetCallback> &callback)
31 {
32 if (callback == nullptr) {
33 return;
34 }
35 callbackProxy_ = callback;
36 auto remoteObject = callback->AsObject();
37 auto deathCb = [this](const wptr<IRemoteObject> &obj) {
38 callbackProxy_ = nullptr;
39 LOGE("client died");
40 };
41 deathRecipient_ = sptr(new SvcDeathRecipient(deathCb));
42 remoteObject->AddDeathRecipient(deathRecipient_);
43 }
44
OnDownloadFinshed(const TaskId taskId,const std::string & uri,const int32_t result)45 void DownloadAssetCallbackManager::OnDownloadFinshed(const TaskId taskId, const std::string &uri, const int32_t result)
46 {
47 auto callback = callbackProxy_;
48 if (callback == nullptr) {
49 LOGE("callbackProxy_ is nullptr");
50 return;
51 }
52 LOGD("On Download finished, taskId:%{public}" PRIu64 ", uri:%{public}s, ret:%{public}d",
53 taskId, GetAnonyString(uri).c_str(), result);
54 callback->OnFinished(taskId, uri, result);
55 }
56 } // namespace OHOS::FileManagement::CloudSync