Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

Multiple Improvements and Support for WDM Subscription to Device #35

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,22 @@ APP = openweave-nrf52840-lock-example

SRCS = \
$(PROJECT_ROOT)/main/main.cpp \
$(PROJECT_ROOT)/main/AppEvent.cpp \
$(PROJECT_ROOT)/main/AppTask.cpp \
$(PROJECT_ROOT)/main/DeviceDiscovery.cpp \
$(PROJECT_ROOT)/main/LEDWidget.cpp \
$(PROJECT_ROOT)/main/BoltLockManager.cpp \
$(PROJECT_ROOT)/main/ButtonManager.cpp \
$(PROJECT_ROOT)/main/WDMFeature.cpp \
$(PROJECT_ROOT)/main/traits/BoltLockTraitDataSource.cpp \
$(PROJECT_ROOT)/main/traits/BoltLockSettingsTraitDataSink.cpp \
$(PROJECT_ROOT)/main/traits/DeviceIdentityTraitDataSource.cpp \
$(PROJECT_ROOT)/main/traits/SecurityOpenCloseTraitDataSink.cpp \
$(PROJECT_ROOT)/main/schema/BoltLockTrait.cpp \
$(PROJECT_ROOT)/main/schema/BoltLockSettingsTrait.cpp \
$(PROJECT_ROOT)/main/schema/DeviceIdentityTrait.cpp \
$(PROJECT_ROOT)/main/schema/OpenCloseTrait.cpp \
$(PROJECT_ROOT)/main/schema/SecurityOpenCloseTrait.cpp \
$(PROJECT_ROOT)/main/support/CXXExceptionStubs.cpp \
$(PROJECT_ROOT)/main/support/nRF5Sbrk.c \
$(PROJECT_ROOT)/main/support/FreeRTOSNewlibLockSupport.c \
Expand Down
83 changes: 83 additions & 0 deletions main/AppEvent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
*
* Copyright (c) 2019 Google LLC.
* 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 "AppEvent.h"

int AppEventDispatcher::AddEventHandler(EventHandler Handler, intptr_t Arg = 0)
{
int ret = NRF_SUCCESS;
EventHandler_t * eventHandler;

// Do nothing if the event handler is already registered.
for (eventHandler = mAppEventHandlerList; eventHandler != NULL; eventHandler = eventHandler->Next)
{
if (eventHandler->Handler == Handler && eventHandler->Arg == Arg)
{
return ret;
}
}

eventHandler = (EventHandler_t *)malloc(sizeof(EventHandler_t));
if (eventHandler == NULL)
{
ret = NRF_ERROR_NO_MEM;
}
else
{
eventHandler->Next = mAppEventHandlerList;
eventHandler->Handler = Handler;
eventHandler->Arg = Arg;

mAppEventHandlerList = eventHandler;
}

return ret;
}


void AppEventDispatcher::RemoveEventHandler(EventHandler Handler, intptr_t Arg = 0)
{
EventHandler_t ** eventHandlerIndirectPtr;

for (eventHandlerIndirectPtr = &mAppEventHandlerList; *eventHandlerIndirectPtr != NULL; )
{
EventHandler_t * eventHandler = (*eventHandlerIndirectPtr);

if (eventHandler->Handler == Handler && eventHandler->Arg == Arg)
{
*eventHandlerIndirectPtr = eventHandler->Next;
free(eventHandler);
}
else
{
eventHandlerIndirectPtr = &eventHandler->Next;
}
}
}


void AppEventDispatcher::DispatchEvent(const AppEvent * event)
{
// Dispatch the event to each of the registered application event handlers.
for (EventHandler_t * eventHandler = mAppEventHandlerList;
eventHandler != NULL;
eventHandler = eventHandler->Next)
{
eventHandler->Handler(event, eventHandler->Arg);
}
}
Loading