diff options
author | Aaron Seigo <aseigo@kde.org> | 2014-11-21 17:56:35 +0100 |
---|---|---|
committer | Aaron Seigo <aseigo@kde.org> | 2014-11-21 17:56:35 +0100 |
commit | 9229f4aea0765265b74111ea51798efde7d07997 (patch) | |
tree | d779e6b619452e76bfe8daddedcc4b6b0abb98ad | |
parent | d77a7ebbdeab5079fea31a5308fd9e1474e6336b (diff) | |
download | sink-9229f4aea0765265b74111ea51798efde7d07997.tar.gz sink-9229f4aea0765265b74111ea51798efde7d07997.zip |
how a command accross the wire might look: initial handshake
-rw-r--r-- | client/resourceaccess.cpp | 12 | ||||
-rw-r--r-- | resource/listener.cpp | 31 | ||||
-rw-r--r-- | resource/listener.h | 1 |
3 files changed, 42 insertions, 2 deletions
diff --git a/client/resourceaccess.cpp b/client/resourceaccess.cpp index 7c92331..2972316 100644 --- a/client/resourceaccess.cpp +++ b/client/resourceaccess.cpp | |||
@@ -1,6 +1,7 @@ | |||
1 | #include "resourceaccess.h" | 1 | #include "resourceaccess.h" |
2 | 2 | ||
3 | #include "common/console.h" | 3 | #include "common/console.h" |
4 | #include "common/commands.h" | ||
4 | 5 | ||
5 | #include <QDebug> | 6 | #include <QDebug> |
6 | #include <QProcess> | 7 | #include <QProcess> |
@@ -64,7 +65,16 @@ void ResourceAccess::connected() | |||
64 | { | 65 | { |
65 | m_startingProcess = false; | 66 | m_startingProcess = false; |
66 | Console::main()->log(QString("Connected: %1").arg(m_socket->fullServerName())); | 67 | Console::main()->log(QString("Connected: %1").arg(m_socket->fullServerName())); |
67 | m_socket->write("100 command " + QString::number((long long)this).toLatin1()); | 68 | |
69 | { | ||
70 | const QByteArray name = QString::number((long long)this).toLatin1(); | ||
71 | const int commandId = Commands::HandshakeCommand; | ||
72 | const int dataSize = name.size(); | ||
73 | m_socket->write((const char*)&commandId, sizeof(int)); | ||
74 | m_socket->write((const char*)&dataSize, sizeof(int)); | ||
75 | m_socket->write(name.data(), name.size()); | ||
76 | } | ||
77 | |||
68 | emit ready(true); | 78 | emit ready(true); |
69 | } | 79 | } |
70 | 80 | ||
diff --git a/resource/listener.cpp b/resource/listener.cpp index f5920b7..da1edc3 100644 --- a/resource/listener.cpp +++ b/resource/listener.cpp | |||
@@ -1,6 +1,7 @@ | |||
1 | #include "listener.h" | 1 | #include "listener.h" |
2 | 2 | ||
3 | #include "common/console.h" | 3 | #include "common/console.h" |
4 | #include "common/commands.h" | ||
4 | 5 | ||
5 | #include <QLocalSocket> | 6 | #include <QLocalSocket> |
6 | #include <QTimer> | 7 | #include <QTimer> |
@@ -106,9 +107,37 @@ void Listener::readFromSocket() | |||
106 | if (client.socket == socket) { | 107 | if (client.socket == socket) { |
107 | Console::main()->log(QString(" Client: %1").arg(client.name)); | 108 | Console::main()->log(QString(" Client: %1").arg(client.name)); |
108 | client.commandBuffer += socket->readAll(); | 109 | client.commandBuffer += socket->readAll(); |
109 | Console::main()->log(QString(" Command: %1").arg(QString(client.commandBuffer))); | 110 | processClientBuffer(client); |
110 | break; | 111 | break; |
111 | } | 112 | } |
112 | } | 113 | } |
114 | } | ||
113 | 115 | ||
116 | void Listener::processClientBuffer(Client &client) | ||
117 | { | ||
118 | static const int headerSize = (sizeof(int) * 2); | ||
119 | Console::main()->log(QString("processing %1").arg(client.commandBuffer.size())); | ||
120 | if (client.commandBuffer.size() < headerSize) { | ||
121 | return; | ||
122 | } | ||
123 | |||
124 | int commandId, size; | ||
125 | commandId = *(int*)client.commandBuffer.constData(); | ||
126 | size = *(int*)(client.commandBuffer.constData() + sizeof(int)); | ||
127 | |||
128 | if (size <= client.commandBuffer.size() - headerSize) { | ||
129 | QByteArray data = client.commandBuffer.mid(headerSize, size); | ||
130 | client.commandBuffer.remove(0, headerSize + size); | ||
131 | |||
132 | switch (commandId) { | ||
133 | case Commands::HandshakeCommand: | ||
134 | client.name = data; | ||
135 | Console::main()->log(QString(" Handshake from %1").arg(client.name)); | ||
136 | //TODO: reply? | ||
137 | break; | ||
138 | default: | ||
139 | // client.hasSentCommand = true; | ||
140 | break; | ||
141 | } | ||
142 | } | ||
114 | } | 143 | } |
diff --git a/resource/listener.h b/resource/listener.h index 536ba39..bfafe5f 100644 --- a/resource/listener.h +++ b/resource/listener.h | |||
@@ -42,6 +42,7 @@ private Q_SLOTS: | |||
42 | void readFromSocket(); | 42 | void readFromSocket(); |
43 | 43 | ||
44 | private: | 44 | private: |
45 | void processClientBuffer(Client &client); | ||
45 | QLocalServer *m_server; | 46 | QLocalServer *m_server; |
46 | QList<Client> m_connections; | 47 | QList<Client> m_connections; |
47 | }; \ No newline at end of file | 48 | }; \ No newline at end of file |