Skip to content

Commit

Permalink
Implement Android isUrgent flag
Browse files Browse the repository at this point in the history
  • Loading branch information
joonhaengHeo committed Feb 24, 2023
1 parent 64cb1ab commit 6ff2b3a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
13 changes: 9 additions & 4 deletions src/controller/java/CHIPDeviceController-JNI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static CHIP_ERROR ParseAttributePathList(jobject attributePathList,
static CHIP_ERROR ParseAttributePath(jobject attributePath, EndpointId & outEndpointId, ClusterId & outClusterId,
AttributeId & outAttributeId);
static CHIP_ERROR ParseEventPathList(jobject eventPathList, std::vector<app::EventPathParams> & outEventPathParamsList);
static CHIP_ERROR ParseEventPath(jobject eventPath, EndpointId & outEndpointId, ClusterId & outClusterId, EventId & outEventId);
static CHIP_ERROR ParseEventPath(jobject eventPath, EndpointId & outEndpointId, ClusterId & outClusterId, EventId & outEventId, bool & outIsUrgent);
static CHIP_ERROR IsWildcardChipPathId(jobject chipPathId, bool & isWildcard);
static CHIP_ERROR CreateDeviceAttestationDelegateBridge(JNIEnv * env, jlong handle, jobject deviceAttestationDelegate,
jint failSafeExpiryTimeoutSecs,
Expand Down Expand Up @@ -1376,34 +1376,38 @@ CHIP_ERROR ParseEventPathList(jobject eventPathList, std::vector<app::EventPathP
EndpointId endpointId;
ClusterId clusterId;
EventId eventId;
ReturnErrorOnFailure(ParseEventPath(eventPathItem, endpointId, clusterId, eventId));
outEventPathParamsList.push_back(app::EventPathParams(endpointId, clusterId, eventId));
bool isUrgent;
ReturnErrorOnFailure(ParseEventPath(eventPathItem, endpointId, clusterId, eventId, isUrgent));
outEventPathParamsList.push_back(app::EventPathParams(endpointId, clusterId, eventId, isUrgent));
}

return CHIP_NO_ERROR;
}

CHIP_ERROR ParseEventPath(jobject eventPath, EndpointId & outEndpointId, ClusterId & outClusterId, EventId & outEventId)
CHIP_ERROR ParseEventPath(jobject eventPath, EndpointId & outEndpointId, ClusterId & outClusterId, EventId & outEventId, bool & outIsUrgent)
{
JNIEnv * env = JniReferences::GetInstance().GetEnvForCurrentThread();

jmethodID getEndpointIdMethod = nullptr;
jmethodID getClusterIdMethod = nullptr;
jmethodID getEventIdMethod = nullptr;
jmethodID isUrgentMethod = nullptr;

ReturnErrorOnFailure(JniReferences::GetInstance().FindMethod(
env, eventPath, "getEndpointId", "()Lchip/devicecontroller/model/ChipPathId;", &getEndpointIdMethod));
ReturnErrorOnFailure(JniReferences::GetInstance().FindMethod(
env, eventPath, "getClusterId", "()Lchip/devicecontroller/model/ChipPathId;", &getClusterIdMethod));
ReturnErrorOnFailure(JniReferences::GetInstance().FindMethod(env, eventPath, "getEventId",
"()Lchip/devicecontroller/model/ChipPathId;", &getEventIdMethod));
ReturnErrorOnFailure(JniReferences::GetInstance().FindMethod(env, eventPath, "isUrgent", "()Z", &isUrgentMethod));

jobject endpointIdObj = env->CallObjectMethod(eventPath, getEndpointIdMethod);
VerifyOrReturnError(endpointIdObj != nullptr, CHIP_ERROR_INCORRECT_STATE);
jobject clusterIdObj = env->CallObjectMethod(eventPath, getClusterIdMethod);
VerifyOrReturnError(clusterIdObj != nullptr, CHIP_ERROR_INCORRECT_STATE);
jobject eventIdObj = env->CallObjectMethod(eventPath, getEventIdMethod);
VerifyOrReturnError(eventIdObj != nullptr, CHIP_ERROR_INCORRECT_STATE);
jboolean isUrgent = env->CallBooleanMethod(eventPath, isUrgentMethod);

uint32_t endpointId = 0;
ReturnErrorOnFailure(GetChipPathIdValue(endpointIdObj, kInvalidEndpointId, endpointId));
Expand All @@ -1415,6 +1419,7 @@ CHIP_ERROR ParseEventPath(jobject eventPath, EndpointId & outEndpointId, Cluster
outEndpointId = static_cast<EndpointId>(endpointId);
outClusterId = static_cast<ClusterId>(clusterId);
outEventId = static_cast<EventId>(eventId);
outIsUrgent = (isUrgent == JNI_TRUE);

return CHIP_NO_ERROR;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
/** An event path that should be used for requests. */
public class ChipEventPath {
private ChipPathId endpointId, clusterId, eventId;
private boolean isUrgent;

private ChipEventPath(ChipPathId endpointId, ChipPathId clusterId, ChipPathId eventId) {
private ChipEventPath(
ChipPathId endpointId, ChipPathId clusterId, ChipPathId eventId, boolean isUrgent) {
this.endpointId = endpointId;
this.clusterId = clusterId;
this.eventId = eventId;
this.isUrgent = isUrgent;
}

public ChipPathId getEndpointId() {
Expand All @@ -42,36 +45,64 @@ public ChipPathId getEventId() {
return eventId;
}

public boolean isUrgent() {
return isUrgent;
}

@Override
public boolean equals(Object object) {
if (object instanceof ChipEventPath) {
ChipEventPath that = (ChipEventPath) object;
return Objects.equals(this.endpointId, that.endpointId)
&& Objects.equals(this.clusterId, that.clusterId)
&& Objects.equals(this.eventId, that.eventId);
&& Objects.equals(this.eventId, that.eventId)
&& (this.isUrgent == that.isUrgent);
}
return false;
}

@Override
public int hashCode() {
return Objects.hash(endpointId, clusterId, eventId);
return Objects.hash(endpointId, clusterId, eventId, isUrgent);
}

@Override
public String toString() {
return String.format(
Locale.ENGLISH, "Endpoint %s, cluster %s, event %s", endpointId, clusterId, eventId);
Locale.ENGLISH,
"Endpoint %s, cluster %s, event %s, isUrgent %s",
endpointId,
clusterId,
eventId,
isUrgent ? "true" : "false");
}

public static ChipEventPath newInstance(
ChipPathId endpointId, ChipPathId clusterId, ChipPathId eventId) {
return new ChipEventPath(endpointId, clusterId, eventId);
return new ChipEventPath(endpointId, clusterId, eventId, false);
}

/** Create a new {@link ChipEventPath} with only concrete ids. */
public static ChipEventPath newInstance(long endpointId, long clusterId, long eventId) {
return new ChipEventPath(
ChipPathId.forId(endpointId), ChipPathId.forId(clusterId), ChipPathId.forId(eventId));
ChipPathId.forId(endpointId),
ChipPathId.forId(clusterId),
ChipPathId.forId(eventId),
false);
}

public static ChipEventPath newInstance(
ChipPathId endpointId, ChipPathId clusterId, ChipPathId eventId, boolean isUrgent) {
return new ChipEventPath(endpointId, clusterId, eventId, isUrgent);
}

/** Create a new {@link ChipEventPath} with only concrete ids. */
public static ChipEventPath newInstance(
long endpointId, long clusterId, long eventId, boolean isUrgent) {
return new ChipEventPath(
ChipPathId.forId(endpointId),
ChipPathId.forId(clusterId),
ChipPathId.forId(eventId),
isUrgent);
}
}

0 comments on commit 6ff2b3a

Please sign in to comment.