Loading tv/hdmi/cec/aidl/default/HdmiCecMock.cpp +19 −13 Original line number Original line Diff line number Diff line Loading @@ -35,8 +35,7 @@ namespace implementation { void HdmiCecMock::serviceDied(void* cookie) { void HdmiCecMock::serviceDied(void* cookie) { ALOGE("HdmiCecMock died"); ALOGE("HdmiCecMock died"); auto hdmiCecMock = static_cast<HdmiCecMock*>(cookie); auto hdmiCecMock = static_cast<HdmiCecMock*>(cookie); hdmiCecMock->mCecThreadRun = false; hdmiCecMock->closeCallback(); pthread_join(hdmiCecMock->mThreadId, NULL); } } ScopedAStatus HdmiCecMock::addLogicalAddress(CecLogicalAddress addr, Result* _aidl_return) { ScopedAStatus HdmiCecMock::addLogicalAddress(CecLogicalAddress addr, Result* _aidl_return) { Loading Loading @@ -86,10 +85,10 @@ ScopedAStatus HdmiCecMock::sendMessage(const CecMessage& message, SendMessageRes } } ScopedAStatus HdmiCecMock::setCallback(const std::shared_ptr<IHdmiCecCallback>& callback) { ScopedAStatus HdmiCecMock::setCallback(const std::shared_ptr<IHdmiCecCallback>& callback) { // If callback is null, mCallback is also set to null so we do not call the old callback. closeCallback(); mCallback = callback; if (callback != nullptr) { if (callback != nullptr) { mCallback = callback; mDeathRecipient = mDeathRecipient = ndk::ScopedAIBinder_DeathRecipient(AIBinder_DeathRecipient_new(serviceDied)); ndk::ScopedAIBinder_DeathRecipient(AIBinder_DeathRecipient_new(serviceDied)); AIBinder_linkToDeath(callback->asBinder().get(), mDeathRecipient.get(), this /* cookie */); AIBinder_linkToDeath(callback->asBinder().get(), mDeathRecipient.get(), this /* cookie */); Loading @@ -104,8 +103,8 @@ ScopedAStatus HdmiCecMock::setCallback(const std::shared_ptr<IHdmiCecCallback>& ScopedAStatus HdmiCecMock::setLanguage(const std::string& language) { ScopedAStatus HdmiCecMock::setLanguage(const std::string& language) { if (language.size() != 3) { if (language.size() != 3) { LOG(ERROR) << "Wrong language code: expected 3 letters, but it was " << language.size() ALOGE("[halimp_aidl] Wrong language code: expected 3 letters, but it was %zu", << "."; language.size()); return ScopedAStatus::ok(); return ScopedAStatus::ok(); } } // TODO Validate if language is a valid language code // TODO Validate if language is a valid language code Loading Loading @@ -169,7 +168,7 @@ int HdmiCecMock::sendMessageToFifo(const CecMessage& message) { // Open the output pipe for writing outgoing cec message // Open the output pipe for writing outgoing cec message mOutputFile = open(CEC_MSG_OUT_FIFO, O_WRONLY | O_CLOEXEC); mOutputFile = open(CEC_MSG_OUT_FIFO, O_WRONLY | O_CLOEXEC); if (mOutputFile < 0) { if (mOutputFile < 0) { ALOGD("[halimp_aidl] file open failed for writing"); ALOGE("[halimp_aidl] file open failed for writing"); return -1; return -1; } } Loading Loading @@ -258,18 +257,25 @@ void HdmiCecMock::threadLoop() { } } HdmiCecMock::HdmiCecMock() { HdmiCecMock::HdmiCecMock() { ALOGE("[halimp_aidl] Opening a virtual CEC HAL for testing and virtual machine."); ALOGD("[halimp_aidl] Opening a virtual CEC HAL for testing and virtual machine."); mCallback = nullptr; mCallback = nullptr; mDeathRecipient = ndk::ScopedAIBinder_DeathRecipient(nullptr); mDeathRecipient = ndk::ScopedAIBinder_DeathRecipient(nullptr); } } HdmiCecMock::~HdmiCecMock() { void HdmiCecMock::closeCallback() { ALOGE("[halimp_aidl] HdmiCecMock shutting down."); if (mCallback != nullptr) { ALOGD("[halimp_aidl] HdmiCecMock close the current callback."); mCallback = nullptr; mCallback = nullptr; mDeathRecipient = ndk::ScopedAIBinder_DeathRecipient(nullptr); mDeathRecipient = ndk::ScopedAIBinder_DeathRecipient(nullptr); mCecThreadRun = false; mCecThreadRun = false; pthread_join(mThreadId, NULL); pthread_join(mThreadId, NULL); } } } HdmiCecMock::~HdmiCecMock() { ALOGD("[halimp_aidl] HdmiCecMock shutting down."); closeCallback(); } } // namespace implementation } // namespace implementation } // namespace cec } // namespace cec Loading tv/hdmi/cec/aidl/default/HdmiCecMock.h +2 −2 Original line number Original line Diff line number Diff line Loading @@ -55,6 +55,7 @@ struct HdmiCecMock : public BnHdmiCec { ::ndk::ScopedAStatus enableCec(bool value) override; ::ndk::ScopedAStatus enableCec(bool value) override; ::ndk::ScopedAStatus enableSystemCecControl(bool value) override; ::ndk::ScopedAStatus enableSystemCecControl(bool value) override; void printCecMsgBuf(const char* msg_buf, int len); void printCecMsgBuf(const char* msg_buf, int len); void closeCallback(); private: private: static void* __threadLoop(void* data); static void* __threadLoop(void* data); Loading @@ -62,9 +63,8 @@ struct HdmiCecMock : public BnHdmiCec { int readMessageFromFifo(unsigned char* buf, int msgCount); int readMessageFromFifo(unsigned char* buf, int msgCount); int sendMessageToFifo(const CecMessage& message); int sendMessageToFifo(const CecMessage& message); void handleCecMessage(unsigned char* msgBuf, int length); void handleCecMessage(unsigned char* msgBuf, int length); private: static void serviceDied(void* cookie); static void serviceDied(void* cookie); std::shared_ptr<IHdmiCecCallback> mCallback; std::shared_ptr<IHdmiCecCallback> mCallback; // Variables for the virtual cec hal impl // Variables for the virtual cec hal impl Loading Loading
tv/hdmi/cec/aidl/default/HdmiCecMock.cpp +19 −13 Original line number Original line Diff line number Diff line Loading @@ -35,8 +35,7 @@ namespace implementation { void HdmiCecMock::serviceDied(void* cookie) { void HdmiCecMock::serviceDied(void* cookie) { ALOGE("HdmiCecMock died"); ALOGE("HdmiCecMock died"); auto hdmiCecMock = static_cast<HdmiCecMock*>(cookie); auto hdmiCecMock = static_cast<HdmiCecMock*>(cookie); hdmiCecMock->mCecThreadRun = false; hdmiCecMock->closeCallback(); pthread_join(hdmiCecMock->mThreadId, NULL); } } ScopedAStatus HdmiCecMock::addLogicalAddress(CecLogicalAddress addr, Result* _aidl_return) { ScopedAStatus HdmiCecMock::addLogicalAddress(CecLogicalAddress addr, Result* _aidl_return) { Loading Loading @@ -86,10 +85,10 @@ ScopedAStatus HdmiCecMock::sendMessage(const CecMessage& message, SendMessageRes } } ScopedAStatus HdmiCecMock::setCallback(const std::shared_ptr<IHdmiCecCallback>& callback) { ScopedAStatus HdmiCecMock::setCallback(const std::shared_ptr<IHdmiCecCallback>& callback) { // If callback is null, mCallback is also set to null so we do not call the old callback. closeCallback(); mCallback = callback; if (callback != nullptr) { if (callback != nullptr) { mCallback = callback; mDeathRecipient = mDeathRecipient = ndk::ScopedAIBinder_DeathRecipient(AIBinder_DeathRecipient_new(serviceDied)); ndk::ScopedAIBinder_DeathRecipient(AIBinder_DeathRecipient_new(serviceDied)); AIBinder_linkToDeath(callback->asBinder().get(), mDeathRecipient.get(), this /* cookie */); AIBinder_linkToDeath(callback->asBinder().get(), mDeathRecipient.get(), this /* cookie */); Loading @@ -104,8 +103,8 @@ ScopedAStatus HdmiCecMock::setCallback(const std::shared_ptr<IHdmiCecCallback>& ScopedAStatus HdmiCecMock::setLanguage(const std::string& language) { ScopedAStatus HdmiCecMock::setLanguage(const std::string& language) { if (language.size() != 3) { if (language.size() != 3) { LOG(ERROR) << "Wrong language code: expected 3 letters, but it was " << language.size() ALOGE("[halimp_aidl] Wrong language code: expected 3 letters, but it was %zu", << "."; language.size()); return ScopedAStatus::ok(); return ScopedAStatus::ok(); } } // TODO Validate if language is a valid language code // TODO Validate if language is a valid language code Loading Loading @@ -169,7 +168,7 @@ int HdmiCecMock::sendMessageToFifo(const CecMessage& message) { // Open the output pipe for writing outgoing cec message // Open the output pipe for writing outgoing cec message mOutputFile = open(CEC_MSG_OUT_FIFO, O_WRONLY | O_CLOEXEC); mOutputFile = open(CEC_MSG_OUT_FIFO, O_WRONLY | O_CLOEXEC); if (mOutputFile < 0) { if (mOutputFile < 0) { ALOGD("[halimp_aidl] file open failed for writing"); ALOGE("[halimp_aidl] file open failed for writing"); return -1; return -1; } } Loading Loading @@ -258,18 +257,25 @@ void HdmiCecMock::threadLoop() { } } HdmiCecMock::HdmiCecMock() { HdmiCecMock::HdmiCecMock() { ALOGE("[halimp_aidl] Opening a virtual CEC HAL for testing and virtual machine."); ALOGD("[halimp_aidl] Opening a virtual CEC HAL for testing and virtual machine."); mCallback = nullptr; mCallback = nullptr; mDeathRecipient = ndk::ScopedAIBinder_DeathRecipient(nullptr); mDeathRecipient = ndk::ScopedAIBinder_DeathRecipient(nullptr); } } HdmiCecMock::~HdmiCecMock() { void HdmiCecMock::closeCallback() { ALOGE("[halimp_aidl] HdmiCecMock shutting down."); if (mCallback != nullptr) { ALOGD("[halimp_aidl] HdmiCecMock close the current callback."); mCallback = nullptr; mCallback = nullptr; mDeathRecipient = ndk::ScopedAIBinder_DeathRecipient(nullptr); mDeathRecipient = ndk::ScopedAIBinder_DeathRecipient(nullptr); mCecThreadRun = false; mCecThreadRun = false; pthread_join(mThreadId, NULL); pthread_join(mThreadId, NULL); } } } HdmiCecMock::~HdmiCecMock() { ALOGD("[halimp_aidl] HdmiCecMock shutting down."); closeCallback(); } } // namespace implementation } // namespace implementation } // namespace cec } // namespace cec Loading
tv/hdmi/cec/aidl/default/HdmiCecMock.h +2 −2 Original line number Original line Diff line number Diff line Loading @@ -55,6 +55,7 @@ struct HdmiCecMock : public BnHdmiCec { ::ndk::ScopedAStatus enableCec(bool value) override; ::ndk::ScopedAStatus enableCec(bool value) override; ::ndk::ScopedAStatus enableSystemCecControl(bool value) override; ::ndk::ScopedAStatus enableSystemCecControl(bool value) override; void printCecMsgBuf(const char* msg_buf, int len); void printCecMsgBuf(const char* msg_buf, int len); void closeCallback(); private: private: static void* __threadLoop(void* data); static void* __threadLoop(void* data); Loading @@ -62,9 +63,8 @@ struct HdmiCecMock : public BnHdmiCec { int readMessageFromFifo(unsigned char* buf, int msgCount); int readMessageFromFifo(unsigned char* buf, int msgCount); int sendMessageToFifo(const CecMessage& message); int sendMessageToFifo(const CecMessage& message); void handleCecMessage(unsigned char* msgBuf, int length); void handleCecMessage(unsigned char* msgBuf, int length); private: static void serviceDied(void* cookie); static void serviceDied(void* cookie); std::shared_ptr<IHdmiCecCallback> mCallback; std::shared_ptr<IHdmiCecCallback> mCallback; // Variables for the virtual cec hal impl // Variables for the virtual cec hal impl Loading