Home | History | Annotate | Download | only in dynamic_sensor
      1 /*
      2  * Copyright (C) 2017 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 #include "HidRawSensorDaemon.h"
     17 #include "ConnectionDetector.h"
     18 #include "DynamicSensorManager.h"
     19 #include "HidRawSensorDevice.h"
     20 
     21 #include <utils/Log.h>
     22 #include <utils/SystemClock.h>
     23 
     24 #include <errno.h>
     25 #include <stdio.h>
     26 #include <stdlib.h>
     27 #include <unistd.h>
     28 
     29 #include <iomanip>
     30 #include <sstream>
     31 
     32 #define DEV_PATH                "/dev/"
     33 #define DEV_NAME_REGEX          "^hidraw[0-9]+$"
     34 
     35 namespace android {
     36 namespace SensorHalExt {
     37 
     38 HidRawSensorDaemon::HidRawSensorDaemon(DynamicSensorManager& manager)
     39         : BaseDynamicSensorDaemon(manager) {
     40     mDetector = new FileConnectionDetector(
     41             this, std::string(DEV_PATH), std::string(DEV_NAME_REGEX));
     42 }
     43 
     44 BaseSensorVector HidRawSensorDaemon::createSensor(const std::string &deviceKey) {
     45     BaseSensorVector ret;
     46     sp<HidRawSensorDevice> device(HidRawSensorDevice::create(deviceKey));
     47 
     48     if (device != nullptr) {
     49         ALOGV("created HidRawSensorDevice(%p) successfully on device %s contains %zu sensors",
     50               device.get(), deviceKey.c_str(), device->getSensors().size());
     51 
     52         // convert type
     53         for (auto &i : device->getSensors()) {
     54             ret.push_back(i);
     55         }
     56         mHidRawSensorDevices.emplace(deviceKey, device);
     57     } else {
     58         ALOGE("failed to create HidRawSensorDevice object");
     59     }
     60 
     61     ALOGE("return %zu sensors", ret.size());
     62     return ret;
     63 }
     64 
     65 void HidRawSensorDaemon::removeSensor(const std::string &deviceKey) {
     66     mHidRawSensorDevices.erase(deviceKey);
     67 }
     68 
     69 } // namespace SensorHalExt
     70 } // namespace android
     71 
     72