mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 15:58:43 +00:00
Merge "move foocallback to hidl_test"
am: 0270fefc48
Change-Id: I8ae866482cb76ccbdd4968c27025270701d98f51
This commit is contained in:
@@ -5,7 +5,6 @@ cc_library_shared {
|
||||
relative_install_path: "hw",
|
||||
srcs: [
|
||||
"Foo.cpp",
|
||||
"FooCallback.cpp",
|
||||
],
|
||||
|
||||
shared_libs: [
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#define LOG_TAG "hidl_test"
|
||||
|
||||
#include "Foo.h"
|
||||
#include "FooCallback.h"
|
||||
#include <android-base/logging.h>
|
||||
#include <hidl-test/FooHelper.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
@@ -1,134 +0,0 @@
|
||||
|
||||
#define LOG_TAG "hidl_test"
|
||||
|
||||
#include "FooCallback.h"
|
||||
#include <android/log.h>
|
||||
#include <hidl-test/FooHelper.h>
|
||||
#include <inttypes.h>
|
||||
#include <utils/Timers.h>
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace tests {
|
||||
namespace foo {
|
||||
namespace V1_0 {
|
||||
namespace implementation {
|
||||
|
||||
enum {
|
||||
NOT_REPORTED = -1LL
|
||||
};
|
||||
|
||||
FooCallback::FooCallback()
|
||||
: mLock{}, mCond{} {
|
||||
for (size_t i = 0; i < invokeInfo.size(); i++) {
|
||||
invokeInfo[i].invoked = false;
|
||||
invokeInfo[i].timeNs = NOT_REPORTED;
|
||||
invokeInfo[i].callerBlockedNs = NOT_REPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
Return<void> FooCallback::heyItsYou(
|
||||
const sp<IFooCallback> &_cb) {
|
||||
nsecs_t start = systemTime();
|
||||
ALOGI("SERVER(FooCallback) 1: heyItsYou cb = %p", _cb.get());
|
||||
nsecs_t end = systemTime();
|
||||
{
|
||||
Mutex::Autolock lock(mLock);
|
||||
invokeInfo[0].invoked = true;
|
||||
invokeInfo[0].timeNs = end - start;
|
||||
mCond.signal();
|
||||
}
|
||||
ALOGI("SERVER(FooCallback) 2: heyItsYou returned");
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<bool> FooCallback::heyItsYouIsntIt(const sp<IFooCallback> &_cb) {
|
||||
nsecs_t start = systemTime();
|
||||
ALOGI("SERVER(FooCallback) 3: heyItsYouIsntIt cb = %p sleeping for %" PRId64 " seconds", _cb.get(), DELAY_S);
|
||||
sleep(DELAY_S);
|
||||
ALOGI("SERVER(FooCallback) 4: heyItsYouIsntIt cb = %p responding", _cb.get());
|
||||
nsecs_t end = systemTime();
|
||||
{
|
||||
Mutex::Autolock lock(mLock);
|
||||
invokeInfo[1].invoked = true;
|
||||
invokeInfo[1].timeNs = end - start;
|
||||
mCond.signal();
|
||||
}
|
||||
ALOGI("SERVER(FooCallback) 5: heyItsYouIsntIt cb = %p responding", _cb.get());
|
||||
return true;
|
||||
}
|
||||
|
||||
Return<void> FooCallback::heyItsTheMeaningOfLife(uint8_t tmol) {
|
||||
nsecs_t start = systemTime();
|
||||
ALOGI("SERVER(FooCallback) 6.1: heyItsTheMeaningOfLife = %d sleeping for %" PRId64 " seconds", tmol, DELAY_S);
|
||||
sleep(DELAY_S);
|
||||
ALOGI("SERVER(FooCallback) 6.2: heyItsTheMeaningOfLife = %d done sleeping", tmol);
|
||||
nsecs_t end = systemTime();
|
||||
{
|
||||
Mutex::Autolock lock(mLock);
|
||||
invokeInfo[2].invoked = true;
|
||||
invokeInfo[2].timeNs = end - start;
|
||||
mCond.signal();
|
||||
}
|
||||
ALOGI("SERVER(FooCallback) 6.3: heyItsTheMeaningOfLife returned");
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> FooCallback::reportResults(int64_t ns, reportResults_cb cb) {
|
||||
ALOGI("SERVER(FooCallback) 8.1: reportResults(%" PRId64 " seconds)", nanoseconds_to_seconds(ns));
|
||||
nsecs_t leftToWaitNs = ns;
|
||||
bool cond;
|
||||
{
|
||||
Mutex::Autolock lock(mLock);
|
||||
while ((cond = ((!invokeInfo[0].invoked ||
|
||||
!invokeInfo[1].invoked ||
|
||||
!invokeInfo[2].invoked ||
|
||||
invokeInfo[0].callerBlockedNs == NOT_REPORTED ||
|
||||
invokeInfo[1].callerBlockedNs == NOT_REPORTED ||
|
||||
invokeInfo[2].callerBlockedNs == NOT_REPORTED) &&
|
||||
leftToWaitNs > 0))) {
|
||||
nsecs_t start = systemTime();
|
||||
::android::status_t rc = mCond.waitRelative(mLock, leftToWaitNs);
|
||||
if (rc != ::android::OK) {
|
||||
ALOGW("SERVER(FooCallback)::reportResults(%" PRId64 " ns) Condition::waitRelative(%" PRId64 ") returned error (%d)", ns, leftToWaitNs, rc);
|
||||
if (rc == -ETIMEDOUT) {
|
||||
// time's up
|
||||
leftToWaitNs = -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
ALOGI("SERVER(FooCallback)::reportResults(%" PRId64 " ns) Condition::waitRelative was signalled", ns);
|
||||
leftToWaitNs -= systemTime() - start;
|
||||
}
|
||||
}
|
||||
ALOGI("SERVER(FooCallback) 8.2: reportResults returned;"
|
||||
"invoked? %d, %d, %d; leftToWaitNs = %" PRId64 "; cond = %d",
|
||||
invokeInfo[0].invoked, invokeInfo[1].invoked, invokeInfo[2].invoked,
|
||||
leftToWaitNs, cond);
|
||||
cb(leftToWaitNs, invokeInfo);
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> FooCallback::youBlockedMeFor(const hidl_array<int64_t, 3> &ns) {
|
||||
ALOGI("SERVER(FooCallback) 7.1: youBlockedMeFor");
|
||||
{
|
||||
Mutex::Autolock lock(mLock);
|
||||
for (size_t i = 0; i < 3; i++) {
|
||||
invokeInfo[i].callerBlockedNs = ns[i];
|
||||
}
|
||||
mCond.signal();
|
||||
}
|
||||
ALOGI("SERVER(FooCallback) 7.2: returned");
|
||||
return Void();
|
||||
}
|
||||
|
||||
IFooCallback* HIDL_FETCH_IFooCallback(const char* /* name */) {
|
||||
return new FooCallback();
|
||||
}
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_0
|
||||
} // namespace foo
|
||||
} // namespace tests
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
@@ -1,46 +0,0 @@
|
||||
#ifndef ANDROID_HARDWARE_TESTS_FOO_V1_0_FOOCALLBACK_H
|
||||
#define ANDROID_HARDWARE_TESTS_FOO_V1_0_FOOCALLBACK_H
|
||||
|
||||
#include <android/hardware/tests/foo/1.0/IFooCallback.h>
|
||||
#include <hidl/Status.h>
|
||||
#include <hidl/MQDescriptor.h>
|
||||
|
||||
#include <utils/Condition.h>
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace tests {
|
||||
namespace foo {
|
||||
namespace V1_0 {
|
||||
namespace implementation {
|
||||
|
||||
using ::android::hardware::tests::foo::V1_0::IFooCallback;
|
||||
using ::android::hardware::Return;
|
||||
using ::android::hardware::Void;
|
||||
using ::android::hardware::hidl_vec;
|
||||
using ::android::hardware::hidl_string;
|
||||
using ::android::sp;
|
||||
|
||||
struct FooCallback : public IFooCallback {
|
||||
FooCallback();
|
||||
// Methods from ::android::hardware::tests::foo::V1_0::IFooCallback follow.
|
||||
Return<void> heyItsYou(const sp<IFooCallback>& cb) override;
|
||||
Return<bool> heyItsYouIsntIt(const sp<IFooCallback>& cb) override;
|
||||
Return<void> heyItsTheMeaningOfLife(uint8_t tmol) override;
|
||||
Return<void> reportResults(int64_t ns, reportResults_cb _hidl_cb) override;
|
||||
Return<void> youBlockedMeFor(const hidl_array<int64_t, 3 /* 3 */>& callerBlockedInfo) override;
|
||||
|
||||
hidl_array<InvokeInfo, 3> invokeInfo;
|
||||
Mutex mLock;
|
||||
Condition mCond;
|
||||
};
|
||||
|
||||
extern "C" IFooCallback* HIDL_FETCH_IFooCallback(const char* name);
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace V1_0
|
||||
} // namespace foo
|
||||
} // namespace tests
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
|
||||
#endif // ANDROID_HARDWARE_TESTS_FOO_V1_0_FOOCALLBACK_H
|
||||
Reference in New Issue
Block a user