Skip to content

Commit

Permalink
Fix ALMemory subscription code
Browse files Browse the repository at this point in the history
  • Loading branch information
victorpaleologue committed Apr 30, 2024
1 parent d480501 commit 2906079
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ set(
TOOLS_SRC
src/tools/robot_description.cpp
src/tools/from_any_value.cpp
src/tools/subscribe_almemory.cpp
)

set(
Expand Down
22 changes: 11 additions & 11 deletions src/tools/subscribe_almemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace naoqi
* This implementation works for NAOqi 2.8 and higher only, using a recent
* libqi.
*/
class QiALMemorySubscriber : ALMemorySubscriber
class QiALMemorySubscriber : public ALMemorySubscriber
{
public:
QiALMemorySubscriber(qi::AnyObject subscriber, qi::SignalLink link_id)
Expand All @@ -22,16 +22,16 @@ class QiALMemorySubscriber : ALMemorySubscriber
int link_id = _link_id.swap(0);
if (link_id == 0)
{
return;
return qi::Future<void>(nullptr);
}

_subscriber->disconnect(link_id).value();
return _subscriber.disconnect(link_id);
}

private:
qi::AnyObject _subscriber;
qi::Atomic<qi::SignalLink> _link_id;
}
};

/**
* Subscribes to an ALMemory event by registering a service with a callback.
Expand All @@ -40,7 +40,7 @@ class QiALMemorySubscriber : ALMemorySubscriber
* This implementation is the only one compatible when connecting to NAOqi 2.5
* from a recent libqi.
*/
class LegacyALMemorySubscriber : ALMemorySubscriber
class LegacyALMemorySubscriber : public ALMemorySubscriber
{
public:
LegacyALMemorySubscriber(qi::SessionPtr session, int service_id)
Expand All @@ -53,16 +53,16 @@ class LegacyALMemorySubscriber : ALMemorySubscriber
int service_id = _service_id.swap(0);
if (service_id == 0)
{
return;
return qi::Future<void>(nullptr);
}

_session->unregisterService(service_id).value();
return _session->unregisterService(service_id);
}

private:
qi::SessionPtr _session;
qi::Atomic<int> _service_id;
}
};

/**
* A service dedicated to receive ALMemory events and forward them to an
Expand All @@ -77,7 +77,7 @@ class ALMemorySubscriberService
}

void onEvent(const std::string& /*key*/, const qi::AnyValue& value,
const AL::ALValue& /* message */)
const qi::AnyValue& /* message */)
{
_callback(value);
}
Expand All @@ -96,7 +96,7 @@ subscribe(const robot::NaoqiVersion& naoqi_version, qi::SessionPtr session,
const std::string& key, std::function<void(qi::AnyValue)> callback)
{
auto memory = session->service("ALMemory").value();
if (helpers::driver::isNaoqiVersionLesser(naoqi_version_, 2, 8))
if (helpers::driver::isNaoqiVersionLesser(naoqi_version, 2, 8))
{
// Create one service per subscription.
auto subscriber_service =
Expand All @@ -116,7 +116,7 @@ subscribe(const robot::NaoqiVersion& naoqi_version, qi::SessionPtr session,
}
else
{
auto qi_subscriber = memory->subscribe(key).value();
auto qi_subscriber = memory.call<qi::AnyObject>("subscribe", key);
auto signal_link =
qi_subscriber.connect("signal", std::move(callback)).value();
return std::make_unique<QiALMemorySubscriber>(std::move(qi_subscriber),
Expand Down

0 comments on commit 2906079

Please sign in to comment.