Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace boost with C++11 [DISCL-391] #130

Merged
merged 1 commit into from
Sep 28, 2016
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
13 changes: 6 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project(Deflect VERSION 0.12.0)
set(Deflect_VERSION_ABI 4)
set(Deflect_VERSION_ABI 5)

list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMake
${CMAKE_SOURCE_DIR}/CMake/common)
Expand All @@ -14,18 +14,15 @@ include(GitExternal)
set(DEFLECT_DESCRIPTION "A fast C++ library for streaming pixels and events")
set(DEFLECT_MAINTAINER "Blue Brain Project <[email protected]>")
set(DEFLECT_LICENSE BSD)
set(DEFLECT_DEPENDENT_LIBRARIES Boost)
set(DEFLECT_DEB_DEPENDS freeglut3-dev libxi-dev libxmu-dev
libjpeg-turbo8-dev libturbojpeg
libboost-date-time-dev libboost-program-options-dev libboost-system-dev
libboost-test-dev libboost-thread-dev
libboost-program-options-dev libboost-test-dev
qtbase5-dev qtdeclarative5-dev)
set(DEFLECT_PORT_DEPENDS boost freeglut qt5)

include(Common)

common_find_package(Boost REQUIRED COMPONENTS date_time program_options system
thread unit_test_framework)
common_find_package(Boost COMPONENTS program_options unit_test_framework)
common_find_package(GLUT)
common_find_package(LibJpegTurbo REQUIRED)
common_find_package(OpenGL)
Expand All @@ -44,7 +41,9 @@ common_find_package_post()

add_subdirectory(deflect)
add_subdirectory(apps)
add_subdirectory(tests)
if(Boost_FOUND)
add_subdirectory(tests)
endif()
add_subdirectory(doc)

set(COMMON_PROJECT_DOMAIN ch.epfl.bluebrain)
Expand Down
2 changes: 2 additions & 0 deletions apps/DesktopStreamer/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@
#include <QScreen>

#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>

#ifdef _WIN32
typedef __int32 int32_t;
Expand Down
3 changes: 2 additions & 1 deletion apps/SimpleStreamer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@

#include <deflect/Stream.h>

#include <string>
#include <cmath>
#include <iostream>
#include <string>

#ifdef __APPLE__
# include <OpenGL/gl.h>
Expand Down
6 changes: 1 addition & 5 deletions deflect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ set(DEFLECT_SOURCES
StreamSendWorker.cpp
)

set(DEFLECT_LINK_LIBRARIES
PUBLIC ${Boost_THREAD_LIBRARY} ${Boost_SYSTEM_LIBRARY}
PRIVATE Qt5::Concurrent Qt5::Core Qt5::Network
)
set(DEFLECT_PUBLIC_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIR})
set(DEFLECT_LINK_LIBRARIES PRIVATE Qt5::Concurrent Qt5::Core Qt5::Network)

