Adding config file for sharing.
[iot2.git] / iotjava / iotrmi / C++ / ConcurrentLinkedListQueue.hpp
1 #ifndef _CONCURRENTLINKEDLISTQUEUE_HPP__
2 #define _CONCURRENTLINKEDLISTQUEUE_HPP__
3 #include <iostream>
4 #include <mutex>
5
6 #include "IoTRMIUtil.hpp"
7
8 /** Class ConcurrentLinkedListQueue is a queue that can handle
9  *  concurrent requests and packets for IoT communication via socket.
10  *  <p>
11  *  It stores object through a char pointer.
12  *
13  * @author      Rahmadi Trimananda <rtrimana @ uci.edu>
14  * @version     1.0
15  * @since       2017-01-27
16  */
17
18 using namespace std;
19
20 mutex queueMutex;
21
22 class Node final {
23
24         private:
25                 Node* next;
26                 char* value;
27                 int length;
28
29         public:
30                 Node(char* val, int len);
31                 ~Node();
32                 char* getValue();
33                 int getLength();
34                 Node* getNext();
35                 void setNext(Node* nxt);
36
37 };
38
39
40 class ConcurrentLinkedListQueue final {
41
42         private:
43                 Node* tail;
44                 Node* head;
45
46         public:
47                 ConcurrentLinkedListQueue();
48                 ~ConcurrentLinkedListQueue();
49                 void enqueue(char* value, int length);  // Enqueue to tail
50                 char* dequeue();                                                // Dequeue from tail
51                 char* deQAndGetLength(int* length);             // Dequeue from tail and return length
52 };
53 #endif