gs-common/modem: clock manager interface
A lot of modem code requires sleeping while vendor services do some background processing. Since we don't want to actually sleep for unit tests, an interface is provided here so that a fake sleep can be injected. Test: N/A. Directly forwards methods or does nothing. Bug: 302435001 Change-Id: I3bcf0307156d93756d69cd9f749c88b508ba9466
This commit is contained in:
parent
047f0aca49
commit
0944a8db52
7 changed files with 111 additions and 0 deletions
9
modem/clock_manager/Android.bp
Normal file
9
modem/clock_manager/Android.bp
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
package {
|
||||||
|
default_applicable_licenses: ["Android-Apache-2.0"],
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_library {
|
||||||
|
name: "modem_clock_manager",
|
||||||
|
export_include_dirs: [ "include" ],
|
||||||
|
vendor_available: true,
|
||||||
|
}
|
15
modem/clock_manager/fake/Android.bp
Normal file
15
modem/clock_manager/fake/Android.bp
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package {
|
||||||
|
default_applicable_licenses: ["Android-Apache-2.0"],
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_defaults {
|
||||||
|
name: "fake_modem_clock_manager_defaults",
|
||||||
|
shared_libs: [ "modem_clock_manager" ],
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_library_static {
|
||||||
|
name: "fake_modem_clock_manager",
|
||||||
|
export_include_dirs: [ "include" ],
|
||||||
|
defaults: [ "fake_modem_clock_manager_defaults" ],
|
||||||
|
vendor_available: true,
|
||||||
|
}
|
21
modem/clock_manager/fake/include/fake_clock_manager.h
Normal file
21
modem/clock_manager/fake/include/fake_clock_manager.h
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#include "clock_manager.h"
|
||||||
|
|
||||||
|
namespace pixel_modem {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Fake implementation of clock manager that doesn't actually sleep.
|
||||||
|
*
|
||||||
|
* A lot of vendor code don't have return values and instead force the client
|
||||||
|
* codes to sleep for a specified period of time before checking some system
|
||||||
|
* properties. However, since unit tests don't rely on the real vendor
|
||||||
|
* implementations, these sleeps should be ignored and so a fake clock should be
|
||||||
|
* used.
|
||||||
|
*
|
||||||
|
* Since this definition is unlikely to change, it will be defined in the header
|
||||||
|
* and not an implementation file.
|
||||||
|
*/
|
||||||
|
struct FakeClockManager : public ClockManager {
|
||||||
|
void Sleep(size_t /*seconds*/) const override{};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace pixel_modem
|
16
modem/clock_manager/impl/Android.bp
Normal file
16
modem/clock_manager/impl/Android.bp
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
package {
|
||||||
|
default_applicable_licenses: ["Android-Apache-2.0"],
|
||||||
|
}
|
||||||
|
|
||||||
|
modem_clock_manager_impl_public_deps = [
|
||||||
|
"modem_clock_manager",
|
||||||
|
]
|
||||||
|
|
||||||
|
cc_library {
|
||||||
|
name: "modem_clock_manager_impl",
|
||||||
|
export_include_dirs: [ "include" ],
|
||||||
|
srcs: [ "clock_manager_impl.cpp" ],
|
||||||
|
shared_libs: modem_clock_manager_impl_public_deps,
|
||||||
|
export_shared_lib_headers: modem_clock_manager_impl_public_deps,
|
||||||
|
vendor_available: true,
|
||||||
|
}
|
9
modem/clock_manager/impl/clock_manager_impl.cpp
Normal file
9
modem/clock_manager/impl/clock_manager_impl.cpp
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#include "clock_manager_impl.h"
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
namespace pixel_modem {
|
||||||
|
|
||||||
|
void ClockManagerImpl::Sleep(size_t seconds) const { sleep(seconds); }
|
||||||
|
|
||||||
|
} // namespace pixel_modem
|
13
modem/clock_manager/impl/include/clock_manager_impl.h
Normal file
13
modem/clock_manager/impl/include/clock_manager_impl.h
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
|
#include "clock_manager.h"
|
||||||
|
|
||||||
|
namespace pixel_modem {
|
||||||
|
|
||||||
|
struct ClockManagerImpl : public ClockManager {
|
||||||
|
void Sleep(size_t seconds) const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace pixel_modem
|
28
modem/clock_manager/include/clock_manager.h
Normal file
28
modem/clock_manager/include/clock_manager.h
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
|
namespace pixel_modem {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Interface for time based operations.
|
||||||
|
*
|
||||||
|
* This interface was intentionally not called `Clock`, like the Java side
|
||||||
|
* counterpart since it's likely that clients would call the local variable
|
||||||
|
* `clock(_)`, which would clash with the C defined `clock` method.
|
||||||
|
*/
|
||||||
|
struct ClockManager {
|
||||||
|
virtual ~ClockManager() = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sleep the thread for a given number of seconds.
|
||||||
|
*
|
||||||
|
* @param seconds Minimum number of seconds to sleep for. Note, this is
|
||||||
|
* different than the Java android clock which accepts seconds. This was done
|
||||||
|
* because C++ developers are likely more familiar with the `sleep` command,
|
||||||
|
* which accepts seconds.
|
||||||
|
*/
|
||||||
|
virtual void Sleep(size_t seconds) const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace pixel_modem
|
Loading…
Add table
Add a link
Reference in a new issue