Skip to content

Commit

Permalink
tmp commit
Browse files Browse the repository at this point in the history
  • Loading branch information
wgtdkp committed Apr 11, 2024
1 parent 7c936cb commit 48d59a5
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 10 deletions.
6 changes: 6 additions & 0 deletions src/app/ps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ target_link_libraries(persistent-storage
commissioner-common
commissioner
commissioner-app
fmt::fmt
)

install(TARGETS persistent-storage
Expand All @@ -67,6 +68,11 @@ if (OT_COMM_TEST)
registry_test.cpp
)

target_link_libraries(commissioner-ps-test
PRIVATE
fmt::fmt
)

target_include_directories(commissioner-ps-test
PRIVATE
${PROJECT_SOURCE_DIR}/include
Expand Down
37 changes: 35 additions & 2 deletions src/app/ps/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
* The file implements JSON-based Thread networks/domains registry.
*/

#include "registry.hpp"
#include "persistent_storage_json.hpp"
#include "app/ps/registry.hpp"

#include "app/ps/persistent_storage_json.hpp"
#include "common/error_macros.hpp"
#include "common/utils.hpp"

Expand Down Expand Up @@ -786,3 +787,35 @@ Registry::Status Registry::Update(const Network &nwk)
} // namespace persistent_storage
} // namespace commissioner
} // namespace ot

auto fmt::formatter<ot::commissioner::persistent_storage::Registry::Status>::format(ot::commissioner::persistent_storage::Registry::Status status,
format_context &ctx) -> decltype(ctx.out())
{
using Status = ot::commissioner::persistent_storage::Registry::Status;

string_view name;
switch (status)
{
case Status::kSuccess:
name = "kSuccess";
break;
case Status::kNotFound:
name = "kNotFound";
break;
case Status::kDataInvalid:
name = "kDataInvalid";
break;
case Status::kAmbiguity:
name = "kAmbiguity";
break;
case Status::kError:
name = "kError";
break;
case Status::kRestricted:
name = "kRestricted";
break;
default:
name = fmt::format(FMT_STRING("unknown({})"), static_cast<int>(status));
}
return formatter<string_view>::format(name, ctx);
}
15 changes: 11 additions & 4 deletions src/app/ps/registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@
#ifndef _REGISTRY_HPP_
#define _REGISTRY_HPP_

#include "persistent_storage.hpp"
#include "registry_entries.hpp"
#include "app/border_agent.hpp"

#include <vector>

#include "app/border_agent.hpp"
#include "app/ps/persistent_storage.hpp"
#include "app/ps/registry_entries.hpp"
#include "fmt/format.h"

namespace ot {
namespace commissioner {
namespace persistent_storage {
Expand Down Expand Up @@ -336,4 +337,10 @@ Registry *CreateRegistry(const std::string &aFile);
} // namespace commissioner
} // namespace ot

/** Makes `Registry::Status` formattable as a string. */
template <> struct fmt::formatter<ot::commissioner::persistent_storage::Registry::Status> : formatter<string_view>
{
auto format(ot::commissioner::persistent_storage::Registry::Status status, format_context &ctx) -> decltype(ctx.out());
};

#endif // _REGISTRY_HPP_
56 changes: 55 additions & 1 deletion src/library/coap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

#include <ctype.h>
#include <memory.h>
#include <type_traits>

#include "common/error_macros.hpp"
#include "common/logging.hpp"
Expand Down Expand Up @@ -1343,7 +1344,60 @@ auto fmt::formatter<ot::commissioner::coap::OptionType>::format(ot::commissioner
name = "kSize1";
break;
default:
name = "unknown";
name = fmt::format(FMT_STRING("unknown({})"), static_cast<int>(optionType));
}
return formatter<string_view>::format(name, ctx);
}

auto fmt::formatter<ot::commissioner::coap::Code>::format(ot::commissioner::coap::Code code,
format_context &ctx) -> decltype(ctx.out())
{
using ot::commissioner::coap::Code;

string_view name;

switch (code) {
case Code::kEmpty:
name = "kEmpty(000)";
break;
case Code::kGet:
name = "kGet(001)";
break;
case Code::kPost: name = "kPost(002)"; break;
case Code::kPut: name = "kPut(003)"; break;
case Code::kDelete: name = "kDelete(004)"; break;
case Code::kResponseMin: name = "kResponseMin(200)"; break;
case Code::kCreated: name = "kCreated(201)"; break;
case Code::kDeleted: name = "kDeleted(202)"; break;

kDeleted = OT_COAP_CODE(2, 2),
kValid = OT_COAP_CODE(2, 3),
kChanged = OT_COAP_CODE(2, 4),
kContent = OT_COAP_CODE(2, 5),

/*
* Client side errors (4.XX).
*/
kBadRequest = OT_COAP_CODE(4, 0),
kUnauthorized = OT_COAP_CODE(4, 1),
kBadOption = OT_COAP_CODE(4, 2),
kForBidden = OT_COAP_CODE(4, 3),
kNotFound = OT_COAP_CODE(4, 4),
kMethodNotAllowed = OT_COAP_CODE(4, 5),
kNotAcceptable = OT_COAP_CODE(4, 6),
kPreconditionFailed = OT_COAP_CODE(4, 12),
kRequestTooLarge = OT_COAP_CODE(4, 13),
kUnsupportedFormat = OT_COAP_CODE(4, 15),

/*
* Server side errors (5.XX).
*/
kInternalError = OT_COAP_CODE(5, 0),
kNotImplemented = OT_COAP_CODE(5, 1),
kBadGateway = OT_COAP_CODE(5, 2),
kServiceUnavailable = OT_COAP_CODE(5, 3),
kGatewayTimeout = OT_COAP_CODE(5, 4),
kProxyNotSupported = OT_COAP_CODE(5, 5),
}

}
8 changes: 7 additions & 1 deletion src/library/coap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,10 +783,16 @@ class Coap

} // namespace ot

/** Makes `OptionType` formattable as a string. */
/** Makes `coap::OptionType` formattable as a string. */
template <> struct fmt::formatter<ot::commissioner::coap::OptionType> : formatter<string_view>
{
auto format(ot::commissioner::coap::OptionType optionType, format_context &ctx) -> decltype(ctx.out());
};

/** Makes `coap::Code` formattable as a string. */
template <> struct fmt::formatter<ot::commissioner::coap::Code> : formatter<string_view>
{
auto format(ot::commissioner::coap::Code code, format_context &ctx) -> decltype(ctx.out());
};

#endif // OT_COMM_LIBRARY_COAP_HPP_
2 changes: 1 addition & 1 deletion src/library/cose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ Error MakeCoseKey(ByteArray &aEncodedCoseKey, const mbedtls_pk_context &aKey, co
ec2Curve = kKeyEC2CurveP521;
break;
default:
ExitNow(error = ERROR_INVALID_ARGS("make COSE key with invalid EC2 curve group ID {}", eckey->grp.id));
ExitNow(error = ERROR_INVALID_ARGS("make COSE key with invalid EC2 curve group ID {}", static_cast<int>(eckey->grp.id)));
}
SuccessOrExit(error = coseKey.Put(kKeyEC2Curve, ec2Curve));

Expand Down
2 changes: 1 addition & 1 deletion third_party/fmtlib/repo
Submodule repo updated 143 files

0 comments on commit 48d59a5

Please sign in to comment.