-/*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+/* ****************************************************************
*
- * Licensed under the Flora License, Version 1.1 (the License);
+ * Copyright 2017 Samsung Electronics All Rights Reserved.
+ *
+ * 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://floralicense.org/license/
+ * 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,
+ * 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 <stdlib.h>
#include <pthread.h>
union {
int int_val;
unsigned int uint_val;
+ bool b_val;
double d_val;
char *str_val;
} value;
retv_if(type == SENSOR_DATA_TYPE_NONE, NULL);
data = calloc(1, sizeof(sensor_data));
- retv_if(type == SENSOR_DATA_TYPE_NONE, NULL);
+ retv_if(!data, NULL);
data->type = type;
pthread_mutex_init(&data->mutex, NULL);
return 0;
}
+int sensor_data_set_bool(sensor_data *data, bool value)
+{
+ retv_if(!data, -1);
+ retv_if(data->type != SENSOR_DATA_TYPE_BOOL, -1);
+
+ pthread_mutex_lock(&data->mutex);
+ data->value.b_val = value;
+ pthread_mutex_unlock(&data->mutex);
+
+ return 0;
+}
+
int sensor_data_set_double(sensor_data *data, double value)
{
retv_if(!data, -1);
retv_if(size == 0, -1);
temp = strndup(value, size);
+ retv_if(!temp, -1);
+
pthread_mutex_lock(&data->mutex);
free(data->value.str_val);
data->value.str_val = temp;
return 0;
}
+sensor_data_type_e sensor_data_get_type(sensor_data *data)
+{
+ retv_if(!data, SENSOR_DATA_TYPE_NONE);
+
+ return data->type;
+}
+
int sensor_data_get_int(sensor_data *data, int *value)
{
retv_if(!data, -1);
return 0;
}
+int sensor_data_get_bool(sensor_data *data, bool *value)
+{
+ retv_if(!data, -1);
+ retv_if(!value, -1);
+ retv_if(data->type != SENSOR_DATA_TYPE_BOOL, -1);
+
+ pthread_mutex_lock(&data->mutex);
+ *value = data->value.b_val;
+ pthread_mutex_unlock(&data->mutex);
+
+ return 0;
+}
+
int sensor_data_get_double(sensor_data *data, double *value)
{
retv_if(!data, -1);