Skip to content

Commit

Permalink
Hook LogEvent
Browse files Browse the repository at this point in the history
Add python test

run codegen
  • Loading branch information
yunhanw-google committed Dec 6, 2021
1 parent 3ebe37c commit 925e63c
Show file tree
Hide file tree
Showing 30 changed files with 137 additions and 389 deletions.
16 changes: 16 additions & 0 deletions examples/all-clusters-app/all-clusters-common/all-clusters-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -15397,6 +15397,14 @@
"incoming": 1,
"outgoing": 0
},
{
"name": "TestEmitTestEventRequest",
"code": 20,
"mfgCode": null,
"source": "client",
"incoming": 1,
"outgoing": 0
},
{
"name": "TestSimpleOptionalArgumentRequest",
"code": 19,
Expand Down Expand Up @@ -15479,6 +15487,14 @@
"source": "server",
"incoming": 0,
"outgoing": 1
},
{
"name": "TestEmitTestEventResponse",
"code": 10,
"mfgCode": null,
"source": "server",
"incoming": 0,
"outgoing": 1
}
],
"attributes": [
Expand Down
7 changes: 5 additions & 2 deletions src/app/EventLogging.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@

#include <app/ConcreteEventPath.h>
#include <app/EventLoggingDelegate.h>
#include <app/EventManagement.h>
#include <app/data-model/Encode.h>
#include <app/data-model/List.h> // So we can encode lists

namespace chip {
namespace app {

template <typename T>
class EventLogger : EventLoggingDelegate
class EventLogger : public EventLoggingDelegate
{
public:
EventLogger(const T & aEventData) : mEventData(aEventData){};
Expand All @@ -44,7 +45,9 @@ CHIP_ERROR LogEvent(const T & aEventData, EndpointId aEndpoint, EventOptions aEv
ConcreteEventPath path(aEndpoint, aEventData.GetClusterId(), aEventData.GetEventId());
// log the actual event
aEventNumber = 0;
return CHIP_NO_ERROR;
EventManagement & logMgmt = chip::app::EventManagement::GetInstance();
aEventOptions.mPath = path;
return logMgmt.LogEvent(&eventData, aEventOptions, aEventNumber);
}

} // namespace app
Expand Down
6 changes: 3 additions & 3 deletions src/app/clusters/test-cluster-server/test-cluster-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,10 @@ bool emberAfTestClusterClusterTestEmitTestEventRequestCallback(
const Commands::TestEmitTestEventRequest::DecodableType & commandData)
{
Commands::TestEmitTestEventResponse::Type responseData;
DataModel::List<const Structs::SimpleStruct::Type> arg5;
DataModel::List<const SimpleEnum> arg6;
//DataModel::List<const Structs::SimpleStruct::Type> arg5;
//DataModel::List<const SimpleEnum> arg6;
EventOptions eventOptions;
Events::TestEvent::Type event{ commandData.arg1, commandData.arg2, commandData.arg3, commandData.arg4, arg5, arg6 };
Events::TestEvent::Type event{ commandData.arg1 };
if (CHIP_NO_ERROR != LogEvent(event, commandPath.mEndpointId, eventOptions, responseData.value))
{
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE);
Expand Down
10 changes: 0 additions & 10 deletions src/app/zap-templates/zcl/data-model/chip/test-cluster.xml
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,6 @@ limitations under the License.
Command that takes identical arguments to the fields of the TestEvent and logs the TestEvent to the buffer. Command returns an event ID as the response.
</description>
<arg name="arg1" type="INT8U"/>
<arg name="arg2" type="SimpleEnum"/>
<arg name="arg3" type="BOOLEAN"/>
<arg name="arg4" type="SimpleStruct"/>
<arg name="arg5" type="SimpleStruct" array="true"/>
<arg name="arg6" type="SimpleEnum" array="true"/>
</command>

<command source="server" code="0x00" name="TestSpecificResponse" optional="false" disableDefaultResponse="true">
Expand Down Expand Up @@ -505,11 +500,6 @@ limitations under the License.
<event code="0x0001" name="TestEvent" priority="info" side="server">
<description>Example test event</description>
<field id="1" name="arg1" type="INT8U"/>
<field id="2" name="arg2" type="SimpleEnum"/>
<field id="3" name="arg3" type="BOOLEAN"/>
<field id="4" name="arg4" type="SimpleStruct"/>
<field id="5" name="arg5" type="SimpleStruct" array="true"/>
<field id="6" name="arg6" type="SimpleEnum" array="true"/>
</event>
</cluster>
</configurator>
20 changes: 0 additions & 20 deletions src/controller/python/chip/clusters/Objects.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/controller/python/test/test_scripts/cluster_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ async def SendCommandWithResponse(cls, devCtrl):
if res.returnValue != 5:
raise ValueError()

@classmethod
async def SendCommandWithTestClusterEventTrigger(cls, devCtrl):
req = Clusters.TestCluster.Commands.TestEmitTestEventRequest(arg1=1)
res = await devCtrl.SendCommand(nodeid=NODE_ID, endpoint=LIGHTING_ENDPOINT_ID, payload=req)
if not isinstance(res, Clusters.TestCluster.Commands.TestEmitTestEventResponse):
logger.error(f"Unexpected response of type {type(res)} received.")
raise ValueError()
logger.info(f"Received response: {res}")
if res.returnValue != 5:
raise ValueError()

@classmethod
async def SendWriteRequest(cls, devCtrl):
res = await devCtrl.WriteAttribute(nodeid=NODE_ID,
Expand Down Expand Up @@ -234,6 +245,7 @@ async def RunTest(cls, devCtrl):
await cls.RoundTripTest(devCtrl)
await cls.RoundTripTestWithBadEndpoint(devCtrl)
await cls.SendCommandWithResponse(devCtrl)
await cls.SendCommandWithTestClusterEventTrigger(devCtrl)
await cls.SendWriteRequest(devCtrl)
await cls.TestReadAttributeRequests(devCtrl)
await cls.TestReadEventRequests(devCtrl)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions src/darwin/Framework/CHIP/zap-generated/CHIPCommandPayloadsObjc.mm

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion zzz_generated/bridge-app/zap-generated/endpoint_config.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 925e63c

Please sign in to comment.