Merge "Add C code to use BDADDR_ANY macro properly. The macro expands into code that is not valid C++. So we need to use a C helper."

This commit is contained in:
Doug Kwan
2011-07-18 17:02:55 -07:00
committed by Android (Google) Code Review
5 changed files with 76 additions and 2 deletions

View File

@@ -139,6 +139,7 @@ LOCAL_SRC_FILES:= \
android_bluetooth_common.cpp \
android_bluetooth_BluetoothAudioGateway.cpp \
android_bluetooth_BluetoothSocket.cpp \
android_bluetooth_c.c \
android_server_BluetoothService.cpp \
android_server_BluetoothEventLoop.cpp \
android_server_BluetoothA2dpService.cpp \

View File

@@ -17,6 +17,7 @@
#define LOG_TAG "BluetoothAudioGateway.cpp"
#include "android_bluetooth_common.h"
#include "android_bluetooth_c.h"
#include "android_runtime/AndroidRuntime.h"
#include "JNIHelp.h"
#include "jni.h"
@@ -491,7 +492,8 @@ static int setup_listening_socket(int dev, int channel) {
}
laddr.rc_family = AF_BLUETOOTH;
memcpy(&laddr.rc_bdaddr, BDADDR_ANY, sizeof(bdaddr_t));
bdaddr_t any = android_bluetooth_bdaddr_any();
memcpy(&laddr.rc_bdaddr, &any, sizeof(bdaddr_t));
laddr.rc_channel = channel;
if (bind(sk, (struct sockaddr *)&laddr, sizeof(laddr)) < 0) {

View File

@@ -17,6 +17,7 @@
#define LOG_TAG "BluetoothSocket.cpp"
#include "android_bluetooth_common.h"
#include "android_bluetooth_c.h"
#include "android_runtime/AndroidRuntime.h"
#include "JNIHelp.h"
#include "utils/Log.h"
@@ -245,7 +246,7 @@ static int bindListenNative(JNIEnv *env, jobject obj) {
jint type;
socklen_t addr_sz;
struct sockaddr *addr;
bdaddr_t bdaddr = *BDADDR_ANY;
bdaddr_t bdaddr = android_bluetooth_bdaddr_any();
struct asocket *s = get_socketData(env, obj);
if (!s)

31
core/jni/android_bluetooth_c.c Executable file
View File

@@ -0,0 +1,31 @@
/*
** Copyright 2011, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
#ifdef HAVE_BLUETOOTH
#include "android_bluetooth_c.h"
/*
* A C helper for creating a bdaddr_t object with the value BDADDR_ANY.
* We have to do this in C because the macro BDADDR_ANY in bluetooth.h
* is not valid C++ code.
*/
bdaddr_t android_bluetooth_bdaddr_any(void)
{
bdaddr_t any = *BDADDR_ANY;
return any;
}
#endif

View File

@@ -0,0 +1,39 @@
/*
** Copyright 2010, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
#ifndef ANDROID_BLUETOOTH_C_H
#define ANDROID_BLUETOOTH_C_H
#ifdef HAVE_BLUETOOTH
#include <bluetooth/bluetooth.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
* A C helper for creating a bdaddr_t object with the value BDADDR_ANY.
* We have to do this in C because the macro BDADDR_ANY in bluetooth.h
* is not valid C++ code.
*/
bdaddr_t android_bluetooth_bdaddr_any(void);
#ifdef __cplusplus
}
#endif
#endif /*HAVE_BLUETOOTH*/
#endif /*ANDROID_BLUETOOTH_C_H*/