19 #include "eventserver.h"
20 #include "threadserver.h"
29 const std::string thread1_id=
"thread1";
33 const std::string thread2_id=
"thread2";
38 const std::string event1_id=
"event1";
42 const std::string event2_id=
"event2";
46 const std::string event3_id=
"event3";
56 void *thread1_function(
void *param)
58 std::list<std::string> event_list1;
60 CLog thread_log(
"thread1");
62 event_list1.push_back(event1_id);
63 std::cout <<
"Thread1 - Waiting for event " << event1_id << std::endl;
64 thread_log.log((
const std::string)
"Thread1 - Waiting for event" + event1_id);
66 std::cout <<
"Thread1 - Event " << event1_id <<
" received" << std::endl;
89 void *thread2_function(
void *param)
91 std::list<std::string> event_list2;
93 CLog thread_log(
"thread2");
95 event_list2.push_back(event1_id);
96 std::cout <<
"Thread2 - Waiting for event " << event1_id << std::endl;
97 thread_log.log((
const std::string)
"Thread2 - Waiting for event" + event1_id);
99 std::cout <<
"Thread2 - Event " << event1_id <<
" received" << std::endl;
149 int main(
int argc,
char *argv[])
153 CLog main_log(
"main");
156 main_log.log(
"Creating events ...");
161 main_log.log((
const std::string)
"Creating threads ...");
164 thread_server->
attach_thread(thread1_id,thread1_function,NULL);
165 thread_server->
attach_thread(thread2_id,thread2_function,NULL);
166 main_log.log((
const std::string)
"Starting thread 1 ...");
169 main_log.log((
const std::string)
"Starting thread 2 ...");
178 std::cout <<
"End of the program" << std::endl;
179 main_log.log((
const std::string)
"End of the program");
void create_event(const std::string &event_id)
Function to create a new event.
void create_thread(const std::string &thread_id)
Function to create a new thread.
void start_thread(const std::string &thread_id)
Function to start a thread.
int wait_first(std::list< std::string > events, int timeout=-1)
Function to wait for the first event in a set.
void end_thread(const std::string &thread_id)
Function to request the termination of a thread.
Implementation of a log file.
void attach_thread(const std::string &thread_id, void *(*user_thread_function)(void *param), void *param)
Function to attach a function to a thread.
void set_event(const std::string &event_id)
Function to activate an event.
static CThreadServer * instance(void)
Function to get a reference to the unique instance.
static CEventServer * instance(void)
Function to get a reference to the unique instance.