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
|
/*
* 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
|