1094332d3Sopenharmony_ci/* 2094332d3Sopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License. 5094332d3Sopenharmony_ci * You may obtain a copy of the License at 6094332d3Sopenharmony_ci * 7094332d3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8094332d3Sopenharmony_ci * 9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and 13094332d3Sopenharmony_ci * limitations under the License. 14094332d3Sopenharmony_ci */ 15094332d3Sopenharmony_ci 16094332d3Sopenharmony_ci#ifndef HOS_CAMERA_H 17094332d3Sopenharmony_ci#define HOS_CAMERA_H 18094332d3Sopenharmony_ci 19094332d3Sopenharmony_ci#include <functional> 20094332d3Sopenharmony_ci#include <cstdio> 21094332d3Sopenharmony_ci#include <cstdint> 22094332d3Sopenharmony_ci#include <pthread.h> 23094332d3Sopenharmony_ci#include <stdint.h> 24094332d3Sopenharmony_ci#include <sys/time.h> 25094332d3Sopenharmony_ci#include <sys/types.h> 26094332d3Sopenharmony_ci#include <time.h> 27094332d3Sopenharmony_ci#include <unistd.h> 28094332d3Sopenharmony_ci#include "securec.h" 29094332d3Sopenharmony_ci 30094332d3Sopenharmony_ci#if __GLIBC__ == 2 && __GLIBC_MINOR__ < 30 31094332d3Sopenharmony_ci#include <sys/syscall.h> 32094332d3Sopenharmony_ci#define gettid() (pid_t)syscall(SYS_gettid) 33094332d3Sopenharmony_ci#endif 34094332d3Sopenharmony_ci 35094332d3Sopenharmony_cinamespace OHOS::Camera { 36094332d3Sopenharmony_ci#define GET_CURRENT_TIME_MS \ 37094332d3Sopenharmony_ci struct timeval _tv; \ 38094332d3Sopenharmony_ci gettimeofday(&_tv, NULL); \ 39094332d3Sopenharmony_ci struct tm* _tm = localtime(&_tv.tv_sec); \ 40094332d3Sopenharmony_ci int _ms = _tv.tv_usec / 1000; \ 41094332d3Sopenharmony_ci char now[25] = {0}; \ 42094332d3Sopenharmony_ci sprintf_s(now, sizeof(now), "%02d-%02d %02d:%02d:%02d.%03d", _tm->tm_mon + 1, _tm->tm_mday, _tm->tm_hour, \ 43094332d3Sopenharmony_ci _tm->tm_min, _tm->tm_sec, _ms) 44094332d3Sopenharmony_ci 45094332d3Sopenharmony_ci#define CAMERA_LOGE(fmt, ...) \ 46094332d3Sopenharmony_ci do { \ 47094332d3Sopenharmony_ci GET_CURRENT_TIME_MS; \ 48094332d3Sopenharmony_ci pid_t pid = getpid(); \ 49094332d3Sopenharmony_ci pid_t tid = gettid(); \ 50094332d3Sopenharmony_ci printf("%s %4u %4u E " fmt "\n", now, (uint32_t)pid, (uint32_t)tid, ##__VA_ARGS__); \ 51094332d3Sopenharmony_ci fflush(stdout); \ 52094332d3Sopenharmony_ci } while (0) 53094332d3Sopenharmony_ci 54094332d3Sopenharmony_ci#define CAMERA_LOGW(fmt, ...) \ 55094332d3Sopenharmony_ci do { \ 56094332d3Sopenharmony_ci GET_CURRENT_TIME_MS; \ 57094332d3Sopenharmony_ci pid_t pid = getpid(); \ 58094332d3Sopenharmony_ci pid_t tid = gettid(); \ 59094332d3Sopenharmony_ci printf("%s %4u %4u W " fmt "\n", now, (uint32_t)pid, (uint32_t)tid, ##__VA_ARGS__); \ 60094332d3Sopenharmony_ci fflush(stdout); \ 61094332d3Sopenharmony_ci } while (0) 62094332d3Sopenharmony_ci 63094332d3Sopenharmony_ci#define CAMERA_LOGI(fmt, ...) \ 64094332d3Sopenharmony_ci do { \ 65094332d3Sopenharmony_ci GET_CURRENT_TIME_MS; \ 66094332d3Sopenharmony_ci pid_t pid = getpid(); \ 67094332d3Sopenharmony_ci pid_t tid = gettid(); \ 68094332d3Sopenharmony_ci printf("%s %4u %4u I " fmt "\n", now, (uint32_t)pid, (uint32_t)tid, ##__VA_ARGS__); \ 69094332d3Sopenharmony_ci fflush(stdout); \ 70094332d3Sopenharmony_ci } while (0) 71094332d3Sopenharmony_ci 72094332d3Sopenharmony_ci#define CAMERA_LOGV(fmt, ...) \ 73094332d3Sopenharmony_ci do { \ 74094332d3Sopenharmony_ci GET_CURRENT_TIME_MS; \ 75094332d3Sopenharmony_ci pid_t pid = getpid(); \ 76094332d3Sopenharmony_ci pid_t tid = gettid(); \ 77094332d3Sopenharmony_ci printf("%s %4u %4u V " fmt "\n", now, (uint32_t)pid, (uint32_t)tid, ##__VA_ARGS__); \ 78094332d3Sopenharmony_ci fflush(stdout); \ 79094332d3Sopenharmony_ci } while (0) 80094332d3Sopenharmony_ci 81094332d3Sopenharmony_ci#define CAMERA_LOGD(fmt, ...) \ 82094332d3Sopenharmony_ci do { \ 83094332d3Sopenharmony_ci GET_CURRENT_TIME_MS; \ 84094332d3Sopenharmony_ci pid_t pid = getpid(); \ 85094332d3Sopenharmony_ci pid_t tid = gettid(); \ 86094332d3Sopenharmony_ci printf("%s %4u %4u D " fmt "\n", now, (uint32_t)pid, (uint32_t)tid, ##__VA_ARGS__); \ 87094332d3Sopenharmony_ci fflush(stdout); \ 88094332d3Sopenharmony_ci } while (0) 89094332d3Sopenharmony_ci 90094332d3Sopenharmony_ciconstexpr uint32_t WATCHDOG_TIMEOUT = 20000; 91094332d3Sopenharmony_ci 92094332d3Sopenharmony_cienum RetCode { 93094332d3Sopenharmony_ci RC_OK = 0, 94094332d3Sopenharmony_ci RC_ERROR, 95094332d3Sopenharmony_ci}; 96094332d3Sopenharmony_ci 97094332d3Sopenharmony_ci} // namespace OHOS::Camera 98094332d3Sopenharmony_ci#endif 99