Skip to content

Commit

Permalink
windows: fix a build issue with serial_protocol on DLL
Browse files Browse the repository at this point in the history
  • Loading branch information
jcelerier committed Dec 16, 2024
1 parent 0a0b7ff commit 84b7311
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
46 changes: 29 additions & 17 deletions src/ossia-qt/serial/serial_protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,31 @@ static auto on_open = [] { };
static auto on_close = [] { };
static auto on_fail = [] { };

namespace
{
struct serial_osc_queue_callback
{
serial_protocol& self;
void operator()(const coalescing_queue::coalesced& elts)
{
thread_local std::vector<std::pair<const serial_parameter*, const ossia::value*>>
osc_messages;
osc_messages.clear();

for(auto& [p, v] : elts)
{
auto serial_param = static_cast<serial_parameter*>(p);
if(serial_param->data().osc_address.isEmpty())
self.do_write(*p, v);
else
osc_messages.emplace_back(serial_param, &v);
}

self.do_write_osc_bundle(osc_messages);
}
};
}

struct serial_wrapper_read
{
serial_wrapper& self;
Expand Down Expand Up @@ -309,23 +334,10 @@ serial_protocol::serial_protocol(
if(res.m_coalesce > 0.)
{
m_coalesce = res.m_coalesce;
m_queue.callback = [this](const coalescing_queue::coalesced& elts) {
thread_local std::vector<
std::pair<const serial_parameter*, const ossia::value*>>
osc_messages;
osc_messages.clear();

for(auto& [p, v] : elts)
{
auto serial_param = static_cast<serial_parameter*>(p);
if(serial_param->data().osc_address.isEmpty())
do_write(*p, v);
else
osc_messages.emplace_back(serial_param, &v);
}

do_write_osc_bundle(osc_messages);
};

// Separate type due to Windows error:
// error: 'osc_messages' cannot be thread local when declared 'dllexport'
m_queue.callback = serial_osc_queue_callback{*this};

ossia::qt::run_async(m_threadWorker, [this] {
m_threadWorker->startTimer(m_coalesce.value(), Qt::PreciseTimer);
Expand Down
3 changes: 2 additions & 1 deletion src/ossia-qt/serial/serial_protocol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ class OSSIA_EXPORT serial_protocol final

static serial_parameter_data read_data(const QJSValue& js) { return js; }

private:
static serial_protocol_object load_serial_object_from_qml(
serial_protocol& proto, const ossia::net::network_context_ptr& ctx,
const ossia::net::serial_configuration& cfg);
Expand All @@ -180,6 +179,8 @@ class OSSIA_EXPORT serial_protocol final
std::span<std::pair<const serial_parameter*, const ossia::value*>> vec);
void do_write_osc_impl(
const serial_parameter& addr, const ossia::value& v, std::string& str);

private:
QQmlEngine* m_engine{};
QQmlComponent* m_component{};

Expand Down

0 comments on commit 84b7311

Please sign in to comment.