Skip to content

Commit

Permalink
[chip-tool] Add support for setting the isUrgent flag of when subscri…
Browse files Browse the repository at this point in the history
…bing to events (#19003)
  • Loading branch information
vivien-apple authored and pull[bot] committed Jul 31, 2023
1 parent 28e69d6 commit 4f4f42d
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 17 deletions.
30 changes: 18 additions & 12 deletions examples/chip-tool/commands/clusters/ReportCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,23 +350,15 @@ class SubscribeEvent : public SubscribeCommand
{
AddArgument("cluster-id", 0, UINT32_MAX, &mClusterIds);
AddArgument("event-id", 0, UINT32_MAX, &mEventIds);
AddArgument("min-interval", 0, UINT16_MAX, &mMinInterval);
AddArgument("max-interval", 0, UINT16_MAX, &mMaxInterval);
AddArgument("fabric-filtered", 0, 1, &mFabricFiltered);
AddArgument("event-min", 0, UINT64_MAX, &mEventNumber);
AddArgument("keepSubscriptions", 0, 1, &mKeepSubscriptions);
AddCommonArguments();
SubscribeCommand::AddArguments();
}

SubscribeEvent(chip::ClusterId clusterId, CredentialIssuerCommands * credsIssuerConfig) :
SubscribeCommand("subscribe-event-by-id", credsIssuerConfig), mClusterIds(1, clusterId)
{
AddArgument("event-id", 0, UINT32_MAX, &mEventIds);
AddArgument("min-interval", 0, UINT16_MAX, &mMinInterval);
AddArgument("max-interval", 0, UINT16_MAX, &mMaxInterval);
AddArgument("fabric-filtered", 0, 1, &mFabricFiltered);
AddArgument("event-min", 0, UINT64_MAX, &mEventNumber);
AddArgument("keepSubscriptions", 0, 1, &mKeepSubscriptions);
AddCommonArguments();
SubscribeCommand::AddArguments();
}

Expand All @@ -376,6 +368,12 @@ class SubscribeEvent : public SubscribeCommand
mClusterIds(1, clusterId), mEventIds(1, eventId)
{
AddArgument("event-name", eventName, "Event name.");
AddCommonArguments();
SubscribeCommand::AddArguments();
}

void AddCommonArguments()
{
AddArgument("min-interval", 0, UINT16_MAX, &mMinInterval,
"The requested minimum interval between reports. Sets MinIntervalFloor in the Subscribe Request.");
AddArgument("max-interval", 0, UINT16_MAX, &mMaxInterval,
Expand All @@ -384,15 +382,22 @@ class SubscribeEvent : public SubscribeCommand
AddArgument("event-min", 0, UINT64_MAX, &mEventNumber);
AddArgument("keepSubscriptions", 0, 1, &mKeepSubscriptions,
"false - Terminate existing subscriptions from initiator.\n true - Leave existing subscriptions in place.");
SubscribeCommand::AddArguments();
AddArgument(
"is-urgent", 0, 1, &mIsUrgents,
"Sets isUrgent in the Subscribe Request.\n"
" The queueing of any urgent event SHALL force an immediate generation of reports containing all events queued "
"leading up to (and including) the urgent event in question.\n"
" This argument takes a comma separated list of true/false values.\n"
" If the number of paths exceeds the number of entries provided to is-urgent, then isUrgent will be false for the "
"extra paths.");
}

~SubscribeEvent() {}

CHIP_ERROR SendCommand(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds) override
{
return SubscribeCommand::SubscribeEvent(device, endpointIds, mClusterIds, mEventIds, mMinInterval, mMaxInterval,
mFabricFiltered, mEventNumber, mKeepSubscriptions);
mFabricFiltered, mEventNumber, mKeepSubscriptions, mIsUrgents);
}

private:
Expand All @@ -404,4 +409,5 @@ class SubscribeEvent : public SubscribeCommand
chip::Optional<bool> mFabricFiltered;
chip::Optional<chip::EventNumber> mEventNumber;
chip::Optional<bool> mKeepSubscriptions;
chip::Optional<std::vector<bool>> mIsUrgents;
};
55 changes: 54 additions & 1 deletion examples/chip-tool/commands/common/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,39 @@ bool Command::InitArgument(size_t argIndex, char * argValue)
return CHIP_NO_ERROR == customArgument->Parse(arg.name, argValue);
}

case ArgumentType::VectorBool: {
// Currently only chip::Optional<std::vector<bool>> is supported.
if (arg.flags != Argument::kOptional)
{
return false;
}

std::vector<bool> vectorArgument;
std::stringstream ss(argValue);
while (ss.good())
{
std::string valueAsString;
getline(ss, valueAsString, ',');

if (strcasecmp(valueAsString.c_str(), "true") == 0)
{
vectorArgument.push_back(true);
}
else if (strcasecmp(valueAsString.c_str(), "false") == 0)
{
vectorArgument.push_back(false);
}
else
{
return false;
}
}

auto optionalArgument = static_cast<chip::Optional<std::vector<bool>> *>(arg.value);
optionalArgument->SetValue(vectorArgument);
return true;
}

