mirror of https://github.com/sipwise/sems.git
- removed AmSIPEventHandler (its functionalities are now in AmEventDispatcher). - added possibility for each plug-in to receive out-of-dialog messages (any kind). - added possibility to handle dialogs without creating a session (=AmSession). git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@1006 8eb893ce-cfd4-0310-b710-fb5ebe64c474sayer/1.4-spce2.6
parent
44cc8a0413
commit
7030673b90
@ -0,0 +1,147 @@
|
||||
/*
|
||||
* $Id: $
|
||||
*
|
||||
* Copyright (C) 2007 Raphael Coeffic
|
||||
*
|
||||
* This file is part of sems, a free SIP media server.
|
||||
*
|
||||
* sems is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version
|
||||
*
|
||||
* For a license to use the ser software under conditions
|
||||
* other than those described here, or to purchase support for this
|
||||
* software, please contact iptel.org by e-mail at the following addresses:
|
||||
* info@iptel.org
|
||||
*
|
||||
* sems is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
#include "AmEventDispatcher.h"
|
||||
#include "AmSipEvent.h"
|
||||
|
||||
AmEventDispatcher* AmEventDispatcher::_instance=NULL;
|
||||
|
||||
AmEventDispatcher* AmEventDispatcher::instance()
|
||||
{
|
||||
return _instance ? _instance : ((_instance = new AmEventDispatcher()));
|
||||
}
|
||||
|
||||
bool AmEventDispatcher::addEventQueue(const string& local_tag,
|
||||
AmEventQueue* q,
|
||||
const string& callid,
|
||||
const string& remote_tag)
|
||||
{
|
||||
bool exists = false;
|
||||
|
||||
m_queues.lock();
|
||||
|
||||
exists = queues.find(local_tag) != queues.end();
|
||||
|
||||
if(!callid.empty() && !remote_tag.empty()) {
|
||||
exists = exists ||
|
||||
(id_lookup.find(callid+remote_tag) != id_lookup.end());
|
||||
}
|
||||
|
||||
if(!exists){
|
||||
queues[local_tag] = q;
|
||||
|
||||
if(!callid.empty() && !remote_tag.empty())
|
||||
id_lookup[callid+remote_tag] = local_tag;
|
||||
}
|
||||
|
||||
m_queues.unlock();
|
||||
|
||||
return exists;
|
||||
}
|
||||
|
||||
AmEventQueue* AmEventDispatcher::delEventQueue(const string& local_tag,
|
||||
const string& callid,
|
||||
const string& remote_tag)
|
||||
{
|
||||
AmEventQueue* q = NULL;
|
||||
|
||||
m_queues.lock();
|
||||
|
||||
EvQueueMapIter qi = queues.find(local_tag);
|
||||
if(qi != queues.end()) {
|
||||
|
||||
q = qi->second;
|
||||
queues.erase(qi);
|
||||
|
||||
if(!callid.empty() && !remote_tag.empty()) {
|
||||
|
||||
DictIter di = id_lookup.find(callid+remote_tag);
|
||||
if(di != id_lookup.end()) {
|
||||
|
||||
id_lookup.erase(di);
|
||||
}
|
||||
}
|
||||
}
|
||||
m_queues.unlock();
|
||||
|
||||
return q;
|
||||
}
|
||||
|
||||
bool AmEventDispatcher::post(const string& local_tag, AmEvent* ev)
|
||||
{
|
||||
bool posted = false;
|
||||
m_queues.lock();
|
||||
|
||||
EvQueueMapIter it = queues.find(local_tag);
|
||||
if(it != queues.end()){
|
||||
it->second->postEvent(ev);
|
||||
posted = true;
|
||||
}
|
||||
|
||||
m_queues.unlock();
|
||||
|
||||
return posted;
|
||||
}
|
||||
|
||||
bool AmEventDispatcher::post(const string& callid, const string& remote_tag, AmEvent* ev)
|
||||
{
|
||||
bool posted = false;
|
||||
m_queues.lock();
|
||||
|
||||
DictIter di = id_lookup.find(callid+remote_tag);
|
||||
if(di != id_lookup.end()) {
|
||||
|
||||
EvQueueMapIter it = queues.find(di->second);
|
||||
if(it != queues.end()){
|
||||
it->second->postEvent(ev);
|
||||
posted = true;
|
||||
}
|
||||
}
|
||||
m_queues.unlock();
|
||||
|
||||
return posted;
|
||||
}
|
||||
|
||||
bool AmEventDispatcher::postSipRequest(const string& callid, const string& remote_tag,
|
||||
const AmSipRequest& req)
|
||||
{
|
||||
bool posted = false;
|
||||
m_queues.lock();
|
||||
|
||||
DictIter di = id_lookup.find(callid+remote_tag);
|
||||
if(di != id_lookup.end()) {
|
||||
|
||||
EvQueueMapIter it = queues.find(di->second);
|
||||
if(it != queues.end()){
|
||||
it->second->postEvent(new AmSipRequestEvent(req));
|
||||
posted = true;
|
||||
}
|
||||
}
|
||||
m_queues.unlock();
|
||||
|
||||
return posted;
|
||||
}
|
||||
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* $Id: $
|
||||
*
|
||||
* Copyright (C) 2008 Raphael Coeffic
|
||||
*
|
||||
* This file is part of sems, a free SIP media server.
|
||||
*
|
||||
* sems is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version
|
||||
*
|
||||
* For a license to use the ser software under conditions
|
||||
* other than those described here, or to purchase support for this
|
||||
* software, please contact iptel.org by e-mail at the following addresses:
|
||||
* info@iptel.org
|
||||
*
|
||||
* sems is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#ifndef _AMEVENTDISPATCHER_h_
|
||||
#define _AMEVENTDISPATCHER_h_
|
||||
|
||||
#include "AmEventQueue.h"
|
||||
#include "AmSipMsg.h"
|
||||
#include <map>
|
||||
|
||||
class AmEventDispatcher
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::map<string, AmEventQueue*> EvQueueMap;
|
||||
typedef EvQueueMap::iterator EvQueueMapIter;
|
||||
|
||||
typedef std::map<string,string> Dictionnary;
|
||||
typedef Dictionnary::iterator DictIter;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
static AmEventDispatcher *_instance;
|
||||
|
||||
/**
|
||||
* Container for active sessions
|
||||
* local tag -> event queue
|
||||
*/
|
||||
EvQueueMap queues;
|
||||
|
||||
/**
|
||||
* Call ID + remote tag -> local tag
|
||||
* (needed for CANCELs and some provisionnal answers)
|
||||
* (UAS sessions only)
|
||||
*/
|
||||
Dictionnary id_lookup;
|
||||
|
||||
// mutex for "queues" and "id_lookup"
|
||||
AmMutex m_queues;
|
||||
|
||||
public:
|
||||
|
||||
static AmEventDispatcher* instance();
|
||||
|
||||
bool postSipRequest(const string& callid, const string& remote_tag,
|
||||
const AmSipRequest& req);
|
||||
|
||||
bool post(const string& local_tag, AmEvent* ev);
|
||||
bool post(const string& callid, const string& remote_tag, AmEvent* ev);
|
||||
|
||||
bool addEventQueue(const string& local_tag,
|
||||
AmEventQueue* q,
|
||||
const string& callid="",
|
||||
const string& remote_tag="");
|
||||
|
||||
AmEventQueue* delEventQueue(const string& local_tag,
|
||||
const string& callid="",
|
||||
const string& remote_tag="");
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Reference in new issue