X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=resource%2Fcsdk%2Fconnectivity%2Fsrc%2Fbt_le_adapter%2Flinux%2Fserver.c;h=be7302dec4ac6cadde454072d938af953cd8b80f;hb=390866079e285d2c74918432c0d597d5da52f8a0;hp=828183c55f6d2db93ae0c162ee2a89d180a28791;hpb=3e9402ad71cb3e93266a77796f44d17bab9853fd;p=platform%2Fupstream%2Fiotivity.git diff --git a/resource/csdk/connectivity/src/bt_le_adapter/linux/server.c b/resource/csdk/connectivity/src/bt_le_adapter/linux/server.c index 828183c..be7302d 100644 --- a/resource/csdk/connectivity/src/bt_le_adapter/linux/server.c +++ b/resource/csdk/connectivity/src/bt_le_adapter/linux/server.c @@ -1,4 +1,4 @@ -/****************************************************************** +/* **************************************************************** * * Copyright 2015 Intel Corporation All Rights Reserved. * @@ -16,9 +16,11 @@ * ******************************************************************/ + #include "server.h" +#include "service.h" +#include "peripheral.h" -#include "cacommon.h" #include "logger.h" #include @@ -27,34 +29,16 @@ // Logging tag. static char const TAG[] = "BLE_SERVER"; -// --------------------------------------------------------------------- -// GATT Request Handling -// --------------------------------------------------------------------- -void CAGattServerHandleRequestData() -{ -} - -// --------------------------------------------------------------------- -// GATT Response Handling -// --------------------------------------------------------------------- -/** - * Send response data to the GATT client. - * - * Respone data will be sent to the client through the given response - * @a characteristic proxy as a GATT characteristic notification. - * - * @param[in] characteristic The D-Bus proxy for the response - * characteristic through which the - * notification will be sent. - * @param[in] data The byte array to be sent. - * @param[in] length The number of elements in the byte - * array. - */ -static bool CAGattServerSendResponseNotification( - GattCharacteristic1 * characteristic, - char const * data, +static CAResult_t CAGattServerSendResponseNotificationImpl( + CAGattService * service, + uint8_t const * data, size_t length) { + assert(service != NULL); + + GattCharacteristic1 * const characteristic = + service->response_characteristic.characteristic; + if (!gatt_characteristic1_get_notifying(characteristic)) { OIC_LOG(WARNING, @@ -64,7 +48,7 @@ static bool CAGattServerSendResponseNotification( "Client must enable notifications. " "No response was sent."); - return false; + return CA_STATUS_FAILED; } GVariant * const value = @@ -73,38 +57,78 @@ static bool CAGattServerSendResponseNotification( length, sizeof(data[0])); - /** - * Send the response fragment by setting the "Value" property on - * the response characteristic, and emitting the - * @c org.freedesktop.Dbus.Properties.PropertiesChanged signal, - * accordingly. - * - * @todo Do we need to explicitly emit the @c GObject @c notify or - * @c org.freedesktop.Dbus.Properties.PropertiesChanged - * signal here? - */ + /* + Send the response fragment by setting the "Value" property on + the response characteristic, and emitting the + org.freedesktop.Dbus.Properties.PropertiesChanged signal, + accordingly. + + @todo Do we need to explicitly emit the GObject notify or + org.freedesktop.Dbus.Properties.PropertiesChanged + signal here? + + @todo It feels like this function should be part of the + response characteristic implementation. + + @todo Do we need to decrease the ref count after setting the + value, i.e. is ownership of the value transferred to the + characteristic object? + */ gatt_characteristic1_set_value(characteristic, value); - return true; + return CA_STATUS_OK; } -bool CAGattServerSendResponse(void const * method_info, - void const * data, - size_t length) +typedef struct _CAGattServerResponseInfo { - assert(method_info != NULL); + uint8_t const * const data; + size_t const length; + CAResult_t result; - CAGattResponseInfo const * const info = method_info; +} CAGattServerResponseInfo; - GattCharacteristic1 * const characteristic = - info->characteristic; +static void CAGattServerSendResponseNotificationToService(gpointer data, + gpointer user_data) +{ + CAGattService * const service = data; + CAGattServerResponseInfo * const info = user_data; + + CAResult_t const result = + CAGattServerSendResponseNotificationImpl(service, + info->data, + info->length); - if (!CAGattServerSendResponseNotification(characteristic, - (char const *) data, - length)) + if (result != CA_STATUS_OK) { - return false; + // Propagate failure if any send operation fails. + info->result = result; } +} + +CAResult_t CAGattServerSendResponseNotification( + char const * address, + uint8_t const * data, + size_t length) +{ + CAGattService * const s = CAGattServiceDecodeAddress(address); + + return CAGattServerSendResponseNotificationImpl(s, data, length); +} + +CAResult_t CAGattServerSendResponseNotificationToAll( + uint8_t const * data, + size_t length) +{ + CAGattServerResponseInfo info = + { + .data = data, + .length = length, + .result = CA_STATUS_OK + }; + + CAPeripheralForEachService( + CAGattServerSendResponseNotificationToService, + &info); - return true; + return info.result; }