case ArgumentType::Vector16:
case ArgumentType::Vector32: {
std::vector<uint64_t> values;
Expand Down Expand Up @@ -623,6 +656,21 @@ size_t Command::AddArgument(const char * name, int64_t min, uint64_t max, chip::
return AddArgumentToList(std::move(arg));
}

size_t Command::AddArgument(const char * name, int64_t min, uint64_t max, chip::Optional<std::vector<bool>> * value,
const char * desc)
{
Argument arg;
arg.type = ArgumentType::VectorBool;
arg.name = name;
arg.value = static_cast<void *>(value);
arg.min = min;
arg.max = max;
arg.flags = Argument::kOptional;
arg.desc = desc;

return AddArgumentToList(std::move(arg));
}

size_t Command::AddArgument(const char * name, ComplexArgument * value, const char * desc)
{
Argument arg;
Expand Down Expand Up @@ -784,7 +832,12 @@ void Command::ResetArguments()
const Argument arg = mArgs[i];
const ArgumentType type = arg.type;
const uint8_t flags = arg.flags;
if (type == ArgumentType::Vector16 && flags != Argument::kOptional)
if (type == ArgumentType::VectorBool && flags == Argument::kOptional)
{
auto vectorArgument = static_cast<std::vector<uint16_t> *>(arg.value);
vectorArgument->clear();
}
else if (type == ArgumentType::Vector16 && flags != Argument::kOptional)
{
auto vectorArgument = static_cast<std::vector<uint16_t> *>(arg.value);
vectorArgument->clear();
Expand Down
3 changes: 3 additions & 0 deletions examples/chip-tool/commands/common/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ enum ArgumentType
Address,
Complex,
Custom,
VectorBool,
Vector16,
Vector32,
};
Expand Down Expand Up @@ -178,6 +179,8 @@ class Command

size_t AddArgument(const char * name, int64_t min, uint64_t max, std::vector<uint16_t> * value, const char * desc = "");
size_t AddArgument(const char * name, int64_t min, uint64_t max, std::vector<uint32_t> * value, const char * desc = "");
size_t AddArgument(const char * name, int64_t min, uint64_t max, chip::Optional<std::vector<bool>> * value,
const char * desc = "");
size_t AddArgument(const char * name, int64_t min, uint64_t max, chip::Optional<std::vector<uint32_t>> * value,
const char * desc = "");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,18 @@ CHIP_ERROR InteractionModelReports::ReportEvent(DeviceProxy * device, std::vecto
std::vector<ClusterId> clusterIds, std::vector<EventId> eventIds,
ReadClient::InteractionType interactionType, uint16_t minInterval,
uint16_t maxInterval, const Optional<bool> & fabricFiltered,
const Optional<EventNumber> & eventNumber, const Optional<bool> & keepSubscriptions)
const Optional<EventNumber> & eventNumber, const Optional<bool> & keepSubscriptions,
const Optional<std::vector<bool>> & isUrgents)
{
const size_t clusterCount = clusterIds.size();
const size_t eventCount = eventIds.size();
const size_t endpointCount = endpointIds.size();
const size_t isUrgentCount = isUrgents.HasValue() ? isUrgents.Value().size() : 0;

VerifyOrReturnError(clusterCount > 0 && clusterCount <= kMaxAllowedPaths, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(eventCount > 0 && eventCount <= kMaxAllowedPaths, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(endpointCount > 0 && endpointCount <= kMaxAllowedPaths, CHIP_ERROR_INVALID_ARGUMENT);
VerifyOrReturnError(isUrgentCount <= kMaxAllowedPaths, CHIP_ERROR_INVALID_ARGUMENT);

const bool hasSameIdsCount = (clusterCount == eventCount) && (clusterCount == endpointCount);
const bool multipleClusters = clusterCount > 1 && eventCount == 1 && endpointCount == 1;
Expand Down Expand Up @@ -389,6 +392,11 @@ CHIP_ERROR InteractionModelReports::ReportEvent(DeviceProxy * device, std::vecto
{
eventPathParams[i].mEndpointId = endpointId;
}

if (isUrgents.HasValue() && isUrgents.Value().size() > i)
{
eventPathParams[i].mIsUrgentEvent = isUrgents.Value().at(i);
}
}

ReadPrepareParams params(device->GetSecureSession().Value());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,20 @@ class InteractionModelReports
uint16_t minInterval = 0, uint16_t maxInterval = 0,
const chip::Optional<bool> & fabricFiltered = chip::Optional<bool>(true),
const chip::Optional<chip::EventNumber> & eventNumber = chip::NullOptional,
const chip::Optional<bool> & keepSubscriptions = chip::NullOptional)
const chip::Optional<bool> & keepSubscriptions = chip::NullOptional,
const chip::Optional<std::vector<bool>> & isUrgents = chip::NullOptional)
{
return ReportEvent(device, endpointIds, clusterIds, eventIds, chip::app::ReadClient::InteractionType::Subscribe,
minInterval, maxInterval, fabricFiltered, eventNumber, keepSubscriptions);
minInterval, maxInterval, fabricFiltered, eventNumber, keepSubscriptions, isUrgents);
}

CHIP_ERROR ReportEvent(chip::DeviceProxy * device, std::vector<chip::EndpointId> endpointIds,
std::vector<chip::ClusterId> clusterIds, std::vector<chip::EventId> eventIds,
chip::app::ReadClient::InteractionType interactionType, uint16_t minInterval = 0,
uint16_t maxInterval = 0, const chip::Optional<bool> & fabricFiltered = chip::Optional<bool>(true),
const chip::Optional<chip::EventNumber> & eventNumber = chip::NullOptional,
const chip::Optional<bool> & keepSubscriptions = chip::NullOptional);
const chip::Optional<bool> & keepSubscriptions = chip::NullOptional,
const chip::Optional<std::vector<bool>> & isUrgents = chip::NullOptional);

void Shutdown() { mReadClients.clear(); }

Expand Down

0 comments on commit 4f4f42d

Please sign in to comment.