diff options
Diffstat (limited to 'synchronizer')
-rw-r--r-- | synchronizer/listener.cpp | 28 | ||||
-rw-r--r-- | synchronizer/main.cpp | 6 |
2 files changed, 17 insertions, 17 deletions
diff --git a/synchronizer/listener.cpp b/synchronizer/listener.cpp index 01daf5d..7905038 100644 --- a/synchronizer/listener.cpp +++ b/synchronizer/listener.cpp | |||
@@ -15,18 +15,18 @@ Listener::Listener(const QString &resource, QObject *parent) | |||
15 | { | 15 | { |
16 | connect(m_server, &QLocalServer::newConnection, | 16 | connect(m_server, &QLocalServer::newConnection, |
17 | this, &Listener::acceptConnection); | 17 | this, &Listener::acceptConnection); |
18 | Console::main()->log(QString("Trying to open %1").arg(resource)); | 18 | Akonadi2::Console::main()->log(QString("Trying to open %1").arg(resource)); |
19 | if (!m_server->listen(resource)) { | 19 | if (!m_server->listen(resource)) { |
20 | // FIXME: multiple starts need to be handled here | 20 | // FIXME: multiple starts need to be handled here |
21 | m_server->removeServer(resource); | 21 | m_server->removeServer(resource); |
22 | if (!m_server->listen(resource)) { | 22 | if (!m_server->listen(resource)) { |
23 | Console::main()->log("Utter failure to start server"); | 23 | Akonadi2::Console::main()->log("Utter failure to start server"); |
24 | exit(-1); | 24 | exit(-1); |
25 | } | 25 | } |
26 | } | 26 | } |
27 | 27 | ||
28 | if (m_server->isListening()) { | 28 | if (m_server->isListening()) { |
29 | Console::main()->log(QString("Listening on %1").arg(m_server->serverName())); | 29 | Akonadi2::Console::main()->log(QString("Listening on %1").arg(m_server->serverName())); |
30 | } | 30 | } |
31 | 31 | ||
32 | QTimer::singleShot(2000, this, SLOT(checkConnections())); | 32 | QTimer::singleShot(2000, this, SLOT(checkConnections())); |
@@ -63,14 +63,14 @@ void Listener::closeAllConnections() | |||
63 | 63 | ||
64 | void Listener::acceptConnection() | 64 | void Listener::acceptConnection() |
65 | { | 65 | { |
66 | Console::main()->log(QString("Accepting connection")); | 66 | Akonadi2::Console::main()->log(QString("Accepting connection")); |
67 | QLocalSocket *socket = m_server->nextPendingConnection(); | 67 | QLocalSocket *socket = m_server->nextPendingConnection(); |
68 | 68 | ||
69 | if (!socket) { | 69 | if (!socket) { |
70 | return; | 70 | return; |
71 | } | 71 | } |
72 | 72 | ||
73 | Console::main()->log("Got a connection"); | 73 | Akonadi2::Console::main()->log("Got a connection"); |
74 | Client client("Unknown Client" /*fixme: actual names!*/, socket); | 74 | Client client("Unknown Client" /*fixme: actual names!*/, socket); |
75 | connect(socket, &QIODevice::readyRead, | 75 | connect(socket, &QIODevice::readyRead, |
76 | this, &Listener::readFromSocket); | 76 | this, &Listener::readFromSocket); |
@@ -87,12 +87,12 @@ void Listener::clientDropped() | |||
87 | return; | 87 | return; |
88 | } | 88 | } |
89 | 89 | ||
90 | Console::main()->log("Dropping connection..."); | 90 | Akonadi2::Console::main()->log("Dropping connection..."); |
91 | QMutableVectorIterator<Client> it(m_connections); | 91 | QMutableVectorIterator<Client> it(m_connections); |
92 | while (it.hasNext()) { | 92 | while (it.hasNext()) { |
93 | const Client &client = it.next(); | 93 | const Client &client = it.next(); |
94 | if (client.socket == socket) { | 94 | if (client.socket == socket) { |
95 | Console::main()->log(QString(" dropped... %1").arg(client.name)); | 95 | Akonadi2::Console::main()->log(QString(" dropped... %1").arg(client.name)); |
96 | it.remove(); | 96 | it.remove(); |
97 | break; | 97 | break; |
98 | } | 98 | } |
@@ -116,10 +116,10 @@ void Listener::readFromSocket() | |||
116 | return; | 116 | return; |
117 | } | 117 | } |
118 | 118 | ||
119 | Console::main()->log("Reading from socket..."); | 119 | Akonadi2::Console::main()->log("Reading from socket..."); |
120 | for (Client &client: m_connections) { | 120 | for (Client &client: m_connections) { |
121 | if (client.socket == socket) { | 121 | if (client.socket == socket) { |
122 | Console::main()->log(QString(" Client: %1").arg(client.name)); | 122 | Akonadi2::Console::main()->log(QString(" Client: %1").arg(client.name)); |
123 | client.commandBuffer += socket->readAll(); | 123 | client.commandBuffer += socket->readAll(); |
124 | // FIXME: schedule these rather than process them all at once | 124 | // FIXME: schedule these rather than process them all at once |
125 | // right now this can lead to starvation of clients due to | 125 | // right now this can lead to starvation of clients due to |
@@ -133,7 +133,7 @@ void Listener::readFromSocket() | |||
133 | bool Listener::processClientBuffer(Client &client) | 133 | bool Listener::processClientBuffer(Client &client) |
134 | { | 134 | { |
135 | static const int headerSize = (sizeof(int) * 2); | 135 | static const int headerSize = (sizeof(int) * 2); |
136 | Console::main()->log(QString("processing %1").arg(client.commandBuffer.size())); | 136 | Akonadi2::Console::main()->log(QString("processing %1").arg(client.commandBuffer.size())); |
137 | if (client.commandBuffer.size() < headerSize) { | 137 | if (client.commandBuffer.size() < headerSize) { |
138 | return false; | 138 | return false; |
139 | } | 139 | } |
@@ -147,9 +147,9 @@ bool Listener::processClientBuffer(Client &client) | |||
147 | client.commandBuffer.remove(0, headerSize + size); | 147 | client.commandBuffer.remove(0, headerSize + size); |
148 | 148 | ||
149 | switch (commandId) { | 149 | switch (commandId) { |
150 | case Commands::HandshakeCommand: { | 150 | case Akonadi2::Commands::HandshakeCommand: { |
151 | auto buffer = Akonadi2::GetHandshake(data.constData()); | 151 | auto buffer = Akonadi2::GetHandshake(data.constData()); |
152 | Console::main()->log(QString(" Handshake from %1").arg(buffer->name()->c_str())); | 152 | Akonadi2::Console::main()->log(QString(" Handshake from %1").arg(buffer->name()->c_str())); |
153 | sendCurrentRevision(client); | 153 | sendCurrentRevision(client); |
154 | break; | 154 | break; |
155 | } | 155 | } |
@@ -172,7 +172,7 @@ void Listener::sendCurrentRevision(Client &client) | |||
172 | 172 | ||
173 | auto command = Akonadi2::CreateRevisionUpdate(m_fbb, m_revision); | 173 | auto command = Akonadi2::CreateRevisionUpdate(m_fbb, m_revision); |
174 | Akonadi2::FinishRevisionUpdateBuffer(m_fbb, command); | 174 | Akonadi2::FinishRevisionUpdateBuffer(m_fbb, command); |
175 | Commands::write(client.socket, Commands::RevisionUpdateCommand, m_fbb); | 175 | Akonadi2::Commands::write(client.socket, Akonadi2::Commands::RevisionUpdateCommand, m_fbb); |
176 | m_fbb.Clear(); | 176 | m_fbb.Clear(); |
177 | } | 177 | } |
178 | 178 | ||
@@ -186,7 +186,7 @@ void Listener::updateClientsWithRevision() | |||
186 | continue; | 186 | continue; |
187 | } | 187 | } |
188 | 188 | ||
189 | Commands::write(client.socket, Commands::RevisionUpdateCommand, m_fbb); | 189 | Akonadi2::Commands::write(client.socket, Akonadi2::Commands::RevisionUpdateCommand, m_fbb); |
190 | } | 190 | } |
191 | m_fbb.Clear(); | 191 | m_fbb.Clear(); |
192 | } | 192 | } |
diff --git a/synchronizer/main.cpp b/synchronizer/main.cpp index f4091df..fbb3c00 100644 --- a/synchronizer/main.cpp +++ b/synchronizer/main.cpp | |||
@@ -9,12 +9,12 @@ int main(int argc, char *argv[]) | |||
9 | QApplication app(argc, argv); | 9 | QApplication app(argc, argv); |
10 | 10 | ||
11 | if (argc < 2) { | 11 | if (argc < 2) { |
12 | new Console(QString("Resource: ???")); | 12 | new Akonadi2::Console(QString("Resource: ???")); |
13 | Console::main()->log("Not enough args passed, no resource loaded."); | 13 | Akonadi2::Console::main()->log("Not enough args passed, no resource loaded."); |
14 | return app.exec(); | 14 | return app.exec(); |
15 | } | 15 | } |
16 | 16 | ||
17 | new Console(QString("Resource: %1").arg(argv[1])); | 17 | new Akonadi2::Console(QString("Resource: %1").arg(argv[1])); |
18 | Listener *listener = new Listener(argv[1]); | 18 | Listener *listener = new Listener(argv[1]); |
19 | 19 | ||
20 | QObject::connect(&app, &QCoreApplication::aboutToQuit, | 20 | QObject::connect(&app, &QCoreApplication::aboutToQuit, |