1 // ANNA - Anna is Not 'N' Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // https://bitbucket.org/testillano/anna
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of Google Inc. nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // Authors: eduardo.ramos.testillano@gmail.com
34 // cisco.tierra@gmail.com
37 #ifndef anna_timex_TimeEvent_hpp
38 #define anna_timex_TimeEvent_hpp
40 #include <anna/core/RuntimeException.hpp>
41 #include <anna/config/defines.hpp>
42 #include <anna/core/util/Millisecond.hpp>
49 class TimeEventObserver;
52 Clase base de los eventos de los eventos de tiempo.
57 Sinonimo usado para el identificador de eventos de tiempo.
59 Se define como un ptrnumber para facilitar la construccion de instancias sin tener que indicar
60 un Id en particular, ya que se usara su direccion de memoria como identificador.
62 typedef anna::ptrnumber Id;
66 Si un evento de tiempo esta activo y se invoca a su destructor se invocaria automaticamente a
67 Engine::cancel para terminar con la ejecucin de este evento.
72 Devuelve el identificador de este evento.
73 \return El identificador de este evento.
75 Id getId() const throw() { return a_id; }
78 Devuelve la duracion maxima a este evento indicada en milisegundos.
79 @return La duracion maxima de este evento indicada en milisegundos.
81 const Millisecond & getTimeout() const throw() { return a_timeout; }
84 Devuelve la instancia del objeto encargado de gestionar el espacio asociado a
85 esta instancia. Puede ser NULL.
86 \return La instancia del objeto encargado de gestionar el espacio asociado a
89 const TimeEventObserver* getObserver() const throw() { return a_observer; }
92 Establece el identificador de este evento de tiempo.
93 \param id El identificador de evento para esta instancia.
95 \warning Exclusivamente uso interno.
97 void setId(const Id id) throw() { a_id = id; }
100 Establece la duracion de este evento indicada en milisegundos.
101 \param timeout Establece la duracion de este evento.
103 void setTimeout(const Millisecond & timeout) throw() { a_timeout = timeout; }
106 Establece la instancia de objeto encargado de gestionar el espacio asociado a esta
107 instancia. Si no es NULL sera invocado cuando el timex::Engine caduque o
108 cancele este evento temporal.
110 \param observer Instancia del objeto encargada de gestional el espacio asignado a esta
113 void setObserver(TimeEventObserver* observer) throw() { a_observer = observer; }
116 Devuelve el estado de activacin de este evento de tiempo.
117 @return \em false si el evento esta activado o \em false en otro caso.
119 bool isActive() const throw() { return (a_controller != NULL); }
122 Devuelve una cadena con la informacion sobre este evento.
123 \return Una cadena con la informacion sobre este evento.
125 virtual std::string asString() const throw();
141 @param id Identificador de este evento.
142 @param timeout La duracion de este evento indicada en milisegundos.
144 TimeEvent(const Id id, const Millisecond & timeout) :
151 metodo que debemos re-escribir para particularizar el comportamiento de nuestra clase cuando
152 el Engine notifica que se ha sobrepasado la duracion maxima del evento si que se invoque
153 a ninguno de los metodos que lo cancelarian. Una vez invocado a este metodo el evento se considera
154 cancelado y todos sus recursos son liberados automaticamente por Engine.
156 @param timeController Controlador de tiempo asociado al evento que esta expirando.
158 virtual void expire(Engine* timeController) throw(RuntimeException) = 0;
161 metodo que debemos re-escribir para particularizar el comportamiento de nuestra clase cuando
162 el Engine notifica que se ha parado el sistema de control de tiempos. Una vez invocado a este
163 metodo el evento se considera cancelado y todos sus recursos son liberados automaticamente
166 Las acciones realizadas nunca deber�n generar nuevos eventos. Por defecto no hace nada.
168 virtual void stop() throw(RuntimeException) {;}
172 Millisecond a_timeout;
173 Engine* a_controller;
174 TimeEventObserver* a_observer;