Skip to content

Commit

Permalink
[Android] Add eventHeader parameter in Java Class (#20473)
Browse files Browse the repository at this point in the history
* Add Event TimeStamp

* Restyled by google-java-format

* Restyled by clang-format

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
joonhaengHeo and restyled-commits authored Jul 8, 2022
1 parent 88ee449 commit 5c8d76f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ class WildcardFragment : Fragment() {
stringBuilder.append("\t\t$attributeName: ${attributeState.value}\n")
}
clusterState.eventStates.forEach { (eventId, eventState) ->
stringBuilder.append("\t\teventNumber: ${eventState.eventNumber}\n")
stringBuilder.append("\t\tpriorityLevel: ${eventState.priorityLevel}\n")
stringBuilder.append("\t\tsystemTimeStamp: ${eventState.systemTimeStamp}\n")

val eventName = ChipIdLookup.eventIdToName(clusterId, eventId)
stringBuilder.append("\t\t$eventName: ${eventState.value}\n")
}
Expand Down
9 changes: 7 additions & 2 deletions src/controller/java/AndroidCallbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,10 @@ void ReportEventCallback::OnEventData(const app::EventHeader & aEventHeader, TLV
readerForJavaTLV.Init(*apData);
readerForJson.Init(*apData);

jlong eventNumber = static_cast<jlong>(aEventHeader.mEventNumber);
jlong priorityLevel = static_cast<jint>(aEventHeader.mPriorityLevel);
jlong timestamp = static_cast<jlong>(aEventHeader.mTimestamp.mValue);

jobject value = DecodeEventValue(aEventHeader.mPath, readerForJavaObject, &err);
// If we don't know this event, just skip it.
VerifyOrReturn(err != CHIP_ERROR_IM_MALFORMED_EVENT_PATH_IB);
Expand Down Expand Up @@ -481,9 +485,10 @@ void ReportEventCallback::OnEventData(const app::EventHeader & aEventHeader, TLV
VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Controller, "Could not find EventState class"));
VerifyOrReturn(eventStateCls != nullptr, ChipLogError(Controller, "Could not find EventState class"));
chip::JniClass eventStateJniCls(eventStateCls);
jmethodID eventStateCtor = env->GetMethodID(eventStateCls, "<init>", "(Ljava/lang/Object;[BLjava/lang/String;)V");
jmethodID eventStateCtor = env->GetMethodID(eventStateCls, "<init>", "(JIJLjava/lang/Object;[BLjava/lang/String;)V");
VerifyOrReturn(eventStateCtor != nullptr, ChipLogError(Controller, "Could not find EventState constructor"));
jobject eventStateObj = env->NewObject(eventStateCls, eventStateCtor, value, jniByteArray.jniValue(), jsonString.jniValue());
jobject eventStateObj = env->NewObject(eventStateCls, eventStateCtor, eventNumber, priorityLevel, timestamp, value,
jniByteArray.jniValue(), jsonString.jniValue());
VerifyOrReturn(eventStateObj != nullptr, ChipLogError(Controller, "Could not create EventState object"));

// Add EventState to NodeState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,25 @@
public final class EventState {
private static final String TAG = "EventState";

private long eventNumber;
private int priorityLevel;
private long systemTimeStamp;

private Object valueObject;
private byte[] tlv;
private JSONObject json;

public EventState(Object valueObject, byte[] tlv, String jsonString) {
public EventState(
long eventNumber,
int priorityLevel,
long systemTimeStamp,
Object valueObject,
byte[] tlv,
String jsonString) {
this.eventNumber = eventNumber;
this.priorityLevel = priorityLevel;
this.systemTimeStamp = systemTimeStamp;

this.valueObject = valueObject;
this.tlv = tlv;
try {
Expand All @@ -39,6 +53,18 @@ public EventState(Object valueObject, byte[] tlv, String jsonString) {
}
}

public long getEventNumber() {
return eventNumber;
}

public int getPriorityLevel() {
return priorityLevel;
}

public long getSystemTimeStamp() {
return systemTimeStamp;
}

public Object getValue() {
return valueObject;
}
Expand Down

0 comments on commit 5c8d76f

Please sign in to comment.