18e9cee63Sopenharmony_ci/*
28e9cee63Sopenharmony_ci* Copyright (C) 2024 Huawei Device Co., Ltd.
38e9cee63Sopenharmony_ci* Licensed under the Apache License, Version 2.0 (the "License");
48e9cee63Sopenharmony_ci* you may not use this file except in compliance with the License.
58e9cee63Sopenharmony_ci* You may obtain a copy of the License at
68e9cee63Sopenharmony_ci*
78e9cee63Sopenharmony_ci*     http://www.apache.org/licenses/LICENSE-2.0
88e9cee63Sopenharmony_ci*
98e9cee63Sopenharmony_ci* Unless required by applicable law or agreed to in writing, software
108e9cee63Sopenharmony_ci* distributed under the License is distributed on an "AS IS" BASIS,
118e9cee63Sopenharmony_ci* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
128e9cee63Sopenharmony_ci* See the License for the specific language governing permissions and
138e9cee63Sopenharmony_ci* limitations under the License.
148e9cee63Sopenharmony_ci*/
158e9cee63Sopenharmony_ci
168e9cee63Sopenharmony_ci#include "wrapper.h"
178e9cee63Sopenharmony_ci
188e9cee63Sopenharmony_ci#include <memory>
198e9cee63Sopenharmony_ci
208e9cee63Sopenharmony_ci#include "http_client_error.h"
218e9cee63Sopenharmony_ci#include "wrapper.rs.h"
228e9cee63Sopenharmony_cinamespace OHOS::Request {
238e9cee63Sopenharmony_ciusing namespace OHOS::NetStack::HttpClient;
248e9cee63Sopenharmony_ci
258e9cee63Sopenharmony_civoid OnCallback(std::shared_ptr<HttpClientTask> task, rust::Box<CallbackWrapper> callback)
268e9cee63Sopenharmony_ci{
278e9cee63Sopenharmony_ci    CallbackWrapper *raw_ptr = callback.into_raw();
288e9cee63Sopenharmony_ci    auto shared = std::shared_ptr<CallbackWrapper>(
298e9cee63Sopenharmony_ci        raw_ptr, [](CallbackWrapper *ptr) { rust::Box<CallbackWrapper>::from_raw(ptr); });
308e9cee63Sopenharmony_ci    task->OnSuccess(
318e9cee63Sopenharmony_ci        [shared](const HttpClientRequest &, const HttpClientResponse &response) { shared->on_success(response); });
328e9cee63Sopenharmony_ci    task->OnFail([shared](const HttpClientRequest &, const HttpClientResponse &response,
338e9cee63Sopenharmony_ci                     const HttpClientError &error) { shared->on_fail(response, error); });
348e9cee63Sopenharmony_ci    task->OnCancel(
358e9cee63Sopenharmony_ci        [shared](const HttpClientRequest &, const HttpClientResponse &response) { shared->on_cancel(response); });
368e9cee63Sopenharmony_ci    task->OnDataReceive(
378e9cee63Sopenharmony_ci        [shared](const HttpClientRequest &, const uint8_t *data, size_t size) { shared->on_data_receive(data, size); });
388e9cee63Sopenharmony_ci    task->OnProgress([shared](const HttpClientRequest &, u_long dlTotal, u_long dlNow, u_long ulTotal, u_long ulNow) {
398e9cee63Sopenharmony_ci        shared->on_progress(dlTotal, dlNow, ulTotal, ulNow);
408e9cee63Sopenharmony_ci    });
418e9cee63Sopenharmony_ci}
428e9cee63Sopenharmony_ci
438e9cee63Sopenharmony_ci} // namespace OHOS::Request