Skip to content

Commit d35380b

Browse files
moleksyvt-tv
authored andcommitted
Move parseCqDepthOption into ofi anonymous namespace
Signed-off-by: Maciej Oleksy <maciej.oleksy@intel.com>
1 parent 46e45b3 commit d35380b

1 file changed

Lines changed: 36 additions & 41 deletions

File tree

lib/fabrics/ofi/src/fabrics.cpp

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -25,53 +25,48 @@
2525
#include "mxl/flow.h"
2626
#include "mxl/platform.h"
2727

28-
namespace
28+
namespace ofi = mxl::lib::fabrics::ofi;
29+
30+
namespace mxl::lib::fabrics::ofi
2931
{
30-
/// Parse the optional target setup options JSON and return the requested completion
31-
/// queue depth, or std::nullopt (use the implementation default) when not specified.
32-
///
33-
/// Recognized form: {"cqDepth": <positive integer>}
34-
std::optional<std::size_t> parseCqDepthOption(char const* options)
32+
namespace
3533
{
36-
using mxl::lib::fabrics::ofi::Exception;
37-
38-
if ((options == nullptr) || (options[0] == '\0'))
34+
/// Parse the optional target setup options JSON and return the requested completion
35+
/// queue depth, or std::nullopt (use the implementation default) when not specified.
36+
///
37+
/// Recognized form: {"cqDepth": <positive integer>}
38+
std::optional<std::size_t> parseCqDepthOption(char const* options)
3939
{
40-
return std::nullopt;
41-
}
40+
if ((options == nullptr) || (options[0] == '\0'))
41+
{
42+
return std::nullopt;
43+
}
4244

43-
auto value = picojson::value{};
44-
auto const err = picojson::parse(value, options);
45-
if (!err.empty() || !value.is<picojson::object>())
46-
{
47-
throw Exception::invalidArgument("Invalid JSON target options: {}", err.empty() ? std::string{"expected an object"} : err);
48-
}
45+
auto value = picojson::value{};
46+
auto const err = picojson::parse(value, options);
47+
if (!err.empty() || !value.is<picojson::object>())
48+
{
49+
throw Exception::invalidArgument("Invalid JSON target options: {}", err.empty() ? std::string{"expected an object"} : err);
50+
}
4951

50-
auto const& root = value.get<picojson::object>();
51-
auto const it = root.find("cqDepth");
52-
if (it == root.end())
53-
{
54-
return std::nullopt;
55-
}
56-
if (!it->second.is<double>())
57-
{
58-
throw Exception::invalidArgument("cqDepth must be a number.");
59-
}
60-
auto const depth = it->second.get<double>();
61-
if (depth < 1.0)
62-
{
63-
throw Exception::invalidArgument("cqDepth must be greater or equal to 1.");
52+
auto const& root = value.get<picojson::object>();
53+
auto const it = root.find("cqDepth");
54+
if (it == root.end())
55+
{
56+
return std::nullopt;
57+
}
58+
if (!it->second.is<double>())
59+
{
60+
throw Exception::invalidArgument("cqDepth must be a number.");
61+
}
62+
auto const depth = it->second.get<double>();
63+
if (depth < 1.0)
64+
{
65+
throw Exception::invalidArgument("cqDepth must be greater or equal to 1.");
66+
}
67+
return static_cast<std::size_t>(depth);
6468
}
65-
return static_cast<std::size_t>(depth);
66-
}
67-
}
68-
69-
namespace ofi = mxl::lib::fabrics::ofi;
7069

71-
namespace mxl::lib::fabrics::ofi
72-
{
73-
namespace
74-
{
7570
template<typename F>
7671
mxlStatus try_run(F&& func, std::string_view errMsg)
7772
{
@@ -194,7 +189,7 @@ mxlStatus mxlFabricsTargetSetup(mxlFabricsTarget in_target, mxlFabricsTargetConf
194189
return ofi::try_run(
195190
[&]()
196191
{
197-
auto const setupOptions = ofi::TargetSetupOptions{.cqDepth = parseCqDepthOption(options)};
192+
auto const setupOptions = ofi::TargetSetupOptions{.cqDepth = ofi::parseCqDepthOption(options)};
198193

199194
// Set up the target, release the returned unique_ptr, convert to external API type, assign the the pointer location
200195
// passed by the user.

0 commit comments

Comments
 (0)