Skip to content

Commit

Permalink
Merge branch 'develop' into simrangestartstop
Browse files Browse the repository at this point in the history
  • Loading branch information
abeltrano authored Mar 1, 2023
2 parents fb8b867 + 406f0f2 commit b83f23e
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 51 deletions.
21 changes: 16 additions & 5 deletions lib/uwb/UwbDevice.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
#include <type_traits>
#include <variant>

#include <magic_enum.hpp>
#include <plog/Log.h>
#include <ranges>
#include <uwb/UwbDevice.hxx>

#include <magic_enum.hpp>

using namespace uwb;
using namespace uwb::protocol::fira;

Expand Down Expand Up @@ -84,9 +84,20 @@ UwbDevice::OnSessionMulticastListStatus(UwbSessionUpdateMulicastListStatus statu
return;
}

for (const auto& peerAddStatus : statusMulticastList.Status) {
if (peerAddStatus.Status == UwbStatusMulticast::OkUpdate) {
session->InsertPeer(peerAddStatus.ControleeMacAddress);
auto peersAdded = std::views::filter(statusMulticastList.Status, [](const auto& peerAddStatus) -> bool {
return peerAddStatus.Status == UwbStatusMulticast::OkUpdate;
});

PLOG_VERBOSE << "Session with id " << statusMulticastList.SessionId << " adding peers";
session->InsertPeers(peersAdded);

// Now log the bad status
IF_PLOG(plog::verbose)
{
for (const auto& peer : statusMulticastList.Status) {
if (peer.Status != UwbStatusMulticast::OkUpdate) {
PLOG_VERBOSE << "peer has bad status: " << peer.ToString();
}
}
}
}
Expand Down
14 changes: 4 additions & 10 deletions lib/uwb/UwbSession.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,8 @@ void
UwbSession::AddPeer(UwbMacAddress peerMacAddress)
{
std::scoped_lock peersLock{ m_peerGate };
PLOG_VERBOSE << "adding peer with address " << peerMacAddress.ToString();
auto [_, inserted] = m_peers.insert(peerMacAddress);

if (inserted) {
AddPeerImpl(std::move(peerMacAddress));
}
PLOG_VERBOSE << "peer added";
PLOG_VERBOSE << "Session with id " << m_sessionId << " requesting to add peer via DDI with mac address " << peerMacAddress.ToString();
AddPeerImpl(std::move(peerMacAddress));
}

void
Expand Down Expand Up @@ -79,9 +74,8 @@ UwbSession::SetSessionStatus(const uwb::protocol::fira::UwbSessionStatus& status
}

void
UwbSession::InsertPeer(const uwb::UwbMacAddress& peerAddress)
UwbSession::InsertPeerImpl(const uwb::UwbMacAddress& peerAddress)
{
std::scoped_lock peersLock{ m_peerGate };
m_peers.insert(peerAddress);
PLOG_VERBOSE << "Added peer " << peerAddress.ToString();
PLOG_VERBOSE << "Session with id " << m_sessionId << " added peer via DDI with mac address " << peerAddress.ToString();
}
2 changes: 1 addition & 1 deletion lib/uwb/include/uwb/UwbDevice.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <shared_mutex>
#include <unordered_map>

#include <uwb/UwbSessionEventCallbacks.hxx>
#include <uwb/UwbSession.hxx>
#include <uwb/protocols/fira/FiraDevice.hxx>
#include <uwb/protocols/fira/UwbCapability.hxx>

Expand Down
65 changes: 33 additions & 32 deletions lib/uwb/include/uwb/UwbSession.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,16 @@
#include <cstdint>
#include <memory>
#include <mutex>
#include <ranges>
#include <unordered_set>

#include <uwb/UwbMacAddress.hxx>
#include <uwb/UwbPeer.hxx>
#include <uwb/UwbSessionEventCallbacks.hxx>
#include <uwb/protocols/fira/UwbSessionData.hxx>

namespace uwb
{
struct UwbSessionEventCallbacks;

/**
* @brief The possible reasons for a session ending.
*/
enum class UwbSessionEndReason {
/**
* @brief The session owner stopped the session.
*
* This is the reason used when the session ends naturally.
*/
Stopped,

/**
* @brief The session was locally canceled.
*/
Canceled,

/**
* @brief The session timed out due to policy.
*/
Timeout,

/**
* @brief The session ended for an unknown or unspecified reason.
*/
Unspecified,
};

/**
* @brief Represents a UWB session.
*/
Expand Down Expand Up @@ -118,14 +92,41 @@ public:
SetSessionStatus(const uwb::protocol::fira::UwbSessionStatus& status);

/**
* @brief Temporarily public function to directly add a peer to m_peers
* @brief Temporarily public function to directly add a list of peers to m_peers
*
* @param peerAddress
* @param peers
*/
template <class View>
// clang-format off
requires std::ranges::view<View> &&
std::same_as<std::decay_t<std::ranges::range_reference_t<View>>, uwb::protocol::fira::UwbMulticastListStatus>
// clang-format on
void
InsertPeer(const uwb::UwbMacAddress& peerAddress);
InsertPeers(View peers)
{
std::vector<UwbPeer> uwbPeers;
{
std::scoped_lock peersLock{ m_peerGate };
for (const auto& peer : peers) {
InsertPeerImpl(peer.ControleeMacAddress);
uwbPeers.push_back(UwbPeer{ peer.ControleeMacAddress });
}
}
auto callbacks = m_callbacks.lock();
if (callbacks) {
callbacks->OnSessionMembershipChanged(this, uwbPeers, {});
}
}

private:
/**
* @brief Internal function to insert a peer address to this session
*
* @param peerAddress
*/
void
InsertPeerImpl(const uwb::UwbMacAddress& peerAddress);

virtual void
ConfigureImpl(const protocol::fira::UwbSessionData& uwbSessionData) = 0;

Expand Down
30 changes: 29 additions & 1 deletion lib/uwb/include/uwb/UwbSessionEventCallbacks.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,38 @@
#include <vector>

#include <uwb/UwbPeer.hxx>
#include <uwb/UwbSession.hxx>

namespace uwb
{
struct UwbSession;

/**
* @brief The possible reasons for a session ending.
*/
enum class UwbSessionEndReason {
/**
* @brief The session owner stopped the session.
*
* This is the reason used when the session ends naturally.
*/
Stopped,

/**
* @brief The session was locally canceled.
*/
Canceled,

/**
* @brief The session timed out due to policy.
*/
Timeout,

/**
* @brief The session ended for an unknown or unspecified reason.
*/
Unspecified,
};

/**
* @brief Interface for receiving events from a UwbSession. This is the primary
* method to receive information from near peers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#ifndef NEAR_OBJECT_CLI_UWB_SESSION_EVENT_CALLBACKS_HXX
#define NEAR_OBJECT_CLI_UWB_SESSION_EVENT_CALLBACKS_HXX

#include <uwb/UwbSessionEventCallbacks.hxx>
#include <uwb/UwbSession.hxx>

namespace nearobject::cli
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <wil/resource.h>

#include <uwb/UwbDevice.hxx>
#include <uwb/UwbSessionEventCallbacks.hxx>
#include <uwb/UwbSession.hxx>
#include <uwb/protocols/fira/FiraDevice.hxx>
#include <windows/devices/DeviceResource.hxx>

Expand Down

0 comments on commit b83f23e

Please sign in to comment.