xts_dcts/common/shm_utils.h
wuxiaodan 6728dc99ed 3. add xts_dcts.server
Signed-off-by: wuxiaodan <wuxiaodan5@huawei.com>
2022-07-04 16:55:23 +08:00

60 lines
2.2 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef SHM_UTILS_H
#define SHM_UTILS_H
#include <cerrno>
#include <cstdarg>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <pthread.h>
#include <securec.h>
#include <sys/shm.h>
#include <sys/time.h>
#include <unistd.h>
#define MAX_WAIT_TIMEOUT 10
#define SHM_SEND_KEY 123456
#define SHM_RECV_KEY 123466
struct shared_use_st {
int written; // 作为一个标志非0表示可读0表示可写
char data[1024]; // 记录写入和读取的文本
};
#define LOG(format, ...) \
do { \
time_t timeSec; \
time(&timeSec); \
struct tm tmRst; \
localtime_r(&timeSec, &tmRst); \
char strTime[10]; \
strftime(strTime, sizeof(strTime), "%H:%M:%S", &tmRst); \
fprintf(stdout, "[shm-utils] %s " format "\n", strTime, ##__VA_ARGS__); \
} while (0)
int createShm(int key);
int disconnectShm(void);
int writeCodeDataToShm(int code, char* buf);
int waitDataWithCode(char* code, char* data);
int writeDataToShm(char* buf);
int deleteShm(void);
char* Int2String(int num, char* str);
void initShm(void);
int readDataFromShm(char* buf);
int readDataFromShmNoClear(char* buf);
#endif