summaryrefslogtreecommitdiff
path: root/src/pmchart/timecontrol.h
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2014-10-26 12:33:50 +0400
committerIgor Pashev <pashev.igor@gmail.com>2014-10-26 12:33:50 +0400
commit47e6e7c84f008a53061e661f31ae96629bc694ef (patch)
tree648a07f3b5b9d67ce19b0fd72e8caa1175c98f1a /src/pmchart/timecontrol.h
downloadpcp-debian.tar.gz
Debian 3.9.10debian/3.9.10debian
Diffstat (limited to 'src/pmchart/timecontrol.h')
-rw-r--r--src/pmchart/timecontrol.h106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/pmchart/timecontrol.h b/src/pmchart/timecontrol.h
new file mode 100644
index 0000000..2884bc7
--- /dev/null
+++ b/src/pmchart/timecontrol.h
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2006-2007, Aconex. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+#ifndef TIMECONTROL_H
+#define TIMECONTROL_H
+
+#include <QtCore/QString>
+#include <QtCore/QProcess>
+#include <QtNetwork/QTcpSocket>
+#include <qmc_time.h>
+
+class TimeControl : public QProcess
+{
+ Q_OBJECT
+
+public:
+ TimeControl();
+
+ void init(int port, bool livemode,
+ struct timeval *interval, struct timeval *position,
+ struct timeval *starttime, struct timeval *endtime,
+ QString tzstring, QString tzlabel);
+ void quit();
+
+ void addArchive(struct timeval starttime, struct timeval endtime,
+ QString tzstring, QString tzlabel, bool atEnd);
+
+ void liveConnect();
+ void archiveConnect();
+
+ int port() { return my.tcpPort; }
+ struct timeval *liveInterval() { return &my.livePacket->delta; }
+ struct timeval *livePosition() { return &my.livePacket->position; }
+ struct timeval *archiveInterval() { return &my.archivePacket->delta; }
+ struct timeval *archivePosition() { return &my.archivePacket->position; }
+ void setArchivePosition(struct timeval *pos) { my.archivePacket->position = *pos; }
+ void setArchiveInterval(struct timeval *delta) { my.archivePacket->delta = *delta; }
+ struct timeval *archiveStart() { return &my.archivePacket->start; }
+ struct timeval *archiveEnd() { return &my.archivePacket->end; }
+
+public slots:
+ void showLiveTimeControl();
+ void hideLiveTimeControl();
+ void showArchiveTimeControl();
+ void hideArchiveTimeControl();
+ void endTimeControl();
+
+ void readPortFromStdout();
+
+ void liveCloseConnection();
+ void liveSocketConnected();
+ void liveProtocolMessage()
+ {
+ protocolMessageLoop(true, my.livePacket, my.liveSocket, &my.liveState);
+ }
+
+ void archiveCloseConnection();
+ void archiveSocketConnected();
+ void archiveProtocolMessage()
+ {
+ protocolMessageLoop(false, my.archivePacket, my.archiveSocket,
+ &my.archiveState);
+ }
+
+private:
+ typedef enum {
+ Disconnected = 1,
+ AwaitingACK = 2,
+ ClientReady = 3,
+ } ProtocolState;
+
+ void startTimeServer();
+ void protocolMessage(bool live, QmcTime::Packet *pmtime,
+ QTcpSocket *socket, ProtocolState *state);
+ void protocolMessageLoop(bool live, QmcTime::Packet *pmtime,
+ QTcpSocket *socket, ProtocolState *state);
+
+ struct {
+ int tcpPort;
+ int tzLength;
+ char *tzData;
+
+ unsigned int bufferLength;
+ char *buffer;
+
+ QTcpSocket *liveSocket;
+ QmcTime::Packet *livePacket;
+ ProtocolState liveState;
+
+ QTcpSocket *archiveSocket;
+ QmcTime::Packet *archivePacket;
+ ProtocolState archiveState;
+ } my;
+};
+
+#endif // TIMECONTROL_H