diff options
-rw-r--r-- | client/resourceaccess.cpp | 8 | ||||
-rw-r--r-- | common/CMakeLists.txt | 1 | ||||
-rw-r--r-- | common/commands.h | 6 | ||||
-rw-r--r-- | resource/listener.cpp | 13 |
4 files changed, 12 insertions, 16 deletions
diff --git a/client/resourceaccess.cpp b/client/resourceaccess.cpp index 6d48c51..641c203 100644 --- a/client/resourceaccess.cpp +++ b/client/resourceaccess.cpp | |||
@@ -73,14 +73,10 @@ void ResourceAccess::connected() | |||
73 | 73 | ||
74 | { | 74 | { |
75 | flatbuffers::FlatBufferBuilder fbb; | 75 | flatbuffers::FlatBufferBuilder fbb; |
76 | auto name = fbb.CreateString("Client PID: " + QString::number((long long)this).toLatin1() + "!"); | 76 | auto name = fbb.CreateString(QString::number((long long)this).toLatin1()); |
77 | auto command = Akonadi::CreateHandshake(fbb, name); | 77 | auto command = Akonadi::CreateHandshake(fbb, name); |
78 | Akonadi::FinishHandshakeBuffer(fbb, command); | 78 | Akonadi::FinishHandshakeBuffer(fbb, command); |
79 | const int commandId = Commands::HandshakeCommand; | 79 | Commands::write(m_socket, Commands::HandshakeCommand, fbb); |
80 | const int dataSize = fbb.GetSize(); | ||
81 | m_socket->write((const char*)&commandId, sizeof(int)); | ||
82 | m_socket->write((const char*)&dataSize, sizeof(int)); | ||
83 | m_socket->write((const char*)fbb.GetBufferPointer(), dataSize); | ||
84 | } | 80 | } |
85 | 81 | ||
86 | emit ready(true); | 82 | emit ready(true); |
diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 6533e28..d409828 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt | |||
@@ -3,6 +3,7 @@ generate_flatbuffers(commands/handshake | |||
3 | commands/revisionupdate) | 3 | commands/revisionupdate) |
4 | 4 | ||
5 | set(command_SRCS | 5 | set(command_SRCS |
6 | commands.cpp | ||
6 | console.cpp | 7 | console.cpp |
7 | ${CMAKE_CURRENT_BINARY_DIR}/commands/handshake_generated.h) | 8 | ${CMAKE_CURRENT_BINARY_DIR}/commands/handshake_generated.h) |
8 | 9 | ||
diff --git a/common/commands.h b/common/commands.h index 68a7c1e..534308d 100644 --- a/common/commands.h +++ b/common/commands.h | |||
@@ -1,5 +1,9 @@ | |||
1 | #pragma once | 1 | #pragma once |
2 | 2 | ||
3 | #include <flatbuffers/flatbuffers.h> | ||
4 | |||
5 | class QIODevice; | ||
6 | |||
3 | namespace Commands | 7 | namespace Commands |
4 | { | 8 | { |
5 | 9 | ||
@@ -10,4 +14,6 @@ enum CommandIds { | |||
10 | CustomCommand = 0xffff | 14 | CustomCommand = 0xffff |
11 | }; | 15 | }; |
12 | 16 | ||
17 | void write(QIODevice *device, int commandId, flatbuffers::FlatBufferBuilder &fbb); | ||
18 | |||
13 | } \ No newline at end of file | 19 | } \ No newline at end of file |
diff --git a/resource/listener.cpp b/resource/listener.cpp index 038b3fa..4b3e4ff 100644 --- a/resource/listener.cpp +++ b/resource/listener.cpp | |||
@@ -173,11 +173,7 @@ void Listener::sendCurrentRevision(Client &client) | |||
173 | flatbuffers::FlatBufferBuilder fbb; | 173 | flatbuffers::FlatBufferBuilder fbb; |
174 | auto command = Akonadi::CreateRevisionUpdate(fbb, m_revision); | 174 | auto command = Akonadi::CreateRevisionUpdate(fbb, m_revision); |
175 | Akonadi::FinishRevisionUpdateBuffer(fbb, command); | 175 | Akonadi::FinishRevisionUpdateBuffer(fbb, command); |
176 | const int commandId = Commands::RevisionUpdateCommand; | 176 | Commands::write(client.socket, Commands::RevisionUpdateCommand, fbb); |
177 | const int dataSize = fbb.GetSize(); | ||
178 | client.socket->write((const char*)&commandId, sizeof(int)); | ||
179 | client.socket->write((const char*)&dataSize, sizeof(int)); | ||
180 | client.socket->write((const char*)fbb.GetBufferPointer(), dataSize); | ||
181 | } | 177 | } |
182 | 178 | ||
183 | void Listener::updateClientsWithRevision() | 179 | void Listener::updateClientsWithRevision() |
@@ -185,15 +181,12 @@ void Listener::updateClientsWithRevision() | |||
185 | flatbuffers::FlatBufferBuilder fbb; | 181 | flatbuffers::FlatBufferBuilder fbb; |
186 | auto command = Akonadi::CreateRevisionUpdate(fbb, m_revision); | 182 | auto command = Akonadi::CreateRevisionUpdate(fbb, m_revision); |
187 | Akonadi::FinishRevisionUpdateBuffer(fbb, command); | 183 | Akonadi::FinishRevisionUpdateBuffer(fbb, command); |
188 | const int commandId = Commands::RevisionUpdateCommand; | ||
189 | const int dataSize = fbb.GetSize(); | ||
190 | 184 | ||
191 | for (const Client &client: m_connections) { | 185 | for (const Client &client: m_connections) { |
192 | if (!client.socket || !client.socket->isValid()) { | 186 | if (!client.socket || !client.socket->isValid()) { |
193 | continue; | 187 | continue; |
194 | } | 188 | } |
195 | client.socket->write((const char*)&commandId, sizeof(int)); | 189 | |
196 | client.socket->write((const char*)&dataSize, sizeof(int)); | 190 | Commands::write(client.socket, Commands::RevisionUpdateCommand, fbb); |
197 | client.socket->write((const char*)fbb.GetBufferPointer(), dataSize); | ||
198 | } | 191 | } |
199 | } | 192 | } |