RDK Documentation (Open Sourced RDK Components)
test_EventQueue.cpp
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
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 * @defgroup hdmicec
23 * @{
24 * @defgroup osal
25 * @{
26 **/
27 
28 
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <unistd.h>
32 
33 #include "osal/Thread.hpp"
34 #include "osal/Runnable.hpp"
35 #include "osal/EventQueue.hpp"
36 
37 using namespace CCEC_OSAL;
38 
39 class Element {
40 public:
41  Element(int i) {
42  printf("at [%s][%d\r\n", __FUNCTION__, __LINE__);
43  value = i;
44  }
45  int value;
46 };
47 
48 static EventQueue<Element *> *intQueue;
49 
50 class producer: public Runnable {
51  void run(void) {
52  while(1) {
53  //sleep(2);
54  Element *p = intQueue->poll();
55  printf("Hello Producer got %d\r\n", p->value);
56  delete p;
57  }
58  }
59 };
60 
61 class consumer: public Runnable {
62  void run(void) {
63  int i = 1000;
64  while(i < 2000) {
65  i++;
66  printf("Hello Consumer sent %d\r\n", i);
67  //sleep (2);
68  intQueue->offer(new Element(i));
69  }
70  }
71 };
72 
73 int main()
74 {
75  intQueue = new EventQueue<Element *>();
76  consumer *con;
77  producer *pro;
78  Thread(*(new consumer())).start();
79  Thread(*(new producer())).start();
80  sleep(10);
81  delete intQueue;
82 }
83 
84 
85 /** @} */
86 /** @} */
CCEC_OSAL::Thread
Definition: Thread.hpp:64
CCEC_OSAL::Runnable
Definition: Runnable.hpp:37
EventQueue.hpp
This file defines interface of EventQueue class.
Thread.hpp
This file defines interface of Thread class.
CCEC_OSAL::EventQueue
Definition: EventQueue.hpp:62
consumer
Definition: test_EventQueue.cpp:61
producer
Definition: test_EventQueue.cpp:50
CCEC_OSAL::Thread::start
void start(void)
Starts excecution of the thread.
Definition: Thread.cpp:62
Element
Definition: test_EventQueue.cpp:39