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 HOS_CAMERA_H 17 #define HOS_CAMERA_H 18 19 #include <functional> 20 #include <cstdio> 21 #include <cstdint> 22 #include <pthread.h> 23 #include <stdint.h> 24 #include <sys/time.h> 25 #include <sys/types.h> 26 #include <time.h> 27 #include <unistd.h> 28 #include "securec.h" 29 30 #if __GLIBC__ == 2 && __GLIBC_MINOR__ < 30 31 #include <sys/syscall.h> 32 #define gettid() (pid_t)syscall(SYS_gettid) 33 #endif 34 35 namespace OHOS::Camera { 36 #define GET_CURRENT_TIME_MS \ 37 struct timeval _tv; \ 38 gettimeofday(&_tv, NULL); \ 39 struct tm* _tm = localtime(&_tv.tv_sec); \ 40 int _ms = _tv.tv_usec / 1000; \ 41 char now[25] = {0}; \ 42 sprintf_s(now, sizeof(now), "%02d-%02d %02d:%02d:%02d.%03d", _tm->tm_mon + 1, _tm->tm_mday, _tm->tm_hour, \ 43 _tm->tm_min, _tm->tm_sec, _ms) 44 45 #define CAMERA_LOGE(fmt, ...) \ 46 do { \ 47 GET_CURRENT_TIME_MS; \ 48 pid_t pid = getpid(); \ 49 pid_t tid = gettid(); \ 50 printf("%s %4u %4u E " fmt "\n", now, (uint32_t)pid, (uint32_t)tid, ##__VA_ARGS__); \ 51 fflush(stdout); \ 52 } while (0) 53 54 #define CAMERA_LOGW(fmt, ...) \ 55 do { \ 56 GET_CURRENT_TIME_MS; \ 57 pid_t pid = getpid(); \ 58 pid_t tid = gettid(); \ 59 printf("%s %4u %4u W " fmt "\n", now, (uint32_t)pid, (uint32_t)tid, ##__VA_ARGS__); \ 60 fflush(stdout); \ 61 } while (0) 62 63 #define CAMERA_LOGI(fmt, ...) \ 64 do { \ 65 GET_CURRENT_TIME_MS; \ 66 pid_t pid = getpid(); \ 67 pid_t tid = gettid(); \ 68 printf("%s %4u %4u I " fmt "\n", now, (uint32_t)pid, (uint32_t)tid, ##__VA_ARGS__); \ 69 fflush(stdout); \ 70 } while (0) 71 72 #define CAMERA_LOGV(fmt, ...) \ 73 do { \ 74 GET_CURRENT_TIME_MS; \ 75 pid_t pid = getpid(); \ 76 pid_t tid = gettid(); \ 77 printf("%s %4u %4u V " fmt "\n", now, (uint32_t)pid, (uint32_t)tid, ##__VA_ARGS__); \ 78 fflush(stdout); \ 79 } while (0) 80 81 #define CAMERA_LOGD(fmt, ...) \ 82 do { \ 83 GET_CURRENT_TIME_MS; \ 84 pid_t pid = getpid(); \ 85 pid_t tid = gettid(); \ 86 printf("%s %4u %4u D " fmt "\n", now, (uint32_t)pid, (uint32_t)tid, ##__VA_ARGS__); \ 87 fflush(stdout); \ 88 } while (0) 89 90 constexpr uint32_t WATCHDOG_TIMEOUT = 20000; 91 92 enum RetCode { 93 RC_OK = 0, 94 RC_ERROR, 95 }; 96 97 } // namespace OHOS::Camera 98 #endif 99