AmSessionContainer.h

Go to the documentation of this file.
00001 /*
00002  * $Id: AmSessionContainer.h 711 2008-02-10 18:52:44Z sayer $
00003  *
00004  * Copyright (C) 2002-2003 Fhg Fokus
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 AmSessionContainer_h
00029 #define AmSessionContainer_h
00030 
00031 #include "AmThread.h"
00032 #include "AmSession.h"
00033 
00034 #include <string>
00035 #include <queue>
00036 #include <map>
00037 
00038 using std::string;
00039 
00048 class AmSessionContainer : public AmThread
00049 {
00050   static AmSessionContainer* _SessionContainer;
00051 
00052   // some typedefs ...
00053   typedef std::map<string,AmSession*> SessionMap;
00054   typedef SessionMap::iterator SessionMapIter;
00055 
00056   typedef std::map<string,string>     Dictionnary;
00057   typedef Dictionnary::iterator  DictIter;
00058 
00059   typedef std::queue<AmSession*>      SessionQueue;
00060 
00065   SessionMap a_sessions;
00066 
00072   Dictionnary as_id_lookup;
00073 
00075   AmMutex    as_mut;
00076 
00077 
00079   SessionQueue d_sessions;
00081   AmMutex      ds_mut;
00082 
00084   AmCondition<bool> _run_cond;
00085 
00087   AmSessionContainer();
00088 
00096   AmSession* getSession(const string& callid, const string& remote_tag);
00097 
00104   AmSession* getSession(const string& local_tag);
00105 
00110   bool addSession_unsafe(const string& callid, 
00111                          const string& remote_tag,
00112                          const string& local_tag,
00113                          AmSession* session);
00114 
00119   bool addSession_unsafe(const string& local_tag,
00120                          AmSession* session);
00121 
00125   void stopAndQueue(AmSession* s);
00126 
00128   void run();
00130   void on_stop();
00131 
00132  public:
00133   static AmSessionContainer* instance();
00134 
00140   AmSession* createSession(AmSipRequest& req, 
00141                            AmArg* session_params = NULL);
00142 
00147   bool addSession(const string& callid,
00148                   const string& remote_tag,
00149                   const string& local_tag,
00150                   AmSession* session);
00151 
00156   bool addSession(const string& local_tag,
00157                   AmSession* session);
00158 
00163   void startSessionUAS(AmSipRequest& req);
00164 
00169   AmSession* startSessionUAC(AmSipRequest& req, 
00170                              AmArg* session_params = NULL);
00171 
00175   void destroySession(AmSession* s);
00176   void destroySession(const string& local_tag);
00177 
00181   int getSize();
00182 
00187   bool postEvent(const string& callid, const string& remote_tag,
00188                  AmEvent* event);
00189 
00198   bool postEvent(const string& local_tag, AmEvent* event);
00199 };
00200 
00201 #endif

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