update for iot-5.0
[apps/native/st-things-co2-meter.git] / src / sensor-data.c
index 87e1ee4..1435e18 100644 (file)
@@ -1,18 +1,20 @@
-/*
- * 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>
@@ -37,7 +39,7 @@ sensor_data *sensor_data_new(sensor_data_type_e type)
        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);
@@ -117,6 +119,8 @@ int sensor_data_set_string(sensor_data *data, const char *value, unsigned int si
        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;
@@ -125,6 +129,13 @@ int sensor_data_set_string(sensor_data *data, const char *value, unsigned int si
        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);