GithubHelp home page GithubHelp logo

ozancansel / speech Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 360 KB

Qt-based generic serialization/deserialization mechanism and strongly-typed messaging over network.

License: GNU General Public License v3.0

CMake 1.00% Shell 0.03% C++ 98.59% C 0.38%

speech's Introduction

develop Build status

master Build status

speech

This project aims to develop a qt-based generic serialization/deserialization mechanism and strongly-typed messaging over network.

The library is composed of only headers. We aim to follow modern c++ approach.

It is under GNU General Public License.

CMake

speech library uses CMake build system and follows modern-cmake paradigm.

QMake

speech library doesn't use qmake as build system currently but it mıght be supported at future.

Dependencies and required(recommended) tools

  • Qt5
  • CMake
  • A compiler which supports C++17

Compiler Support

  • GCC ( Tested 7.4.0 )
  • MinGW ( Tested 7.3.0 )
  • VS Compiler ( Tested MSVC 2017 )
  • Clang ( Not Tested )

Compile & Install

Windows

Qt - MinGW

Run git bash shell as administrator

git clone https://github.com/OzanCansel/speech
cd speech
mkdir build
cd build
## example run => cmake -G"MinGW Makefiles" -DCMAKE_MAKE_PROGRAM=/c/Qt/Tools/mingw730_64/bin/mingw32-make.exe -DCMAKE_PREFIX_PATH=/c/Qt/5.12.2/mingw73_64/lib/cmake ..
cmake -G"MinGW Makefiles" -DCMAKE_MAKE_PROGRAM=<make_executable_path> -DCMAKE_PREFIX_PATH=<qt_cmake_definitions_path> ..
cmake --build . --target install -- -j$(nproc)

Linux

Ubuntu 18.04

sudo apt-get update
sudo apt-get install qt5-default cmake build-essential
git clone https://github.com/OzanCansel/speech
cd speech
mkdir build
cd build
cmake ..
make -j$(nproc)
sudo make install

How to include 'speech' library in CMake ?

project(speech-usage)
cmake_minimum_required(VERSION 3.1)

find_package( speech REQUIRED )

add_executable( speech-usage your_main.cpp )

target_link_libraries( speech-usage speech::speech )

tcp server

#include <QCoreApplication>
#include <QDebug>
#include <QDateTime>
#include <speech/speech.h>

struct greeting
{
    QString my_name_is;

    SPEECH_SERIALIZE( my_name_is )
};

struct roll_dice {
     int chance { rand() % 100 };
     QDateTime timestamp { QDateTime::currentDateTime() };

     SPEECH_SERIALIZE( chance , timestamp )
};

int main ( int argc, char** argv )
{
    QCoreApplication app ( argc, argv );

    using namespace speech;
    using namespace speech::tcp;

    auto port = 24942;

    tcp_server server { QHostAddress::Any , speech::port { port } };

    auto listeners =
            listen( []( const roll_dice& e , std::weak_ptr<QTcpSocket> ) {
        qDebug() << "Received : " << e;
    }) |
            listen( [] ( const greeting& g , std::weak_ptr<QTcpSocket> ){
        qDebug() << "Received : " << g;
    });

    server.listen( listeners );

    qDebug() << "Tcp Server running at" << server.port() << "port";

    return QCoreApplication::exec();
}

tcp transmit

#include <QCoreApplication>
#include <QDebug>
#include <QDateTime>
#include <speech/speech.h>

struct greeting
{
    QString my_name_is;

    SPEECH_SERIALIZE( my_name_is )
};

struct roll_dice {
     int chance { rand() % 100 };
     QDateTime timestamp { QDateTime::currentDateTime() };

     SPEECH_SERIALIZE( chance , timestamp )
};

int main(int argc, char** argv)
{
    QCoreApplication app(argc , argv);

    using namespace speech;
    using namespace speech::tcp;

    tcp_transmitter<greeting , roll_dice> tcp{ QHostAddress::LocalHost , speech::port { 24942 } };
    tcp.transmit( greeting { "from speech-lib" } );
    tcp.transmit( roll_dice {} );

    // Transmit without instance
    transmit( roll_dice {} , QHostAddress::LocalHost , speech::port { 24942 } );

    app.exec();
}

udp transmit

//a main .cpp file
#include <QCoreApplication>
#include <QDebug>
#include <QDateTime>
#include <speech/speech.h>

struct greeting
{
    QString my_name_is;

    SPEECH_SERIALIZE( my_name_is )
};

struct roll_dice {
     int chance { rand() % 100 };
     QDateTime timestamp { QDateTime::currentDateTime() };

     SPEECH_SERIALIZE( chance , timestamp )
};

int main(int argc, char** argv)
{
    QCoreApplication app(argc, argv);

    using namespace speech;
    using namespace speech::udp;

    udp_transmitter<greeting, roll_dice> udp { QHostAddress { QHostAddress::Broadcast } , speech::port { 12345 } };

    udp.transmit( greeting{ "from speech-lib" } );
    udp.transmit( roll_dice{ } );

    // Transmit without instance
    transmit( roll_dice { } , QHostAddress {  QHostAddress::Broadcast } ,  speech::port { 12345 } );

    app.exec();
}

udp receive with inheritance

#include <QCoreApplication>
#include <QDebug>
#include <QDateTime>
#include <speech/speech.h>

struct greeting
{
    QString my_name_is;

    SPEECH_SERIALIZE( my_name_is )
};

struct roll_dice {
     int chance { rand() % 100 };
     QDateTime timestamp { QDateTime::currentDateTime() };

     SPEECH_SERIALIZE( chance , timestamp )
};

struct my_receiver : speech::udp::udp_receiver<greeting , roll_dice>
{

    my_receiver() : speech::udp::udp_receiver<greeting , roll_dice>{ speech::port(12345) } { }

    protected:

        void on_receive(const greeting& greeting) override
        {
            qDebug() << "receive => " << greeting;
        }

        void on_receive(const roll_dice& dice) override
        {
            qDebug() << "receive => " << dice;
        }
};

int main(int argc, char** argv)
{
    QCoreApplication app(argc , argv);

    my_receiver receiver;

    return app.exec();
}

udp receive from queue

//a main .cpp file
#include <QCoreApplication>
#include <QDebug>
#include <QDateTime>
#include <QTimer>
#include <speech/speech.h>

struct greeting
{
    QString my_name_is;

    SPEECH_SERIALIZE( my_name_is )
};

struct roll_dice {
     int chance { rand() % 100 };
     QDateTime timestamp { QDateTime::currentDateTime() };

     SPEECH_SERIALIZE( chance , timestamp )
};

int main(int argc, char **argv)
{
    using namespace speech::udp;

    QCoreApplication app(argc, argv);

    queued_udp_receiver<greeting, roll_dice> udp { speech::port { 12345 } };

    QTimer checkMessages;

    checkMessages.setInterval( 30 );

    QObject::connect(&checkMessages, &QTimer::timeout, [&]() {
        while (!udp.messages<roll_dice>().empty())
        {
            qDebug() << "roll_dice => " << udp.messages<roll_dice>().front();
            udp.messages<roll_dice>().pop();
        }

        while (!udp.messages<greeting>().empty())
        {
            qDebug() << "greeting => " << udp.messages<greeting>().front();
            udp.messages<greeting>().pop();
        }
    });

    checkMessages.start();

    return app.exec();
}

speech's People

Contributors

ozancansel avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.