Corrected @file tags and restored 'Files' section.
[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 /**
22  * @file
23  *
24  * This file contains common utility function for handling message ques.
25  */
26
27 #ifndef __CA_THREAD_H_
28 #define __CA_THREAD_H_
29
30 #include <stdint.h>
31
32 #include "uthreadpool.h"
33 #include "umutex.h"
34 #include "uqueue.h"
35 #include "cacommon.h"
36 #ifdef __cplusplus
37 extern "C"
38 {
39 #endif
40
41 /**Thread function to be invoked**/
42 typedef void (*CAThreadTask)(void *threadData);
43
44 /**Data destroy function**/
45 typedef void (*CADataDestroyFunction)(void *data, uint32_t size);
46
47 typedef struct
48 {
49     /** Thread pool of the thread started **/
50     u_thread_pool_t threadPool;
51     /** mutex for synchrnoization **/
52     u_mutex threadMutex;
53     /** conditional mutex for synchrnoization **/
54     u_cond threadCond;
55     /**Thread function to be invoked**/
56     CAThreadTask threadTask;
57     /**Data destroy function**/
58     CADataDestroyFunction destroy;
59     /** Variable to inform the thread to stop **/
60     bool isStop;
61     /** Que on which the thread is operating. **/
62     u_queue_t *dataQueue;
63 } CAQueueingThread_t;
64
65 /**
66  * @brief   Initializes the queing thread
67  * @param   thread      [IN] thread data for each thread
68  * @param   handle      [IN] thread pool handle created
69  * @param   task        [IN] function to be called for each data
70  * @param   destroy     [IN] function to data destroy
71  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
72  */
73 CAResult_t CAQueueingThreadInitialize(CAQueueingThread_t *thread, u_thread_pool_t handle,
74                                       CAThreadTask task, CADataDestroyFunction destroy);
75
76 /**
77  * @brief   Starting the queueing thread
78  * @param   thread       [IN] thread data that needs to be started
79  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
80  */
81 CAResult_t CAQueueingThreadStart(CAQueueingThread_t *thread);
82
83 /**
84  * @brief   Add queueing thread data for new thread
85  * @param   thread      [IN] thread data for new thread control
86  * @param   data        [IN] data that needs to be given for each thread
87  * @param   size        [IN] length of the data
88  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
89  */
90 CAResult_t CAQueueingThreadAddData(CAQueueingThread_t *thread, void *data, uint32_t size);
91
92 /**
93  * @brief   Stopping the queueing thread
94  * @param   thread      [IN] thread data that needs to be started
95  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
96  */
97
98 CAResult_t CAQueueingThreadStop(CAQueueingThread_t *thread);
99
100 /**
101  * @brief   Terminating  the queing thread
102  * @param   thread      [IN] thread data for each thread
103  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
104  */
105
106 CAResult_t CAQueueingThreadDestroy(CAQueueingThread_t *thread);
107
108 #ifdef __cplusplus
109 } /* extern "C" */
110 #endif
111
112 #endif  // __CA_THREAD_H_
113