Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion deflect/MessageHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ enum MessageType
MESSAGE_TYPE_BIND_EVENTS_REPLY = 8,
MESSAGE_TYPE_EVENT = 9,
MESSAGE_TYPE_QUIT = 12,
MESSAGE_TYPE_SIZE_HINTS = 13
MESSAGE_TYPE_SIZE_HINTS = 13,
MESSAGE_TYPE_DATA = 14
};

#define MESSAGE_HEADER_URI_LENGTH 64
Expand Down
2 changes: 2 additions & 0 deletions deflect/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ void Server::incomingConnection( const qintptr socketHandle )
this, &Server::registerToEvents );
connect( worker, &ServerWorker::receivedSizeHints,
this, &Server::receivedSizeHints );
connect( worker, &ServerWorker::receivedData,
this, &Server::receivedData );
connect( this, &Server::_pixelStreamerClosed,
worker, &ServerWorker::closeConnection );
connect( this, &Server::_eventRegistrationReply,
Expand Down
2 changes: 2 additions & 0 deletions deflect/Server.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class DEFLECT_API Server : public QTcpServer

void receivedSizeHints( QString uri, deflect::SizeHints hints );

void receivedData( QString uri, QByteArray data );

public slots:
void onPixelStreamerClosed( QString uri );
void onEventRegistrationReply( QString uri, bool success );
Expand Down
4 changes: 4 additions & 0 deletions deflect/ServerWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ void ServerWorker::_handleMessage( const MessageHeader& messageHeader,
break;
}

case MESSAGE_TYPE_DATA:
emit receivedData( _streamId, byteArray );
break;

case MESSAGE_TYPE_BIND_EVENTS:
case MESSAGE_TYPE_BIND_EVENTS_EX:
if( _registeredToEvents )
Expand Down
2 changes: 2 additions & 0 deletions deflect/ServerWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public slots:

void receivedSizeHints( QString uri, deflect::SizeHints hints );

void receivedData( QString uri, QByteArray data );

void connectionClosed();

/** @internal */
Expand Down
5 changes: 5 additions & 0 deletions deflect/Stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,9 @@ void Stream::sendSizeHints( const SizeHints& hints )
_impl->sendSizeHints( hints );
}

bool Stream::sendData( const char* data, const size_t count )
{
return _impl->send( QByteArray::fromRawData( data, count ));
}

}
10 changes: 10 additions & 0 deletions deflect/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,16 @@ class Stream
*/
DEFLECT_API void sendSizeHints( const SizeHints& hints );

/**
* Send data to the Server.
*
* @param data the pointer to the data buffer.
* @param count the number of bytes to send.
* @return true if the data could be sent, false otherwise
* @version 1.3
*/
DEFLECT_API bool sendData( const char* data, size_t count );

private:
Stream( const Stream& ) = delete;
const Stream& operator = ( const Stream& ) = delete;
Expand Down
6 changes: 6 additions & 0 deletions deflect/StreamPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,10 @@ bool StreamPrivate::sendSizeHints( const SizeHints& hints )
return socket.send( mh, message );
}

bool StreamPrivate::send( const QByteArray data )
{
const MessageHeader mh( MESSAGE_TYPE_DATA, data.size(), id );
return socket.send( mh, data );
}

}
3 changes: 3 additions & 0 deletions deflect/StreamPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ class StreamPrivate
/** @sa Stream::sendSizeHints */
bool sendSizeHints( const SizeHints& hints );

/** Send a user-defined block of data to the server. */
bool send( QByteArray data );

/** The stream identifier. */
const std::string id;

Expand Down
3 changes: 3 additions & 0 deletions doc/Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Changelog {#Changelog}

### 0.12.0 (git master)

* [119](https://github.com/BlueBrain/Deflect/pull/119):
Added deflect::Stream::sendData() to allow sending user-defined information
to the deflect::Server.
* [118](https://github.com/BlueBrain/Deflect/pull/118):
New "pan" event for multi-finger pan gestures.
* [117](https://github.com/BlueBrain/Deflect/pull/117):
Expand Down
55 changes: 55 additions & 0 deletions tests/cpp/ServerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,58 @@ BOOST_AUTO_TEST_CASE( testRegisterForEventReceivedByServer )
}
BOOST_CHECK( !"reachable" );
}

BOOST_AUTO_TEST_CASE( testDataReceivedByServer )
{
QThread serverThread;
deflect::Server* server = new deflect::Server( 0 /* OS-chosen port */ );
server->moveToThread( &serverThread );
serverThread.connect( &serverThread, &QThread::finished,
server, &deflect::Server::deleteLater );
serverThread.start();

QWaitCondition received;
QMutex mutex;

QString streamId;
std::string receivedData;
const auto sentData = std::string{ "Hello World!" };

bool receivedState = false;
server->connect( server, &deflect::Server::receivedData,
[&]( const QString id, QByteArray data )
{
streamId = id;
receivedData = QString( data ).toStdString();
mutex.lock();
receivedState = true;
received.wakeAll();
mutex.unlock();
});

{
deflect::Stream stream( testStreamId.toStdString(), "localhost",
server->serverPort( ));
BOOST_REQUIRE( stream.isConnected( ));
stream.sendData( sentData.data(), sentData.size( ));
}

for( size_t i = 0; i < 20; ++i )
{
mutex.lock();
received.wait( &mutex, 100 /*ms*/ );
if( receivedState )
{
BOOST_CHECK_EQUAL( streamId.toStdString(),
testStreamId.toStdString( ));
BOOST_CHECK_EQUAL( receivedData, sentData );

serverThread.quit();
serverThread.wait();
mutex.unlock();
return;
}
mutex.unlock();
}
BOOST_CHECK( !"reachable" );
}