summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Zaoui <daniel.zaoui@samsung.com>2015-07-28 10:23:27 +0300
committerDaniel Zaoui <daniel.zaoui@samsung.com>2015-07-28 10:23:27 +0300
commit45278cd4bf784b774eb6b65d45e971bcfc72714a (patch)
tree9c7fce35f515fe29c1ac8e071acb50474a7599f8
parent3f6201d07947c98239b343406ab5b58bdb97e637 (diff)
CLI: Add main + epoll support for keyboard
-rw-r--r--src/bin/cli.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/bin/cli.c b/src/bin/cli.c
index e69de29..e5466bf 100644
--- a/src/bin/cli.c
+++ b/src/bin/cli.c
@@ -0,0 +1,73 @@
1#include <sys/epoll.h>
2#include <unistd.h>
3#include <termios.h>
4
5#include <Eina.h>
6#include <Eolian.h>
7
8int _edbg_log_dom = -1;
9
10#ifdef ERR
11# undef ERR
12#endif
13#define ERR(...) EINA_LOG_DOM_ERR(_edbg_log_dom, __VA_ARGS__)
14
15#ifdef DBG
16# undef DBG
17#endif
18#define DBG(...) EINA_LOG_DOM_DBG(_edbg_log_dom, __VA_ARGS__)
19
20#ifdef INF
21# undef INF
22#endif
23#define INF(...) EINA_LOG_DOM_INFO(_edbg_log_dom, __VA_ARGS__)
24
25#ifdef WRN
26# undef WRN
27#endif
28#define WRN(...) EINA_LOG_DOM_WARN(_edbg_log_dom, __VA_ARGS__)
29
30#ifdef CRIT
31# undef CRIT
32#endif
33#define CRIT(...) EINA_LOG_DOM_CRIT(_edbg_log_dom, __VA_ARGS__)
34
35#define MAX_EVENTS 5
36
37int
38main()
39{
40 struct termios oldt, newt;
41 int poll = epoll_create(10);
42 struct epoll_event event, *events;
43
44 tcgetattr(STDIN_FILENO, &oldt);
45 newt = oldt;
46 newt.c_lflag &= ~(ICANON);
47 tcsetattr(STDIN_FILENO, TCSANOW, &newt);
48
49 event.data.fd = STDIN_FILENO;
50 event.events = EPOLLIN | EPOLLET;
51 epoll_ctl (poll, EPOLL_CTL_ADD, STDIN_FILENO, &event);
52
53 events = calloc(MAX_EVENTS, sizeof(event));
54
55 while(1)
56 {
57 int i, n = epoll_wait(poll, events, MAX_EVENTS, -1);
58 for (i = 0; i < n; i++)
59 {
60 if (events[i].data.fd == STDIN_FILENO)
61 {
62 char c;
63 while (read(0, &c, 1))
64 {
65 printf("Character %c received\n", c);
66 }
67 }
68 }
69 }
70 tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
71 return 0;
72}
73