Home | History | Annotate | Download | only in include
      1 /******************************************************************************
      2  *
      3  *  Copyright (C) 2009-2012 Broadcom Corporation
      4  *
      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:
      8  *
      9  *  http://www.apache.org/licenses/LICENSE-2.0
     10  *
     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.
     16  *
     17  ******************************************************************************/
     18 
     19 /*******************************************************************************
     20  *
     21  *  Filename:      btif_sock_util.h
     22  *
     23  *  Description:   Bluetooth socket Interface Helper functions
     24  *
     25  *******************************************************************************/
     26 
     27 #ifndef BTIF_SOCK_UTIL_H
     28 #define BTIF_SOCK_UTIL_H
     29 
     30 #include <pthread.h>
     31 #include <cutils/log.h>
     32 
     33 /*******************************************************************************
     34 **  Functions
     35 ********************************************************************************/
     36 
     37 static inline void init_slot_lock( pthread_mutex_t* mutex)
     38 {
     39     pthread_mutexattr_t attr;
     40     pthread_mutexattr_init(&attr);
     41     pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
     42     pthread_mutex_init(mutex, &attr);
     43 }
     44 
     45 static inline void lock_slot(pthread_mutex_t* mutex)
     46 {
     47     if(mutex->value)
     48         pthread_mutex_lock(mutex);
     49     else ALOGE("mutex: %p is not initialized", mutex);
     50 }
     51 
     52 static inline void unlock_slot(pthread_mutex_t* mutex)
     53 {
     54    if(mutex->value)
     55         pthread_mutex_unlock(mutex);
     56    else ALOGE("mutex: %p is not initialized", mutex);
     57 }
     58 
     59 void dump_bin(const char* title, const char* data, int size);
     60 
     61 int sock_send_fd(int sock_fd, const uint8_t* buffer, int len, int send_fd);
     62 int sock_send_all(int sock_fd, const uint8_t* buf, int len);
     63 int sock_recv_all(int sock_fd, uint8_t* buf, int len);
     64 
     65 #endif
     66