1 /*
2 * Copyright (C) 2011 Stefan Sayer
3 *
4 * This file is part of SEMS, a free SIP media server.
5 *
6 * SEMS is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * For a license to use the SEMS software under conditions
12 * other than those described here, or to purchase support for this
13 * software, please contact iptel.org by e-mail at the following addresses:
14 * info@iptel.org
15 *
16 * SEMS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
26 #include "AmEventProcessingThread.h"
27 #include "log.h"
28
AmEventProcessingThread()29 AmEventProcessingThread::AmEventProcessingThread()
30 : AmEventQueue(this),
31 processing_events(true)
32 {
33 }
34
~AmEventProcessingThread()35 AmEventProcessingThread::~AmEventProcessingThread() {
36 }
37
police_event(AmEvent * ev)38 bool AmEventProcessingThread::police_event(AmEvent* ev) {
39 // default: accept all events
40 return true;
41 }
42
postEvent(AmEvent * ev)43 void AmEventProcessingThread::postEvent(AmEvent* ev) {
44 if (police_event(ev)) {
45 AmEventQueue::postEvent(ev);
46 } else {
47 DBG("dropping event [%p] due to policing\n", ev);
48 delete ev;
49 }
50 }
51
on_stop()52 void AmEventProcessingThread::on_stop() {
53 DBG("AmEventProcessingThread::on_stop\n");
54 }
55
run()56 void AmEventProcessingThread::run() {
57 DBG("AmEventProcessingThread running...\n");
58
59 while (processing_events) {
60 waitForEvent();
61 processEvents();
62 }
63
64 DBG("AmEventProcessingThread stopping.\n");
65 }
66
stop_processing()67 void AmEventProcessingThread::stop_processing() {
68 DBG("stop of event processing requested.\n");
69 processing_events = false;
70 }
71
process(AmEvent * ev)72 void AmEventProcessingThread::process(AmEvent* ev) {
73
74 // check for shutdown
75 if (ev->event_id == E_SYSTEM) {
76 AmSystemEvent* sys_ev = dynamic_cast<AmSystemEvent*>(ev);
77 if(sys_ev){
78 DBG("received system Event\n");
79 if (sys_ev->sys_event == AmSystemEvent::ServerShutdown) {
80 DBG("received system Event: ServerShutdown. Stopping event processing.\n");
81 processing_events = false;
82 }
83 }
84 }
85
86 onEvent(ev);
87 }
88
89