Commit d7653648 authored by Dominik Charousset's avatar Dominik Charousset

Fix setup for Qt and Protobuf examples

parent 52110a9b
......@@ -4,9 +4,7 @@ RUN yum update -y \
&& yum install -y centos-release-scl \
&& yum install -y epel-release \
&& yum update -y \
&& yum clean all
RUN yum install -y \
&& yum install -y \
cmake3 \
devtoolset-7 \
devtoolset-7-libasan-devel \
......
FROM centos:8
RUN yum install -y \
RUN dnf update -y \
&& dnf install -y \
cmake \
gcc-c++ \
git \
libasan \
libubsan \
git \
make \
openssl-devel \
&& yum clean all
&& dnf clean all
FROM debian:10
RUN apt update -y && \
apt upgrade -y
RUN apt install -y \
RUN apt update -y \
&& apt upgrade -y \
&& apt install -y \
cmake \
g++ \
git \
......
FROM debian:9
RUN apt update -y && \
apt upgrade -y
RUN apt install -y \
RUN apt update -y \
&& apt upgrade -y \
&& apt install -y \
clang-7 \
libc++-7-dev \
libc++abi-7-dev \
cmake \
git \
libc++-7-dev \
libc++abi-7-dev \
libprotobuf-dev \
libssl-dev \
make \
&& apt autoclean
......
FROM fedora:31
RUN dnf update -y && \
dnf clean all
RUN dnf install -y \
git \
make \
RUN dnf update -y \
&& dnf clean all \
&& dnf install -y \
cmake \
gcc-c++ \
openssl-devel \
git \
libasan \
libubsan \
make \
openssl-devel \
&& dnf clean all
FROM fedora:32
RUN dnf update -y && \
dnf clean all
RUN dnf install -y \
git \
make \
RUN dnf update -y \
&& dnf clean all \
&& dnf install -y \
cmake \
gcc-c++ \
openssl-devel \
git \
libasan \
libubsan \
libcurl-devel \
qt5-devel \
protobuf-devel \
make \
openssl-devel \
&& dnf clean all
FROM ubuntu:16.04
RUN \
apt update -y \
RUN apt update -y \
&& apt upgrade -y \
&& apt install -y \
clang-8 \
libc++-8-dev \
libc++abi-8-dev \
cmake \
git \
libc++-8-dev \
libc++abi-8-dev \
libssl-dev \
make \
&& apt autoclean
......
FROM ubuntu:18.04
RUN apt update -y && \
apt upgrade -y
RUN apt install -y \
RUN apt update -y \
&& apt upgrade -y \
&& apt install -y \
cmake \
g++-8 \
git \
......
FROM ubuntu:20.04
ENV TZ=Europe/Berlin
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apt update -y && \
apt upgrade -y
RUN apt install -y \
RUN apt update -y \
&& apt upgrade -y \
&& DEBIAN_FRONTEND="noninteractive" apt install -y \
cmake \
g++ \
git \
......
......@@ -59,4 +59,7 @@ SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
UseTab: Never
---
Language: Proto
DisableFormat: true
...
......@@ -17,8 +17,9 @@ config = [
],
// Default CMake flags by build type.
buildFlags: [
'CAF_ENABLE_RUNTIME_CHECKS:BOOL=ON',
'CAF_ENABLE_ACTOR_PROFILER:BOOL=ON',
'CAF_ENABLE_EXAMPLES:BOOL=ON',
'CAF_ENABLE_RUNTIME_CHECKS:BOOL=ON',
],
extraDebugFlags: [
'CAF_LOG_LEVEL:STRING=TRACE',
......@@ -107,25 +108,16 @@ config = [
'LDFLAGS=-fno-sanitize-recover=undefined',
],
]],
// One extra debug build with all examples.
['fedora-32', [
numCores: 4,
tags: ['docker'],
builds: ['debug'],
extraBuildFlags: [
'CAF_ENABLE_EXAMPLES:BOOL=ON',
'CAF_ENABLE_QT5_EXAMPLES:BOOL=ON',
'CAF_ENABLE_CURL_EXAMPLES:BOOL=ON',
'CAF_ENABLE_PROTOBUF_EXAMPLES:BOOL=ON',
],
]],
// Other UNIX systems.
// Other UNIX systems. On macOS, we also build *all* examples.
['macOS', [
numCores: 4,
builds: ['debug', 'release'],
extraBuildFlags: [
'CAF_ENABLE_CURL_EXAMPLES:BOOL=ON',
'CAF_ENABLE_PROTOBUF_EXAMPLES:BOOL=ON',
'CAF_ENABLE_QT5_EXAMPLES:BOOL=ON',
'OPENSSL_ROOT_DIR:PATH=/usr/local/opt/openssl',
'OPENSSL_INCLUDE_DIR:PATH=/usr/local/opt/openssl/include',
'Qt5_DIR:PATH=/usr/local/opt/qt/lib/cmake/Qt5',
],
extraDebugBuildFlags: [
'CAF_SANITIZERS:STRING=address',
......@@ -145,7 +137,7 @@ config = [
//builds: ['debug', 'release'],
builds: ['release'],
extraBuildFlags: [
'CAF_ENABLE_OPENSSL_MODULE:BOOL=OFF'
'CAF_ENABLE_OPENSSL_MODULE:BOOL=OFF',
],
]],
],
......
......@@ -70,7 +70,6 @@ Influential Environment Variables (only on first invocation):
CXX C++ compiler command
CXXFLAGS Additional C++ compiler flags
LDFLAGS Additional linker flags
CMAKE_GENERATOR Selects a custom generator
"
# Appends a CMake cache entry definition to the CMakeCacheEntries variable.
......
......@@ -82,28 +82,31 @@ if(TARGET CAF::io)
if(CAF_ENABLE_QT5_EXAMPLES)
find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED)
message(STATUS "Found Qt5")
#include(${QT_USE_FILE})
QT5_ADD_RESOURCES(GROUP_CHAT_RCS )
QT5_WRAP_UI(GROUP_CHAT_UI_HDR qtsupport/chatwindow.ui)
QT5_WRAP_CPP(GROUP_CHAT_MOC_SRC qtsupport/chatwidget.hpp)
qt5_wrap_ui(GROUP_CHAT_UI_HDR qtsupport/chatwindow.ui)
qt5_wrap_cpp(GROUP_CHAT_MOC_SRC qtsupport/chatwidget.hpp)
# generated headers will be in cmake build directory
include_directories(qtsupport
${CMAKE_CURRENT_BINARY_DIR}
${Qt5Core_INCLUDE_DIRS}
${Qt5Gui_INCLUDE_DIRS}
${Qt5Widgets_INCLUDE_DIRS})
set(GROUP_CHAT_SRC qtsupport/qt_group_chat.cpp qtsupport/chatwidget.cpp)
add_executable(qt_group_chat
${GROUP_CHAT_SRC}
qtsupport/qt_group_chat.cpp
qtsupport/chatwidget.cpp
${GROUP_CHAT_MOC_SRC}
${GROUP_CHAT_UI_HDR})
target_link_libraries(qt_group_chat
CAF::io
CAF::internal
Qt5::Core
Qt5::Gui
Qt5::Widgets
CAF::io
CAF::internal)
Qt5::Widgets)
target_include_directories(qt_group_chat PRIVATE
qtsupport
${CMAKE_CURRENT_BINARY_DIR}
${Qt5Core_INCLUDE_DIRS}
${Qt5Gui_INCLUDE_DIRS}
${Qt5Widgets_INCLUDE_DIRS})
if (CMAKE_VERSION VERSION_LESS 3.8)
message(STATUS "Note: build fails if Qt5 sets incompatible -std=ARG flag")
else()
set_property(TARGET qt_group_chat PROPERTY CXX_STANDARD 17)
endif()
add_dependencies(qt_group_chat all_examples)
endif()
......
#include <vector>
#include <string>
#include <iostream>
#include <limits>
#include <memory>
#include <iostream>
#include <string>
#include <vector>
#include "caf/all.hpp"
#include "caf/io/all.hpp"
#ifdef CAF_WINDOWS
#include <winsock2.h>
# include <winsock2.h>
#else
#include <arpa/inet.h>
# include <arpa/inet.h>
#endif
CAF_PUSH_WARNINGS
......@@ -25,15 +25,13 @@ CAF_END_TYPE_ID_BLOCK(protobuf_example)
namespace {
using namespace std;
using namespace caf;
using namespace caf::io;
// utility function to print an exit message with custom name
void print_on_exit(scheduled_actor* self, const std::string& name) {
self->attach_functor([=](const error& reason) {
aout(self) << name << " exited: " << to_string(reason) << endl;
aout(self) << name << " exited: " << to_string(reason) << std::endl;
});
}
......@@ -43,14 +41,16 @@ struct ping_state {
behavior ping(stateful_actor<ping_state>* self, size_t num_pings) {
print_on_exit(self, "ping");
return {[=](kickoff_atom, const actor& pong) {
return {
[=](kickoff_atom, const actor& pong) {
self->send(pong, ping_atom_v, 1);
self->become([=](pong_atom, int value) -> message {
self->become([=](pong_atom, int value) -> result<ping_atom, int> {
if (++(self->state.count) >= num_pings)
self->quit();
return make_message(ping_atom_v, value + 1);
return {ping_atom_v, value + 1};
});
}};
},
};
}
behavior pong(event_based_actor* self) {
......@@ -62,44 +62,43 @@ behavior pong(event_based_actor* self) {
void protobuf_io(broker* self, connection_handle hdl, const actor& buddy) {
print_on_exit(self, "protobuf_io");
aout(self) << "protobuf broker started" << endl;
aout(self) << "protobuf broker started" << std::endl;
self->monitor(buddy);
self->set_down_handler(
[=](const down_msg& dm) {
self->set_down_handler([=](const down_msg& dm) {
if (dm.source == buddy) {
aout(self) << "our buddy is down" << endl;
aout(self) << "our buddy is down" << std::endl;
self->quit(dm.reason);
}
});
auto write = [=](const org::libcppa::PingOrPong& p) {
string buf = p.SerializeAsString();
auto write = [=](const org::caf::PingOrPong& p) {
std::string buf = p.SerializeAsString();
auto s = htonl(static_cast<uint32_t>(buf.size()));
self->write(hdl, sizeof(uint32_t), &s);
self->write(hdl, buf.size(), buf.data());
self->flush(hdl);
};
message_handler default_bhvr = {
auto default_callbacks = message_handler{
[=](const connection_closed_msg&) {
aout(self) << "connection closed" << endl;
aout(self) << "connection closed" << std::endl;
self->send_exit(buddy, exit_reason::remote_link_unreachable);
self->quit(exit_reason::remote_link_unreachable);
},
[=](ping_atom, int i) {
aout(self) << "'ping' " << i << endl;
org::libcppa::PingOrPong p;
aout(self) << "'ping' " << i << std::endl;
org::caf::PingOrPong p;
p.mutable_ping()->set_id(i);
write(p);
},
[=](pong_atom, int i) {
aout(self) << "'pong' " << i << endl;
org::libcppa::PingOrPong p;
aout(self) << "'pong' " << i << std::endl;
org::caf::PingOrPong p;
p.mutable_pong()->set_id(i);
write(p);
}
},
};
auto await_protobuf_data = message_handler {
[=](const new_data_msg& msg) {
org::libcppa::PingOrPong p;
org::caf::PingOrPong p;
p.ParseFromArray(msg.buf.data(), static_cast<int>(msg.buf.size()));
if (p.has_ping()) {
self->send(buddy, ping_atom_v, p.ping().id());
......@@ -109,20 +108,20 @@ void protobuf_io(broker* self, connection_handle hdl, const actor& buddy) {
}
else {
self->quit(exit_reason::user_shutdown);
cerr << "neither Ping nor Pong!" << endl;
std::cerr << "neither Ping nor Pong!" << std::endl;
}
// receive next length prefix
self->configure_read(hdl, receive_policy::exactly(sizeof(uint32_t)));
self->unbecome();
}
}.or_else(default_bhvr);
},
}.or_else(default_callbacks);
auto await_length_prefix = message_handler {
[=](const new_data_msg& msg) {
uint32_t num_bytes;
memcpy(&num_bytes, msg.buf.data(), sizeof(uint32_t));
num_bytes = htonl(num_bytes);
if (num_bytes > (1024 * 1024)) {
aout(self) << "someone is trying something nasty" << endl;
aout(self) << "someone is trying something nasty" << std::endl;
self->quit(exit_reason::user_shutdown);
return;
}
......@@ -130,8 +129,8 @@ void protobuf_io(broker* self, connection_handle hdl, const actor& buddy) {
auto nb = static_cast<size_t>(num_bytes);
self->configure_read(hdl, receive_policy::exactly(nb));
self->become(keep_behavior, await_protobuf_data);
}
}.or_else(default_bhvr);
},
}.or_else(default_callbacks);
// initial setup
self->configure_read(hdl, receive_policy::exactly(sizeof(uint32_t)));
self->become(await_length_prefix);
......@@ -139,14 +138,14 @@ void protobuf_io(broker* self, connection_handle hdl, const actor& buddy) {
behavior server(broker* self, const actor& buddy) {
print_on_exit(self, "server");
aout(self) << "server is running" << endl;
aout(self) << "server is running" << std::endl;
return {
[=](const new_connection_msg& msg) {
aout(self) << "server accepted new connection" << endl;
aout(self) << "server accepted new connection" << std::endl;
auto io_actor = self->fork(protobuf_io, msg.handle, buddy);
// only accept 1 connection in our example
self->quit();
}
},
};
}
......@@ -165,23 +164,23 @@ public:
};
void run_server(actor_system& system, const config& cfg) {
cout << "run in server mode" << endl;
std::cout << "run in server mode" << std::endl;
auto pong_actor = system.spawn(pong);
auto server_actor = system.middleman().spawn_server(server, cfg.port,
pong_actor);
if (!server_actor)
cerr << "unable to spawn server: " << to_string(server_actor.error())
<< endl;
std::cerr << "unable to spawn server: " << to_string(server_actor.error())
<< std::endl;
}
void run_client(actor_system& system, const config& cfg) {
cout << "run in client mode" << endl;
std::cout << "run in client mode" << std::endl;
auto ping_actor = system.spawn(ping, 20u);
auto io_actor = system.middleman().spawn_client(protobuf_io, cfg.host,
cfg.port, ping_actor);
if (!io_actor) {
cout << "cannot connect to " << cfg.host << " at port " << cfg.port << ": "
<< to_string(io_actor.error()) << endl;
std::cout << "cannot connect to " << cfg.host << " at port " << cfg.port
<< ": " << to_string(io_actor.error()) << std::endl;
return;
}
send_as(*io_actor, ping_actor, kickoff_atom_v, *io_actor);
......
......@@ -75,7 +75,10 @@ void ChatWidget::sendChatMessage() {
// Ignore empty lines.
} else if (line.startsWith('/')) {
vector<string> words;
split(words, line.midRef(1).toUtf8().constData(), is_any_of(" "));
auto utf8 = line.midRef(1).toUtf8();
auto sv = caf::string_view{utf8.constData(),
static_cast<size_t>(utf8.size())};
split(words, sv, is_any_of(" "));
if (words.size() == 3 && words[0] == "join") {
if (auto x = system().groups().get(words[1], words[2]))
send_as(as_actor(), as_actor(), join_atom_v, std::move(*x));
......
package org.libcppa;
syntax = "proto2";
package org.caf;
message Ping {
required int32 id = 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment