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
|
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <stdint.h>
#include <string.h>
#include <pthread.h>
#include "slices_evt.h"
#include "recover.h"
#include "utils.h"
int end=0;
//FIXME remove me, only for tests
unsigned long c=0;
struct threadArgs {
struct progArgs *progArgs;
slices_evt_t *slices;
};
void sigHookAbrt() {
end=1;
}
/*TODO : remove that when procViewer is done
void dumper(slices_evt_t *slicesEvt, slice_t *modifiedSlice) {
address_t blockSize=0;
char *dump;
dump=slicesDump(slicesEvt->data, &blockSize, 3000, 0, 21474836480ULL);
system("clear");
puts(dump);
free(dump);
}
*/
void *procWorker(void *a);
void *procViewer(void *a);
int main(int argc, char **argv) {
// System structures
struct sigaction sa;
pthread_t tWorker;
// Main data structures
slices_evt_t slices;
// Progam and threads arguments
struct progArgs args;
struct threadArgs tArgs;
// Algorithmic needs
int res, i;
// Parse command-line arguments
res=parseArgs(argc, argv, &args);
if (res!=0) {
usage(argv[0]);
return 1;
}
// Set signals behavior
memset(&sa,0,sizeof(sa));
sa.sa_handler=sigHookAbrt;
res=sigaction(SIGABRT, &sa, NULL);
if (res!=0) {
return 2;
}
//XXX Remove srand : only for simulation
srand(4);
// Data structure initialization
memset(&slices, 0, sizeof(slices));
slices.data=slicesNewSingleton(args.beginSector, args.endSector, S_UNKNOWN);
// slices.eventListener=dumper;
res=pthread_mutex_init(&(slices.mutex), NULL);
if (res!=0) {
return 3;
}
// Threads preparation, creation and start
memset(&tArgs, 0, sizeof(tArgs));
tArgs.progArgs=&args;
tArgs.slices=&slices;
res=pthread_create(&tWorker, NULL, procWorker, &tArgs);
if (res!=0) {
return 4;
}
// Ncurses interface run in the main thread
(void) procViewer((void*)&tArgs);
// Thread join point
(void) pthread_join(tWorker, NULL);
/*Final dump of datas
address_t blockSize=0;
char *dump;
dump=slicesDump(slices.data, &blockSize, 1000, args.beginSector, args.endSector);
puts(dump);
free(dump);
printf("blockSize==%lld\n", blockSize);
printf("slices->count==%d\n", slices.data->count);
*/
//Resources desallocation
(void) pthread_mutex_destroy(&(slices.mutex));
slice_t *curr, *toFree;
i=0; curr=slices.data->first;
while (curr!=NULL) {
i++;
toFree=curr;
curr=curr->next;
free(toFree);
}
free(slices.data);
return 0;
}
void * procWorker(void *a) {
struct threadArgs *tArgs = (struct threadArgs *)a;
recover(
tArgs->slices,
tArgs->progArgs->src,
tArgs->progArgs->dst,
tArgs->progArgs->ddOpts
);
return a;
}
#define CURSESWIN_COUNT 3
void *procViewer(void *a) {
WINDOW *wins[CURSESWIN_COUNT];
PANEL *panels[CURSESWIN_COUNT];
int ch;
//struct threadArgs *tArgs = (struct threadArgs *)a;
cursesInit(wins, panels, CURSESWIN_COUNT);
/* Show it on the screen */
attron(COLOR_PAIR(4));
mvprintw(LINES - 2, 0, "Use tab to browse through the windows (F2 to Exit)");
attroff(COLOR_PAIR(4));
doupdate();
while((ch = getch()) != KEY_F(2)) {
switch(ch) {
case 1:
case 2:
case 3:
top_panel(panels[ch]);
break;
}
update_panels();
doupdate();
}
endwin();
return a;
}
|