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
16 #include "common.h"
17
18 #include "request_preload.h"
19 using namespace OHOS::Request;
TestCallback(size_t size)20 TestCallback::TestCallback(size_t size)
21 {
22 auto flagS = std::make_shared<std::atomic_bool>(false);
23 auto flagF = std::make_shared<std::atomic_bool>(false);
24 auto flagC = std::make_shared<std::atomic_bool>(false);
25 auto flagP = std::make_shared<std::atomic_bool>(false);
26 this->callback = PreloadCallback{
27 .OnSuccess =
28 [flagS, size](const std::shared_ptr<Data> &&data, const std::string &taskId) {
29 if (size == 0 || data->bytes().length() == size) {
30 flagS->store(true);
31 }
32 },
33 .OnCancel = [flagC]() { flagC->store(true); },
34 .OnFail = [flagF](const PreloadError &error, const std::string &taskId) { flagF->store(true); },
35 .OnProgress = [flagP](uint64_t current, uint64_t total) { flagP->store(true); },
36 };
37 this->flagS = flagS;
38 this->flagF = flagF;
39 this->flagC = flagC;
40 this->flagP = flagP;
41 }