Bluetooth的子协议学习系列-HL
2015-09-06 15:50
453 查看
分析蓝牙很重要的一部分就是要搞懂JNI到bluedroid的调用关系.
代码路径为:
Z:\8939_21391\packages\apps\Bluetooth\jni\com_android_bluetooth_hdp.cpp
#define LOG_TAG "BluetoothHealthServiceJni"
#define LOG_NDEBUG 0
#define CHECK_CALLBACK_ENV \
if (!checkCallbackThread()) { \
ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__);\
return; \
}
#include "com_android_bluetooth.h"
#include "hardware/bt_hl.h"
#include "utils/Log.h"
#include "android_runtime/AndroidRuntime.h"
#include <string.h>
namespace android {
static jmethodID method_onAppRegistrationState;
static jmethodID method_onChannelStateChanged;
static const bthl_interface_t
*sBluetoothHdpInterface = NULL;//这里的bthl_interface_t 就是bluedroid里面定义的类型.
static jobject mCallbacksObj = NULL;
static jint registerHealthAppNative(JNIEnv *env, jobject object, jint data_type,
jint role, jstring name, jint channel_type) {
bt_status_t status;
bthl_mdep_cfg_t mdep_cfg;
bthl_reg_param_t reg_param;
int app_id;
if (!sBluetoothHdpInterface) return NULL;
mdep_cfg.mdep_role = (bthl_mdep_role_t) role;
mdep_cfg.data_type = data_type;
mdep_cfg.channel_type = (bthl_channel_type_t) channel_type;
// TODO(BT) pass all the followings in from java instead of reuse name
mdep_cfg.mdep_description = env->GetStringUTFChars(name, NULL);
reg_param.application_name = env->GetStringUTFChars(name, NULL);
reg_param.provider_name = NULL;
reg_param.srv_name = NULL;
reg_param.srv_desp = NULL;
reg_param.number_of_mdeps = 1;
reg_param.mdep_cfg = &mdep_cfg;
if ( (status = sBluetoothHdpInterface->register_application(®_param, &app_id)) !=
BT_STATUS_SUCCESS) {
ALOGE("Failed register health app, status: %d", status);
return -1;
}
env->ReleaseStringUTFChars(name, mdep_cfg.mdep_description);
env->ReleaseStringUTFChars(name, reg_param.application_name);
return app_id;
}
sBluetoothHdpInterface->register_application 这部分实现在
Z:\8939_21391\external\bluetooth\bluedroid\btif\src\btif_hl.c
static const bthl_interface_t bthlInterface = {
sizeof(bthl_interface_t),
init,
register_application,//这里就是上面调用的register_application 接口实现.
unregister_application,
connect_channel,
destroy_channel,
cleanup,
};
从这个流程可以看到HL协议在运行时需要走的流程. 其他的service 和bta 部分的分析后续会写.
代码路径为:
Z:\8939_21391\packages\apps\Bluetooth\jni\com_android_bluetooth_hdp.cpp
#define LOG_TAG "BluetoothHealthServiceJni"
#define LOG_NDEBUG 0
#define CHECK_CALLBACK_ENV \
if (!checkCallbackThread()) { \
ALOGE("Callback: '%s' is not called on the correct thread", __FUNCTION__);\
return; \
}
#include "com_android_bluetooth.h"
#include "hardware/bt_hl.h"
#include "utils/Log.h"
#include "android_runtime/AndroidRuntime.h"
#include <string.h>
namespace android {
static jmethodID method_onAppRegistrationState;
static jmethodID method_onChannelStateChanged;
static const bthl_interface_t
*sBluetoothHdpInterface = NULL;//这里的bthl_interface_t 就是bluedroid里面定义的类型.
static jobject mCallbacksObj = NULL;
static void initializeNative(JNIEnv *env, jobject object) { const bt_interface_t* btInf; bt_status_t status; if ( (btInf = getBluetoothInterface()) == NULL) { ALOGE("Bluetooth module is not loaded"); return; } if (sBluetoothHdpInterface !=NULL) { ALOGW("Cleaning up Bluetooth Health Interface before initializing..."); sBluetoothHdpInterface->cleanup(); sBluetoothHdpInterface = NULL; } if (mCallbacksObj != NULL) { ALOGW("Cleaning up Bluetooth Health callback object"); env->DeleteGlobalRef(mCallbacksObj); mCallbacksObj = NULL; } if ( (sBluetoothHdpInterface = (bthl_interface_t *) btInf->get_profile_interface(BT_PROFILE_HEALTH_ID)) == NULL) {
// get_profile_interface 实现在bluedroid里面的.bluetooth.c 里面.根据//BT_PROFILE_HEALTH_ID 获取对应的interface
//.Z:\8939_21391\external\bluetooth\bluedroid\btif\src\bluetooth.cALOGE("Failed to get Bluetooth Health Interface"); return; }
// 通过hal层代码来获取bluedroid的interface来进行init 初始化操作
if ( (status = sBluetoothHdpInterface->init(&sBluetoothHdpCallbacks)) != BT_STATUS_SUCCESS) {
ALOGE("Failed to initialize Bluetooth HDP, status: %d", status);
sBluetoothHdpInterface = NULL;
return;
}
mCallbacksObj = env->NewGlobalRef(object);
}
static jint registerHealthAppNative(JNIEnv *env, jobject object, jint data_type,
jint role, jstring name, jint channel_type) {
bt_status_t status;
bthl_mdep_cfg_t mdep_cfg;
bthl_reg_param_t reg_param;
int app_id;
if (!sBluetoothHdpInterface) return NULL;
mdep_cfg.mdep_role = (bthl_mdep_role_t) role;
mdep_cfg.data_type = data_type;
mdep_cfg.channel_type = (bthl_channel_type_t) channel_type;
// TODO(BT) pass all the followings in from java instead of reuse name
mdep_cfg.mdep_description = env->GetStringUTFChars(name, NULL);
reg_param.application_name = env->GetStringUTFChars(name, NULL);
reg_param.provider_name = NULL;
reg_param.srv_name = NULL;
reg_param.srv_desp = NULL;
reg_param.number_of_mdeps = 1;
reg_param.mdep_cfg = &mdep_cfg;
if ( (status = sBluetoothHdpInterface->register_application(®_param, &app_id)) !=
BT_STATUS_SUCCESS) {
ALOGE("Failed register health app, status: %d", status);
return -1;
}
env->ReleaseStringUTFChars(name, mdep_cfg.mdep_description);
env->ReleaseStringUTFChars(name, reg_param.application_name);
return app_id;
}
sBluetoothHdpInterface->register_application 这部分实现在
Z:\8939_21391\external\bluetooth\bluedroid\btif\src\btif_hl.c
static const bthl_interface_t bthlInterface = {
sizeof(bthl_interface_t),
init,
register_application,//这里就是上面调用的register_application 接口实现.
unregister_application,
connect_channel,
destroy_channel,
cleanup,
};
从这个流程可以看到HL协议在运行时需要走的流程. 其他的service 和bta 部分的分析后续会写.
相关文章推荐
- UITabBarController 【标签控制器】自己的见解
- uibutton和uiimageview图片不变形设置
- UIColor和UIImage的相互转换
- 解决UIImageView的tintColor无效的问题
- iOS开发--标签视图控制器--UITabBarController
- UISwitch(开关)
- true、false和1、0
- UIStepper(计数器)
- Arduino 控制超声波测距模块
- iOS开发UI -- UIAlertController(提示框)
- iOS开发UI -- 在storeBoard中通过标识符找到页面
- ctf很好的很详细的一篇guide
- UIPickerView隐藏黑线
- jboss无法自动创建Queue和Topic 发布时出现错误javax.naming.namenotfoundexception: myqueue not bound
- UIKit Dynamics 教程:抛掷 Views
- [LintCode]Segment Tree Query 线段树的查询
- Arduino控制继电器模块
- iOS 动画Animation详解, UIView动画,CALayer动画
- TBluetoothLE
- 一个共通的viewModel搞定所有的编辑页面-经典ERP录入页面(easyui + knockoutjs + mvc4.0)