11e934351Sopenharmony_ci/*
21e934351Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
31e934351Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
41e934351Sopenharmony_ci * you may not use this file except in compliance with the License.
51e934351Sopenharmony_ci * You may obtain a copy of the License at
61e934351Sopenharmony_ci *
71e934351Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
81e934351Sopenharmony_ci *
91e934351Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
101e934351Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
111e934351Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
121e934351Sopenharmony_ci * See the License for the specific language governing permissions and
131e934351Sopenharmony_ci * limitations under the License.
141e934351Sopenharmony_ci */
151e934351Sopenharmony_ci
161e934351Sopenharmony_ci#ifndef COMMUNICATIONNETSTACK_HTTP_CLIENT_H
171e934351Sopenharmony_ci#define COMMUNICATIONNETSTACK_HTTP_CLIENT_H
181e934351Sopenharmony_ci
191e934351Sopenharmony_ci#include <atomic>
201e934351Sopenharmony_ci#include <condition_variable>
211e934351Sopenharmony_ci#include <iostream>
221e934351Sopenharmony_ci#include <map>
231e934351Sopenharmony_ci#include <memory>
241e934351Sopenharmony_ci#include <mutex>
251e934351Sopenharmony_ci#include <queue>
261e934351Sopenharmony_ci#include <string>
271e934351Sopenharmony_ci#include <thread>
281e934351Sopenharmony_ci#include <vector>
291e934351Sopenharmony_ci
301e934351Sopenharmony_ci#include "http_client_error.h"
311e934351Sopenharmony_ci#include "http_client_request.h"
321e934351Sopenharmony_ci#include "http_client_task.h"
331e934351Sopenharmony_ci
341e934351Sopenharmony_cinamespace OHOS {
351e934351Sopenharmony_cinamespace NetStack {
361e934351Sopenharmony_cinamespace HttpClient {
371e934351Sopenharmony_ciclass HttpSession {
381e934351Sopenharmony_cipublic:
391e934351Sopenharmony_ci    /**
401e934351Sopenharmony_ci     * Gets the singleton instance of HttpSession.
411e934351Sopenharmony_ci     * @return The singleton instance of HttpSession.
421e934351Sopenharmony_ci     */
431e934351Sopenharmony_ci    static HttpSession &GetInstance();
441e934351Sopenharmony_ci
451e934351Sopenharmony_ci    /**
461e934351Sopenharmony_ci     * Creates an HTTP client task with the provided request.
471e934351Sopenharmony_ci     * @param request The HTTP request to be executed.
481e934351Sopenharmony_ci     * @return A shared pointer to the created HttpClientTask object.
491e934351Sopenharmony_ci     */
501e934351Sopenharmony_ci    [[nodiscard]] std::shared_ptr<HttpClientTask> CreateTask(const HttpClientRequest &request);
511e934351Sopenharmony_ci
521e934351Sopenharmony_ci    /**
531e934351Sopenharmony_ci     * Creates an HTTP client task with the provided request and file path.
541e934351Sopenharmony_ci     * @param request The HTTP request to be executed.
551e934351Sopenharmony_ci     * @param type The type of the task.
561e934351Sopenharmony_ci     * @param filePath The file path to read the uploaded file (applicable for upload tasks).
571e934351Sopenharmony_ci     * @return A shared pointer to the created HttpClientTask object.
581e934351Sopenharmony_ci     */
591e934351Sopenharmony_ci    [[nodiscard]] std::shared_ptr<HttpClientTask> CreateTask(const HttpClientRequest &request, TaskType type,
601e934351Sopenharmony_ci                                                             const std::string &filePath);
611e934351Sopenharmony_ci
621e934351Sopenharmony_ciprivate:
631e934351Sopenharmony_ci    friend class HttpClientTask;
641e934351Sopenharmony_ci
651e934351Sopenharmony_ci    /**
661e934351Sopenharmony_ci     * Default constructor.
671e934351Sopenharmony_ci     */
681e934351Sopenharmony_ci    HttpSession();
691e934351Sopenharmony_ci    ~HttpSession();
701e934351Sopenharmony_ci
711e934351Sopenharmony_ci    /**
721e934351Sopenharmony_ci     * Starts the specified HTTP client task.
731e934351Sopenharmony_ci     * @param ptr A shared pointer to the HttpClientTask object.
741e934351Sopenharmony_ci     */
751e934351Sopenharmony_ci    void StartTask(const std::shared_ptr<HttpClientTask> &ptr);
761e934351Sopenharmony_ci};
771e934351Sopenharmony_ci} // namespace HttpClient
781e934351Sopenharmony_ci} // namespace NetStack
791e934351Sopenharmony_ci} // namespace OHOS
801e934351Sopenharmony_ci
811e934351Sopenharmony_ci#endif // COMMUNICATIONNETSTACK_HTTP_CLIENT_H