if(DEFLECT_USE_LIBJPEGTURBO)
list(APPEND DEFLECT_PUBLIC_HEADERS
Expand Down
10 changes: 4 additions & 6 deletions deflect/FrameDispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
#include "Frame.h"
#include "ReceiveBuffer.h"

#include <cassert>

namespace deflect
{

Expand Down Expand Up @@ -74,13 +76,9 @@ class FrameDispatcher::Impl

FrameDispatcher::FrameDispatcher()
: _impl( new Impl )
{
}
{}

FrameDispatcher::~FrameDispatcher()
{
delete _impl;
}
FrameDispatcher::~FrameDispatcher() {}

void FrameDispatcher::addSource( const QString uri, const size_t sourceIndex )
{
Expand Down
2 changes: 1 addition & 1 deletion deflect/FrameDispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public slots:

private:
class Impl;
Impl* _impl;
std::unique_ptr<Impl> _impl;
};

}
Expand Down
2 changes: 1 addition & 1 deletion deflect/ImageSegmenter.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*********************************************************************/
/* Copyright (c) 2013-2015, EPFL/Blue Brain Project */
/* Copyright (c) 2013-2016, EPFL/Blue Brain Project */
/* Raphael Dumusc <[email protected]> */
/* [email protected] */
/* All rights reserved. */
Expand Down
6 changes: 3 additions & 3 deletions deflect/ImageSegmenter.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*********************************************************************/
/* Copyright (c) 2013-2015, EPFL/Blue Brain Project */
/* Copyright (c) 2013-2016, EPFL/Blue Brain Project */
/* Raphael Dumusc <[email protected]> */
/* [email protected] */
/* All rights reserved. */
Expand Down Expand Up @@ -47,7 +47,7 @@
#include <deflect/MTQueue.h>
#include <deflect/Segment.h>

#include <boost/function/function1.hpp>
#include <functional>
#include <vector>

namespace deflect
Expand All @@ -63,7 +63,7 @@ class ImageSegmenter
DEFLECT_API ImageSegmenter();

/** Function called on each segment. */
typedef boost::function< bool( const Segment& ) > Handler;
using Handler = std::function< bool( const Segment& ) >;

/**
* Generate segments.
Expand Down
12 changes: 6 additions & 6 deletions deflect/ReceiveBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@

#include "ReceiveBuffer.h"

#include <cassert>

namespace deflect
{

Expand Down Expand Up @@ -91,10 +93,9 @@ bool ReceiveBuffer::hasCompleteFrame() const
assert( !_sourceBuffers.empty( ));

// Check if all sources for Stream have reached the same index
for( SourceBufferMap::const_iterator it = _sourceBuffers.begin();
it != _sourceBuffers.end(); ++it )
for( const auto& kv : _sourceBuffers )
{
const SourceBuffer& buffer = it->second;
const auto& buffer = kv.second;
if( buffer.backFrameIndex <= _lastFrameComplete )
return false;
}
Expand All @@ -104,10 +105,9 @@ bool ReceiveBuffer::hasCompleteFrame() const
Segments ReceiveBuffer::popFrame()
{
Segments frame;
for( SourceBufferMap::iterator it = _sourceBuffers.begin();
it != _sourceBuffers.end(); ++it )
for( auto& kv : _sourceBuffers )
{
SourceBuffer& buffer = it->second;
auto& buffer = kv.second;
frame.insert( frame.end(), buffer.segments.front().begin(),
buffer.segments.front().end( ));
buffer.pop();
Expand Down
8 changes: 2 additions & 6 deletions deflect/SegmentDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,9 @@ class SegmentDecoder::Impl

SegmentDecoder::SegmentDecoder()
: _impl( new Impl )
{
}
{}

SegmentDecoder::~SegmentDecoder()
{
delete _impl;
}
SegmentDecoder::~SegmentDecoder() {}

void decodeSegment( ImageJpegDecompressor* decompressor, Segment* segment )
{
Expand Down
6 changes: 2 additions & 4 deletions deflect/SegmentDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,13 @@
#include <deflect/api.h>
#include <deflect/types.h>

#include <boost/noncopyable.hpp>

namespace deflect
{

/**
* Decode a Segment's image asynchronously.
*/
class SegmentDecoder : public boost::noncopyable
class SegmentDecoder
{
public:
/** Construct a Decoder */
Expand Down Expand Up @@ -89,7 +87,7 @@ class SegmentDecoder : public boost::noncopyable

private:
class Impl;
Impl* _impl;
std::unique_ptr<Impl> _impl;
};

}
Expand Down
4 changes: 1 addition & 3 deletions deflect/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@

#ifdef DEFLECT_USE_SERVUS
# include <servus/servus.h>
# include <boost/lexical_cast.hpp>
#endif

