AmCallWatcher.h

Go to the documentation of this file.
00001 /*
00002  * $Id: AmCallWatcher.h 279 2007-03-23 21:30:44Z sayer $
00003  *
00004  *  (c) 2007 iptego GmbH
00005  *
00006  * This file is part of sems, a free SIP media server.
00007  *
00008  * sems is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version
00012  *
00013  * For a license to use the ser software under conditions
00014  * other than those described here, or to purchase support for this
00015  * software, please contact iptel.org by e-mail at the following addresses:
00016  *    info@iptel.org
00017  *
00018  * sems is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License 
00024  * along with this program; if not, write to the Free Software 
00025  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026  */
00028 #ifndef _AM_CALL_WATCHER_H
00029 #define _AM_CALL_WATCHER_H
00030 
00031 //
00032 // States are put into map on an Initialize event.
00033 // States are held in a map identified by call_id
00034 // (opaque identifier) and updated with Update events.
00035 // Once an Obsolete event is received, the states are 
00036 // moved to soft-state map, where they are held until
00037 // queried to a maximum of WATCHER_SOFT_EXPIRE_SECONDS
00038 
00039 #define WATCHER_SOFT_EXPIRE_SECONDS  5
00040 
00041 #include <string>
00042 using std::string;
00043 
00044 #include <map>
00045 
00046 #include <utility>
00047 using std::pair;
00048 
00049 #include "AmEventQueue.h"
00050 #include "AmEvent.h"
00051 #include "AmThread.h"
00052 
00053 class CallStatus;
00054 
00058 class CallStatusUpdateEvent : public AmEvent {
00059   string call_id;
00060 
00061   CallStatus* init_status;
00062 
00063  public:
00064   enum UpdateType {
00065     Initialize = 0,
00066     Update,
00067     Obsolete
00068   };
00069 
00070   CallStatusUpdateEvent(UpdateType t, const string& call_id)
00071     : call_id(call_id), AmEvent(t)  { }
00072 
00073   // implicit: initialize
00074   CallStatusUpdateEvent(const string& call_id, CallStatus* init_status)
00075     : call_id(call_id), init_status(init_status), AmEvent(Initialize)  { }
00076 
00077   ~CallStatusUpdateEvent() { }
00078 
00079   string get_call_id() { return call_id; }
00080   CallStatus* get_init_status() { return init_status; }
00081 };
00082 
00086 class CallStatus
00087 {
00088  public:
00089   CallStatus()  { }
00090   virtual ~CallStatus() { }
00091 
00093   virtual void update(CallStatusUpdateEvent* e) = 0;
00094 
00096   virtual CallStatus* copy() = 0;
00097   virtual void dump() { }
00098 };
00099 
00100 class AmCallWatcherGarbageCollector;
00109 class AmCallWatcher
00110 : public AmThread, 
00111   public AmEventQueue,
00112   public AmEventHandler
00113 {
00114  public:
00115   typedef std::map<string, CallStatus*> CallStatusMap;
00116   typedef std::map<string, pair<CallStatus*, time_t> > CallStatusTimedMap;
00117 
00118  private:
00119   CallStatusMap states;
00120   AmMutex       states_mut;
00121 
00122 
00123   CallStatusTimedMap soft_states;
00124   AmMutex            soft_states_mut;
00125   AmCallWatcherGarbageCollector* garbage_collector;
00126 
00127  public:
00128   AmCallWatcher();
00129   ~AmCallWatcher();
00130 
00131   // thread
00132   void run();
00133   void on_stop();
00134 
00135   // eventhandler
00136   void process(AmEvent*);
00137 
00138   CallStatus* getStatus(const string& call_id);
00139 
00140   // dump all states
00141   void dump();
00142 };
00143 
00151 class AmCallWatcherGarbageCollector 
00152 : public AmThread
00153 {
00154   AmMutex& mut;
00155   AmCallWatcher::CallStatusTimedMap& garbage;
00156  public: 
00157   AmCallWatcherGarbageCollector(AmMutex& mut,
00158                                 AmCallWatcher::CallStatusTimedMap& garbage)
00159     : mut(mut), garbage(garbage) {}
00160   void run();
00161   void on_stop() { }
00162 };
00163 
00164 #endif

Generated on Fri May 16 12:02:05 2008 for SEMS by  doxygen 1.5.1
Home |  Recent changes |  Search |  Glossary |  Sitemap |  Login