23
23
*/
24
24
struct mqueue {
25
25
int pfd [2 ];
26
+ mqueue_h * h ;
27
+ void * arg ;
26
28
};
27
29
28
30
struct msg {
29
- mqueue_h * h ;
30
31
int id ;
31
32
void * data ;
32
33
uint32_t magic ;
@@ -71,30 +72,34 @@ static void event_handler(int flags, void *arg)
71
72
return ;
72
73
}
73
74
74
- if (msg .h )
75
- msg .h (msg .id , msg .data );
75
+ mq -> h (msg .id , msg .data , mq -> arg );
76
76
}
77
77
78
78
79
79
/**
80
80
* Allocate a new Message Queue
81
81
*
82
82
* @param mqp Pointer to allocated Message Queue
83
+ * @param h Message handler
84
+ * @param arg Handler argument
83
85
*
84
86
* @return 0 if success, otherwise errorcode
85
87
*/
86
- int mqueue_alloc (struct mqueue * * mqp )
88
+ int mqueue_alloc (struct mqueue * * mqp , mqueue_h * h , void * arg )
87
89
{
88
90
struct mqueue * mq ;
89
91
int err = 0 ;
90
92
91
- if (!mqp )
93
+ if (!mqp || ! h )
92
94
return EINVAL ;
93
95
94
96
mq = mem_zalloc (sizeof (* mq ), destructor );
95
97
if (!mq )
96
98
return ENOMEM ;
97
99
100
+ mq -> h = h ;
101
+ mq -> arg = arg ;
102
+
98
103
mq -> pfd [0 ] = mq -> pfd [1 ] = -1 ;
99
104
if (pipe (mq -> pfd ) < 0 ) {
100
105
err = errno ;
@@ -119,21 +124,19 @@ int mqueue_alloc(struct mqueue **mqp)
119
124
* Push a new message onto the Message Queue
120
125
*
121
126
* @param mq Message Queue
122
- * @param h Message handler
123
127
* @param id General purpose Identifier
124
128
* @param data Application data
125
129
*
126
130
* @return 0 if success, otherwise errorcode
127
131
*/
128
- int mqueue_push (struct mqueue * mq , mqueue_h * h , int id , void * data )
132
+ int mqueue_push (struct mqueue * mq , int id , void * data )
129
133
{
130
134
struct msg msg ;
131
135
ssize_t n ;
132
136
133
137
if (!mq )
134
138
return EINVAL ;
135
139
136
- msg .h = h ;
137
140
msg .id = id ;
138
141
msg .data = data ;
139
142
msg .magic = MAGIC ;
0 commit comments