General IRI utilities
event.h
1 // Copyright (C) 2009-2010 Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
2 // Author Sergi Hernandez (shernand@iri.upc.edu)
3 // All rights reserved.
4 //
5 // This file is part of iriutils
6 // iriutils is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU Lesser General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 #ifndef _EVENT_H
20 #define _EVENT_H
21 
22 #include "mutex.h"
23 #include <string>
24 
65 class CEvent
66 {
67  private:
76  int pipe_fd[2];
77 
88  int num_activations;
89 
98  std::string event_id;
99 
110  CMutex access;
111  protected:
124  void set_id(const std::string& id);
125 
126  public:
150  CEvent(const std::string& id);
151 
172  CEvent(const std::string& id,bool create_signaled);
173 
190  void reset(void);
191 
208  void set(void);
209 
234  void wait(int timeout_us);
235 
251  bool is_set(void);
252 
267  int get_num_activations(void);
268 
285  std::string get_id(void);
286 
297  int get_fd(void);
298 
309  virtual ~CEvent();
310 };
311 
312 #endif
Implementation of a logical event.
Definition: event.h:65
void wait(int timeout_us)
Function to wait for the activation of the event.
Definition: event.cpp:91
std::string get_id(void)
Function to get the event identifier.
Definition: event.cpp:161
int get_num_activations(void)
Function to get the number of event instances.
Definition: event.cpp:156
CEvent(const std::string &id)
Constructor with parameters.
Definition: event.cpp:28
Implementation of a mutual exclusion mechanism.
Definition: mutex.h:46
virtual ~CEvent()
Destructor.
Definition: event.cpp:171
void reset(void)
Function to reset the event.
Definition: event.cpp:58
int get_fd(void)
Function to get the read file descriptor of the pipe.
Definition: event.cpp:166
bool is_set(void)
Function to check the state of the event.
Definition: event.cpp:129
void set(void)
Function to activate the event.
Definition: event.cpp:76
void set_id(const std::string &id)
Function to set the event identifier.
Definition: event.cpp:145