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 17 #ifndef PRINT_HTTP_SERVER_MANAGER_H_ 18 #define PRINT_HTTP_SERVER_MANAGER_H_ 19 #ifdef IPPOVERUSB_ENABLE 20 21 #include <string> 22 #include <map> 23 #include "singleton.h" 24 #include "httplib.h" 25 #include "print_ipp_over_usb_constant.h" 26 #include "print_http_request_process.h" 27 28 namespace OHOS::Print { 29 30 class PrintHttpServerManager final : public DelayedSingleton<PrintHttpServerManager> { 31 public: 32 PrintHttpServerManager(); 33 ~PrintHttpServerManager(); 34 35 bool CreateServer(std::string printerName, int32_t &port); 36 static void StartServer(std::shared_ptr<httplib::Server> svr, 37 std::shared_ptr<PrintHttpRequestProcess> process); 38 void StopServer(std::string printerName); 39 void DealUsbDevDetach(const std::string &devStr); 40 41 private: 42 bool AllocatePort(std::shared_ptr<httplib::Server> svr, int32_t &port); 43 44 private: 45 std::map<std::string, std::shared_ptr<httplib::Server>> printHttpServerMap; 46 std::map<std::string, int32_t> printHttpPortMap; 47 std::map<std::string, std::shared_ptr<PrintHttpRequestProcess>> printHttpProcessMap; 48 }; 49 50 } 51 52 #endif // IPPOVERUSB_ENABLE 53 #endif // PRINT_HTTP_SERVER_MANAGER_H_