IoT-243 Connectivity Abstraction single-threaded module missing definition for CASend...
[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 /**Data destroy function**/
42 typedef void (*CADataDestroyFunction)(void *data, uint32_t size);
43
44 typedef struct
45 {
46     /** Thread pool of the thread started **/
47     u_thread_pool_t threadPool;
48     /** mutex for synchrnoization **/
49     u_mutex threadMutex;
50     /** conditional mutex for synchrnoization **/
51     u_cond threadCond;
52     /**Thread function to be invoked**/
53     CAThreadTask threadTask;
54     /**Data destroy function**/
55     CADataDestroyFunction destroy;
56     /** Variable to inform the thread to stop **/
57     CABool_t isStop;
58     /** Que on which the thread is operating. **/
59     u_queue_t *dataQueue;
60 } CAQueueingThread_t;
61
62 /**
63  * @brief   Initializes the queing thread
64  * @param   thread       [IN]    thread data for each thread
65  * @param   handle              [IN]    thread pool handle created
66  * @param   task              [IN]   function to be called for reach data
67  * @param   destroy     [IN] function to data destroy
68  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
69  */
70 CAResult_t CAQueueingThreadInitialize(CAQueueingThread_t *thread, u_thread_pool_t handle,
71                                       CAThreadTask task, CADataDestroyFunction destroy);
72
73 /**
74  * @brief   Starting the queueing thread
75  * @param   thread       [IN]    thread data that needs to be started
76  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
77  */
78 CAResult_t CAQueueingThreadStart(CAQueueingThread_t *thread);
79
80 /**
81  * @brief   Add queueing thread data for new thread
82  * @param   thread       [IN]    thread data for new thread control
83  * @param   data              [IN]    data that needs to be given for each thread
84  * @param   size              [IN]    length of the data
85  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
86  */
87 CAResult_t CAQueueingThreadAddData(CAQueueingThread_t *thread, void *data, uint32_t size);
88
89 /**
90  * @brief   Stopping the queueing thread
91  * @param   thread       [IN]    thread data that needs to be started
92  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
93  */
94
95 CAResult_t CAQueueingThreadStop(CAQueueingThread_t *thread);
96
97 /**
98  * @brief   Terminating  the queing thread
99  * @param   thread       [IN]    thread data for each thread
100  * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
101  */
102
103 CAResult_t CAQueueingThreadDestroy(CAQueueingThread_t *thread);
104
105 #ifdef __cplusplus
106 } /* extern "C" */
107 #endif
108
109 #endif  // __CA_THREAD_H_