-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
87 lines (70 loc) · 1.51 KB
/
main.cpp
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
/*
* main.cpp
*/
#ifndef MAIN_H_
#define MAIN_H_
#include <locale>
#include <string>
#include <time.h>
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/filesystem.hpp>
#include "Logger.h"
using namespace std ;
int _kbhit(void)
{
struct termios oldt, newt;
int ch;
int oldf;
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
ch = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
fcntl(STDIN_FILENO, F_SETFL, oldf);
if(ch != EOF)
{
ungetc(ch, stdin);
return 1;
}
return 0;
}
int main(int argc, char **argv)
{
Logger * logger = new Logger();
if ( argc != 5 )
cout<<"usage: "<< argv[0] <<" --duration X --destination '/absolute/path/to/file.klg'\n";
else {
int duration = atoi(argv[2]) ;
string path = argv[4] ;
time_t end = time(NULL) + duration;
if(path == "")
{
cout<< "Information", "You have not selected an output log file";
return 0 ;
}
else
{
logger->startWriting(path);
}
while(time(NULL) < end && !_kbhit())
{
}
logger->stopWriting() ;
}
return 0;
}
#endif /* MAIN_H_ */