1 /* 2 * Copyright (C) 2021 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 #ifndef WIFI_C_UTILS_H_ 17 #define WIFI_C_UTILS_H_ 18 19 #include <string> 20 #include <vector> 21 #include "kits/c/wifi_device_config.h" 22 #include "kits/c/wifi_error_code.h" 23 #include "wifi_errcode.h" 24 25 #ifndef IPV4_ARRAY_LEN 26 #define IPV4_ARRAY_LEN 4 27 #endif 28 29 namespace OHOS { 30 namespace Wifi { 31 #ifndef CHECK_PTR_RETURN 32 #define CHECK_PTR_RETURN(ptr, retValue) \ 33 if ((ptr) == nullptr) { \ 34 WIFI_LOGE("Error: the ptr is null!"); \ 35 return retValue; \ 36 } 37 #endif 38 39 #ifndef CHECK_PTR_RETURN_VOID 40 #define CHECK_PTR_RETURN_VOID(ptr) \ 41 if ((ptr) == nullptr) { \ 42 WIFI_LOGE("Error: the ptr is null!"); \ 43 return; \ 44 } 45 #endif 46 47 /** 48 * @Description Convert c++ error code to c error code. 49 * 50 * @param errCode - c++ error code 51 * @return WifiErrorCode - c error code 52 */ 53 WifiErrorCode GetCErrorCode(ErrCode errCode); 54 55 /** 56 * @Description Convert IP address from string to int array. 57 * 58 * @param str - IP address of string type 59 * @param ipAddr - Convert result which is a 4-bit int array, example: 127.0.0.1 -> ipAddr[ 127, 0, 0, 1 ] 60 * @return WifiErrorCode - operation result 61 */ 62 WifiErrorCode IpStrToArray(const std::string& str, unsigned int ipAddr[IPV4_ARRAY_LEN]); 63 64 /** 65 * @Description Convert IP address from int array to string. 66 * example: ipAddr[ 127, 0, 0, 1 ] -> 127.0.0.1 67 * 68 * @param ipAddr - IP address of int array 69 * @return std::string - result 70 */ 71 std::string IpArrayToStr(const unsigned int ipAddr[IPV4_ARRAY_LEN]); 72 } // namespace Wifi 73 } // namespace OHOS 74 75 #endif 76