Home | History | Annotate | Download | only in gui
      1 /*
      2  * Copyright (C) 2010 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #include <stdint.h>
     18 #include <sys/types.h>
     19 
     20 #include <utils/Errors.h>
     21 #include <utils/RefBase.h>
     22 #include <utils/Vector.h>
     23 #include <utils/Timers.h>
     24 
     25 #include <binder/Parcel.h>
     26 #include <binder/IInterface.h>
     27 
     28 #include <gui/Sensor.h>
     29 #include <gui/ISensorServer.h>
     30 #include <gui/ISensorEventConnection.h>
     31 
     32 namespace android {
     33 // ----------------------------------------------------------------------------
     34 
     35 enum {
     36     GET_SENSOR_LIST = IBinder::FIRST_CALL_TRANSACTION,
     37     CREATE_SENSOR_EVENT_CONNECTION,
     38 };
     39 
     40 class BpSensorServer : public BpInterface<ISensorServer>
     41 {
     42 public:
     43     BpSensorServer(const sp<IBinder>& impl)
     44         : BpInterface<ISensorServer>(impl)
     45     {
     46     }
     47 
     48     virtual Vector<Sensor> getSensorList()
     49     {
     50         Parcel data, reply;
     51         data.writeInterfaceToken(ISensorServer::getInterfaceDescriptor());
     52         remote()->transact(GET_SENSOR_LIST, data, &reply);
     53         Sensor s;
     54         Vector<Sensor> v;
     55         int32_t n = reply.readInt32();
     56         v.setCapacity(n);
     57         while (n--) {
     58             reply.read(s);
     59             v.add(s);
     60         }
     61         return v;
     62     }
     63 
     64     virtual sp<ISensorEventConnection> createSensorEventConnection()
     65     {
     66         Parcel data, reply;
     67         data.writeInterfaceToken(ISensorServer::getInterfaceDescriptor());
     68         remote()->transact(CREATE_SENSOR_EVENT_CONNECTION, data, &reply);
     69         return interface_cast<ISensorEventConnection>(reply.readStrongBinder());
     70     }
     71 };
     72 
     73 IMPLEMENT_META_INTERFACE(SensorServer, "android.gui.SensorServer");
     74 
     75 // ----------------------------------------------------------------------
     76 
     77 status_t BnSensorServer::onTransact(
     78     uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
     79 {
     80     switch(code) {
     81         case GET_SENSOR_LIST: {
     82             CHECK_INTERFACE(ISensorServer, data, reply);
     83             Vector<Sensor> v(getSensorList());
     84             size_t n = v.size();
     85             reply->writeInt32(n);
     86             for (size_t i=0 ; i<n ; i++) {
     87                 reply->write(v[i]);
     88             }
     89             return NO_ERROR;
     90         } break;
     91         case CREATE_SENSOR_EVENT_CONNECTION: {
     92             CHECK_INTERFACE(ISensorServer, data, reply);
     93             sp<ISensorEventConnection> connection(createSensorEventConnection());
     94             reply->writeStrongBinder(connection->asBinder());
     95             return NO_ERROR;
     96         } break;
     97     }
     98     return BBinder::onTransact(code, data, reply, flags);
     99 }
    100 
    101 // ----------------------------------------------------------------------------
    102 }; // namespace android
    103