AmSessionContainer.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2002-2003 Fhg Fokus
00003  *
00004  * This file is part of SEMS, a free SIP media server.
00005  *
00006  * SEMS is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version. This program is released under
00010  * the GPL with the additional exemption that compiling, linking,
00011  * and/or using OpenSSL is allowed.
00012  *
00013  * For a license to use the SEMS 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 "ampi/MonitoringAPI.h"
00035 
00036 #include <string>
00037 #include <queue>
00038 #include <map>
00039 
00040 using std::string;
00041 
00050 class AmSessionContainer : public AmThread
00051 {
00052   static AmSessionContainer* _instance;
00053 
00054   typedef std::queue<AmSession*>      SessionQueue;
00055 
00057   SessionQueue d_sessions;
00059   AmMutex      ds_mut;
00060 
00062   AmCondition<bool> _container_closed;
00063 
00065   AmCondition<bool> _run_cond;
00066 
00068   AmSessionContainer();
00069 
00070 
00071   bool enable_unclean_shutdown;
00072 
00076   void stopAndQueue(AmSession* s);
00077 
00079   void run();
00081   void on_stop();
00082 
00083   bool clean_sessions();
00084 
00085  public:
00086   static AmSessionContainer* instance();
00087 
00088   static void dispose();
00089 
00090   enum AddSessionStatus {
00091     ShutDown,
00092     Inserted,
00093     AlreadyExist
00094   };
00095 
00101   AmSession* createSession(const AmSipRequest& req, 
00102                            string& app_name,
00103                            AmArg* session_params = NULL);
00104 
00109   AddSessionStatus addSession(const string& callid,
00110                               const string& remote_tag,
00111                               const string& local_tag,
00112                               const string& via_branch,
00113                               AmSession* session);
00114 
00119   AddSessionStatus addSession(const string& local_tag,
00120                               AmSession* session);
00121 
00126   void startSessionUAS(AmSipRequest& req);
00127 
00132   string startSessionUAC(const AmSipRequest& req, 
00133                          string& app_name,
00134                          AmArg* session_params = NULL);
00135 
00139   void destroySession(AmSession* s);
00140 
00145   bool postEvent(const string& callid, 
00146                  const string& remote_tag,
00147                  const string& via_branch,
00148                  AmEvent* event);
00149 
00158   bool postEvent(const string& local_tag, AmEvent* event);
00159 
00163   void  broadcastShutdown();
00164 
00166   void enableUncleanShutdown();
00167 
00168   _MONITORING_DEFINE_INTERFACE;
00169 
00170 };
00171 
00172 #endif
Home |  Recent changes |  Search |  Glossary |  Sitemap |  Login