Skip to content

Commit

Permalink
Simplify ChipDeviceEvent initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
arkq committed Jun 5, 2024
1 parent 0e6b211 commit 74c70a9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 54 deletions.
84 changes: 33 additions & 51 deletions src/platform/Tizen/BLEManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ void BLEManagerImpl::NotificationStateChangedCb(bool notify, bt_gatt_server_h se

ChipLogProgress(DeviceLayer, "Notification State Changed %d on %s: %s", notify, __ConvertAttTypeToStr(type),
StringOrNullMarker(uuid.get()));
NotifyBLESubscribed(notify ? true : false, conn);
NotifyBLESubscribed(conn, notify ? true : false);
}

void BLEManagerImpl::WriteCompletedCb(int result, bt_gatt_h gattHandle, void * userData)
Expand Down Expand Up @@ -347,83 +347,70 @@ void BLEManagerImpl::AdvertisingStateChangedCb(int result, bt_advertiser_h adver

void BLEManagerImpl::NotifyBLEPeripheralGATTServerRegisterComplete(CHIP_ERROR error)
{
ChipDeviceEvent event;
event.Type = DeviceEventType::kPlatformTizenBLEPeripheralGATTServerRegisterComplete;
event.Platform.BLEPeripheralGATTServerRegisterComplete.mError = error;
ChipDeviceEvent event{ .Type = DeviceEventType::kPlatformTizenBLEPeripheralGATTServerRegisterComplete,
.Platform = { .BLEPeripheralGATTServerRegisterComplete = { .mError = error } } };
PlatformMgr().PostEventOrDie(&event);
}

void BLEManagerImpl::NotifyBLEPeripheralAdvConfiguredComplete(CHIP_ERROR error)
{
ChipDeviceEvent event;
event.Type = DeviceEventType::kPlatformTizenBLEPeripheralAdvConfiguredComplete;
event.Platform.BLEPeripheralAdvConfiguredComplete.mError = error;
ChipDeviceEvent event{ .Type = DeviceEventType::kPlatformTizenBLEPeripheralAdvConfiguredComplete,
.Platform = { .BLEPeripheralAdvConfiguredComplete = { .mError = error } } };
PlatformMgr().PostEventOrDie(&event);
}

void BLEManagerImpl::NotifyBLEPeripheralAdvStartComplete(CHIP_ERROR error)
{
ChipDeviceEvent event;
event.Type = DeviceEventType::kPlatformTizenBLEPeripheralAdvStartComplete;
event.Platform.BLEPeripheralAdvStartComplete.mError = error;
ChipDeviceEvent event{ .Type = DeviceEventType::kPlatformTizenBLEPeripheralAdvStartComplete,
.Platform = { .BLEPeripheralAdvStartComplete = { .mError = error } } };
PlatformMgr().PostEventOrDie(&event);
}

void BLEManagerImpl::NotifyBLEPeripheralAdvStopComplete(CHIP_ERROR error)
{
ChipDeviceEvent event;
event.Type = DeviceEventType::kPlatformTizenBLEPeripheralAdvStopComplete;
event.Platform.BLEPeripheralAdvStopComplete.mError = error;
ChipDeviceEvent event{ .Type = DeviceEventType::kPlatformTizenBLEPeripheralAdvStopComplete,
.Platform = { .BLEPeripheralAdvStopComplete = { .mError = error } } };
PlatformMgr().PostEventOrDie(&event);
}

void BLEManagerImpl::NotifyBLEWriteReceived(System::PacketBufferHandle & buf, BLE_CONNECTION_OBJECT conId)
void BLEManagerImpl::NotifyBLEWriteReceived(BLE_CONNECTION_OBJECT conId, System::PacketBufferHandle & buf)
{
ChipDeviceEvent event;
event.Type = DeviceEventType::kCHIPoBLEWriteReceived;
event.CHIPoBLEWriteReceived.ConId = conId;
event.CHIPoBLEWriteReceived.Data = std::move(buf).UnsafeRelease();
ChipDeviceEvent event{ .Type = DeviceEventType::kCHIPoBLEWriteReceived,
.CHIPoBLEWriteReceived = { .ConId = conId, .Data = std::move(buf).UnsafeRelease() } };
PlatformMgr().PostEventOrDie(&event);
}

void BLEManagerImpl::NotifyBLENotificationReceived(System::PacketBufferHandle & buf, BLE_CONNECTION_OBJECT conId)
void BLEManagerImpl::NotifyBLENotificationReceived(BLE_CONNECTION_OBJECT conId, System::PacketBufferHandle & buf)
{
ChipDeviceEvent event;
event.Type = DeviceEventType::kPlatformTizenBLEIndicationReceived;
event.Platform.BLEIndicationReceived.mConnection = conId;
event.Platform.BLEIndicationReceived.mData = std::move(buf).UnsafeRelease();
ChipDeviceEvent event{ .Type = DeviceEventType::kPlatformTizenBLEIndicationReceived,
.Platform = {
.BLEIndicationReceived = { .mConnection = conId, .mData = std::move(buf).UnsafeRelease() } } };
PlatformMgr().PostEventOrDie(&event);
}

void BLEManagerImpl::NotifyBLESubscribed(bool indicationsEnabled, BLE_CONNECTION_OBJECT conId)
void BLEManagerImpl::NotifyBLESubscribed(BLE_CONNECTION_OBJECT conId, bool indicationsEnabled)
{
ChipDeviceEvent event;
event.Type = (indicationsEnabled) ? DeviceEventType::kCHIPoBLESubscribe : DeviceEventType::kCHIPoBLEUnsubscribe;
event.CHIPoBLESubscribe.ConId = conId;
ChipDeviceEvent event{ .Type = indicationsEnabled ? DeviceEventType::kCHIPoBLESubscribe : DeviceEventType::kCHIPoBLEUnsubscribe,
.CHIPoBLESubscribe = { .ConId = conId } };
PlatformMgr().PostEventOrDie(&event);
}

void BLEManagerImpl::NotifyBLEIndicationConfirmation(BLE_CONNECTION_OBJECT conId)
{
ChipDeviceEvent event;
event.Type = DeviceEventType::kCHIPoBLEIndicateConfirm;
event.CHIPoBLEIndicateConfirm.ConId = conId;
ChipDeviceEvent event{ .Type = DeviceEventType::kCHIPoBLEIndicateConfirm, .CHIPoBLEIndicateConfirm = { .ConId = conId } };
PlatformMgr().PostEventOrDie(&event);
}

void BLEManagerImpl::NotifyBLEConnectionEstablished(BLE_CONNECTION_OBJECT conId, CHIP_ERROR error)
{
ChipDeviceEvent event;
event.Type = DeviceEventType::kCHIPoBLEConnectionEstablished;
ChipDeviceEvent event{ .Type = DeviceEventType::kCHIPoBLEConnectionEstablished };
PlatformMgr().PostEventOrDie(&event);
}

void BLEManagerImpl::NotifyBLEDisconnection(BLE_CONNECTION_OBJECT conId, CHIP_ERROR error)
{
ChipDeviceEvent event;
event.Type = DeviceEventType::kCHIPoBLEConnectionError;
event.CHIPoBLEConnectionError.ConId = conId;
event.CHIPoBLEConnectionError.Reason = error;
ChipDeviceEvent event{ .Type = DeviceEventType::kCHIPoBLEConnectionError,
.CHIPoBLEConnectionError = { .ConId = conId, .Reason = error } };
PlatformMgr().PostEventOrDie(&event);
}

Expand All @@ -432,9 +419,8 @@ void BLEManagerImpl::NotifyHandleConnectFailed(CHIP_ERROR error)
ChipLogProgress(DeviceLayer, "Connection failed: %" CHIP_ERROR_FORMAT, error.Format());
if (mIsCentral)
{
ChipDeviceEvent event;
event.Type = DeviceEventType::kPlatformTizenBLECentralConnectFailed;
event.Platform.BLECentralConnectFailed.mError = error;
ChipDeviceEvent event{ .Type = DeviceEventType::kPlatformTizenBLECentralConnectFailed,
.Platform = { .BLECentralConnectFailed = { .mError = error } } };
PlatformMgr().PostEventOrDie(&event);
}
}
Expand All @@ -443,27 +429,23 @@ void BLEManagerImpl::NotifyHandleNewConnection(BLE_CONNECTION_OBJECT conId)
{
if (mIsCentral)
{
ChipDeviceEvent event;
event.Type = DeviceEventType::kPlatformTizenBLECentralConnected;
event.Platform.BLECentralConnected.mConnection = conId;
ChipDeviceEvent event{ .Type = DeviceEventType::kPlatformTizenBLECentralConnected,
.Platform = { .BLECentralConnected = { .mConnection = conId } } };
PlatformMgr().PostEventOrDie(&event);
}
}

