MultiHal 2.0 - proxying api calls helper methods

Create getSubHalForSensorHandle method which will get the proper subhal
pointer by getting the subhal list index from the first byte of the
sensor handle. Create the zeroOutFirstByte static helper method that
will return a version of the sensor handle without the first byte when
passed a handle.

Test: Tested compilation.
Bug: 136511617
Change-Id: I7d07003e1903aa1d8abaf904b778248c7b352653
This commit is contained in:
Stan Rokita
2019-09-10 14:54:36 -07:00
parent d909580269
commit 1638531dfb
2 changed files with 26 additions and 0 deletions

View File

@@ -218,6 +218,14 @@ Return<void> HalProxy::onDynamicSensorsDisconnected(
return Return<void>();
}
ISensorsSubHal* HalProxy::getSubHalForSensorHandle(uint32_t sensorHandle) {
return mSubHalList[static_cast<size_t>(sensorHandle >> 24)];
}
uint32_t HalProxy::zeroOutFirstByte(uint32_t num) {
return num & 0x00FFFFFF;
}
} // namespace implementation
} // namespace V2_0
} // namespace sensors

View File

@@ -118,6 +118,24 @@ struct HalProxy : public ISensors {
* SubHal object pointers that have been saved from vendor dynamic libraries.
*/
std::vector<ISensorsSubHal*> mSubHalList;
/*
* Get the subhal pointer which can be found by indexing into the mSubHalList vector
* using the index from the first byte of sensorHandle.
*
* @param sensorHandle The handle used to identify a sensor in one of the subhals.
*/
ISensorsSubHal* getSubHalForSensorHandle(uint32_t sensorHandle);
/*
* Zero out the first (most significant) byte in a number. Used in modifying the sensor handles
* before passing them to subhals.
*
* @param num The uint32_t number to work with.
*
* @return The modified version of num param.
*/
static uint32_t zeroOutFirstByte(uint32_t num);
};
} // namespace implementation