text: /* Copyright Statement:
   *
   * This software/firmware and related documentation ("MediaTek Software") are
   * protected under relevant copyright laws. The information contained herein
   * is confidential and proprietary to MediaTek Inc. and/or its licensors.
   * Without the prior written permission of MediaTek inc. and/or its licensors,
   * any reproduction, modification, use or disclosure of MediaTek Software,
   * and information contained herein, in whole or in part, shall be strictly prohibited.
   */
  /* MediaTek Inc. (C) 2012. All rights reserved.
   *
   * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
   * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
   * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON
   * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
   * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
   * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
   * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
   * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
   * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
   * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
   * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
   * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
   * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
   * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
   * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
   * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
   * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
   * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
   *
   * The following software/firmware and/or related documentation ("MediaTek Software")
   * have been modified by MediaTek Inc. All revisions are subject to any receiver's
   * applicable license agreements with MediaTek Inc.
   */
  
  #include <fcntl.h>
  #include <errno.h>
  #include <math.h>
  #include <poll.h>
  #include <unistd.h>
  #include <dirent.h>
  #include <sys/select.h>
  #include <cutils/log.h>
  #include <linux/input.h>
  #include "SensorBase.h"
  #include <utils/SystemClock.h>
  #include <string.h>
  
  #ifdef LOG_TAG
  #undef LOG_TAG
  #define LOG_TAG "SensorBase"
  #endif
  
  
  /*****************************************************************************/
  
  SensorBase::SensorBase(
          const char* dev_name,
          const char* data_name)
      : dev_name(dev_name), data_name(data_name),
        dev_fd(-1), data_fd(-1)
  {
      //data_fd = openInput(data_name);
  }
  
  SensorBase::~SensorBase() {
      if (data_fd >= 0) {
          close(data_fd);
      }
      if (dev_fd >= 0) {
          close(dev_fd);
      }
  }
  
  int SensorBase::open_device() {
      if (dev_fd<0 && dev_name) {
          dev_fd = open(dev_name, O_RDONLY);
          ALOGE_IF(dev_fd<0, "Couldn't open %s (%s)", dev_name, strerror(errno));
      }
      return 0;
  }
  
  int SensorBase::close_device() {
      if (dev_fd >= 0) {
          close(dev_fd);
          dev_fd = -1;
      }
      return 0;
  }
  
  int SensorBase::getFd() const {
      return data_fd;
  }
  
  int SensorBase::setDelay(int32_t handle, int64_t ns) {
      ALOGD("handle=%d,ns=%lld\n",handle,ns);
      return 0;
  }
  
  bool SensorBase::hasPendingEvents() const {
      return false;
  }
  
  int64_t SensorBase::getTimestamp() {
      return android::elapsedRealtimeNano();
  }
  /*
  int SensorBase::openInput(const char* inputName) {
      int fd = -1;
      const char *dirname = "/dev/input";
      char devname[PATH_MAX];
      char *filename;
      DIR *dir;
      struct dirent *de;
      dir = opendir(dirname);
      if(dir == NULL)
          return -1;
      strcpy(devname, dirname);
      filename = devname + strlen(devname);
      *filename++ = '/';
      while((de = readdir(dir))) {
          if(de->d_name[0] == '.' &&
                  (de->d_name[1] == '\0' ||
                          (de->d_name[1] == '.' && de->d_name[2] == '\0')))
              continue;
          strcpy(filename, de->d_name);
          fd = open(devname, O_RDONLY);
          if (fd>=0) {
              char name[80];
              if (ioctl(fd, EVIOCGNAME(sizeof(name) - 1), &name) < 1) {
                  name[0] = '\0';
              }
              if (!strcmp(name, inputName)) {
                  break;
              } else {
                  close(fd);
                  fd = -1;
              }
          }
      }
      closedir(dir);
      ALOGE_IF(fd<0, "couldn't find '%s' input device", inputName);
      return fd;
  }
  */
  