Merge "Fix compiler warnings" into connectivity-abstraction
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / caqueueingthread.h
1 /******************************************************************
2  *
3  * Copyright 2014 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ******************************************************************/
20 /**
21  * @file caqueueingthread.h
22  * @brief This file contains common utility function for handling message ques
23  */
24 #ifndef __CA_THREAD_H_
25 #define __CA_THREAD_H_
26
27 #include <stdint.h>
28
29 #include "uthreadpool.h"
30 #include "umutex.h"
31 #include "uqueue.h"
32 #include "cacommon.h"
33 #ifdef __cplusplus
34 extern "C"
35 {
36 #endif
37
38 /**Thread function to be invoked**/
39 typedef void (*CAThreadTask)(void *threadData);
40
41 typedef struct
42 {
43     /** Thread pool of the thread started **/
44     u_thread_pool_t threadPool;
45     /** mutex for synchrnoization **/
46     u_mutex threadMutex;
47     /** conditional mutex for synchrnoization **/
48     u_cond threadCond;
49     /**Thread function to be invoked**/
50     CAThreadTask threadTask;
51     /** Variable to inform the thread to stop **/
52     CABool_t isStop;
53     /** Que on which the thread is operating. **/
54     u_queue_t *dataQueue;
55 } CAQueueingThread_t;
56
57 /**
58  * @brief   Initializes the queing thread
59  * @param   thread       [IN]    thread data for each thread
60  * @param   handle              [IN]    thread pool handle created
61  * @param   task              [IN]   function to be called for reach data
62  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
63  */
64 CAResult_t CAQueueingThreadInitialize(CAQueueingThread_t *thread, u_thread_pool_t handle,
65                                       CAThreadTask task);
66
67 /**
68  * @brief   Starting the queueing thread
69  * @param   thread       [IN]    thread data that needs to be started
70  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
71  */
72 CAResult_t CAQueueingThreadStart(CAQueueingThread_t *thread);
73
74 /**
75  * @brief   Add queueing thread data for new thread
76  * @param   thread       [IN]    thread data for new thread control
77  * @param   data              [IN]    data that needs to be given for each thread
78  * @param   size              [IN]    length of the data
79  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
80  */
81 CAResult_t CAQueueingThreadAddData(CAQueueingThread_t *thread, void *data, uint32_t size);
82
83 /**
84  * @brief   Stopping the queueing thread
85  * @param   thread       [IN]    thread data that needs to be started
86  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
87  */
88
89 CAResult_t CAQueueingThreadStop(CAQueueingThread_t *thread);
90
91 /**
92  * @brief   Terminating  the queing thread
93  * @param   thread       [IN]    thread data for each thread
94  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
95  */
96
97 CAResult_t CAQueueingThreadDestroy(CAQueueingThread_t *thread);
98
99 #ifdef __cplusplus
100 } /* extern "C" */
101 #endif
102
103 #endif  // __CA_THREAD_H_