-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
44 lines (34 loc) · 1.01 KB
/
main.cpp
File metadata and controls
44 lines (34 loc) · 1.01 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
#include "pch.h"
#include "Server.h"
#include "CoAmp.h"
#include "KeyLogger.h"
#define APP "EMGDataServer"
int main() {
std::string lockFile = std::string("/tmp/") + APP + "_lockFile";
int pid_file = open(lockFile.c_str(), O_CREAT | O_RDWR, 0666);
auto rc = flock(pid_file, LOCK_EX | LOCK_NB);
if(rc != 0) {
std::cerr << "Server already running...\n";
return 1;
}
auto pid = getpid();
write(pid_file, &pid, sizeof(pid_t));
Logger::init(Logger::trace);
// EMG Sensors
CoAmp::SensorParam_t sensorParam;
sensorParam.iWindowLength = 256;
sensorParam.iHopLength = 256;
sensorParam.iGain = 8;
CoAmp* pSensor = CoAmp::getInstance();
pSensor->init(sensorParam);
// Key Logger
auto* pKeyLogger = KeyLogger::getInstance();
Server* pServer = Server::getInstance();
pServer->init(pSensor, pKeyLogger, 8080, 128);
pServer->run(-1);
delete pSensor;
delete pServer;
flock(pid_file, LOCK_UN);
close(pid_file);
return 0;
}