3 * Copyright (c) 2020 Project CHIP Authors
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #import "CHIPDeviceStatusDelegateBridge.h"
19 #import <Foundation/Foundation.h>
21 CHIPDeviceStatusDelegateBridge::CHIPDeviceStatusDelegateBridge(void)
26 CHIPDeviceStatusDelegateBridge::~CHIPDeviceStatusDelegateBridge() {}
28 void CHIPDeviceStatusDelegateBridge::setDelegate(id<CHIPDeviceStatusDelegate> delegate, dispatch_queue_t queue)
30 if (delegate && queue) {
39 void CHIPDeviceStatusDelegateBridge::OnMessage(chip::System::PacketBufferHandle message)
41 NSLog(@"DeviceStatusDelegate received message from the device");
43 size_t data_len = message->DataLength();
45 NSMutableData * dataBuffer = [[NSMutableData alloc] initWithBytes:message->Start() length:data_len];
48 while (!message.IsNull()) {
49 data_len = message->DataLength();
50 [dataBuffer appendBytes:message->Start() length:data_len];
54 id<CHIPDeviceStatusDelegate> strongDelegate = mDelegate;
55 if (strongDelegate && mQueue) {
56 dispatch_async(mQueue, ^{
57 [strongDelegate onMessageReceived:dataBuffer];
62 void CHIPDeviceStatusDelegateBridge::OnStatusChange() { NSLog(@"CHIPDeviceStatusDelegateBridge device status changed"); }