// GattServer implementation
// ========================================================
-GattServer::GattServer(const UUID& uuid, int server_if)
+GattServer::GattServer(const UUID& uuid, int server_id)
: app_identifier_(uuid),
- server_if_(server_if),
+ server_id_(server_id),
delegate_(nullptr) {
}
GattServer::~GattServer() {
// Automatically unregister the server.
- VLOG(1) << "GattServer unregistering: " << server_if_;
+ VLOG(1) << "GattServer unregistering: " << server_id_;
// Unregister as observer so we no longer receive any callbacks.
hal::BluetoothGattInterface::Get()->RemoveServerObserver(this);
// TODO(armansito): stop and remove all services here? unregister_server
// should really take care of that.
hal::BluetoothGattInterface::Get()->
- GetServerHALInterface()->unregister_server(server_if_);
+ GetServerHALInterface()->unregister_server(server_id_);
}
void GattServer::SetDelegate(Delegate* delegate) {
return app_identifier_;
}
-int GattServer::GetClientId() const {
- return server_if_;
+int GattServer::GetInstanceId() const {
+ return server_id_;
}
std::unique_ptr<GattIdentifier> GattServer::BeginServiceDeclaration(
const UUID& uuid, bool is_primary) {
- VLOG(1) << __func__ << " server_if: " << server_if_
+ VLOG(1) << __func__ << " server_id: " << server_id_
<< " - UUID: " << uuid.ToString()
<< ", is_primary: " << is_primary;
lock_guard<mutex> lock(mutex_);
std::unique_ptr<GattIdentifier> GattServer::AddCharacteristic(
const UUID& uuid, int properties, int permissions) {
- VLOG(1) << __func__ << " server_if: " << server_if_
+ VLOG(1) << __func__ << " server_id: " << server_id_
<< " - UUID: " << uuid.ToString()
<< ", properties: " << properties
<< ", permissions: " << permissions;
std::unique_ptr<GattIdentifier> GattServer::AddDescriptor(
const UUID& uuid, int permissions) {
- VLOG(1) << __func__ << " server_if: " << server_if_
+ VLOG(1) << __func__ << " server_id: " << server_id_
<< " - UUID: " << uuid.ToString()
<< ", permissions: " << permissions;
lock_guard<mutex> lock(mutex_);
}
bool GattServer::EndServiceDeclaration(const ResultCallback& callback) {
- VLOG(1) << __func__ << " server_if: " << server_if_;
+ VLOG(1) << __func__ << " server_id: " << server_id_;
lock_guard<mutex> lock(mutex_);
if (!callback) {
bt_status_t status = hal::BluetoothGattInterface::Get()->
GetServerHALInterface()->add_service(
- server_if_, &hal_id, pending_decl_->num_handles);
+ server_id_, &hal_id, pending_decl_->num_handles);
if (status != BT_STATUS_SUCCESS) {
LOG(ERROR) << "Failed to initiate call to populate GATT service";
CleanUpPendingData();
const std::string& device_address, int request_id,
GATTError error, int offset,
const std::vector<uint8_t>& value) {
- VLOG(1) << __func__ << " - server_if: " << server_if_
+ VLOG(1) << __func__ << " - server_id: " << server_id_
<< " device_address: " << device_address
<< " request_id: " << request_id
<< " error: " << error
bool confirm,
const std::vector<uint8_t>& value,
const GattCallback& callback) {
- VLOG(1) << " - server_if: " << server_if_
+ VLOG(1) << " - server_id: " << server_id_
<< " device_address: " << device_address
<< " confirm: " << confirm;
lock_guard<mutex> lock(mutex_);
// TODO(armansito): Make HAL accept const char*.
bt_status_t status = hal::BluetoothGattInterface::Get()->
GetServerHALInterface()->send_indication(
- server_if_,
+ server_id_,
handle_iter->second,
conn->conn_id,
value.size(),
void GattServer::ConnectionCallback(
hal::BluetoothGattInterface* /* gatt_iface */,
- int conn_id, int server_if,
+ int conn_id, int server_id,
int connected,
const bt_bdaddr_t& bda) {
lock_guard<mutex> lock(mutex_);
- if (server_if != server_if_)
+ if (server_id != server_id_)
return;
std::string device_address = BtAddrString(&bda);
void GattServer::ServiceAddedCallback(
hal::BluetoothGattInterface* gatt_iface,
- int status, int server_if,
+ int status, int server_id,
const btgatt_srvc_id_t& srvc_id,
int service_handle) {
lock_guard<mutex> lock(mutex_);
- if (server_if != server_if_)
+ if (server_id != server_id_)
return;
// Construct a GATT identifier.
CHECK(pending_id_->IsService());
VLOG(1) << __func__ << " - status: " << status
- << " server_if: " << server_if
+ << " server_id: " << server_id
<< " handle: " << service_handle
<< " UUID: " << gatt_id->service_uuid().ToString();
void GattServer::CharacteristicAddedCallback(
hal::BluetoothGattInterface* gatt_iface,
- int status, int server_if,
+ int status, int server_id,
const bt_uuid_t& uuid,
int service_handle,
int char_handle) {
lock_guard<mutex> lock(mutex_);
- if (server_if != server_if_)
+ if (server_id != server_id_)
return;
CHECK(pending_decl_);
CHECK(pending_id_->characteristic_uuid() == UUID(uuid));
VLOG(1) << __func__ << " - status: " << status
- << " server_if: " << server_if
+ << " server_id: " << server_id
<< " service_handle: " << service_handle
<< " char_handle: " << char_handle;
void GattServer::DescriptorAddedCallback(
hal::BluetoothGattInterface* gatt_iface,
- int status, int server_if,
+ int status, int server_id,
const bt_uuid_t& uuid,
int service_handle,
int desc_handle) {
lock_guard<mutex> lock(mutex_);
- if (server_if != server_if_)
+ if (server_id != server_id_)
return;
CHECK(pending_decl_);
CHECK(pending_id_->descriptor_uuid() == UUID(uuid));
VLOG(1) << __func__ << " - status: " << status
- << " server_if: " << server_if
+ << " server_id: " << server_id
<< " service_handle: " << service_handle
<< " desc_handle: " << desc_handle;
void GattServer::ServiceStartedCallback(
hal::BluetoothGattInterface* gatt_iface,
- int status, int server_if,
+ int status, int server_id,
int service_handle) {
lock_guard<mutex> lock(mutex_);
- if (server_if != server_if_)
+ if (server_id != server_id_)
return;
CHECK(pending_id_);
CHECK(pending_decl_);
CHECK(pending_decl_->service_handle == service_handle);
- VLOG(1) << __func__ << " - server_if: " << server_if
+ VLOG(1) << __func__ << " - server_id: " << server_id
<< " handle: " << service_handle;
// If we failed to start the service, remove it from the database and ignore
// the result.
if (status != BT_STATUS_SUCCESS) {
gatt_iface->GetServerHALInterface()->delete_service(
- server_if_, service_handle);
+ server_id_, service_handle);
}
// Complete the operation.
void GattServer::ServiceStoppedCallback(
hal::BluetoothGattInterface* /* gatt_iface */,
int /* status */,
- int /* server_if */,
+ int /* server_id */,
int /* service_handle */) {
// TODO(armansito): Support stopping a service.
}
if (!next_entry) {
// No more entries. Call start_service to finish up.
bt_status_t status = gatt_iface->GetServerHALInterface()->start_service(
- server_if_,
+ server_id_,
pending_decl_->service_handle,
TRANSPORT_BREDR | TRANSPORT_LE);
bt_uuid_t char_uuid = next_entry->id.characteristic_uuid().GetBlueDroid();
bt_status_t status = gatt_iface->GetServerHALInterface()->
add_characteristic(
- server_if_,
+ server_id_,
pending_decl_->service_handle,
&char_uuid,
next_entry->char_properties,
bt_uuid_t desc_uuid = next_entry->id.descriptor_uuid().GetBlueDroid();
bt_status_t status = gatt_iface->GetServerHALInterface()->
add_descriptor(
- server_if_,
+ server_id_,
pending_decl_->service_handle,
&desc_uuid,
next_entry->permissions);
hal::BluetoothGattInterface::Get()->RemoveServerObserver(this);
}
-bool GattServerFactory::RegisterClient(const UUID& uuid,
- const RegisterCallback& callback) {
+bool GattServerFactory::RegisterInstance(
+ const UUID& uuid,
+ const RegisterCallback& callback) {
VLOG(1) << __func__ << " - UUID: " << uuid.ToString();
lock_guard<mutex> lock(pending_calls_lock_);
void GattServerFactory::RegisterServerCallback(
hal::BluetoothGattInterface* gatt_iface,
- int status, int server_if,
+ int status, int server_id,
const bt_uuid_t& app_uuid) {
UUID uuid(app_uuid);
std::unique_ptr<GattServer> server;
BLEStatus result = BLE_STATUS_FAILURE;
if (status == BT_STATUS_SUCCESS) {
- server.reset(new GattServer(uuid, server_if));
+ server.reset(new GattServer(uuid, server_id));
- // Use the unsafe variant to register this as an observer to prevent a
- // deadlock since this callback is currently holding the lock.
- gatt_iface->AddServerObserverUnsafe(server.get());
+ gatt_iface->AddServerObserver(server.get());
result = BLE_STATUS_SUCCESS;
}