summaryrefslogtreecommitdiff
path: root/src/cprlisten.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/cprlisten.cc')
-rw-r--r--src/cprlisten.cc50
1 files changed, 42 insertions, 8 deletions
diff --git a/src/cprlisten.cc b/src/cprlisten.cc
index 9a816d2..9ecac86 100644
--- a/src/cprlisten.cc
+++ b/src/cprlisten.cc
@@ -26,36 +26,68 @@
*/
#include "cprlisten.h"
-#include "socket.h"
+#include "aa_socket.h"
#include <iostream>
#include <string>
using namespace std;
+#define MAGIC_STOP_STRING "SHUTTHEFUCKUP"
+
CPRListen::CPRListen(unsigned short port)
{
this->port = port;
cpr = "N/A";
+ cprchanged = false;
+ running = true;
}
CPRListen::~CPRListen()
{
}
+void CPRListen::stop()
+{
+ running = false;
+ try {
+ AASocket socket;
+ socket.connect("localhost", port);
+ socket.send_string(MAGIC_STOP_STRING);
+ } catch(Network_error &e) {
+ cerr << "In stop(): " << e.error << endl;
+ }
+}
+
void CPRListen::thread_main()
{
- while(1) {
+ while(running) {
try {
- Socket socket;
+ string newcpr;
+ AASocket socket;
socket.listen(port);
- mutex.lock();
- cpr = socket.receive_string();
- mutex.unlock();
- cerr << "Got CPR: " << cpr << endl;
+ newcpr = socket.receive_string();
+
+ if(newcpr == MAGIC_STOP_STRING) {
+ running = false;
+ } else {
+ mutex.lock();
+ cprchanged = true;
+ cpr = newcpr;
+ mutex.unlock();
+ // cerr << "Got CPR: " << cpr << endl;
+ }
+
} catch(Network_error &e) {
- cerr << e.error << endl;
+ cerr << "In thread_main(): " << e.error << endl;
+ running = false;
}
}
+ // cout << "fisk!" << endl;
+}
+
+bool CPRListen::cprChanged()
+{
+ return cprchanged;
}
string CPRListen::getCpr()
@@ -66,5 +98,7 @@ string CPRListen::getCpr()
cpr_copy = cpr;
mutex.unlock();
+ cprchanged = false;
+
return cpr_copy;
}