1eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu/* 2eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu * Copyright (C) 2010 The Android Open Source Project 3eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu * 4eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu * Licensed under the Apache License, Version 2.0 (the "License"); 5eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu * you may not use this file except in compliance with the License. 6eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu * You may obtain a copy of the License at 7eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu * 8eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu * http://www.apache.org/licenses/LICENSE-2.0 9eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu * 10eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu * Unless required by applicable law or agreed to in writing, software 11eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu * distributed under the License is distributed on an "AS IS" BASIS, 12eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu * See the License for the specific language governing permissions and 14eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu * limitations under the License. 15eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu */ 16eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu 17eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu#include "SensorRecord.h" 18eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu 19eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu#include "SensorEventConnection.h" 20eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu 21eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xunamespace android { 22eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu 23eb4d628b69831d533f14c09fd63400f75e69ba76Peng XuSensorService::SensorRecord::SensorRecord( 24eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu const sp<SensorEventConnection>& connection) 25eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu{ 26eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu mConnections.add(connection); 27eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu} 28eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu 29eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xubool SensorService::SensorRecord::addConnection( 30eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu const sp<SensorEventConnection>& connection) 31eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu{ 32eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu if (mConnections.indexOf(connection) < 0) { 33eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu mConnections.add(connection); 34eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu return true; 35eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu } 36eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu return false; 37eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu} 38eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu 39eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xubool SensorService::SensorRecord::removeConnection( 40eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu const wp<SensorEventConnection>& connection) 41eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu{ 42eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu ssize_t index = mConnections.indexOf(connection); 43eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu if (index >= 0) { 44eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu mConnections.removeItemsAt(index, 1); 45eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu } 46eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu // Remove this connections from the queue of flush() calls made on this sensor. 47eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu for (Vector< wp<SensorEventConnection> >::iterator it = mPendingFlushConnections.begin(); 48eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu it != mPendingFlushConnections.end(); ) { 49eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu if (it->unsafe_get() == connection.unsafe_get()) { 50eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu it = mPendingFlushConnections.erase(it); 51eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu } else { 52eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu ++it; 53eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu } 54eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu } 55eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu return mConnections.size() ? false : true; 56eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu} 57eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu 58eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xuvoid SensorService::SensorRecord::addPendingFlushConnection( 59eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu const sp<SensorEventConnection>& connection) { 60eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu mPendingFlushConnections.add(connection); 61eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu} 62eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu 63eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xuvoid SensorService::SensorRecord::removeFirstPendingFlushConnection() { 64eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu if (mPendingFlushConnections.size() > 0) { 65eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu mPendingFlushConnections.removeAt(0); 66eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu } 67eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu} 68eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu 69eb4d628b69831d533f14c09fd63400f75e69ba76Peng XuSensorService::SensorEventConnection * 70eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu SensorService::SensorRecord::getFirstPendingFlushConnection() { 71eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu if (mPendingFlushConnections.size() > 0) { 72eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu return mPendingFlushConnections[0].unsafe_get(); 73eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu } 74eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu return NULL; 75eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu} 76eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu 77eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xuvoid SensorService::SensorRecord::clearAllPendingFlushConnections() { 78eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu mPendingFlushConnections.clear(); 79eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu} 80eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu 81eb4d628b69831d533f14c09fd63400f75e69ba76Peng Xu} // namespace android 82