#include <QThread>
Expand Down Expand Up @@ -77,8 +76,7 @@ Server::Server( const int port )
{
if( !listen( QHostAddress::Any, port ))
{
const QString err =
QString( "could not listen on port: %1" ).arg( port );
const auto err = QString( "could not listen on port: %1" ).arg( port );
throw std::runtime_error( err.toStdString( ));
}
#ifdef DEFLECT_USE_SERVUS
Expand Down
24 changes: 8 additions & 16 deletions deflect/Stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,33 +49,20 @@

#include <QDataStream>

#include <cassert>
#include <iostream>

namespace deflect
{

Stream::Stream()
: _impl( new StreamPrivate( "", "", Socket::defaultPortNumber ))
{
if( isConnected( ))
{
_impl->socket.connect( &_impl->socket, &Socket::disconnected,
[this]() { disconnected(); });
_impl->sendOpen();
}
}
{}

Stream::Stream( const std::string& id, const std::string& host,
const unsigned short port )
: _impl( new StreamPrivate( id, host, port ))
{
if( isConnected( ))
{
_impl->socket.connect( &_impl->socket, &Socket::disconnected,
[this]() { disconnected(); });
_impl->sendOpen();
}
}
{}

Stream::~Stream()
{
Expand Down Expand Up @@ -200,6 +187,11 @@ void Stream::sendSizeHints( const SizeHints& hints )
_impl->sendSizeHints( hints );
}

void Stream::setDisconnectedCallback( const std::function<void()> callback )
{
_impl->disconnectedCallback = callback;
}

bool Stream::sendData( const char* data, const size_t count )
{
return _impl->send( QByteArray::fromRawData( data, count ));
Expand Down
26 changes: 12 additions & 14 deletions deflect/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,11 @@
#include <deflect/Event.h>
#include <deflect/ImageWrapper.h>

#include <functional>
#include <future>
#include <memory>
#include <string>

#ifndef Q_MOC_RUN // See: https://bugreports.qt-project.org/browse/QTBUG-22829
// needed for future.hpp with Boost 1.41
# include <boost/thread/mutex.hpp>
# include <boost/thread/condition_variable.hpp>

# include <boost/thread/future.hpp>
# include <boost/signals2/signal.hpp>
#endif

class Application;

namespace deflect
Expand Down Expand Up @@ -126,13 +119,10 @@ class Stream
/** @return the host defined by the constructor. @version 1.3 */
DEFLECT_API const std::string& getHost() const;

/** Emitted after the stream was disconnected. @version 1.0 */
boost::signals2::signal< void() > disconnected;

/** @name Asynchronous send API */
//@{
/** Future signaling success of asyncSend(). @version 1.1 */
typedef boost::unique_future< bool > Future;
/** Future signaling success of asyncSend(). @version 1.5 */
using Future = std::future< bool >;

/**
* Send an image and finish the frame asynchronously.
Expand Down Expand Up @@ -269,6 +259,14 @@ class Stream
*/
DEFLECT_API bool sendData( const char* data, size_t count );

/**
* Set a function to be be called just after the stream gets disconnected.
* @param callback the function to call
* @note replaces the previous disconnected signal
* @version 1.5
*/
void setDisconnectedCallback( std::function<void()> callback );

private:
Stream( const Stream& ) = delete;
const Stream& operator = ( const Stream& ) = delete;
Expand Down
15 changes: 13 additions & 2 deletions deflect/StreamPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,17 @@ StreamPrivate::StreamPrivate( const std::string& id_,
, registeredForEvents( false )
{
imageSegmenter.setNominalSegmentDimensions( SEGMENT_SIZE, SEGMENT_SIZE );

if( !socket.isConnected( ))
return;

socket.connect( &socket, &Socket::disconnected, [this]()
{
if( disconnectedCallback )
disconnectedCallback();
});

sendOpen();
}

StreamPrivate::~StreamPrivate()
Expand Down Expand Up @@ -128,8 +139,8 @@ bool StreamPrivate::send( const ImageWrapper& image )
return false;
}

const ImageSegmenter::Handler sendFunc =
boost::bind( &StreamPrivate::sendPixelStreamSegment, this, _1 );
const auto sendFunc = std::bind( &StreamPrivate::sendPixelStreamSegment,
this, std::placeholders::_1 );
return imageSegmenter.generate( image, sendFunc );
}

Expand Down
3 changes: 3 additions & 0 deletions deflect/StreamPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include "Socket.h" // member
#include "Stream.h" // Stream::Future

#include <functional>
#include <string>
#include <memory>

Expand Down Expand Up @@ -123,6 +124,8 @@ class StreamPrivate
/** Has a successful event registration reply been received */
bool registeredForEvents;

std::function<void()> disconnectedCallback;

private:
std::unique_ptr< StreamSendWorker > _sendWorker;
};
Expand Down
Loading