tizen 2.3 release
[framework/connectivity/multirat.git] / include / multirat_watch_dog_thread.h
1 #ifndef MULTIRAT_WATCH_DOG_H_
2 #define MULTIRAT_WATCH_DOG_H_
3
4 #include "multirat_SB_http.h"
5 #include "multirat_connection.h"
6
7 typedef enum  {
8          THREAD_INIT = 0,
9          THREAD_RUNNING,
10          THREAD_FINISH
11 }THREAD_STATUS;
12
13 /*struct http_sample  {
14   char *request;
15   int length;
16   }; */
17
18 /**
19  * @brief                           initialize cthread
20  * @param[in]         void
21  * @return
22  */
23
24 CThread * cthread_init(void);
25
26 /**
27  * @brief                            thread function running
28  * @param[in]           cthread      CThread object
29  * @return
30  * @retval
31  * @retval
32  */
33
34 void cthread_run_thread(SmartBondingData *SBData);
35
36 /**
37  * @brief                           get the bytes from range request header
38  * @param[in]           start       buffer to store the bytes
39  * @param[in]           rangeHeader rangeHeader to decode
40  * @return                          bytes of range request
41  * @retval              1           bytes updated in param start
42  * @retval              0           error
43  */
44
45 int32 get_bytesof_range_request(uint64 *start, int8 *rangeHeader);
46
47 /**
48  * @brief                           check if connection is keep-alive
49  * @param[in]           SBData      Smart bonding object
50  * @return                          status of connection
51  * @retval              1           connection header is keep alive
52  * @retval              0           connection header is not keep alive
53  */
54
55 int32 is_connection_header_keepalive(SmartBondingData *SBData);
56
57 /**
58  * @brief                            start the watch_dog_thread
59  * @param[in]         cthread        cthread object
60  * @return                           void
61  */
62
63 void cthread_start_thread(SmartBondingData *SBData);
64
65 /**
66  * @brief                           watch dog thread entry function
67  * @param[in]         pArg          cthread entry params
68  * @return                          void
69  */
70 void * cthread_entry_function (void *pArg);
71
72 /**
73  * @brief                           check the status of the thread
74  * @param[in]         cthread       cthread object
75  * @return                          status of cthread
76  * @return             0            thread init
77  * @retval             1            thread running
78  * @retval             2            thread finish
79  */
80 int32 cthread_get_thread_status(CThread *cthread);
81
82 /**
83  * @brief                           exit the watch dog thread
84  * @param[in]         cthread       cthread object
85  * @return                          void
86  */
87 void cthread_exit(CThread *cthread);
88
89 /**
90  * @brief                            creat,bind and check the watch dog thread
91  * @param[in]           SBData       smartbonding data object
92  * @return                           status of connection
93  * @retval              0            successful connection
94  * @retval              -1           error
95  */
96 int32 watchdog_test_connection_type(SmartBondingData *SBData);
97
98 /**
99  * @brief                            calculate no of chunks in watchdog thread
100  * @param[in]           chunkSize    chunk size
101  * @param[in]           noOfChunks   total no of chunks
102  * @param[in]           lastChunk    last chunk
103  * @param[in]           totalSize    total size
104  * @return                           void
105  */
106 void multirat_watchdogthread_calnochunks(uint32 chunkSize,uint32 *noOfChunks,uint32 *lastChunk,uint64 totalSize);
107
108 /**
109  * @brief                            get request without range from range header
110  * @param[in]           oldReq       old request
111  * @param[in]           newReq       new request
112  * @param[in]           rangeHeader  rangeHeader
113  * @param[in]           rangeStart   range start buffer
114  * @return                           status of getting request from header
115  * @retval              1            successfully removed range header
116  * @retval              0            copied old request to new request
117  * @retval              -1           unseccessful decoding of range request
118  */
119 int32 get_req_without_range(int8 *oldReq, int8 *newReq, int8 *rangeHeader, uint64 *rangeStart);
120
121 int32 check_speed(SmartBondingData *SBData, uint32 timeT2, uint32 resp_offset,
122                               uint32 resp_len, int8 *recv_buf, int32 socket, uint64 contLength);
123
124 void switch_to_watchdog(SmartBondingData *SBData, uint32 resp_offset, uint32 resp_len, int8 *recv_buf, int32 socket);
125
126 void file_cthread_run_thread(SmartBondingData *SBData);
127
128 int32 file_thread_FirstConnection(SmartBondingData *SBData, fileThread *fThread, int64 *chunkInfo, int8 *recv_buf, int32 *lengthRcvd);
129
130 #endif