24 #include <sys/types.h>
25 #include <sys/select.h>
26 #include "eventexceptions.h"
33 this->num_activations=0;
34 if(pipe(this->pipe_fd)==-1)
37 throw CEventException(_HERE_,
"Impossible to create the internal pipe to generate the events",
id);
47 this->num_activations=0;
48 if(pipe(this->pipe_fd)==-1)
51 throw CEventException(_HERE_,
"Impossible to create the internal pipe to generate the events",
id);
63 if(this->num_activations>0)
65 if(read(this->pipe_fd[0],&event_instance,1)==-1)
69 throw CEventException(_HERE_,
"Impossible to read from the internal pipe",this->event_id);
71 this->num_activations--;
78 char event_instance=0x55;
81 if(write(this->pipe_fd[1],&event_instance,1)==-1)
85 throw CEventException(_HERE_,
"Impossible to write to the internal pipe",this->event_id);
87 this->num_activations++;
93 struct timeval timeout_t;
99 FD_SET(this->pipe_fd[0],&wait_set);
103 error=select(this->pipe_fd[0]+1,&wait_set,NULL,NULL,NULL);
108 timeout_t.tv_usec=timeout_us;
110 error=select(this->pipe_fd[0]+1,&wait_set,NULL,NULL,&timeout_t);
115 throw CEventException(_HERE_,
"Unexpected error while waiting the activation of the event",this->event_id);
131 this->access.
enter();
132 if(this->num_activations>0)
158 return this->num_activations;
163 return this->event_id;
168 return this->pipe_fd[0];
173 this->access.
enter();
174 if(this->pipe_fd[0]!=-1)
175 close(this->pipe_fd[0]);
176 if(this->pipe_fd[1]!=-1)
177 close(this->pipe_fd[1]);
178 this->num_activations=0;
void wait(int timeout_us)
Function to wait for the activation of the event.
std::string get_id(void)
Function to get the event identifier.
int get_num_activations(void)
Function to get the number of event instances.
Event timeout exception class.
CEvent(const std::string &id)
Constructor with parameters.
virtual ~CEvent()
Destructor.
void reset(void)
Function to reset the event.
void exit(void)
function to release the critical section
void enter(void)
function to request access to the critical section
int get_fd(void)
Function to get the read file descriptor of the pipe.
bool is_set(void)
Function to check the state of the event.
void set(void)
Function to activate the event.
void set_id(const std::string &id)
Function to set the event identifier.