1 /* __LICENSE_HEADER_BEGIN__ */
4 * Copyright (C) 2012 Emmanuel Roullit <emmanuel.roullit@gmail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or (at
9 * your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
22 /* __LICENSE_HEADER_END__ */
28 #include <dabbad/ipc.h>
29 #include <dabbad/list.h>
30 #include <dabbad/capture.h>
32 static int dabbad_handle_msg(struct dabba_ipc_msg
*msg
)
37 switch (msg
->msg_body
.type
) {
39 rc
= dabbad_ifconf_get(msg
);
41 case DABBA_CAPTURE_START
:
42 rc
= dabbad_capture_start(msg
);
44 case DABBA_CAPTURE_LIST
:
45 rc
= dabbad_capture_list(msg
);
47 case DABBA_CAPTURE_STOP
:
48 rc
= dabbad_capture_stop(msg
);
59 int dabbad_ipc_msg_init(void)
61 return msgctl(dabba_get_ipc_queue_id(0), IPC_RMID
, NULL
);
64 void dabbad_ipc_msg_flush(int qid
)
66 struct dabba_ipc_msg msg
;
71 msgrcv(qid
, &msg
, sizeof(msg
.msg_body
), 0,
72 IPC_NOWAIT
| MSG_NOERROR
);
76 int dabbad_ipc_msg_poll(void)
81 struct dabba_ipc_msg msg
;
83 qid
= dabba_get_ipc_queue_id(IPC_CREAT
| IPC_EXCL
| 0660);
86 perror("Cannot get IPC id");
90 dabbad_ipc_msg_flush(qid
);
93 memset(&msg
, 0, sizeof(msg
));
94 rcv
= msgrcv(qid
, &msg
, sizeof(msg
.msg_body
), 0, 0);
97 perror("Error while receiving IPC msg");
101 rcv
= dabbad_handle_msg(&msg
);
103 msg
.msg_body
.error
= rcv
;
106 perror("Error while handling IPC msg");
109 snd
= msgsnd(qid
, &msg
, sizeof(msg
.msg_body
), 0);
112 perror("Error while sending back IPC msg");