4 * Observer counting traps and terminating the
5 * application after a specified amount of calls.
7 * (c) 2012-2013 Björn Döbel <doebel@os.inf.tu-dresden.de>,
8 * economic rights: Technische Universität Dresden (Germany)
9 * This file is part of TUD:OS and distributed under the terms of the
10 * GNU General Public License 2.
11 * Please see the COPYING-GPL-2 file for details.
14 #include "../app_loading"
15 #include "observers.h"
19 class TrapLimitObserver_priv : public TrapLimitObserver
24 bool limitIsValid() { return _limit != -1; }
25 int count() { return _callcount; }
26 int limit() { return _limit; }
27 void increment() { ++_callcount; }
30 TrapLimitObserver_priv()
33 _limit = ConfigIntValue("general:max_traps");
34 INFO() << "Limit: " << _limit;
37 DECLARE_OBSERVER("trap_limit");
41 DEFINE_EMPTY_STARTUP(TrapLimitObserver_priv)
43 void Romain::TrapLimitObserver_priv::status() const
49 INFO() << "Trap Limit: " << _callcount
55 Romain::Observer::ObserverReturnVal
56 Romain::TrapLimitObserver_priv::notify(Romain::App_instance *inst,
57 Romain::App_thread *t,
58 Romain::Thread_group *tg,
64 if (count() >= limit()) {
69 // Replicatable, so that we only count this once
70 return Romain::Observer::Continue;
73 Romain::TrapLimitObserver*
74 Romain::TrapLimitObserver::Create()
76 return new TrapLimitObserver_priv();