replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / caqueueingthread.h
index e12fc0f..91deeda 100644 (file)
  * This file contains common utility function for handling message ques.
  */
 
-#ifndef CA_QUEUEINGTHREAD_H_
-#define CA_QUEUEINGTHREAD_H_
+#ifndef CA_QUEUEING_THREAD_H_
+#define CA_QUEUEING_THREAD_H_
 
 #include <stdint.h>
 
-#include "uthreadpool.h"
-#include "umutex.h"
+#include "cathreadpool.h"
+#include "octhread.h"
 #include "uqueue.h"
 #include "cacommon.h"
 #ifdef __cplusplus
@@ -38,69 +38,92 @@ extern "C"
 {
 #endif
 
-/**Thread function to be invoked**/
+/** Thread function to be invoked. **/
 typedef void (*CAThreadTask)(void *threadData);
 
-/**Data destroy function**/
+/** Data destroy function. **/
 typedef void (*CADataDestroyFunction)(void *data, uint32_t size);
 
+/** Context based Data destroy function. **/
+typedef bool (*CAContextDataDestroy)(void *data, uint32_t size, void *ctx);
+
 typedef struct
 {
-    /** Thread pool of the thread started **/
-    u_thread_pool_t threadPool;
-    /** mutex for synchrnoization **/
-    u_mutex threadMutex;
-    /** conditional mutex for synchrnoization **/
-    u_cond threadCond;
-    /**Thread function to be invoked**/
+    /** Thread pool of the thread started. **/
+    ca_thread_pool_t threadPool;
+    /** mutex for synchronization. **/
+    oc_mutex threadMutex;
+    /** conditional mutex for synchronization. **/
+    oc_cond threadCond;
+    /** Thread function to be invoked. **/
     CAThreadTask threadTask;
-    /**Data destroy function**/
+    /** Data destroy function. **/
     CADataDestroyFunction destroy;
-    /** Variable to inform the thread to stop **/
+    /** Variable to inform the thread to stop. **/
     bool isStop;
     /** Que on which the thread is operating. **/
     u_queue_t *dataQueue;
 } CAQueueingThread_t;
 
 /**
- * @brief   Initializes the queing thread
- * @param   thread      [IN] thread data for each thread
- * @param   handle      [IN] thread pool handle created
- * @param   task        [IN] function to be called for each data
- * @param   destroy     [IN] function to data destroy
- * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
+ * Initializes the queuing thread.
+ * @param[in]   thread       thread data for each thread.
+ * @param[in]   handle       thread pool handle created.
+ * @param[in]   task         function to be called for each data.
+ * @param[in]   destroy      function to data destroy.
+ * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h).
  */
-CAResult_t CAQueueingThreadInitialize(CAQueueingThread_t *thread, u_thread_pool_t handle,
+CAResult_t CAQueueingThreadInitialize(CAQueueingThread_t *thread, ca_thread_pool_t handle,
                                       CAThreadTask task, CADataDestroyFunction destroy);
 
 /**
- * @brief   Starting the queueing thread
- * @param   thread       [IN] thread data that needs to be started
- * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
+ * Start the queuing thread.
+ * @param[in]   thread        thread data that needs to be started.
+ * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h).
  */
+#ifndef __TIZENRT__
 CAResult_t CAQueueingThreadStart(CAQueueingThread_t *thread);
-
+#else
+CAResult_t CAQueueingThreadStart(CAQueueingThread_t *thread, const char *thread_name);
+#endif
 /**
- * @brief   Add queueing thread data for new thread
- * @param   thread      [IN] thread data for new thread control
- * @param   data        [IN] data that needs to be given for each thread
- * @param   size        [IN] length of the data
- * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
+ * Add queuing thread data for new thread.
+ * @param[in]   thread       thread data for new thread control.
+ * @param[in]   data         data that needs to be given for each thread.
+ * @param[in]   size         length of the data.
+ * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h).
  */
 CAResult_t CAQueueingThreadAddData(CAQueueingThread_t *thread, void *data, uint32_t size);
 
 /**
- * @brief   Stopping the queueing thread
- * @param   thread      [IN] thread data that needs to be started
- * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
+ * Clears queue thread data.
+ * @param[in]   thread       thread data for new thread control.
+ * @return  ::CA_STATUS_OK or Appropriate error code.
+ */
+CAResult_t CAQueueingThreadClearData(CAQueueingThread_t *thread);
+
+/**
+ * Clears queue thread data of specific context.
+ * @param[in]   thread           thread data for new thread control.
+ * @param[in]   callback         Function which should return true if the data
+ *                               needs to be deleted, else returns false
+ * @param[in]   ctx              Data to pass to callback
+ */
+CAResult_t CAQueueingThreadClearContextData(CAQueueingThread_t *thread,
+                                            CAContextDataDestroy callback, void *ctx);
+
+/**
+ * Stop the queuing thread.
+ * @param[in]   thread       thread data that needs to be started.
+ * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h).
  */
 
 CAResult_t CAQueueingThreadStop(CAQueueingThread_t *thread);
 
 /**
- * @brief   Terminating  the queing thread
- * @param   thread      [IN] thread data for each thread
- * @return  CA_STATUS_OK or ERROR CODES ( CAResult_t error codes in cacommon.h)
+ * Terminate the queuing thread.
+ * @param[in]   thread       thread data for each thread.
+ * @return  CA_STATUS_OK or ERROR CODES (CAResult_t error codes in cacommon.h).
  */
 
 CAResult_t CAQueueingThreadDestroy(CAQueueingThread_t *thread);
@@ -109,5 +132,5 @@ CAResult_t CAQueueingThreadDestroy(CAQueueingThread_t *thread);
 } /* extern "C" */
 #endif
 
-#endif  // CA_QUEUEINGTHREAD_H_
+#endif  /* CA_QUEUEING_THREAD_H_ */