forked from embedded2013/rtenv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpath_server.h
67 lines (55 loc) · 2.19 KB
/
path_server.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
59
60
61
62
63
64
65
66
67
#ifndef PATH_SERVER_H_20131005
#define PATH_SERVER_H_20131005
#include <stddef.h>
#include "task.h"
#define PIPE_BUF 64 /* Size of largest atomic pipe message */
#define PATH_MAX 32 /* Longest absolute path */
#define PIPE_LIMIT (TASK_LIMIT * 2)
#define PATHSERVER_FD (TASK_LIMIT + 3)
/* File descriptor of pipe to pathserver */
#define S_IFIFO 1
#define S_IMSGQ 2
#define O_CREAT 4
#define PATH_SERVER_NAME "/sys/pathserver"
struct pipe_ringbuffer {
int start;
int end;
char data[PIPE_BUF];
int (*readable) (struct pipe_ringbuffer*, struct task_control_block*);
int (*writable) (struct pipe_ringbuffer*, struct task_control_block*);
int (*read) (struct pipe_ringbuffer*, struct task_control_block*);
int (*write) (struct pipe_ringbuffer*, struct task_control_block*);
};
#define RB_PUSH(rb, size, v) do { \
(rb).data[(rb).end] = (v); \
(rb).end++; \
if ((rb).end >= size) (rb).end = 0; \
} while (0)
#define RB_POP(rb, size, v) do { \
(v) = (rb).data[(rb).start]; \
(rb).start++; \
if ((rb).start >= size) (rb).start = 0; \
} while (0)
#define RB_PEEK(rb, size, v, i) do { \
int _counter = (i); \
int _src_index = (rb).start; \
int _dst_index = 0; \
while (_counter--) { \
((char*)&(v))[_dst_index++] = (rb).data[_src_index++]; \
if (_src_index >= size) _src_index = 0; \
} \
} while (0)
#define RB_LEN(rb, size) (((rb).end - (rb).start) + \
(((rb).end < (rb).start) ? size : 0))
#define PIPE_PUSH(pipe, v) RB_PUSH((pipe), PIPE_BUF, (v))
#define PIPE_POP(pipe, v) RB_POP((pipe), PIPE_BUF, (v))
#define PIPE_PEEK(pipe, v, i) RB_PEEK((pipe), PIPE_BUF, (v), (i))
#define PIPE_LEN(pipe) (RB_LEN((pipe), PIPE_BUF))
void pathserver_task();
int open(const char *pathname, int flags);
void _read(struct task_control_block *task, struct task_control_block *tasks, struct pipe_ringbuffer *pipes);
void _write(struct task_control_block *task, struct task_control_block *tasks, struct pipe_ringbuffer *pipes);
int mq_open(const char *name, int oflag);
int mkfifo(const char *pathname, int mode);
int _mknod(struct pipe_ringbuffer *pipe, int dev);
#endif /* TASK_H_20131005 */