4 * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jungki Kwak <jungki.kwak@samsung.com>, Keunsoon Lee <keunsoon.lee@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
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)
25 #include "download-agent-type.h"
26 #include "download-agent-utils.h"
27 #include "download-agent-utils-dl-req-id-history.h"
29 da_result_t init_dl_req_id_history(dl_req_id_history_t *dl_req_id_history)
31 da_result_t ret = DA_RESULT_OK;
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));
42 DA_LOG_CRITICAL(Default,"starting num = %d", dl_req_id_history->starting_num);
46 da_result_t deinit_dl_req_id_history(dl_req_id_history_t *dl_req_id_history)
48 da_result_t ret = DA_RESULT_OK;
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));
55 _da_thread_mutex_destroy(&(dl_req_id_history->mutex));
60 int get_available_dl_req_id(dl_req_id_history_t *dl_req_id_history)
64 _da_thread_mutex_lock(&(dl_req_id_history->mutex));
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;
71 dl_req_id_history->cur_dl_req_id++;
73 dl_req_id = dl_req_id_history->cur_dl_req_id;
75 _da_thread_mutex_unlock(&(dl_req_id_history->mutex));
77 DA_LOG_CRITICAL(Default,"dl_req_id = %d", dl_req_id);