Revert manifest to default one
[profile/ivi/download-provider.git] / src / agent / download-agent-utils-dl-req-id-history.c
1 /*
2  * Download Agent
3  *
4  * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Jungki Kwak <jungki.kwak@samsung.com>, Keunsoon Lee <keunsoon.lee@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  * @file                download-agent-utils-dl-req-id-history.c
21  * @brief               Including operations for dl-req-id-history
22  * @author              Keunsoon Lee(keunsoon.lee@samsung.com)
23  ***/
24
25 #include "download-agent-type.h"
26 #include "download-agent-utils.h"
27 #include "download-agent-utils-dl-req-id-history.h"
28
29 da_result_t init_dl_req_id_history(dl_req_id_history_t *dl_req_id_history)
30 {
31         da_result_t ret = DA_RESULT_OK;
32
33         /* Initial dl_req_id_history will be starting number for dl_req_id.
34          * dl_req_id will be sequentially increased from the dl_req_id_history,
35          * then dl_req_id_history will be updated. */
36         _da_thread_mutex_init(&(dl_req_id_history->mutex), DA_NULL);
37         _da_thread_mutex_lock(&(dl_req_id_history->mutex));
38         get_random_number(&(dl_req_id_history->starting_num));
39         dl_req_id_history->cur_dl_req_id = DA_INVALID_ID;
40         _da_thread_mutex_unlock(&(dl_req_id_history->mutex));
41
42         DA_LOG_CRITICAL(Default,"starting num = %d", dl_req_id_history->starting_num);
43         return ret;
44 }
45
46 da_result_t deinit_dl_req_id_history(dl_req_id_history_t *dl_req_id_history)
47 {
48         da_result_t ret = DA_RESULT_OK;
49
50         _da_thread_mutex_lock(&(dl_req_id_history->mutex));
51         dl_req_id_history->starting_num = DA_INVALID_ID;
52         dl_req_id_history->cur_dl_req_id = DA_INVALID_ID;
53         _da_thread_mutex_unlock(&(dl_req_id_history->mutex));
54
55         _da_thread_mutex_destroy(&(dl_req_id_history->mutex));
56
57         return ret;
58 }
59
60 int get_available_dl_req_id(dl_req_id_history_t *dl_req_id_history)
61 {
62         int dl_req_id = 0;
63
64         _da_thread_mutex_lock(&(dl_req_id_history->mutex));
65
66         if (dl_req_id_history->cur_dl_req_id == DA_INVALID_ID)
67                 dl_req_id_history->cur_dl_req_id = dl_req_id_history->starting_num;
68         else if (dl_req_id_history->cur_dl_req_id > 254)
69                 dl_req_id_history->cur_dl_req_id = 1;
70         else
71                 dl_req_id_history->cur_dl_req_id++;
72
73         dl_req_id = dl_req_id_history->cur_dl_req_id;
74
75         _da_thread_mutex_unlock(&(dl_req_id_history->mutex));
76
77         DA_LOG_CRITICAL(Default,"dl_req_id = %d", dl_req_id);
78         return dl_req_id;
79 }