Tizen 2.1 base
[platform/framework/web/download-provider.git] / provider / include / download-provider-slots.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_PROVIDER2_SLOTS_H
18 #define DOWNLOAD_PROVIDER2_SLOTS_H
19
20 #include "download-provider.h"
21 #include "download-provider-pthread.h"
22
23 // Backgound Daemon should has the limitation of resource.
24 #define DP_MAX_GROUP 15
25 #define DP_MAX_REQUEST 64
26
27 typedef struct {
28         pid_t pid;
29         uid_t uid;
30         gid_t gid;
31 } dp_credential;
32
33 typedef struct {
34         // send command * get return value.
35         int cmd_socket;
36         // send event to client
37         int event_socket;
38         unsigned queued_count; // start ++, finish or failed -- ( queue & active )
39         // fill by app-manager
40         char *pkgname;
41         dp_credential credential;
42 } dp_client_group;
43
44 typedef struct {
45         int id; // ID created in create request in requests thread.
46         int agent_id;
47         int create_time;
48         int start_time; // setted by START command
49         int pause_time; // setted by PAUSE command
50         int stop_time; // time setted by finished_cb
51         int noti_priv_id;
52         unsigned state_cb; // set : 1 unset : 0
53         unsigned progress_cb; // set : 1 unset : 0
54         unsigned startcount;
55         unsigned auto_notification;
56         dp_state_type state; // downloading state
57         dp_error_type error;
58         dp_network_type network_type;
59         size_t progress_lasttime;
60         unsigned long long received_size; // progress
61         unsigned long long file_size;
62         char *packagename;
63         dp_credential credential;
64         dp_client_group *group; // indicate dp_client_group included this request
65         pthread_mutex_t mutex;
66 } dp_request;
67
68 typedef struct {
69         dp_client_group *group;
70 } dp_group_slots;
71
72 typedef struct {
73         dp_request *request;
74 } dp_request_slots;
75
76
77 // functions
78 dp_group_slots *dp_client_group_slots_new(int size);
79 dp_request_slots *dp_request_slots_new(int size);
80 int dp_client_group_free(dp_client_group *group);
81 int dp_client_group_slots_free(dp_group_slots *slots, int size);
82 dp_request *dp_request_new();
83 void dp_request_init(dp_request *request);
84 int dp_request_free(dp_request *request);
85 int dp_request_slots_free(dp_request_slots *slots, int size);
86 int dp_get_request_count(dp_request_slots *slots);
87
88 #endif