2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
4 * Licensed under the Flora License, Version 1.1 (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
8 * http://floralicense.org/license/
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.
23 #include <arpa/inet.h>
26 #include "cloud/lap_info.h"
28 #define MAX_CAR_ID_LENGTH 256
37 lap_info_t *lap_info_create(void)
39 struct lap_info *lap_info = g_new0(struct lap_info, 1);
40 retvm_if(!lap_info, NULL, "Could not allocate memory!");
45 lap_info_t *lap_info_copy(const lap_info_t *lap_info)
47 retv_if(!lap_info, NULL);
49 struct lap_info *lap_info_cpy = g_new0(struct lap_info, 1);
50 lap_info_cpy->user_name = strndup(lap_info->user_name, MAX_CAR_ID_LENGTH);
51 lap_info_cpy->car_id = strndup(lap_info->car_id, MAX_CAR_ID_LENGTH);
52 lap_info_cpy->lap_time = lap_info->lap_time;
57 void lap_info_destroy(lap_info_t *lap_info)
61 free(lap_info->user_name);
62 free(lap_info->car_id);
66 const char *lap_info_get_car_id(lap_info_t *lap_info)
68 retv_if(!lap_info, NULL);
69 return lap_info->car_id;
72 int lap_info_set_car_id(lap_info_t *lap_info, const char *car_id)
74 retv_if(!lap_info, -1);
75 retv_if(car_id == NULL, -1);
76 retv_if(strlen(car_id) >= MAX_CAR_ID_LENGTH, -1);
78 if (!lap_info->car_id)
79 lap_info->car_id = (char *)g_malloc(MAX_CAR_ID_LENGTH * sizeof(char));
81 snprintf(lap_info->car_id, MAX_CAR_ID_LENGTH, "%s", car_id);
85 const char *lap_info_get_user_name(lap_info_t *lap_info)
87 retv_if(!lap_info, NULL);
88 return lap_info->user_name;
91 int lap_info_set_user_name(lap_info_t *lap_info, const char *user_name)
93 retv_if(!lap_info, -1);
94 retv_if(user_name == NULL, -1);
95 retv_if(strlen(user_name) >= MAX_CAR_ID_LENGTH, -1);
97 if (!lap_info->user_name)
98 lap_info->user_name = (char *)g_malloc(MAX_CAR_ID_LENGTH * sizeof(char));
100 snprintf(lap_info->user_name, MAX_CAR_ID_LENGTH, "%s", user_name);
104 long lap_info_get_lap_time(lap_info_t *lap_info)
106 retv_if(!lap_info, 0);
107 return lap_info->lap_time;
110 int lap_info_set_lap_time(lap_info_t *lap_info, long lap_time)
112 retv_if(!lap_info, -1);
113 lap_info->lap_time = lap_time;