%define accel_state ON
%define gyro_state OFF
-%define proxi_state ON
+%define proxi_state OFF
%define light_state OFF
%define geo_state OFF
%define pressure_state OFF
add_library(${PROJECT_NAME} SHARED
${SRCS}
- lib/cbase_lock.cpp
lib/cconfig.cpp
- lib/cmutex.cpp
lib/csensor_config.cpp
lib/sensor_logs.cpp
interface/sensor_hal_base.cpp
using std::fstream;
using std::string;
-cmutex sensor_hal_base::m_shared_mutex;
-
sensor_hal_base::sensor_hal_base()
{
}
{
int prev_status, status;
- AUTOLOCK(m_shared_mutex);
-
if (!get_node_value(node_path, prev_status)) {
ERR("Failed to get node: %s", node_path.c_str());
return false;
#define _SENSOR_HAL_BASE_H_
#include <sys/time.h>
#include <sensor_common.h>
-#include <cmutex.h>
#include <sensor_logs.h>
#include <string>
#include <sensor_hal.h>
int send_sensorhub_data(const char *data, int data_len);
protected:
- cmutex m_mutex;
- static cmutex m_shared_mutex;
-
bool set_enable_node(const std::string &node_path, bool sensorhub_controlled, bool enable, int enable_bit = 0);
static unsigned long long get_timestamp(void);
+++ /dev/null
-/*
- * libsensord-share
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <pthread.h>
-#include <cbase_lock.h>
-#include <stdio.h>
-#include <sensor_logs.h>
-#include <errno.h>
-#include <sys/time.h>
-
-
-cbase_lock::cbase_lock()
-{
- m_history_mutex = PTHREAD_MUTEX_INITIALIZER;
-}
-
-cbase_lock::~cbase_lock()
-{
- pthread_mutex_destroy(&m_history_mutex);
-}
-
-void cbase_lock::lock(lock_type type, const char* expr, const char *module, const char *func, int line)
-{
- int ret = 0;
- char m_curent_info[OWNER_INFO_LEN];
- struct timeval sv;
- unsigned long long lock_waiting_start_time = 0;
- unsigned long long lock_acquired_time = 0;
- unsigned long long waiting_time = 0;
-
-
- snprintf(m_curent_info, OWNER_INFO_LEN, "%s:%s(%d)", module, func, line);
-
- if (type == LOCK_TYPE_MUTEX)
- ret = try_lock_impl();
- else if (type == LOCK_TYPE_READ)
- ret = try_read_lock_impl();
- else if (type == LOCK_TYPE_WRITE)
- ret = try_write_lock_impl();
-
- if (ret == 0) {
- pthread_mutex_lock(&m_history_mutex);
- snprintf(m_owner_info, OWNER_INFO_LEN, "%s", m_curent_info);
- pthread_mutex_unlock(&m_history_mutex);
- return;
- }
-
- gettimeofday(&sv, NULL);
- lock_waiting_start_time = MICROSECONDS(sv);
-
- pthread_mutex_lock(&m_history_mutex);
- INFO("%s is waiting for getting %s(0x%x) owned in %s",
- m_curent_info, expr, this, m_owner_info);
- pthread_mutex_unlock(&m_history_mutex);
-
-
- if (type == LOCK_TYPE_MUTEX)
- lock_impl();
- else if (type == LOCK_TYPE_READ)
- read_lock_impl();
- else if (type == LOCK_TYPE_WRITE)
- write_lock_impl();
-
- gettimeofday(&sv, NULL);
- lock_acquired_time = MICROSECONDS(sv);
-
- waiting_time = lock_acquired_time - lock_waiting_start_time;
-
- pthread_mutex_lock(&m_history_mutex);
- INFO("%s acquires lock after waiting %lluus, %s(0x%x) was previously owned in %s",
- m_curent_info, waiting_time, expr, this, m_owner_info);
- snprintf(m_owner_info, OWNER_INFO_LEN, "%s", m_curent_info);
- pthread_mutex_unlock(&m_history_mutex);
-}
-
-
-void cbase_lock::lock(lock_type type)
-{
- if (type == LOCK_TYPE_MUTEX)
- lock_impl();
- else if (type == LOCK_TYPE_READ)
- read_lock_impl();
- else if (type == LOCK_TYPE_WRITE)
- write_lock_impl();
-}
-
-void cbase_lock::unlock(void)
-{
- unlock_impl();
-}
-
-
-int cbase_lock::lock_impl(void)
-{
- return 0;
-}
-
-int cbase_lock::read_lock_impl(void)
-{
- return 0;
-}
-
-int cbase_lock::write_lock_impl(void)
-{
- return 0;
-}
-
-int cbase_lock::try_lock_impl(void)
-{
- return 0;
-}
-
-int cbase_lock::try_read_lock_impl(void)
-{
- return 0;
-}
-
-int cbase_lock::try_write_lock_impl(void)
-{
- return 0;
-}
-
-int cbase_lock::unlock_impl(void)
-{
- return 0;
-}
-
-Autolock::Autolock(cbase_lock &m, lock_type type, const char* expr, const char *module, const char *func, int line)
-: m_lock(m)
-{
- m_lock.lock(type, expr, module, func, line);
-}
-
-Autolock::Autolock(cbase_lock &m, lock_type type)
-: m_lock(m)
-{
- m_lock.lock(type);
-}
-
-Autolock::~Autolock()
-{
- m_lock.unlock();
-}
+++ /dev/null
-/*
- * libsensord-share
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#if !defined(_CBASE_LOCK_CLASS_H_)
-#define _CBASE_LOCK_CLASS_H_
-
-#include <pthread.h>
-
-enum lock_type {
- LOCK_TYPE_MUTEX,
- LOCK_TYPE_READ,
- LOCK_TYPE_WRITE,
-};
-
-#ifdef _LOCK_DEBUG
-#define AUTOLOCK(x) Autolock x##_autolock((x),LOCK_TYPE_MUTEX, #x, __MODULE__, __func__, __LINE__)
-#define AUTOLOCK_R(x) Autolock x##_autolock_r((x),LOCK_TYPE_READ, #x, __MODULE__, __func__, __LINE__)
-#define AUTOLOCK_W(x) Autolock x##_autolock_w((x),LOCK_TYPE_WRITE, #x, __MODULE__, __func__, __LINE__)
-#define LOCK(x) (x).lock(#x, __MODULE__, __func__, __LINE__)
-#define LOCK_R(x) (x).lock(LOCK_TYPE_READ, #x, __MODULE__, __func__, __LINE__)
-#define LOCK_W(x) (x).lock(LOCK_TYPE_WRITE, #x, __MODULE__, __func__, __LINE__)
-#define UNLOCK(x) (x).unlock()
-#else
-#define AUTOLOCK(x) Autolock x##_autolock((x),LOCK_TYPE_MUTEX)
-#define AUTOLOCK_R(x) Autolock x##_autolock_r((x),LOCK_TYPE_READ)
-#define AUTOLOCK_W(x) Autolock x##_autolock_w((x),LOCK_TYPE_WRITE)
-#define LOCK(x) (x).lock()
-#define LOCK_R(x) (x).lock(LOCK_TYPE_READ)
-#define LOCK_W(x) (x).lock(LOCK_TYPE_WRITE)
-#define UNLOCK(x) (x).unlock()
-#endif
-
-
-class cbase_lock
-{
-public:
- cbase_lock();
- virtual ~cbase_lock();
-
- void lock(lock_type type, const char* expr, const char *module, const char *func, int line);
- void lock(lock_type type);
- void unlock(void);
-
-protected:
- virtual int lock_impl(void);
- virtual int read_lock_impl(void);
- virtual int write_lock_impl(void);
-
- virtual int try_lock_impl(void);
- virtual int try_read_lock_impl(void);
- virtual int try_write_lock_impl(void);
-
- virtual int unlock_impl(void);
-private:
- pthread_mutex_t m_history_mutex;
- static const int OWNER_INFO_LEN = 256;
- char m_owner_info[OWNER_INFO_LEN];
-};
-
-class Autolock
-{
-private:
- cbase_lock& m_lock;
-public:
- Autolock(cbase_lock &m, lock_type type, const char* expr, const char *module, const char *func, int line);
- Autolock(cbase_lock &m, lock_type type);
- ~Autolock();
-};
-
-#endif
-// End of a file
+++ /dev/null
-/*
- * libsensord-share
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <cmutex.h>
-#include "sensor_logs.h"
-
-cmutex::cmutex()
-{
- pthread_mutexattr_t mutex_attr;
- pthread_mutexattr_init(&mutex_attr);
- pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE);
- pthread_mutex_init(&m_mutex, &mutex_attr);
- pthread_mutexattr_destroy(&mutex_attr);
-}
-
-cmutex::~cmutex()
-{
- pthread_mutex_destroy(&m_mutex);
-}
-
-void cmutex::lock()
-{
-#ifdef _LOCK_DEBUG
- cbase_lock::lock(LOCK_TYPE_MUTEX, "mutex", __MODULE__, __func__, __LINE__);
-#else
- cbase_lock::lock(LOCK_TYPE_MUTEX);
-#endif
-}
-
-void cmutex::lock(const char* expr, const char *module, const char *func, int line)
-{
- cbase_lock::lock(LOCK_TYPE_MUTEX, expr, module, func, line);
-}
-
-int cmutex::lock_impl(void)
-{
- return pthread_mutex_lock(&m_mutex);
-}
-
-int cmutex::try_lock_impl(void)
-{
- return pthread_mutex_trylock(&m_mutex);
-
-}
-
-int cmutex::unlock_impl()
-{
- return pthread_mutex_unlock(&m_mutex);
-}
+++ /dev/null
-/*
- * libsensord-share
- *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#if !defined(_CMUTEX_CLASS_H_)
-#define _CMUTEX_CLASS_H_
-
-#include "cbase_lock.h"
-
-class cmutex : public cbase_lock
-{
-public:
- cmutex();
- virtual ~cmutex();
-
- void lock(void);
- void lock(const char* expr, const char *module, const char *func, int line);
-
-protected:
- int lock_impl(void);
- int try_lock_impl(void);
- int unlock_impl();
-private:
- pthread_mutex_t m_mutex;
-};
-
-#endif
-// End of a file
bool accel_sensor_hal::enable(void)
{
- AUTOLOCK(m_mutex);
-
set_enable_node(m_enable_node, m_sensorhub_controlled, true, SENSORHUB_ACCELEROMETER_ENABLE_BIT);
set_interval(m_polling_interval);
bool accel_sensor_hal::disable(void)
{
- AUTOLOCK(m_mutex);
-
set_enable_node(m_enable_node, m_sensorhub_controlled, false, SENSORHUB_ACCELEROMETER_ENABLE_BIT);
INFO("Accel sensor real stopping");
bool accel_sensor_hal::set_interval(unsigned long val)
{
unsigned long long polling_interval_ns;
-
- AUTOLOCK(m_mutex);
-
polling_interval_ns = ((unsigned long long)(val) * 1000llu * 1000llu);
if (!set_node_value(m_interval_node, polling_interval_ns)) {
return false;
}
- AUTOLOCK(m_value_mutex);
-
if (x)
m_x = accel_raw[0];
if (y)
return false;
}
- AUTOLOCK(m_value_mutex);
-
short *short_data = (short *)(data);
m_x = *(short_data);
m_y = *((short *)(data + 2));
INFO("m_x = %d, m_y = %d, m_z = %d, time = %lluus", m_x, m_y, m_z, m_fired_time);
return true;
-
}
bool accel_sensor_hal::is_data_ready(void)
int accel_sensor_hal::get_sensor_data(sensor_data_t &data)
{
- AUTOLOCK(m_value_mutex);
-
data.accuracy = SENSOR_ACCURACY_GOOD;
data.timestamp = m_fired_time;
data.value_count = 3;
bool m_sensorhub_controlled;
- cmutex m_value_mutex;
-
bool update_value_input_event(void);
bool update_value_iio(void);
};