Merge "Added tools - mockup of cloud and injector. Changed code to support task-worker."
[apps/native/tizen-things-daemon.git] / daemon / src / ttd-app-data.c
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://floralicense.org/license/
9  *
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.
15  */
16
17 #include <glib.h>
18 #include "ttd-log.h"
19 #include "ttd-app-data.h"
20
21 struct __ttd_app_data {
22         char *p_name;
23         char *data;
24         unsigned int retry;
25 };
26
27 ttd_app_data *ttd_app_data_new(const char *project, const char *data)
28 {
29         ttd_app_data *app_data = NULL;
30
31         retv_if(!project, NULL);
32         retv_if(!data, NULL);
33
34         app_data = g_try_malloc0(sizeof(ttd_app_data));
35         retv_if(!app_data, NULL);
36
37         app_data->p_name = g_strdup(project);
38         app_data->data = g_strdup(data);
39
40         return app_data;
41 }
42
43 void ttd_app_data_free(ttd_app_data *app_data)
44 {
45         if (!app_data)
46                 return;
47
48         g_free(app_data->p_name);
49         g_free(app_data->data);
50         g_free(app_data);
51 }
52
53 int ttd_app_data_set_retry_count(
54         ttd_app_data *app_data, unsigned int count)
55 {
56         retv_if(!app_data, -1);
57
58         app_data->retry = count;
59
60         return 0;
61 }
62
63 const char *ttd_app_data_get_project_name(ttd_app_data *app_data)
64 {
65         retv_if(!app_data, NULL);
66         return app_data->p_name;
67 }
68
69 const char *ttd_app_data_get_data(ttd_app_data *app_data)
70 {
71         retv_if(!app_data, NULL);
72         return app_data->data;
73 }
74
75 int ttd_app_data_get_retry_count(
76         ttd_app_data *app_data, unsigned int *count)
77 {
78         retv_if(!app_data, -1);
79         retv_if(!count, -1);
80
81         *count = app_data->retry;
82         app_data->retry--;
83
84         return 0;
85 }