2019-03-12 23:00:14 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2019 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
decltype(ircd::stats::items)
|
|
|
|
ircd::stats::items
|
|
|
|
{};
|
|
|
|
|
2019-05-06 04:01:29 +02:00
|
|
|
std::ostream &
|
|
|
|
ircd::stats::operator<<(std::ostream &s, const item &item)
|
|
|
|
{
|
|
|
|
s << static_cast<long long>(item.val);
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2019-03-12 23:00:14 +01:00
|
|
|
//
|
|
|
|
// item
|
|
|
|
//
|
|
|
|
|
|
|
|
decltype(ircd::stats::item::NAME_MAX_LEN)
|
|
|
|
ircd::stats::item::NAME_MAX_LEN
|
|
|
|
{
|
|
|
|
127
|
|
|
|
};
|
|
|
|
|
2019-05-06 04:01:29 +02:00
|
|
|
//
|
|
|
|
// item::item
|
|
|
|
//
|
|
|
|
|
2019-04-19 02:56:09 +02:00
|
|
|
ircd::stats::item::item(const json::members &opts)
|
2019-03-12 23:00:14 +01:00
|
|
|
:feature_
|
|
|
|
{
|
|
|
|
opts
|
|
|
|
}
|
|
|
|
,feature
|
|
|
|
{
|
|
|
|
feature_
|
|
|
|
}
|
|
|
|
,name
|
|
|
|
{
|
|
|
|
unquote(feature.at("name"))
|
|
|
|
}
|
2019-04-19 02:56:09 +02:00
|
|
|
,val
|
2019-03-12 23:00:14 +01:00
|
|
|
{
|
2019-07-11 22:11:12 +02:00
|
|
|
feature.get<long>("default", 0L)
|
2019-03-12 23:00:14 +01:00
|
|
|
}
|
|
|
|
{
|
|
|
|
if(name.size() > NAME_MAX_LEN)
|
|
|
|
throw error
|
|
|
|
{
|
|
|
|
"Stats item '%s' name length:%zu exceeds max:%zu",
|
|
|
|
name,
|
|
|
|
name.size(),
|
|
|
|
NAME_MAX_LEN
|
|
|
|
};
|
|
|
|
|
|
|
|
if(!items.emplace(name, this).second)
|
|
|
|
throw error
|
|
|
|
{
|
2019-07-11 22:11:12 +02:00
|
|
|
"Stats item named '%s' already exists", name
|
2019-03-12 23:00:14 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
ircd::stats::item::~item()
|
|
|
|
noexcept
|
|
|
|
{
|
|
|
|
if(name)
|
|
|
|
{
|
|
|
|
const auto it{items.find(name)};
|
|
|
|
assert(data(it->first) == data(name));
|
|
|
|
items.erase(it);
|
|
|
|
}
|
|
|
|
}
|