Commit 7038de3c authored by jpbl's avatar jpbl

*** empty log message ***

parent c01c24a1
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author: Jean-Philippe Barrette-LaPierre
* <jean-philippe.barrette-lapierre@savoirfairelinux.com>
*
* This program 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.
*
* This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "Account.hpp"
#include "Requester.hpp"
#include "Call.hpp"
Account::Account(const QString &sessionId,
const QString &name)
: mSessionId(sessionId)
, mId(name)
{}
Request *
Account::registerAccount() const
{
std::list< QString > args;
args.push_back(mId);
return Requester::instance().send(mSessionId, "register", args);
}
Request *
Account::unregisterAccount() const
{
std::list< QString > args;
args.push_back(mId);
return Requester::instance().send(mSessionId, "unregister", args);
}
Request *
Account::createCall(Call * &call, const QString &to) const
{
QString callId = Requester::instance().generateCallId();
call = new Call(mSessionId, mId, callId, to);
std::list< QString> args;
args.push_back(mId);
args.push_back(callId);
args.push_back(to);
return Requester::instance().send(mSessionId, "call", args);
}
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author: Jean-Philippe Barrette-LaPierre
* <jean-philippe.barrette-lapierre@savoirfairelinux.com>
*
* This program 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.
*
* This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef SFLPHONEGUI_ACCOUNT_H
#define SFLPHONEGUI_ACCOUNT_H
#include <qstring.h>
#include "Call.hpp"
class Request;
class Account {
public:
Account(const QString &sessionId,
const QString &name);
/**
* This will generate a call ready to be used.
*/
Request *registerAccount() const;
Request *unregisterAccount() const;
/**
* This function will create a call. The call pointer will
* point to a newly allocated memory. You're responsible for
* deleting this memory.
*/
Request *createCall(Call * &call, const QString &to) const;
QString id() const
{return mId;}
private:
Account();
/**
* This is the session id that we are related to.
*/
QString mSessionId;
/**
* This is the account id that we are related to.
*/
QString mId;
};
#endif
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author: Jean-Philippe Barrette-LaPierre
* <jean-philippe.barrette-lapierre@savoirfairelinux.com>
*
* This program 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.
*
* This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <qstring.h>
#include <list>
#include "Account.hpp"
#include "Call.hpp"
#include "CallManager.hpp"
#include "Session.hpp"
#include "Requester.hpp"
Call::Call(const QString &sessionId,
const QString &accountId,
const QString &callId,
const QString &peer,
bool incomming)
: mSessionId(sessionId)
, mAccountId(accountId)
, mId(callId)
, mPeer(peer)
, mIsIncomming(incomming)
{
CallManager::instance().registerCall(*this);
}
Call::Call(const Session &session,
const Account &account,
const QString &callId,
const QString &peer,
bool incomming)
: mSessionId(session.id())
, mAccountId(account.id())
, mId(callId)
, mPeer(peer)
, mIsIncomming(incomming)
{
CallManager::instance().registerCall(*this);
}
bool
Call::isIncomming()
{return mIsIncomming;}
Request *
Call::answer()
{
mIsIncomming = false;
std::list< QString> args;
args.push_back(mId);
return Requester::instance().send(mSessionId, "answer", args);
}
Request *
Call::hangup()
{
std::list< QString> args;
args.push_back(mId);
return Requester::instance().send(mSessionId, "hangup", args);
}
Request *
Call::cancel()
{
std::list< QString> args;
args.push_back(mId);
return Requester::instance().send(mSessionId, "cancel", args);
}
Request *
Call::hold()
{
std::list< QString> args;
args.push_back(mId);
return Requester::instance().send(mSessionId, "hold", args);
}
Request *
Call::unhold()
{
std::list< QString> args;
args.push_back(mId);
return Requester::instance().send(mSessionId, "unhold", args);
}
Request *
Call::refuse()
{
mIsIncomming = false;
std::list< QString> args;
args.push_back(mId);
return Requester::instance().send(mSessionId, "refuse", args);
}
Request *
Call::notAvailable()
{
mIsIncomming = false;
std::list< QString> args;
args.push_back(mId);
return Requester::instance().send(mSessionId, "notavailable", args);
}
Request *
Call::transfer(const QString &to)
{
std::list< QString> args;
args.push_back(mId);
args.push_back(to);
return Requester::instance().send(mSessionId, "transfer", args);
}
Request *
Call::sendDtmf(char c)
{
std::list< QString> args;
args.push_back(mId);
QString s;
s += c;
args.push_back(s);
return Requester::instance().send(mSessionId, "senddtmf", args);
}
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author: Jean-Philippe Barrette-LaPierre
* <jean-philippe.barrette-lapierre@savoirfairelinux.com>
*
* This program 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.
*
* This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef SFLPHONEGUI_CALL_H
#define SFLPHONEGUI_CALL_H
#include <qstring.h>
class Account;
class Request;
class Session;
class Call
{
public:
/**
* A call is automaticaly registered in
* the CallManager. However, a call isn't
* registered when you have a copy constructor.
*/
Call(const QString &sessionId,
const QString &accountId,
const QString &callId,
const QString &destination,
bool incomming = false);
Call(const Session &session,
const Account &account,
const QString &callId,
const QString &destination,
bool incomming = false);
/**
* This function returns true if the
* call is waiting to be picked up.
*/
bool isIncomming();
QString id() const
{return mId;}
QString peer() const
{return mPeer;}
/**
* This function will answer the call.
*/
Request *answer();
/**
* This function will try to transfer the
* call to the peer.
*/
Request *transfer(const QString &to);
/**
* This function will hangup on a call.
*/
Request *hangup();
/**
* ///TODO need to clarify this function.
*/
Request *cancel();
/**
* This function will put the call on hold.
* This *should* stop temporarly the streaming.
*/
Request *hold();
/**
* This function will unhold a holding call.
* This *should* restart a stopped streaming.
*/
Request *unhold();
/**
* This function refuse and incomming call.
* It means that the phone is ringing but we
* don't want to answer.
*/
Request *refuse();
/**
* This function will set this client to be
* not able to receive the call. It means that
* the phone can still ring. But if every client
* sent notavailable, then it will be refused.
*/
Request *notAvailable();
/**
* This function will send a tone to the line.
* This is used if you make a choice when you
* have a voice menu.
*/
Request *sendDtmf(char c);
private:
/**
* This is the session id that we belong to.
*/
QString mSessionId;
/**
* This is the account id that we belong to.
*/
QString mAccountId;
/**
* This is the unique identifier of the call.
*/
QString mId;
/**
* This is the destination of the call.
*/
QString mPeer;
bool mIsIncomming;
};
#endif
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author : Jean-Philippe Barrette-LaPierre
* <jean-philippe.barrette-lapierre@savoirfairelinux.com>
*
* This program 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.
*
* This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __CALL_MANAGER_HPP__
#define __CALL_MANAGER_HPP__
#include "utilspp/Singleton.hpp"
#include "CallManagerImpl.hpp"
typedef utilspp::SingletonHolder< CallManagerImpl > CallManager;
#endif
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author: Jean-Philippe Barrette-LaPierre
* <jean-philippe.barrette-lapierre@savoirfairelinux.com>
*
* This program 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.
*
* This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <qobject.h>
#include <stdexcept>
#include "CallManagerImpl.hpp"
#include "DebugOutput.hpp"
void
CallManagerImpl::registerCall(const Call &call)
{
mCalls.insert(std::make_pair(call.id(), call));
}
void
CallManagerImpl::unregisterCall(const Call &call)
{
unregisterCall(call.id());
}
void
CallManagerImpl::unregisterCall(const QString &id)
{
std::map< QString, Call >::iterator pos = mCalls.find(id);
if(pos != mCalls.end()) {
mCalls.erase(pos);
}
}
bool
CallManagerImpl::exist(const QString &id)
{
std::map< QString, Call >::iterator pos = mCalls.find(id);
if(pos == mCalls.end()) {
return false;
}
return true;
}
Call
CallManagerImpl::getCall(const QString &id)
{
std::map< QString, Call >::iterator pos = mCalls.find(id);
if(pos == mCalls.end()) {
throw std::runtime_error("Trying to retreive an unregistred call\n");
}
return pos->second;
}
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author: Jean-Philippe Barrette-LaPierre
* <jean-philippe.barrette-lapierre@savoirfairelinux.com>
*
* This program 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.
*
* This program 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __CALL_MANAGER_IMPL_HPP__
#define __CALL_MANAGER_IMPL_HPP__
#include <qmutex.h>
#include <qstring.h>
#include <map>
#include "Call.hpp"
class CallManagerImpl
{
public:
void registerCall(const Call &call);
void unregisterCall(const Call &call);
void unregisterCall(const QString &id);
/**
* Return true if the call is registered.
*/
bool exist(const QString &id);
/**
* Return the call with the given id. If
* there's no such call it will throw a
* std::runtime_error.
*/
Call getCall(const QString &id);
private:
std::map< QString, Call > mCalls;
};
#endif