void BLEManagerImpl::NotifyHandleWriteComplete(BLE_CONNECTION_OBJECT conId)
{
ChipDeviceEvent event;
event.Type = DeviceEventType::kPlatformTizenBLEWriteComplete;
event.Platform.BLEWriteComplete.mConnection = conId;
ChipDeviceEvent event{ .Type = DeviceEventType::kPlatformTizenBLEWriteComplete,
.Platform = { .BLEWriteComplete = { .mConnection = conId } } };
PlatformMgr().PostEventOrDie(&event);
}

void BLEManagerImpl::NotifySubscribeOpComplete(BLE_CONNECTION_OBJECT conId, bool isSubscribed)
{
ChipDeviceEvent event;
event.Type = DeviceEventType::kPlatformTizenBLESubscribeOpComplete;
event.Platform.BLESubscribeOpComplete.mConnection = conId;
event.Platform.BLESubscribeOpComplete.mIsSubscribed = isSubscribed;
ChipDeviceEvent event{ .Type = DeviceEventType::kPlatformTizenBLESubscribeOpComplete,
.Platform = { .BLESubscribeOpComplete = { .mConnection = conId, .mIsSubscribed = isSubscribed } } };
PlatformMgr().PostEventOrDie(&event);
}

Expand Down Expand Up @@ -899,7 +881,7 @@ void BLEManagerImpl::HandleC1CharWriteEvent(BLE_CONNECTION_OBJECT conId, const u
// Copy the data to a packet buffer.
buf = System::PacketBufferHandle::NewWithData(value, len);
VerifyOrExit(!buf.IsNull(), err = CHIP_ERROR_NO_MEMORY);
NotifyBLEWriteReceived(buf, conId);
NotifyBLEWriteReceived(conId, buf);
return;
exit:
if (err != CHIP_NO_ERROR)
Expand All @@ -918,7 +900,7 @@ void BLEManagerImpl::HandleRXCharChanged(BLE_CONNECTION_OBJECT conId, const uint
// Copy the data to a packet buffer.
buf = System::PacketBufferHandle::NewWithData(value, len);
VerifyOrExit(!buf.IsNull(), err = CHIP_ERROR_NO_MEMORY);
NotifyBLENotificationReceived(buf, conId);
NotifyBLENotificationReceived(conId, buf);
return;
exit:
if (err != CHIP_NO_ERROR)
Expand Down
6 changes: 3 additions & 3 deletions src/platform/Tizen/BLEManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ class BLEManagerImpl final : public BLEManager,
void NotifyBLEPeripheralAdvConfiguredComplete(CHIP_ERROR error);
void NotifyBLEPeripheralAdvStartComplete(CHIP_ERROR error);
void NotifyBLEPeripheralAdvStopComplete(CHIP_ERROR error);
void NotifyBLESubscribed(bool indicationsEnabled, BLE_CONNECTION_OBJECT conId);
void NotifyBLESubscribed(BLE_CONNECTION_OBJECT conId, bool indicationsEnabled);
void NotifyBLEIndicationConfirmation(BLE_CONNECTION_OBJECT conId);
void NotifyBLEWriteReceived(System::PacketBufferHandle & buf, BLE_CONNECTION_OBJECT conId);
void NotifyBLEWriteReceived(BLE_CONNECTION_OBJECT conId, System::PacketBufferHandle & buf);
static void HandleAdvertisingTimeout(chip::System::Layer *, void * appState);
AdvertisingIntervals GetAdvertisingIntervals() const;

Expand All @@ -214,7 +214,7 @@ class BLEManagerImpl final : public BLEManager,
void NotifyHandleConnectFailed(CHIP_ERROR error);
void NotifyHandleWriteComplete(BLE_CONNECTION_OBJECT conId);
void NotifySubscribeOpComplete(BLE_CONNECTION_OBJECT conId, bool isSubscribed);
void NotifyBLENotificationReceived(System::PacketBufferHandle & buf, BLE_CONNECTION_OBJECT conId);
void NotifyBLENotificationReceived(BLE_CONNECTION_OBJECT conId, System::PacketBufferHandle & buf);

CHIP_ERROR RegisterGATTServer();
CHIP_ERROR StartBLEAdvertising();
Expand Down

0 comments on commit 74c70a9

Please sign in to comment.