Skip to content
Prev Previous commit
Next Next commit
Formatted with clang
  • Loading branch information
wsobel committed Sep 2, 2026
commit 3e5ef40e172ead27f3146286823292d378fda2da
153 changes: 77 additions & 76 deletions src/mtconnect/agent.cpp

Large diffs are not rendered by default.

152 changes: 76 additions & 76 deletions src/mtconnect/agent.hpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/mtconnect/asset/asset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace mtconnect {
Requirement("timestamp", ValueType::TIMESTAMP, false), Requirement("hash", false),
Requirement("Configuration", ValueType::ENTITY, Configuration::getFactory(), false),
Requirement("removed", ValueType::BOOL, false)}),
[](const std::string &name, Properties &props) -> EntityPtr {
[](const std::string& name, Properties& props) -> EntityPtr {
return make_shared<Asset>(name, props);
});

Expand All @@ -51,7 +51,7 @@ namespace mtconnect {
return asset;
}

void Asset::registerAssetType(const std::string &type, FactoryPtr factory)
void Asset::registerAssetType(const std::string& type, FactoryPtr factory)
{
auto root = getRoot();
root->registerFactory(type, factory);
Expand Down
28 changes: 14 additions & 14 deletions src/mtconnect/asset/asset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace mtconnect {
/// @brief Abstract Asset constructor
/// @param name asset name, sometimes referred to as the asset type
/// @param props asset properties
Asset(const std::string &name, const entity::Properties &props)
Asset(const std::string& name, const entity::Properties& props)
: entity::Entity(name, props), m_removed(false)
{
auto removed = maybeGet<bool>("removed");
Expand All @@ -55,7 +55,7 @@ namespace mtconnect {

/// @brief an assets identity is its `assetId` property
/// @return the `assetId`
const entity::Value &getIdentity() const override { return getProperty("assetId"); }
const entity::Value& getIdentity() const override { return getProperty("assetId"); }

/// @brief get the static asset factory
/// @return shared pointer to the factory
Expand All @@ -69,7 +69,7 @@ namespace mtconnect {
/// Special handling of `removed`. If `true` sets the asset state to removed.
/// @param key property `key`
/// @param v property value
void setProperty(const std::string &key, const entity::Value &v) override
void setProperty(const std::string& key, const entity::Value& v) override
{
entity::Value r = v;
if (key == "removed")
Expand All @@ -84,31 +84,31 @@ namespace mtconnect {
}
/// @brief Set a property
/// @param property the property
void setProperty(const entity::Property &property) { Entity::setProperty(property); }
void setProperty(const entity::Property& property) { Entity::setProperty(property); }

/// @brief Cover method for `getName()`
const auto &getType() const { return getName(); }
const auto& getType() const { return getName(); }

/// @brief gets the asset id
///
/// Every asset must have an asset id.
/// @return the assets identity
/// @throws PropertyError if there is no assetId
const std::string &getAssetId() const
const std::string& getAssetId() const
{
if (m_assetId.empty())
{
const auto &v = getProperty("assetId");
const auto& v = getProperty("assetId");
if (std::holds_alternative<std::string>(v))
*const_cast<std::string *>(&m_assetId) = std::get<std::string>(v);
*const_cast<std::string*>(&m_assetId) = std::get<std::string>(v);
else
throw entity::PropertyError("Asset has no assetId");
}
return m_assetId;
}
/// @brief Set the asset id
/// @param id the id
void setAssetId(const std::string &id)
void setAssetId(const std::string& id)
{
m_assetId = id;
setProperty("assetId", id);
Expand All @@ -120,7 +120,7 @@ namespace mtconnect {
/// @return optional device uuid
const std::optional<std::string> getDeviceUuid() const
{
const auto &v = getProperty("deviceUuid");
const auto& v = getProperty("deviceUuid");
if (std::holds_alternative<std::string>(v))
return std::get<std::string>(v);
else
Expand All @@ -130,7 +130,7 @@ namespace mtconnect {
/// @return optional timestamp if available
const std::optional<Timestamp> getTimestamp() const
{
const auto &v = getProperty("timestamp");
const auto& v = getProperty("timestamp");
if (std::holds_alternative<Timestamp>(v))
return std::get<Timestamp>(v);
else
Expand All @@ -146,12 +146,12 @@ namespace mtconnect {
/// @brief register the factory for an asset type
/// @param t the type or name of the asset
/// @param factory the factory to create assets
static void registerAssetType(const std::string &t, entity::FactoryPtr factory);
static void registerAssetType(const std::string& t, entity::FactoryPtr factory);

/// @brief compares two asset ids
/// @param another other asset
/// @return `true` if they have the same asset id
bool operator==(const Asset &another) const { return getAssetId() == another.getAssetId(); }
bool operator==(const Asset& another) const { return getAssetId() == another.getAssetId(); }

protected:
/// @brief The virtual method that covers `hash(boost::uuids::detail::sha1&,
Expand All @@ -160,7 +160,7 @@ namespace mtconnect {
/// Override to skip the `hash`, `timestamp`, and `removed` properties.
///
/// @param[in,out] sha1 The boost sha1 accumulator
void hash(::boost::uuids::detail::sha1 &sha1) const override
void hash(::boost::uuids::detail::sha1& sha1) const override
{
static const ::boost::unordered_set<std::string> skip {"hash", "timestamp", "removed"};
entity::Entity::hash(sha1, skip);
Expand Down
72 changes: 36 additions & 36 deletions src/mtconnect/asset/asset_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,25 @@ namespace mtconnect::asset {
/// @brief Structure to store asset for boost multi index container
struct AssetNode
{
AssetNode(AssetPtr &asset) : m_asset(asset), m_identity(asset->getAssetId()) {}
AssetNode(AssetPtr& asset) : m_asset(asset), m_identity(asset->getAssetId()) {}
~AssetNode() = default;

using element_type = AssetPtr;

const std::string &getAssetId() const { return m_identity; }
const std::string &getType() const { return m_asset->getType(); }
const std::string &getDeviceUuid() const
const std::string& getAssetId() const { return m_identity; }
const std::string& getType() const { return m_asset->getType(); }
const std::string& getDeviceUuid() const
{
static const std::string unknown {"UNKNOWN"};
const auto &dev = m_asset->getProperty("deviceUuid");
const auto& dev = m_asset->getProperty("deviceUuid");
if (std::holds_alternative<std::string>(dev))
return std::get<std::string>(dev);
else
return unknown;
}
bool isRemoved() const { return m_asset->isRemoved(); }

bool operator<(const AssetNode &o) const { return m_identity < o.m_identity; }
bool operator<(const AssetNode& o) const { return m_identity < o.m_identity; }

AssetPtr operator*() const { return m_asset; }

Expand Down Expand Up @@ -144,7 +144,7 @@ namespace mtconnect::asset {
if (!added.second)
{
old = added.first->m_asset;
m_index.modify(added.first, [&asset](AssetNode &n) { n.m_asset = asset; });
m_index.modify(added.first, [&asset](AssetNode& n) { n.m_asset = asset; });
m_index.relocate(m_index.begin(), added.first);
if (asset->isRemoved() && !old->isRemoved())
adjustCount(asset, 1);
Expand All @@ -165,13 +165,13 @@ namespace mtconnect::asset {
return old;
}

AssetPtr removeAsset(const std::string &id,
const std::optional<Timestamp> &time = std::nullopt) override
AssetPtr removeAsset(const std::string& id,
const std::optional<Timestamp>& time = std::nullopt) override
{
AssetPtr asset {};
std::lock_guard<std::recursive_mutex> lock(m_bufferLock);

auto &idx = m_index.get<ByAssetId>();
auto& idx = m_index.get<ByAssetId>();
auto it = idx.find(id);
if (it != idx.end())
{
Expand All @@ -188,18 +188,18 @@ namespace mtconnect::asset {
return asset;
}

AssetPtr getAsset(const std::string &id) const override
AssetPtr getAsset(const std::string& id) const override
{
std::lock_guard<std::recursive_mutex> lock(m_bufferLock);
const auto &idx = m_index.get<ByAssetId>();
const auto& idx = m_index.get<ByAssetId>();
auto it = idx.find(id);
if (it != idx.end())
return it->m_asset;
else
return nullptr;
}

virtual size_t getAssets(AssetList &list, size_t max, const bool active = true,
virtual size_t getAssets(AssetList& list, size_t max, const bool active = true,
const std::optional<std::string> device = std::nullopt,
const std::optional<std::string> type = std::nullopt) const override
{
Expand All @@ -219,11 +219,11 @@ namespace mtconnect::asset {
}
else
{
auto &idx = m_index.get<ByFifo>();
auto& idx = m_index.get<ByFifo>();
range = std::make_pair(idx.begin(), idx.end());
}

for (auto &a : range)
for (auto& a : range)
{
if (!active || !a.isRemoved())
list.push_back(a.m_asset);
Expand All @@ -234,7 +234,7 @@ namespace mtconnect::asset {
return list.size();
}

virtual size_t getAssets(AssetList &list, const std::list<std::string> &ids) const override
virtual size_t getAssets(AssetList& list, const std::list<std::string>& ids) const override
{
for (auto id : ids)
{
Expand All @@ -245,7 +245,7 @@ namespace mtconnect::asset {
return list.size();
}

size_t getCountForDeviceAndType(const std::string &device, const std::string &type,
size_t getCountForDeviceAndType(const std::string& device, const std::string& type,
bool active = true) const override
{
using namespace boost::adaptors;
Expand All @@ -257,7 +257,7 @@ namespace mtconnect::asset {
activePredicate(active));
}

size_t getCountForType(const std::string &type, bool active = true) const override
size_t getCountForType(const std::string& type, bool active = true) const override
{
using namespace boost::adaptors;

Expand All @@ -266,7 +266,7 @@ namespace mtconnect::asset {
return boost::count_if(m_index.get<ByType>().equal_range(type), activePredicate(active));
}

size_t getCountForDevice(const std::string &device, bool active = true) const override
size_t getCountForDevice(const std::string& device, bool active = true) const override
{
std::lock_guard<std::recursive_mutex> lock(m_bufferLock);

Expand All @@ -278,12 +278,12 @@ namespace mtconnect::asset {
{
std::lock_guard<std::recursive_mutex> lock(m_bufferLock);
TypeCount res;
auto &idx = m_index.get<ByType>();
auto& idx = m_index.get<ByType>();
auto it = idx.begin();
while (it != idx.end())
{
int delta = 0;
auto &type = it->getType();
auto& type = it->getType();
auto rng = idx.equal_range(type);
if (active)
{
Expand All @@ -299,20 +299,20 @@ namespace mtconnect::asset {
return res;
}

TypeCount getCountsByTypeForDevice(const std::string &device, bool active = true) const override
TypeCount getCountsByTypeForDevice(const std::string& device, bool active = true) const override
{
std::lock_guard<std::recursive_mutex> lock(m_bufferLock);
TypeCount res;
auto &idx = m_index.get<ByDeviceAndType>();
auto& idx = m_index.get<ByDeviceAndType>();
auto removes = m_deviceRemoveCount.find(device);
const auto *ridx {removes == m_deviceRemoveCount.end() ? nullptr : &removes->second};
const auto* ridx {removes == m_deviceRemoveCount.end() ? nullptr : &removes->second};

auto range = idx.equal_range(std::make_tuple(device));
auto it = range.first;
while (it != range.second)
{
int delta = 0;
auto &type = it->getType();
auto& type = it->getType();
auto rng = idx.equal_range(std::make_tuple(device, type));
if (ridx != nullptr && active)
{
Expand All @@ -328,25 +328,25 @@ namespace mtconnect::asset {
return res;
}

size_t removeAll(AssetList &list, const std::optional<std::string> device = std::nullopt,
size_t removeAll(AssetList& list, const std::optional<std::string> device = std::nullopt,
const std::optional<std::string> type = std::nullopt,
const std::optional<Timestamp> &time = std::nullopt) override
const std::optional<Timestamp>& time = std::nullopt) override
{
std::lock_guard<std::recursive_mutex> lock(m_bufferLock);
getAssets(list, std::numeric_limits<size_t>().max(), false, device, type);
for (auto &a : list)
for (auto& a : list)
removeAsset(a->getAssetId(), time);

return list.size();
}

int32_t getIndex(const std::string &id) const
int32_t getIndex(const std::string& id) const
{
auto &idx = m_index.get<ByAssetId>();
auto& idx = m_index.get<ByAssetId>();
auto it = idx.find(id);
if (it != idx.end())
{
auto &fifo = m_index.get<ByFifo>();
auto& fifo = m_index.get<ByFifo>();
auto pos = mic::project<ByFifo>(m_index, it);
return int32_t(std::distance(fifo.begin(), pos));
}
Expand All @@ -357,8 +357,8 @@ namespace mtconnect::asset {
protected:
void adjustCount(AssetPtr asset, int delta)
{
const auto &type = asset->getType();
const auto &dev = asset->getDeviceUuid();
const auto& type = asset->getType();
const auto& dev = asset->getDeviceUuid();
bool found = false;

if (dev)
Expand Down Expand Up @@ -392,12 +392,12 @@ namespace mtconnect::asset {
}
}

std::function<bool(const AssetNode &)> activePredicate(bool active) const
std::function<bool(const AssetNode&)> activePredicate(bool active) const
{
if (active)
return [](const AssetNode &a) -> bool { return !a.isRemoved(); };
return [](const AssetNode& a) -> bool { return !a.isRemoved(); };
else
return [](const AssetNode &a) -> bool { return true; };
return [](const AssetNode& a) -> bool { return true; };
}

protected:
Expand Down
Loading
Loading