summaryrefslogtreecommitdiff
path: root/libs/gui/SensorManager.cpp
diff options
context:
space:
mode:
authorMathias Agopian <mathias@google.com>2010-07-14 23:41:37 -0700
committerMathias Agopian <mathias@google.com>2010-07-19 17:57:29 -0700
commit1bf797857e025e8a71db86fb9e79765a767ec1eb (patch)
treee8d1aabae069f2b7368be746b99667eb150363f5 /libs/gui/SensorManager.cpp
parentff7049ab2886acc73e145367118646f7741ce333 (diff)
new SensorService
remove old sensor service and implement SensorManager on top of the new (native) SensorManger API. Change-Id: Iddb77d498755da3e11646473a44d651f12f40281
Diffstat (limited to 'libs/gui/SensorManager.cpp')
-rw-r--r--libs/gui/SensorManager.cpp31
1 files changed, 25 insertions, 6 deletions
diff --git a/libs/gui/SensorManager.cpp b/libs/gui/SensorManager.cpp
index cd892851f74d..d719efb5f11e 100644
--- a/libs/gui/SensorManager.cpp
+++ b/libs/gui/SensorManager.cpp
@@ -14,6 +14,8 @@
* limitations under the License.
*/
+#define LOG_TAG "Sensors"
+
#include <stdint.h>
#include <sys/types.h>
@@ -21,6 +23,8 @@
#include <utils/RefBase.h>
#include <utils/Singleton.h>
+#include <binder/IServiceManager.h>
+
#include <gui/ISensorServer.h>
#include <gui/ISensorEventConnection.h>
#include <gui/Sensor.h>
@@ -36,25 +40,40 @@ ANDROID_SINGLETON_STATIC_INSTANCE(SensorManager)
SensorManager::SensorManager()
: mSensorList(0)
{
+ const String16 name("sensorservice");
+ while (getService(name, &mSensorServer) != NO_ERROR) {
+ usleep(250000);
+ }
+
mSensors = mSensorServer->getSensorList();
- // TODO: needs implementation
+ size_t count = mSensors.size();
+ mSensorList = (Sensor const**)malloc(count * sizeof(Sensor*));
+ for (size_t i=0 ; i<count ; i++) {
+ mSensorList[i] = mSensors.array() + i;
+ }
}
SensorManager::~SensorManager()
{
- // TODO: needs implementation
+ free(mSensorList);
}
-ssize_t SensorManager::getSensorList(Sensor** list) const
+ssize_t SensorManager::getSensorList(Sensor const* const** list) const
{
*list = mSensorList;
return mSensors.size();
}
-Sensor* SensorManager::getDefaultSensor(int type)
+Sensor const* SensorManager::getDefaultSensor(int type)
{
- // TODO: needs implementation
- return mSensorList;
+ // For now we just return the first sensor of that type we find.
+ // in the future it will make sense to let the SensorService make
+ // that decision.
+ for (size_t i=0 ; i<mSensors.size() ; i++) {
+ if (mSensorList[i]->getType() == type)
+ return mSensorList[i];
+ }
+ return NULL;
}
sp<SensorEventQueue> SensorManager::createEventQueue()