Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
simple-mbed-cloud-client/mbed-cloud-client/mbed-client/source/m2mnotificationhandler.cpp@0:8f0bb79ddd48, 2021-05-04 (annotated)
- Committer:
- leothedragon
- Date:
- Tue May 04 08:55:12 2021 +0000
- Revision:
- 0:8f0bb79ddd48
nmn
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
leothedragon | 0:8f0bb79ddd48 | 1 | /* |
leothedragon | 0:8f0bb79ddd48 | 2 | * Copyright (c) 2018 ARM Limited. All rights reserved. |
leothedragon | 0:8f0bb79ddd48 | 3 | * SPDX-License-Identifier: Apache-2.0 |
leothedragon | 0:8f0bb79ddd48 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
leothedragon | 0:8f0bb79ddd48 | 5 | * not use this file except in compliance with the License. |
leothedragon | 0:8f0bb79ddd48 | 6 | * You may obtain a copy of the License at |
leothedragon | 0:8f0bb79ddd48 | 7 | * |
leothedragon | 0:8f0bb79ddd48 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
leothedragon | 0:8f0bb79ddd48 | 9 | * |
leothedragon | 0:8f0bb79ddd48 | 10 | * Unless required by applicable law or agreed to in writing, software |
leothedragon | 0:8f0bb79ddd48 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
leothedragon | 0:8f0bb79ddd48 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
leothedragon | 0:8f0bb79ddd48 | 13 | * See the License for the specific language governing permissions and |
leothedragon | 0:8f0bb79ddd48 | 14 | * limitations under the License. |
leothedragon | 0:8f0bb79ddd48 | 15 | */ |
leothedragon | 0:8f0bb79ddd48 | 16 | #include "m2mnotificationhandler.h" |
leothedragon | 0:8f0bb79ddd48 | 17 | #include "eventOS_scheduler.h" |
leothedragon | 0:8f0bb79ddd48 | 18 | #include "m2mnsdlinterface.h" |
leothedragon | 0:8f0bb79ddd48 | 19 | #include "mbed-trace/mbed_trace.h" |
leothedragon | 0:8f0bb79ddd48 | 20 | #include <assert.h> |
leothedragon | 0:8f0bb79ddd48 | 21 | #include <inttypes.h> |
leothedragon | 0:8f0bb79ddd48 | 22 | #include <stdlib.h> |
leothedragon | 0:8f0bb79ddd48 | 23 | |
leothedragon | 0:8f0bb79ddd48 | 24 | #define MBED_CLIENT_NOTIFICATION_HANDLER_TASKLET_INIT_EVENT 0 // Tasklet init occurs always when generating a tasklet |
leothedragon | 0:8f0bb79ddd48 | 25 | #define MBED_CLIENT_NOTIFICATION_HANDLER_EVENT 40 |
leothedragon | 0:8f0bb79ddd48 | 26 | #define TRACE_GROUP "mClt" |
leothedragon | 0:8f0bb79ddd48 | 27 | |
leothedragon | 0:8f0bb79ddd48 | 28 | int8_t M2MNotificationHandler::_tasklet_id = -1; |
leothedragon | 0:8f0bb79ddd48 | 29 | |
leothedragon | 0:8f0bb79ddd48 | 30 | extern "C" void notification_tasklet_func(arm_event_s *event) |
leothedragon | 0:8f0bb79ddd48 | 31 | { |
leothedragon | 0:8f0bb79ddd48 | 32 | M2MNsdlInterface *iface = (M2MNsdlInterface*)event->data_ptr; |
leothedragon | 0:8f0bb79ddd48 | 33 | if (event->event_type == MBED_CLIENT_NOTIFICATION_HANDLER_EVENT) { |
leothedragon | 0:8f0bb79ddd48 | 34 | iface->send_next_notification(false); |
leothedragon | 0:8f0bb79ddd48 | 35 | event->event_data = 0; |
leothedragon | 0:8f0bb79ddd48 | 36 | } |
leothedragon | 0:8f0bb79ddd48 | 37 | } |
leothedragon | 0:8f0bb79ddd48 | 38 | |
leothedragon | 0:8f0bb79ddd48 | 39 | M2MNotificationHandler::M2MNotificationHandler() |
leothedragon | 0:8f0bb79ddd48 | 40 | { |
leothedragon | 0:8f0bb79ddd48 | 41 | if (M2MNotificationHandler::_tasklet_id < 0) { |
leothedragon | 0:8f0bb79ddd48 | 42 | M2MNotificationHandler::_tasklet_id = eventOS_event_handler_create(notification_tasklet_func, MBED_CLIENT_NOTIFICATION_HANDLER_TASKLET_INIT_EVENT); |
leothedragon | 0:8f0bb79ddd48 | 43 | assert(M2MNotificationHandler::_tasklet_id >= 0); |
leothedragon | 0:8f0bb79ddd48 | 44 | } |
leothedragon | 0:8f0bb79ddd48 | 45 | |
leothedragon | 0:8f0bb79ddd48 | 46 | initialize_event(); |
leothedragon | 0:8f0bb79ddd48 | 47 | } |
leothedragon | 0:8f0bb79ddd48 | 48 | |
leothedragon | 0:8f0bb79ddd48 | 49 | M2MNotificationHandler::~M2MNotificationHandler() |
leothedragon | 0:8f0bb79ddd48 | 50 | { |
leothedragon | 0:8f0bb79ddd48 | 51 | } |
leothedragon | 0:8f0bb79ddd48 | 52 | |
leothedragon | 0:8f0bb79ddd48 | 53 | void M2MNotificationHandler::send_notification(M2MNsdlInterface *interface) |
leothedragon | 0:8f0bb79ddd48 | 54 | { |
leothedragon | 0:8f0bb79ddd48 | 55 | tr_debug("M2MNotificationHandler::send_notification"); |
leothedragon | 0:8f0bb79ddd48 | 56 | if (!_event.data.event_data) { |
leothedragon | 0:8f0bb79ddd48 | 57 | _event.data.event_data = 1; |
leothedragon | 0:8f0bb79ddd48 | 58 | _event.data.event_type = MBED_CLIENT_NOTIFICATION_HANDLER_EVENT; |
leothedragon | 0:8f0bb79ddd48 | 59 | _event.data.data_ptr = interface; |
leothedragon | 0:8f0bb79ddd48 | 60 | |
leothedragon | 0:8f0bb79ddd48 | 61 | eventOS_event_send_user_allocated(&_event); |
leothedragon | 0:8f0bb79ddd48 | 62 | } else { |
leothedragon | 0:8f0bb79ddd48 | 63 | tr_debug("M2MNotificationHandler::send_notification - event already in queue"); |
leothedragon | 0:8f0bb79ddd48 | 64 | } |
leothedragon | 0:8f0bb79ddd48 | 65 | } |
leothedragon | 0:8f0bb79ddd48 | 66 | |
leothedragon | 0:8f0bb79ddd48 | 67 | void M2MNotificationHandler::initialize_event() |
leothedragon | 0:8f0bb79ddd48 | 68 | { |
leothedragon | 0:8f0bb79ddd48 | 69 | _event.data.data_ptr = NULL; |
leothedragon | 0:8f0bb79ddd48 | 70 | _event.data.event_data = 0; |
leothedragon | 0:8f0bb79ddd48 | 71 | _event.data.event_id = 0; |
leothedragon | 0:8f0bb79ddd48 | 72 | _event.data.sender = 0; |
leothedragon | 0:8f0bb79ddd48 | 73 | _event.data.event_type = 0; |
leothedragon | 0:8f0bb79ddd48 | 74 | _event.data.priority = ARM_LIB_MED_PRIORITY_EVENT; |
leothedragon | 0:8f0bb79ddd48 | 75 | _event.data.receiver = M2MNotificationHandler::_tasklet_id; |
leothedragon | 0:8f0bb79ddd48 | 76 | } |