summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2017-11-10 21:44:13 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2017-11-10 21:44:13 +0000
commit62ab659b28f60dcbe2ae6a16afbd8974cf713bcb (patch)
tree04e43562d71471e887f0ebf0e1a51c4a6f94b795
parent641fc32fc066196d80e51d9dc0bac903dd87b670 (diff)
parent461deddb4d456904e887053682aaaee4ee40d432 (diff)
Merge "Remove strong pointer in contructor to "this""
-rw-r--r--nfc/1.0/default/Nfc.cpp8
-rw-r--r--nfc/1.0/default/Nfc.h71
2 files changed, 36 insertions, 43 deletions
diff --git a/nfc/1.0/default/Nfc.cpp b/nfc/1.0/default/Nfc.cpp
index d337a36e29..fcdcbbc301 100644
--- a/nfc/1.0/default/Nfc.cpp
+++ b/nfc/1.0/default/Nfc.cpp
@@ -14,9 +14,7 @@ namespace implementation {
sp<INfcClientCallback> Nfc::mCallback = nullptr;
-Nfc::Nfc(nfc_nci_device_t* device) : mDevice(device),
- mDeathRecipient(new NfcDeathRecipient(this)) {
-}
+Nfc::Nfc(nfc_nci_device_t* device) : mDevice(device) {}
// Methods from ::android::hardware::nfc::V1_0::INfc follow.
::android::hardware::Return<NfcStatus> Nfc::open(const sp<INfcClientCallback>& clientCallback) {
@@ -25,7 +23,7 @@ Nfc::Nfc(nfc_nci_device_t* device) : mDevice(device),
if (mDevice == nullptr || mCallback == nullptr) {
return NfcStatus::FAILED;
}
- mCallback->linkToDeath(mDeathRecipient, 0 /*cookie*/);
+ mCallback->linkToDeath(this, 0 /*cookie*/);
int ret = mDevice->open(mDevice, eventCallback, dataCallback);
return ret == 0 ? NfcStatus::OK : NfcStatus::FAILED;
}
@@ -58,7 +56,7 @@ Nfc::Nfc(nfc_nci_device_t* device) : mDevice(device),
if (mDevice == nullptr || mCallback == nullptr) {
return NfcStatus::FAILED;
}
- mCallback->unlinkToDeath(mDeathRecipient);
+ mCallback->unlinkToDeath(this);
return mDevice->close(mDevice) ? NfcStatus::FAILED : NfcStatus::OK;
}
diff --git a/nfc/1.0/default/Nfc.h b/nfc/1.0/default/Nfc.h
index d8787fd043..ab95d064e5 100644
--- a/nfc/1.0/default/Nfc.h
+++ b/nfc/1.0/default/Nfc.h
@@ -19,50 +19,45 @@ using ::android::hardware::hidl_vec;
using ::android::hardware::hidl_string;
using ::android::sp;
-struct NfcDeathRecipient : hidl_death_recipient {
- NfcDeathRecipient(const sp<INfc> nfc) : mNfc(nfc) {
- }
+struct Nfc : public INfc, public hidl_death_recipient {
+ Nfc(nfc_nci_device_t* device);
+ ::android::hardware::Return<NfcStatus> open(
+ const sp<INfcClientCallback>& clientCallback) override;
+ ::android::hardware::Return<uint32_t> write(const hidl_vec<uint8_t>& data) override;
+ ::android::hardware::Return<NfcStatus> coreInitialized(const hidl_vec<uint8_t>& data) override;
+ ::android::hardware::Return<NfcStatus> prediscover() override;
+ ::android::hardware::Return<NfcStatus> close() override;
+ ::android::hardware::Return<NfcStatus> controlGranted() override;
+ ::android::hardware::Return<NfcStatus> powerCycle() override;
- virtual void serviceDied(uint64_t /*cookie*/, const wp<::android::hidl::base::V1_0::IBase>& /*who*/) {
- mNfc->close();
+ static void eventCallback(uint8_t event, uint8_t status) {
+ if (mCallback != nullptr) {
+ auto ret = mCallback->sendEvent((::android::hardware::nfc::V1_0::NfcEvent)event,
+ (::android::hardware::nfc::V1_0::NfcStatus)status);
+ if (!ret.isOk()) {
+ ALOGW("Failed to call back into NFC process.");
+ }
+ }
+ }
+ static void dataCallback(uint16_t data_len, uint8_t* p_data) {
+ hidl_vec<uint8_t> data;
+ data.setToExternal(p_data, data_len);
+ if (mCallback != nullptr) {
+ auto ret = mCallback->sendData(data);
+ if (!ret.isOk()) {
+ ALOGW("Failed to call back into NFC process.");
+ }
+ }
}
- sp<INfc> mNfc;
-};
-struct Nfc : public INfc {
- Nfc(nfc_nci_device_t* device);
- ::android::hardware::Return<NfcStatus> open(const sp<INfcClientCallback>& clientCallback) override;
- ::android::hardware::Return<uint32_t> write(const hidl_vec<uint8_t>& data) override;
- ::android::hardware::Return<NfcStatus> coreInitialized(const hidl_vec<uint8_t>& data) override;
- ::android::hardware::Return<NfcStatus> prediscover() override;
- ::android::hardware::Return<NfcStatus> close() override;
- ::android::hardware::Return<NfcStatus> controlGranted() override;
- ::android::hardware::Return<NfcStatus> powerCycle() override;
+ virtual void serviceDied(uint64_t /*cookie*/,
+ const wp<::android::hidl::base::V1_0::IBase>& /*who*/) {
+ close();
+ }
- static void eventCallback(uint8_t event, uint8_t status) {
- if (mCallback != nullptr) {
- auto ret = mCallback->sendEvent(
- (::android::hardware::nfc::V1_0::NfcEvent) event,
- (::android::hardware::nfc::V1_0::NfcStatus) status);
- if (!ret.isOk()) {
- ALOGW("Failed to call back into NFC process.");
- }
- }
- }
- static void dataCallback(uint16_t data_len, uint8_t* p_data) {
- hidl_vec<uint8_t> data;
- data.setToExternal(p_data, data_len);
- if (mCallback != nullptr) {
- auto ret = mCallback->sendData(data);
- if (!ret.isOk()) {
- ALOGW("Failed to call back into NFC process.");
- }
- }
- }
- private:
+ private:
static sp<INfcClientCallback> mCallback;
const nfc_nci_device_t* mDevice;
- sp<NfcDeathRecipient> mDeathRecipient;
};
extern "C" INfc* HIDL_FETCH_INfc(const char* name);