General IRI utilities
eventserver.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_SERVER
20 #define _EVENT_SERVER
21 
22 #include <list>
23 #include "event.h"
24 #include "mutex.h"
25 
58 {
59  private:
68  static CEventServer* pinstance;
77  std::list<CEvent> event_list;
79 
83  CMutex access_events;
84  protected:
97  CEventServer();
110  CEventServer(const CEventServer& object);
121  CEventServer& operator = (const CEventServer& object);
145  std::list<CEvent>::iterator search_event(const std::string& event_id);
146  public:
162  static CEventServer* instance(void);
163  // Event handler functions
188  void create_event(const std::string& event_id);
205  void delete_event(const std::string& event_id);
223  void set_event(const std::string& event_id);
241  void reset_event(const std::string& event_id);
259  bool event_is_set(const std::string& event_id);
273  int get_num_events(void);
287  int get_num_activations(const std::string& event_id);
331  int wait_first(std::list<std::string> events,int timeout = -1);
361  void wait_all(std::list<std::string> events, int timeout = -1);
362 };
363 
364 #endif
void create_event(const std::string &event_id)
Function to create a new event.
Definition: eventserver.cpp:73
int get_num_activations(const std::string &event_id)
Function to get the number of activations of a single event.
Global event server.
Definition: eventserver.h:57
void wait_all(std::list< std::string > events, int timeout=-1)
Function to wait for all the events is a set.
bool event_is_set(const std::string &event_id)
Function to query if the event is active or not.
CEventServer & operator=(const CEventServer &object)
assign operator overloading
Definition: eventserver.cpp:36
Implementation of a mutual exclusion mechanism.
Definition: mutex.h:46
std::list< CEvent >::iterator search_event(const std::string &event_id)
Function to search for an specific event.
Definition: eventserver.cpp:41
int get_num_events(void)
function to get the number of event
int wait_first(std::list< std::string > events, int timeout=-1)
Function to wait for the first event in a set.
void delete_event(const std::string &event_id)
Function to delete an existing event.
Definition: eventserver.cpp:93
void set_event(const std::string &event_id)
Function to activate an event.
CEventServer()
Default constructor.
Definition: eventserver.cpp:28
static CEventServer * instance(void)
Function to get a reference to the unique instance.
Definition: eventserver.cpp:64
void reset_event(const std::string &event_id)
Function to deactivate an event.