replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / caqueueingthread.h
index 89bf067..91deeda 100644 (file)
@@ -1,4 +1,4 @@
-/******************************************************************
+/* ****************************************************************
  *
  * Copyright 2014 Samsung Electronics All Rights Reserved.
  *
  ******************************************************************/
 
 /**
- * @file caqueueingthread.h
+ * @file
+ *
+ * This file contains common utility function for handling message ques.
  */
-#ifndef __CA_THREAD_H_
-#define __CA_THREAD_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
@@ -35,32 +38,99 @@ extern "C"
 {
 #endif
 
-typedef void (*CAThreadTask)(void* threadData);
+/** Thread function to be invoked. **/
+typedef void (*CAThreadTask)(void *threadData);
+
+/** 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
 {
-    u_thread_pool_t threadPool;
-    u_mutex threadMutex;
-    u_cond threadCond;
+    /** 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;
-    CABool_t isStop;
-    u_queue_t* dataQueue;
+    /** Data destroy function. **/
+    CADataDestroyFunction destroy;
+    /** Variable to inform the thread to stop. **/
+    bool isStop;
+    /** Que on which the thread is operating. **/
+    u_queue_t *dataQueue;
 } CAQueueingThread_t;
 
-CAResult_t CAQueueingThreadInitialize(CAQueueingThread_t* thread, u_thread_pool_t handle,
-        CAThreadTask task);
+/**
+ * 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, ca_thread_pool_t handle,
+                                      CAThreadTask task, CADataDestroyFunction destroy);
 
-CAResult_t CAQueueingThreadStart(CAQueueingThread_t* thread);
+/**
+ * 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
+/**
+ * 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);
 
-// shallow copy
-CAResult_t CAQueueingThreadAddData(CAQueueingThread_t* thread, void* data, uint32_t size);
+/**
+ * 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);
 
-CAResult_t CAQueueingThreadStop(CAQueueingThread_t* thread);
+/**
+ * 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 CAQueueingThreadDestroy(CAQueueingThread_t* thread);
+CAResult_t CAQueueingThreadStop(CAQueueingThread_t *thread);
+
+/**
+ * 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);
 
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
 
-#endif  // __CA_THREAD_H_
+#endif  /* CA_QUEUEING_THREAD_H_ */
+