-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
178 lines (164 loc) · 4.7 KB
/
main.cpp
File metadata and controls
178 lines (164 loc) · 4.7 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include <iostream>
#include <curses.h>
#include <unistd.h>
#include <signal.h>
#include <locale.h>
#include <termios.h>
#include <sys/ioctl.h>
#include <sys/eventfd.h>
#include <poll.h>
using namespace std;
void sig(int n)
{
}
int fd, fd2;
void *functionC(void*);
int main()
{
SCREEN* screen = newterm("xterm-1003", stdin, stdout);
set_term(screen);
setlocale(LC_ALL, "");
//signal(SIGINT, sig);
cout << "Hello world!" << endl;
WINDOW* window = initscr();
cbreak();
noecho();
nonl();
intrflush(stdscr, FALSE);
keypad(stdscr, TRUE);
//
mousemask(ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, NULL);
start_color();
init_pair(1, COLOR_BLUE, COLOR_GREEN);
init_pair(2, COLOR_BLUE, COLOR_BLACK);
attron(COLOR_PAIR(1));
//char buffer[40];
//sprintf(buffer, "%s", "Hello ncurses ! фывфыв russian text,");
addstr("lksjdf ыловаыва\u2591");
refresh();
long c = '\u2591';
cchar_t ch;
ch.attr = 1;
ch.chars[0] = ' ';
ch.chars[1] = '\u2591';
ch.chars[2] = 'f';
ch.chars[3] = 'x';
ch.chars[4] = 'n';
//mvadd_wch(3, 3, &ch);
attroff(COLOR_PAIR(2));//attron(COLOR_PAIR(2));
void* _stdscr = stdscr;
// if (window != _stdscr ) {
// printw("%s", "assertion failed");
// }
addstr("lksjdf ыловаыва\u2591");
//mousemask(BUTTON1_CLICKED)
//chtype
//addwstr((const wchar_t*) "Hello ncurses ! ываыва");
//char text[]="Русский UTF-8 текст\n";
//printw("%s",text);
refresh();
int c1 = getch();
refresh();
int c2 = getch();
refresh();
int c3 = getch();
refresh();
int c4 = getch();
refresh();
int c5 = getch();
refresh();
int cc = KEY_MOUSE;
//getch();
endwin();
printf("%d %d %d %d %d %d", c1, c2, c3, c4, c5, cc);
if (c1 == KEY_MOUSE) {
printf("Mouse.");
}
return 0;
printf("%x\n", EFD_NONBLOCK);
fd = eventfd(0, EFD_CLOEXEC);
if (fd == -1) {
printf("%s", "eventfd returned -1");
return -1;
}
printf("fd = %x\n", fd);
pthread_t thread1;
int rc1;
if( (rc1=pthread_create( &thread1, NULL, &functionC, NULL)) ) {
printf("Thread creation failed: %d\n", rc1);
}
fd2 = eventfd(0, EFD_CLOEXEC);
printf("fd2 = %x\n", fd2);
if (fd2 == -1) {
printf("%s", "eventfd returned -1");
return -1;
}
// осталось научиться определять, какой из файловых дескрипторов сработал
pollfd pollfds[2];
pollfds[0].fd = fd2;
pollfds[0].events = POLLIN;
pollfds[1].fd = fd;
pollfds[1].events = POLLIN;
bool flag = false;
for (int k = 0; k < 10; k++) {
int pollResult = poll(pollfds, 2, 1000);
printf("poll returned %d\n", pollResult);
// определим сработавшие файловые дескрипторы
if (pollResult > 0) {
for (int i = 0; i < 2; i++) {
printf("pollfds[%d].revents = %X\n", i, pollfds[i].revents);
if (pollfds[i].revents != 0 && flag && i == 0) {
printf("Reading 1 time to clear the eventfd counter..\n");
uint64_t u;
read(i == 0 ? fd2 : fd, &u, sizeof(uint64_t));
}
}
if (pollfds[0].revents != 0 && pollfds[1].revents != 0)
flag = true;
if (!flag)
sleep(1);
}
}
/*int pollResult = poll(pollfds, 2, -1);
printf("poll returned %d\n", pollResult);
// определим сработавшие файловые дескрипторы
if (pollResult > 0) {
for (int i = 0; i < 2; i++) {
printf("pollfds[%d].revents = %X\n", i, pollfds[i].revents);
}
}
//
printf("Reading 1 time to clear the eventfd counter..");
uint64_t u;
read(fd, &u, sizeof(uint64_t));
//
pollResult = poll(pollfds, 2, -1);
printf("poll returned %d\n", pollResult);
// определим сработавшие файловые дескрипторы
if (pollResult > 0) {
for (int i = 0; i < 2; i++) {
printf("pollfds[%d].revents = %X\n", i, pollfds[i].revents);
}
}*/
//pthread_join(thread1, NULL);
//close(fd);
//close(fd2);
//return 0;
}
void *functionC(void* data) {
sleep(1);
{
uint64_t u = 2;
write(fd, &u, sizeof(uint64_t));
}
for (int i = 0; i < 5; i++) {
printf("Thread message : %d\n", i);
sleep(1);
uint64_t u = 2;
write(fd2, &u, sizeof(uint64_t));
}
{
uint64_t u = 5;
write(fd2, &u, sizeof(uint64_t));
}
}