本文整理汇总了C++中ca_mutex_lock函数的典型用法代码示例。如果您正苦于以下问题:C++ ca_mutex_lock函数的具体用法?C++ ca_mutex_lock怎么用?C++ ca_mutex_lock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ca_mutex_lock函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ca_context_change_device
/**
* ca_context_change_device:
* @c: the context to change the backend device for
* @device: the backend device to use, in a format that is specific to the backend.
*
* Specify the backend device to use. This function may be called not be called after
* ca_context_open() suceeded. This function might suceed even when
* the specified driver backend is not available. Use
* ca_context_open() to find out whether the backend is available
*
* Depending on the backend use this might or might not cause all
* currently playing event sounds to be moved to the new device..
*
* Returns: 0 on success, negative error code on error.
*/
int ca_context_change_device(ca_context *c, const char *device) {
char *n;
int ret;
ca_return_val_if_fail(!ca_detect_fork(), CA_ERROR_FORKED);
ca_return_val_if_fail(c, CA_ERROR_INVALID);
ca_mutex_lock(c->mutex);
if (!device)
n = NULL;
else if (!(n = ca_strdup(device))) {
ret = CA_ERROR_OOM;
goto fail;
}
ret = c->opened ? driver_change_device(c, n) : CA_SUCCESS;
if (ret == CA_SUCCESS) {
ca_free(c->device);
c->device = n;
} else
ca_free(n);
fail:
ca_mutex_unlock(c->mutex);
return ret;
}
示例2: ca_context_set_driver
/**
* ca_context_set_driver:
* @c: the context to change the backend driver for
* @driver: the backend driver to use (e.g. "alsa", "pulse", "null", ...)
*
* Specify the backend driver used. This function may not be called again after
* ca_context_open() suceeded. This function might suceed even when
* the specified driver backend is not available. Use
* ca_context_open() to find out whether the backend is available.
*
* Returns: 0 on success, negative error code on error.
*/
int ca_context_set_driver(ca_context *c, const char *driver) {
char *n;
int ret;
ca_return_val_if_fail(!ca_detect_fork(), CA_ERROR_FORKED);
ca_return_val_if_fail(c, CA_ERROR_INVALID);
ca_mutex_lock(c->mutex);
ca_return_val_if_fail_unlock(!c->opened, CA_ERROR_STATE, c->mutex);
if (!driver)
n = NULL;
else if (!(n = ca_strdup(driver))) {
ret = CA_ERROR_OOM;
goto fail;
}
ca_free(c->driver);
c->driver = n;
ret = CA_SUCCESS;
fail:
ca_mutex_unlock(c->mutex);
return ret;
}
示例3: CAAddNewCharacteristicsToGattServer
CAResult_t CAAddNewCharacteristicsToGattServer(const char *svcPath, const char *charUUID,
const char *charValue, int charValueLen, bool read)
{
OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
char *charFlags[1];
if(read)
{
charFlags[0] = "notify";
}
else
{
charFlags[0] = "write-without-response";
}
size_t flagLen = sizeof(charFlags) / sizeof(charFlags[0]);
char *charPath = NULL;
int ret = bt_gatt_add_characteristic(charUUID, charValue, charValueLen, charFlags, flagLen,
svcPath, &charPath);
if (0 != ret || NULL == charPath)
{
OIC_LOG_V(ERROR, TZ_BLE_SERVER_TAG,
"bt_gatt_add_characteristic failed with ret [%d]", ret);
return CA_STATUS_FAILED;
}
OIC_LOG_V(DEBUG, TZ_BLE_SERVER_TAG,
"bt_gatt_add_characteristic charPath obtained: %s", charPath);
ca_mutex_lock(g_bleCharacteristicMutex);
if (read)
{
if (NULL != g_gattReadCharPath)
{
OICFree(g_gattReadCharPath);
g_gattReadCharPath = NULL;
}
g_gattReadCharPath = charPath;
}
else
{
if (NULL != g_gattWriteCharPath)
{
OICFree(g_gattWriteCharPath);
g_gattWriteCharPath = NULL;
}
g_gattWriteCharPath = charPath;
}
ca_mutex_unlock(g_bleCharacteristicMutex);
OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "OUT");
return CA_STATUS_OK;
}
示例4: CALETearDownDBus
static void CALETearDownDBus(CALEContext * context)
{
assert(context != NULL);
/*
Minimize the time we hold the global lock by only clearing the
global state, and pushing resource finalization outside the global
lock.
*/
ca_mutex_lock(context->lock);
GDBusConnection * const connection = context->connection;
context->connection = NULL;
GDBusObjectManager * const object_manager = context->object_manager;
context->object_manager = NULL;
GList * const objects = context->objects;
context->objects = NULL;
GList * const adapters = context->adapters;
context->adapters = NULL;
GList * const devices = context->devices;
context->devices = NULL;
guint const interfaces_added = context->interfaces_added_sub_id;
guint const interfaces_removed = context->interfaces_removed_sub_id;
context->interfaces_added_sub_id = 0;
context->interfaces_removed_sub_id = 0;
ca_mutex_unlock(context->lock);
// Destroy the device proxies list.
g_list_free_full(devices, g_object_unref);
// Destroy the adapter proxies list.
g_list_free_full(adapters, g_object_unref);
// Destroy the list of objects obtained from the ObjectManager.
g_list_free_full(objects, g_object_unref);
// Destroy the ObjectManager proxy.
if (object_manager != NULL)
{
g_object_unref(object_manager);
}
// Tear down the D-Bus connection to the system bus.
if (connection != NULL)
{
g_dbus_connection_signal_unsubscribe(connection,
interfaces_added);
g_dbus_connection_signal_unsubscribe(connection,
interfaces_removed);
g_object_unref(connection);
}
}
示例5: CAPeripheralForEachService
void CAPeripheralForEachService(GFunc func, void * user_data)
{
ca_mutex_lock(g_context.lock);
g_list_foreach(g_context.gatt_services, func, user_data);
ca_mutex_unlock(g_context.lock);
}
示例6: CAUnSetLEAdapterStateChangedCb
CAResult_t CAUnSetLEAdapterStateChangedCb()
{
ca_mutex_lock(g_context.lock);
g_context.on_device_state_changed = NULL;
ca_mutex_unlock(g_context.lock);
return CA_STATUS_OK;
}
示例7: CASetLEServerThreadPoolHandle
void CASetLEServerThreadPoolHandle(ca_thread_pool_t handle)
{
OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "IN");
ca_mutex_lock(g_bleServerThreadPoolMutex);
g_bleServerThreadPool = handle;
ca_mutex_unlock(g_bleServerThreadPoolMutex);
OIC_LOG(DEBUG, TZ_BLE_SERVER_TAG, "OUT");
}
示例8: CAStartLEGattClient
CAResult_t CAStartLEGattClient()
{
CAResult_t result = CACentralStart(&g_context);
if (result != CA_STATUS_OK)
{
return result;
}
ca_mutex_lock(g_context.lock);
bool found_peripherals = (g_context.devices != NULL);
ca_mutex_unlock(g_context.lock);
if (!found_peripherals)
{
// Wait for LE peripherals to be discovered.
// Number of times to wait for discovery to complete.
static int const retries = 5;
static uint64_t const timeout =
2 * MICROSECS_PER_SEC; // Microseconds
if (!CALEWaitForNonEmptyList(&g_context.devices,
retries,
timeout))
{
return result;
}
}
/*
Stop discovery so that we can connect to LE peripherals.
Otherwise, the bluetooth subsystem will claim the adapter is
busy.
*/
result = CACentralStopDiscovery(&g_context);
if (result != CA_STATUS_OK)
{
return result;
}
bool const connected = CACentralConnectToAll(&g_context);
if (!connected)
{
return result;
}
/**
* @todo Verify notifications have been enabled on all response
* characteristics.
*/
return CAGattClientInitialize(&g_context);
}
示例9: CAUpdateCharacteristicsToGattServer
CAResult_t CAUpdateCharacteristicsToGattServer(const char *remoteAddress,
const uint8_t *data, uint32_t dataLen,
CALETransferType_t type, int32_t position)
{
OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "IN");
VERIFY_NON_NULL(data, TZ_BLE_CLIENT_TAG, "data is NULL");
if (0 >= dataLen)
{
OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "dataLen is less than or equal zero. Invalid input!");
return CA_STATUS_INVALID_PARAM;
}
BLEServiceInfo *bleServiceInfo = NULL;
CAResult_t ret = CA_STATUS_FAILED;
ca_mutex_lock(g_bleServiceListMutex);
if ( LE_UNICAST == type)
{
VERIFY_NON_NULL(remoteAddress, TZ_BLE_CLIENT_TAG, "remoteAddress is NULL");
ret = CAGetBLEServiceInfo(g_bLEServiceList, remoteAddress, &bleServiceInfo);
}
else if ( LE_MULTICAST == type)
{
ret = CAGetBLEServiceInfoByPosition(g_bLEServiceList, position, &bleServiceInfo);
}
ca_mutex_unlock(g_bleServiceListMutex);
if (CA_STATUS_OK != ret)
{
OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "CAGetBLEServiceInfoByPosition is failed");
return CA_STATUS_FAILED;
}
VERIFY_NON_NULL(bleServiceInfo, TZ_BLE_CLIENT_TAG, "bleServiceInfo is NULL");
OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, "Updating the data of length [%u] to [%s] ", dataLen,
bleServiceInfo->bdAddress);
OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, "Updating to write char [%s]",
bleServiceInfo->read_char);
int result = bt_gatt_set_characteristic_value(bleServiceInfo->write_char, (unsigned char *)data,
dataLen);
if (BT_ERROR_NONE != result)
{
OIC_LOG_V(ERROR, TZ_BLE_CLIENT_TAG,
"bt_gatt_set_characteristic_value Failed with return val [%d]",
result);
return CA_STATUS_FAILED;
}
OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "OUT");
return CA_STATUS_OK;
}
示例10: CAStartBleGattClientThread
void CAStartBleGattClientThread(void *data)
{
OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "IN");
ca_mutex_lock(g_bleClientStateMutex);
if (true == g_isBleGattClientStarted)
{
OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "Gatt Client is already running!!");
ca_mutex_unlock(g_bleClientStateMutex);
return;
}
CAResult_t ret = CABleGattSetScanParameter();
if (CA_STATUS_OK != ret)
{
OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "CABleSetScanParameter Failed");
ca_mutex_unlock(g_bleClientStateMutex);
CATerminateLEGattClient();
return;
}
ret = CABleGattSetCallbacks();
if (CA_STATUS_OK != ret)
{
OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "CABleGattSetCallbacks Failed");
ca_mutex_unlock(g_bleClientStateMutex);
CATerminateLEGattClient();
return;
}
OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "Starting LE device discovery");
ret = CABleGattStartDeviceDiscovery();
if (CA_STATUS_OK != ret)
{
OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "bt_adapter_le_start_device_discovery Failed");
ca_mutex_unlock(g_bleClientStateMutex);
CATerminateLEGattClient();
return;
}
g_isBleGattClientStarted = true;
ca_mutex_unlock(g_bleClientStateMutex);
OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "Giveing the control to threadPool");
GMainContext *thread_context = g_main_context_new();
g_eventLoop = g_main_loop_new(thread_context, FALSE);
g_main_context_push_thread_default(thread_context);
g_main_loop_run(g_eventLoop);
OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "OUT");
}
示例11: CAPeripheralRegisterGattServices
static bool CAPeripheralRegisterGattServices(
CAPeripheralContext * context)
{
assert(context != NULL);
bool success = true;
ca_mutex_lock(context->lock);
for (GList * l = context->gatt_services; l != NULL; l = l->next)
{
CAGattService * const service = l->data;
// Register the OIC service with the corresponding BlueZ Gatt
// Manager.
/*
org.bluez.GattManager1.RegisterService() accepts two
parameters: the service object path, and an options
dictionary. No options are used so pass a NULL pointer to
reflect an empty dictionary.
*/
GVariant * const parameters =
g_variant_new("(oa{sv})", service->object_path, NULL);
GError * error = NULL;
GVariant * const ret =
g_dbus_proxy_call_sync(
service->gatt_manager,
"RegisterService",
parameters,
G_DBUS_CALL_FLAGS_NONE,
-1, // timeout (default == -1),
NULL, // cancellable
&error);
if (ret == NULL)
{
OIC_LOG_V(ERROR,
TAG,
"GATT service registration failed: %s",
error->message);
g_error_free(error);
success = false;
break;
}
g_variant_unref(ret);
}
ca_mutex_unlock(context->lock);
return success;
}
示例12: CABleGattDescriptorDiscoveredCb
void CABleGattDescriptorDiscoveredCb(int result, unsigned char format, int total,
bt_gatt_attribute_h descriptor,
bt_gatt_attribute_h characteristic, void *userData)
{
OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "IN");
stGattCharDescriptor_t *stTemp = (stGattCharDescriptor_t *)OICCalloc(1, sizeof(
stGattCharDescriptor_t));
VERIFY_NON_NULL_VOID(stTemp, TZ_BLE_CLIENT_TAG, "malloc failed!");
stTemp->desc = (uint8_t *)OICMalloc(total);
if (NULL == stTemp->desc)
{
OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "malloc failed");
OICFree(stTemp);
return;
}
memcpy(stTemp->desc, descriptor, total);
OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, "result[%d] format[%d] total[%d]", result, format, total);
OIC_LOG_V(DEBUG, TZ_BLE_CLIENT_TAG, "characteristic [%s]", (const char *) characteristic);
bt_gatt_clone_attribute_handle(&(stTemp->characteristic), characteristic);
stTemp->total = total;
ca_mutex_lock(g_bleClientThreadPoolMutex);
if (NULL == g_bleClientThreadPool)
{
OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "g_bleClientThreadPool is NULL");
bt_gatt_destroy_attribute_handle(stTemp->characteristic);
OICFree(stTemp->desc);
OICFree(stTemp);
ca_mutex_unlock(g_bleClientThreadPoolMutex);
return;
}
CAResult_t ret = ca_thread_pool_add_task(g_bleClientThreadPool,
CASetCharacteristicDescriptorValueThread,
stTemp);
if (CA_STATUS_OK != ret)
{
OIC_LOG(ERROR, TZ_BLE_CLIENT_TAG, "ca_thread_pool_add_task failed");
bt_gatt_destroy_attribute_handle(stTemp->characteristic);
OICFree(stTemp->desc);
OICFree(stTemp);
ca_mutex_unlock(g_bleClientThreadPoolMutex);
return;
}
OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG,
"LE Client initialization flow complete");
ca_mutex_unlock(g_bleClientThreadPoolMutex);
OIC_LOG(DEBUG, TZ_BLE_CLIENT_TAG, "OUT");
}
示例13: CASetLEAdapterStateChangedCb
CAResult_t CASetLEAdapterStateChangedCb(
CALEDeviceStateChangedCallback callback)
{
ca_mutex_lock(g_context.lock);
g_context.on_device_state_changed = callback;
ca_mutex_unlock(g_context.lock);
return CA_STATUS_OK;
}
示例14: CAUnsetLENWConnectionStateChangedCb
CAResult_t CAUnsetLENWConnectionStateChangedCb()
{
OIC_LOG(DEBUG, TAG, "IN");
ca_mutex_lock(g_bleConnectionStateChangedCbMutex);
g_bleConnectionStateChangedCallback = NULL;
ca_mutex_unlock(g_bleConnectionStateChangedCbMutex);
OIC_LOG(DEBUG, TAG, "OUT");
return CA_STATUS_OK;
}
示例15: CAIPGetInterfaceInfo
CAResult_t CAIPGetInterfaceInfo(u_arraylist_t **netInterfaceList)
{
OIC_LOG(DEBUG, IP_MONITOR_TAG, "IN");
VERIFY_NON_NULL(netInterfaceList, IP_MONITOR_TAG, "u_array_list is null");
VERIFY_NON_NULL(g_networkMonitorContext, IP_MONITOR_TAG, "g_networkMonitorContext is null");
VERIFY_NON_NULL(g_networkMonitorContextMutex, IP_MONITOR_TAG,
"g_networkMonitorContextMutex is null");
// Get the interface and ipaddress information from cache
ca_mutex_lock(g_networkMonitorContextMutex);
if (!g_networkMonitorContext->netInterfaceList
|| !(u_arraylist_length(g_networkMonitorContext->netInterfaceList)))
{
OIC_LOG(ERROR, IP_MONITOR_TAG, "Network not enabled");
ca_mutex_unlock(g_networkMonitorContextMutex);
return CA_ADAPTER_NOT_ENABLED;
}
uint32_t list_length = u_arraylist_length(g_networkMonitorContext->netInterfaceList);
OIC_LOG_V(DEBUG, IP_MONITOR_TAG, "CAIPGetInterfaceInfo list length [%d]",
list_length);
for (uint32_t list_index = 0; list_index < list_length; list_index++)
{
CANetInfo_t *info = (CANetInfo_t *) u_arraylist_get(
g_networkMonitorContext->netInterfaceList, list_index);
if (!info)
{
continue;
}
OIC_LOG_V(DEBUG, IP_MONITOR_TAG, "CAIPGetInterfaceInfo ip [%s]",
info->ipAddress);
CANetInfo_t *newNetinfo = (CANetInfo_t *) OICMalloc(sizeof(CANetInfo_t));
if (!newNetinfo)
{
OIC_LOG(ERROR, IP_MONITOR_TAG, "Malloc failed!");
ca_mutex_unlock(g_networkMonitorContextMutex);
return CA_MEMORY_ALLOC_FAILED;
}
*newNetinfo = *info;
CAResult_t result = u_arraylist_add(*netInterfaceList, (void *) newNetinfo);
if (CA_STATUS_OK != result)
{
OIC_LOG(ERROR, IP_MONITOR_TAG, "u_arraylist_add failed!");
ca_mutex_unlock(g_networkMonitorContextMutex);
return CA_STATUS_FAILED;
}
}
ca_mutex_unlock(g_networkMonitorContextMutex);
OIC_LOG(DEBUG, IP_MONITOR_TAG, "OUT");
return CA_STATUS_OK;
}