Tizen 2.1 base
[platform/framework/web/download-provider.git] / src / agent / include / download-agent-http-queue.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_Http_Queue_H
18 #define _Download_Agent_Http_Queue_H
19
20
21 #include "download-agent-type.h"
22 #include "download-agent-http-msg-handler.h"
23
24 #include <pthread.h>
25 #include <stdlib.h>
26
27 #define MAX_QUEUE_SIZE  1024*64
28
29 typedef enum
30 {
31         Q_EVENT_TYPE_DATA_HTTP,
32         Q_EVENT_TYPE_DATA_DRM,
33         Q_EVENT_TYPE_CONTROL,
34 }q_event_type;
35
36 typedef enum
37 {
38         Q_EVENT_TYPE_CONTROL_CANCEL,
39         Q_EVENT_TYPE_CONTROL_SUSPEND,
40         Q_EVENT_TYPE_CONTROL_RESUME,
41         Q_EVENT_TYPE_CONTROL_NET_DISCONNECTED,
42         Q_EVENT_TYPE_CONTROL_ABORT,
43 // [090205][jungki]not used yet.
44 //      Q_EVENT_TYPE_CONTROL_USER_CONFIRM_RESULT,
45 //      Q_EVENT_TYPE_CONTROL_INSTALL_RESULT,
46 }q_event_type_control;
47
48 typedef enum
49 {
50         Q_EVENT_TYPE_DATA_PACKET,
51         Q_EVENT_TYPE_DATA_FINAL,
52         Q_EVENT_TYPE_DATA_ABORT,
53 }q_event_type_data;
54
55 typedef struct _q_event_data_http_t
56 {
57         q_event_type_data data_type;
58
59         int status_code;
60
61         http_msg_response_t* http_response_msg;
62
63         int body_len;
64         char *body_data;
65
66         da_result_t error_type;
67 }q_event_data_http_t;
68
69 typedef struct _q_event_control_t
70 {
71         q_event_type_control control_type;
72 }q_event_control_t;
73
74 typedef struct _q_event_t q_event_t;
75 struct _q_event_t
76 {
77         int size;
78         q_event_type event_type;
79         union _type
80         {
81                 q_event_data_http_t q_event_data_http;
82                 q_event_control_t q_event_control;
83         } type;
84
85         q_event_t *next;
86 };
87
88 typedef struct _queue_t
89 {
90         da_bool_t having_data;
91
92         q_event_t *control_head;
93         q_event_t *data_head;
94
95         pthread_mutex_t mutex_queue;
96         pthread_cond_t cond_queue;
97
98         int queue_size;
99 }queue_t;
100
101 void Q_init_queue(queue_t *queue);
102 void Q_destroy_queue(queue_t *queue);
103
104 void Q_init_q_event(q_event_t *q_event);
105 void Q_destroy_q_event(q_event_t **q_event);
106
107 da_result_t  Q_make_control_event(q_event_type_control control_type, q_event_t **out_event);
108
109 da_result_t  Q_make_http_data_event(q_event_type_data data_type, q_event_t **out_event);
110 da_result_t  Q_set_status_code_on_http_data_event(q_event_t *q_event, int status_code);
111 da_result_t  Q_set_http_body_on_http_data_event(q_event_t *q_event, int body_len, char *body_data);
112 da_result_t  Q_set_error_type_on_http_data_event(q_event_t *q_event, int error_type);
113
114
115 da_bool_t Q_push_event(const queue_t *in_queue, const q_event_t *in_event);
116 da_bool_t Q_push_event_without_lock(const queue_t *in_queue, const q_event_t *in_event);
117 void Q_pop_event(const queue_t *in_queue, q_event_t **out_event);
118
119 #define GET_IS_Q_HAVING_DATA(QUEUE)             (QUEUE->having_data)
120
121 void Q_goto_sleep(const queue_t *in_queue);
122 void Q_wake_up(const queue_t *in_queue);
123
124
125 #endif