-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsgq.h
58 lines (44 loc) · 1.33 KB
/
msgq.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/******************************************************************************
* Copyright (C) Dean Zou 2016-2017
* file: msgq.h
* author: Dean Zou <deboot@msn.cn>
* created: 2017-07-31 16:29:41
* updated: 2017-07-31 16:29:41
*****************************************************************************/
#ifndef MSGQ_H
#define MSGQ_H
#include <mqueue.h>
#include <pthread.h>
#define MAX_IPC_MESSAGES 5
#define MAX_IPC_MESSAGE_SIZE 1024
#define MQ_MSG_PRIO 10
#include "libipc.h"
#ifdef __cplusplus
extern "C" {
#endif
struct mq_ctx;
typedef enum ipc_role {
IPC_RECEIVE = 0,
IPC_SEND = 1,
}ipc_role;
typedef void (*mq_recv_cb) (struct msg_st *);
typedef void (*msg_recv_cb)(struct mq_ctx *mq_ctx,struct msg_st *msg);
typedef struct mq_ctx{
mqd_t mqdes;
long msgsize;
long maxmsg;
pthread_t thread_id;
mq_recv_cb recv_cb;
msg_recv_cb msg_cb;
void *recv_buf;
}mq_ctx;
typedef void (mq_notify_cb)(union sigval sv);
mq_ctx *_mq_init(const char *name,mq_recv_cb recv_cb,msg_recv_cb msg_cb,ipc_role role);
void _mq_deinit(struct mq_ctx *mq_ctx,const char *name);
int _mq_send(struct mq_ctx *mq_ctx, const char *buf, long len,long msg_prio);
int _mq_recv(struct mq_ctx *mq_ctx, void *buf, long len);
int _mq_setattr(struct mq_ctx *mq_ctx);
#ifdef __cplusplus
}
#endif
#endif