Skip to content

Commit

Permalink
Fix Android build failure no member named 'StatusName' in namespace '…
Browse files Browse the repository at this point in the history
…chip::Protocols::InteractionModel' (#24610)
  • Loading branch information
vivien-apple authored and pull[bot] committed Oct 10, 2023
1 parent ae00dbd commit 1178784
Show file tree
Hide file tree
Showing 12 changed files with 213 additions and 144 deletions.
2 changes: 2 additions & 0 deletions examples/chip-tool/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ static_library("chip-tool-utils") {
"commands/common/Commands.h",
"commands/common/CredentialIssuerCommands.h",
"commands/common/HexConversion.h",
"commands/common/RemoteDataModelLogger.cpp",
"commands/common/RemoteDataModelLogger.h",
"commands/delay/SleepCommand.cpp",
"commands/delay/WaitForCommissioneeCommand.cpp",
"commands/discover/DiscoverCommand.cpp",
Expand Down
6 changes: 3 additions & 3 deletions examples/chip-tool/commands/clusters/ClusterCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub
CHIP_ERROR error = status.ToChipError();
if (CHIP_NO_ERROR != error)
{
ReturnOnFailure(DataModelLogger::LogErrorAsJSON(path, status));
ReturnOnFailure(RemoteDataModelLogger::LogErrorAsJSON(path, status));

ChipLogError(chipTool, "Response Failure: %s", chip::ErrorStr(error));
mError = error;
Expand All @@ -83,7 +83,7 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub

if (data != nullptr)
{
ReturnOnFailure(DataModelLogger::LogCommandAsJSON(path, data));
ReturnOnFailure(RemoteDataModelLogger::LogCommandAsJSON(path, data));

error = DataModelLogger::LogCommand(path, data);
if (CHIP_NO_ERROR != error)
Expand All @@ -97,7 +97,7 @@ class ClusterCommand : public InteractionModelCommands, public ModelCommand, pub

virtual void OnError(const chip::app::CommandSender * client, CHIP_ERROR error) override
{
ReturnOnFailure(DataModelLogger::LogErrorAsJSON(error));
ReturnOnFailure(RemoteDataModelLogger::LogErrorAsJSON(error));

ChipLogProgress(chipTool, "Error: %s", chip::ErrorStr(error));
mError = error;
Expand Down
130 changes: 1 addition & 129 deletions examples/chip-tool/commands/clusters/DataModelLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,8 @@
#include <app/EventHeader.h>
#include <app/MessageDef/StatusIB.h>
#include <app/data-model/DecodableList.h>
#include <commands/common/RemoteDataModelLogger.h>
#include <lib/support/BytesToHex.h>
#include <lib/support/jsontlv/TlvJson.h>

constexpr const char * kClusterIdKey = "clusterId";
constexpr const char * kEndpointIdKey = "endpointId";
constexpr const char * kAttributeIdKey = "attributeId";
constexpr const char * kEventIdKey = "eventId";
constexpr const char * kCommandIdKey = "commandId";
constexpr const char * kErrorIdKey = "error";
constexpr const char * kClusterErrorIdKey = "clusterError";

class DataModelLoggerJSONDelegate
{
public:
CHIP_ERROR virtual LogJSON(const char *) = 0;
virtual ~DataModelLoggerJSONDelegate(){};
};

class DataModelLogger
{
Expand All @@ -51,119 +36,7 @@ class DataModelLogger
static CHIP_ERROR LogCommand(const chip::app::ConcreteCommandPath & path, chip::TLV::TLVReader * data);
static CHIP_ERROR LogEvent(const chip::app::EventHeader & header, chip::TLV::TLVReader * data);

static CHIP_ERROR LogAttributeAsJSON(const chip::app::ConcreteDataAttributePath & path, chip::TLV::TLVReader * data)
{
VerifyOrReturnError(mJSONDelegate != nullptr, CHIP_NO_ERROR);

Json::Value value;
value[kClusterIdKey] = path.mClusterId;
value[kEndpointIdKey] = path.mEndpointId;
value[kAttributeIdKey] = path.mAttributeId;

chip::TLV::TLVReader reader;
reader.Init(*data);
ReturnErrorOnFailure(chip::TlvToJson(reader, value));

auto valueStr = chip::JsonToString(value);
return mJSONDelegate->LogJSON(valueStr.c_str());
}

static CHIP_ERROR LogErrorAsJSON(const chip::app::ConcreteDataAttributePath & path, const chip::app::StatusIB & status)
{
VerifyOrReturnError(mJSONDelegate != nullptr, CHIP_NO_ERROR);

Json::Value value;
value[kClusterIdKey] = path.mClusterId;
value[kEndpointIdKey] = path.mEndpointId;
value[kAttributeIdKey] = path.mAttributeId;

return LogError(value, status);
}

static CHIP_ERROR LogCommandAsJSON(const chip::app::ConcreteCommandPath & path, chip::TLV::TLVReader * data)
{
VerifyOrReturnError(mJSONDelegate != nullptr, CHIP_NO_ERROR);

Json::Value value;
value[kClusterIdKey] = path.mClusterId;
value[kEndpointIdKey] = path.mEndpointId;
value[kCommandIdKey] = path.mCommandId;

chip::TLV::TLVReader reader;
reader.Init(*data);
ReturnErrorOnFailure(chip::TlvToJson(reader, value));

auto valueStr = chip::JsonToString(value);
return mJSONDelegate->LogJSON(valueStr.c_str());
}

static CHIP_ERROR LogErrorAsJSON(const chip::app::ConcreteCommandPath & path, const chip::app::StatusIB & status)
{
VerifyOrReturnError(mJSONDelegate != nullptr, CHIP_NO_ERROR);

Json::Value value;
value[kClusterIdKey] = path.mClusterId;
value[kEndpointIdKey] = path.mEndpointId;
value[kCommandIdKey] = path.mCommandId;

return LogError(value, status);
}

static CHIP_ERROR LogEventAsJSON(const chip::app::EventHeader & header, chip::TLV::TLVReader * data)
{
VerifyOrReturnError(mJSONDelegate != nullptr, CHIP_NO_ERROR);

Json::Value value;
value[kClusterIdKey] = header.mPath.mClusterId;
value[kEndpointIdKey] = header.mPath.mEndpointId;
value[kEventIdKey] = header.mPath.mEventId;

chip::TLV::TLVReader reader;
reader.Init(*data);
ReturnErrorOnFailure(chip::TlvToJson(reader, value));

auto valueStr = chip::JsonToString(value);
return mJSONDelegate->LogJSON(valueStr.c_str());
}

static CHIP_ERROR LogErrorAsJSON(const chip::app::EventHeader & header, const chip::app::StatusIB & status)
{
VerifyOrReturnError(mJSONDelegate != nullptr, CHIP_NO_ERROR);

Json::Value value;
value[kClusterIdKey] = header.mPath.mClusterId;
value[kEndpointIdKey] = header.mPath.mEndpointId;
value[kEventIdKey] = header.mPath.mEventId;

return LogError(value, status);
}

static CHIP_ERROR LogErrorAsJSON(const CHIP_ERROR & error)
{
Json::Value value;
chip::app::StatusIB status;
status.InitFromChipError(error);
return LogError(value, status);
}

static void SetJSONDelegate(DataModelLoggerJSONDelegate * delegate) { mJSONDelegate = delegate; }

private:
static CHIP_ERROR LogError(Json::Value & value, const chip::app::StatusIB & status)
{
if (status.mClusterStatus.HasValue())
{
auto statusValue = status.mClusterStatus.Value();
value[kClusterErrorIdKey] = statusValue;
}

auto statusName = chip::Protocols::InteractionModel::StatusName(status.mStatus);
value[kErrorIdKey] = statusName;

auto valueStr = chip::JsonToString(value);
return mJSONDelegate->LogJSON(valueStr.c_str());
}

static CHIP_ERROR LogValue(const char * label, size_t indent, bool value)
{
DataModelLogger::LogString(label, indent, value ? "TRUE" : "FALSE");
Expand Down Expand Up @@ -323,5 +196,4 @@ class DataModelLogger
}

static size_t ComputePrefixSize(const std::string label, size_t indent) { return ComputePrefix(label, indent).size(); }
static DataModelLoggerJSONDelegate * mJSONDelegate;
};
6 changes: 3 additions & 3 deletions examples/chip-tool/commands/clusters/ReportCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class ReportCommand : public InteractionModelReports, public ModelCommand, publi
CHIP_ERROR error = status.ToChipError();
if (CHIP_NO_ERROR != error)
{
ReturnOnFailure(DataModelLogger::LogErrorAsJSON(path, status));
ReturnOnFailure(RemoteDataModelLogger::LogErrorAsJSON(path, status));

ChipLogError(chipTool, "Response Failure: %s", chip::ErrorStr(error));
mError = error;
Expand All @@ -51,7 +51,7 @@ class ReportCommand : public InteractionModelReports, public ModelCommand, publi
return;
}

ReturnOnFailure(DataModelLogger::LogAttributeAsJSON(path, data));
ReturnOnFailure(RemoteDataModelLogger::LogAttributeAsJSON(path, data));

error = DataModelLogger::LogAttribute(path, data);
if (CHIP_NO_ERROR != error)
Expand All @@ -70,7 +70,7 @@ class ReportCommand : public InteractionModelReports, public ModelCommand, publi
CHIP_ERROR error = status->ToChipError();
if (CHIP_NO_ERROR != error)
{
ReturnOnFailure(DataModelLogger::LogErrorAsJSON(eventHeader, *status));
ReturnOnFailure(RemoteDataModelLogger::LogErrorAsJSON(eventHeader, *status));

ChipLogError(chipTool, "Response Failure: %s", chip::ErrorStr(error));
mError = error;
Expand Down
4 changes: 2 additions & 2 deletions examples/chip-tool/commands/clusters/WriteAttributeCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class WriteAttribute : public InteractionModelWriter, public ModelCommand, publi
CHIP_ERROR error = status.ToChipError();
if (CHIP_NO_ERROR != error)
{
ReturnOnFailure(DataModelLogger::LogErrorAsJSON(path, status));
ReturnOnFailure(RemoteDataModelLogger::LogErrorAsJSON(path, status));

ChipLogError(chipTool, "Response Failure: %s", chip::ErrorStr(error));
mError = error;
Expand All @@ -118,7 +118,7 @@ class WriteAttribute : public InteractionModelWriter, public ModelCommand, publi

void OnError(const chip::app::WriteClient * client, CHIP_ERROR error) override
{
ReturnOnFailure(DataModelLogger::LogErrorAsJSON(error));
ReturnOnFailure(RemoteDataModelLogger::LogErrorAsJSON(error));

ChipLogProgress(chipTool, "Error: %s", chip::ErrorStr(error));
mError = error;
Expand Down
155 changes: 155 additions & 0 deletions examples/chip-tool/commands/common/RemoteDataModelLogger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

#include "RemoteDataModelLogger.h"

#include <lib/support/jsontlv/TlvJson.h>

constexpr const char * kClusterIdKey = "clusterId";
constexpr const char * kEndpointIdKey = "endpointId";
constexpr const char * kAttributeIdKey = "attributeId";
constexpr const char * kEventIdKey = "eventId";
constexpr const char * kCommandIdKey = "commandId";
constexpr const char * kErrorIdKey = "error";
constexpr const char * kClusterErrorIdKey = "clusterError";

namespace {
RemoteDataModelLoggerDelegate * gDelegate;

CHIP_ERROR LogError(Json::Value & value, const chip::app::StatusIB & status)
{
if (status.mClusterStatus.HasValue())
{
auto statusValue = status.mClusterStatus.Value();
value[kClusterErrorIdKey] = statusValue;
}

#if CHIP_CONFIG_IM_STATUS_CODE_VERBOSE_FORMAT
auto statusName = chip::Protocols::InteractionModel::StatusName(status.mStatus);
value[kErrorIdKey] = statusName;
#else
auto statusName = status.mStatus;
value[kErrorIdKey] = chip::to_underlying(statusName);
#endif // CHIP_CONFIG_IM_STATUS_CODE_VERBOSE_FORMAT

auto valueStr = chip::JsonToString(value);
return gDelegate->LogJSON(valueStr.c_str());
}
} // namespace

namespace RemoteDataModelLogger {
CHIP_ERROR LogAttributeAsJSON(const chip::app::ConcreteDataAttributePath & path, chip::TLV::TLVReader * data)
{
VerifyOrReturnError(gDelegate != nullptr, CHIP_NO_ERROR);

Json::Value value;
value[kClusterIdKey] = path.mClusterId;
value[kEndpointIdKey] = path.mEndpointId;
value[kAttributeIdKey] = path.mAttributeId;

chip::TLV::TLVReader reader;
reader.Init(*data);
ReturnErrorOnFailure(chip::TlvToJson(reader, value));

auto valueStr = chip::JsonToString(value);
return gDelegate->LogJSON(valueStr.c_str());
}

CHIP_ERROR LogErrorAsJSON(const chip::app::ConcreteDataAttributePath & path, const chip::app::StatusIB & status)
{
VerifyOrReturnError(gDelegate != nullptr, CHIP_NO_ERROR);

Json::Value value;
value[kClusterIdKey] = path.mClusterId;
value[kEndpointIdKey] = path.mEndpointId;
value[kAttributeIdKey] = path.mAttributeId;

return LogError(value, status);
}

CHIP_ERROR LogCommandAsJSON(const chip::app::ConcreteCommandPath & path, chip::TLV::TLVReader * data)
{
VerifyOrReturnError(gDelegate != nullptr, CHIP_NO_ERROR);

Json::Value value;
value[kClusterIdKey] = path.mClusterId;
value[kEndpointIdKey] = path.mEndpointId;
value[kCommandIdKey] = path.mCommandId;

chip::TLV::TLVReader reader;
reader.Init(*data);
ReturnErrorOnFailure(chip::TlvToJson(reader, value));

auto valueStr = chip::JsonToString(value);
return gDelegate->LogJSON(valueStr.c_str());
}

CHIP_ERROR LogErrorAsJSON(const chip::app::ConcreteCommandPath & path, const chip::app::StatusIB & status)
{
VerifyOrReturnError(gDelegate != nullptr, CHIP_NO_ERROR);

Json::Value value;
value[kClusterIdKey] = path.mClusterId;
value[kEndpointIdKey] = path.mEndpointId;
value[kCommandIdKey] = path.mCommandId;

return LogError(value, status);
}

CHIP_ERROR LogEventAsJSON(const chip::app::EventHeader & header, chip::TLV::TLVReader * data)
{
VerifyOrReturnError(gDelegate != nullptr, CHIP_NO_ERROR);

Json::Value value;
value[kClusterIdKey] = header.mPath.mClusterId;
value[kEndpointIdKey] = header.mPath.mEndpointId;
value[kEventIdKey] = header.mPath.mEventId;

chip::TLV::TLVReader reader;
reader.Init(*data);
ReturnErrorOnFailure(chip::TlvToJson(reader, value));

auto valueStr = chip::JsonToString(value);
return gDelegate->LogJSON(valueStr.c_str());
}

CHIP_ERROR LogErrorAsJSON(const chip::app::EventHeader & header, const chip::app::StatusIB & status)
{
VerifyOrReturnError(gDelegate != nullptr, CHIP_NO_ERROR);

Json::Value value;
value[kClusterIdKey] = header.mPath.mClusterId;
value[kEndpointIdKey] = header.mPath.mEndpointId;
value[kEventIdKey] = header.mPath.mEventId;

return LogError(value, status);
}

CHIP_ERROR LogErrorAsJSON(const CHIP_ERROR & error)
{
Json::Value value;
chip::app::StatusIB status;
status.InitFromChipError(error);
return LogError(value, status);
}

void SetDelegate(RemoteDataModelLoggerDelegate * delegate)
{
gDelegate = delegate;
}
}; // namespace RemoteDataModelLogger
Loading

0 comments on commit 1178784

Please sign in to comment.