Tizen 2.1 base
[platform/framework/web/download-provider.git] / agent / include / download-agent-client-mgr.h
1 /*
2  * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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 #ifndef _Download_Agent_Client_Mgr_H
18 #define _Download_Agent_Client_Mgr_H
19
20 #include <string.h>
21
22 #include "download-agent-type.h"
23 #include "download-agent-interface.h"
24
25 #include "download-agent-pthread.h"
26
27 typedef enum {
28         Q_CLIENT_NOTI_TYPE_STARTED_INFO = 0,
29         Q_CLIENT_NOTI_TYPE_PROGRESS_INFO,
30         Q_CLIENT_NOTI_TYPE_PAUSED_INFO,
31         Q_CLIENT_NOTI_TYPE_FINISHED_INFO,
32         Q_CLIENT_NOTI_TYPE_TERMINATE,
33 } client_noti_type;
34
35 typedef struct _client_noti_t client_noti_t;
36 struct _client_noti_t {
37         int slot_id;
38         void *user_data;
39         client_noti_type noti_type;
40         union _client_type {
41                 user_download_info_t update_dl_info;
42                 user_progress_info_t update_progress_info;
43                 user_paused_info_t paused_info;
44                 user_finished_info_t finished_info;
45         } type;
46
47         client_noti_t *next;
48 };
49
50 typedef struct _client_queue_t {
51         da_bool_t having_data;
52         client_noti_t *client_q_head;
53         pthread_mutex_t mutex_client_queue;
54         pthread_cond_t cond_client_queue;
55 } client_queue_t;
56
57 typedef struct _client_app_info_t {
58         da_client_cb_t client_callback;
59         char *client_user_agent;
60 } client_app_info_t;
61
62 typedef struct _client_app_mgr_t {
63         da_bool_t is_init;
64         client_queue_t client_queue;
65         client_app_info_t client_app_info;
66         pthread_t thread_id;
67         da_bool_t is_thread_init;
68         pthread_mutex_t mutex_client_mgr;
69 } client_app_mgr_t;
70
71 da_result_t init_client_app_mgr(void);
72 da_bool_t is_client_app_mgr_init(void);
73
74 da_result_t reg_client_app(da_client_cb_t *da_client_callback);
75 da_result_t dereg_client_app(void);
76
77 da_result_t send_client_paused_info (int slot_id);
78 da_result_t send_client_update_dl_info (int slot_id, int dl_id,
79                 char *file_type, unsigned long int file_size, char *tmp_saved_path,
80                 char *pure_file_name, char *etag, char *extension);
81 da_result_t send_client_update_progress_info (int slot_id, int dl_id,
82                 unsigned long int received_size);
83 da_result_t send_client_finished_info (int slot_id, int dl_id,
84                 char *saved_path, char *etag, int error, int http_status);
85
86 char *get_client_user_agent_string(void);
87
88 void push_client_noti(client_noti_t *client_noti);
89
90 #endif