Skip to content
Snippets Groups Projects
Commit dcac44ee authored by jpbl's avatar jpbl
Browse files

a call is now an account related request

parent 2e264c52
Branches
Tags
No related merge requests found
Showing with 209 additions and 42 deletions
......@@ -29,7 +29,7 @@ Account::Account(const QString &sessionId,
{}
QString
Account::registerAccount()
Account::registerAccount() const
{
std::list< QString > args;
args.push_back(mId);
......@@ -37,10 +37,24 @@ Account::registerAccount()
}
QString
Account::unregisterAccount()
Account::unregisterAccount() const
{
std::list< QString > args;
args.push_back(mId);
return Requester::instance().send(mSessionId, "unregister", args);
}
Call
Account::createCall(const QString &to) const
{
QString callId = Requester::instance().generateCallId();
std::list< QString> args;
args.push_back(mId);
args.push_back(callId);
args.push_back(to);
Requester::instance().send(mSessionId, "call", args);
return Call(mSessionId, mId, callId);
}
......@@ -33,10 +33,15 @@ class Account {
/**
* This will generate a call ready to be used.
*/
QString registerAccount();
QString unregisterAccount();
QString registerAccount() const;
QString unregisterAccount() const;
private:
QString id() const
{return mId;}
Call createCall(const QString &to) const;
private:
Account();
/**
......
......@@ -21,41 +21,41 @@
#include <QString>
#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,
bool incomming)
: mSessionId(sessionId)
, mAccountId(accountId)
, mId(callId)
, mIsIncomming(incomming)
{}
{
CallManager::instance().registerCall(*this);
}
Call::Call(const Session &session,
const Account &account,
const QString &callId,
bool incomming)
: mSessionId(session.id())
, mAccountId(account.id())
, mId(callId)
, mIsIncomming(incomming)
{}
{
CallManager::instance().registerCall(*this);
}
bool
Call::isIncomming()
{return mIsIncomming;}
QString
Call::call(const QString &to)
{
std::list< QString> args;
args.push_back("acc1");
args.push_back(mId);
args.push_back(to);
return Requester::instance().send(mSessionId, "call", args);
}
QString
Call::answer()
{
......
......@@ -24,14 +24,22 @@
#include <QString>
class Session;
class Account;
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,
bool incomming = false);
Call(const Session &session,
const Account &account,
const QString &callId,
bool incomming = false);
......@@ -44,8 +52,6 @@ class Call
QString id() const
{return mId;}
QString call(const QString &to);
/**
* This function will answer the call.
*/
......@@ -103,6 +109,11 @@ class Call
*/
QString mSessionId;
/**
* This is the account id that we belong to.
*/
QString mAccountId;
/**
* This is the unique identifier of the call.
*/
......
/**
* 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 <stdexcept>
#include "CallManagerImpl.hpp"
void
CallManagerImpl::registerCall(const Call &call)
{
mCallsMutex.lock();
mCalls.insert(std::make_pair(call.id(), call));
mCallsMutex.unlock();
}
void
CallManagerImpl::unregisterCall(const Call &call)
{
unregisterCall(call.id());
}
void
CallManagerImpl::unregisterCall(const QString &id)
{
QMutexLocker guard(&mCallsMutex);
std::map< QString, Call >::iterator pos = mCalls.find(id);
if(pos == mCalls.end()) {
throw std::runtime_error("Trying to unregister an unregistred call");
}
mCalls.erase(pos);
}
Call
CallManagerImpl::getCall(const QString &id)
{
QMutexLocker guard(&mCallsMutex);
std::map< QString, Call >::iterator pos = mCalls.find(id);
if(pos == mCalls.end()) {
throw std::runtime_error("Trying to retreive an unregistred call");
}
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>
#include <QString>
#include <map>
#include "Call.hpp"
class CallManagerImpl
{
public:
void registerCall(const Call &call);
void unregisterCall(const Call &call);
void unregisterCall(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:
QMutex mCallsMutex;
std::map< QString, Call > mCalls;
};
#endif
......@@ -5,8 +5,10 @@
#include "Call.hpp"
PhoneLine::PhoneLine(const Session &session,
const Account &account,
unsigned int line)
: mSession(session)
, mAccount(account)
, mCall(NULL)
, mLine(line)
, mSelected(false)
......@@ -227,8 +229,7 @@ PhoneLine::call(const QString &to)
_debug("PhoneLine %d: Calling %s.\n", mLine, to.toStdString().c_str());
if(!mCall) {
setLineStatus("Calling " + to + "...");
mCall = new Call(mSession.createCall());
mCall->call(to);
mCall = new Call(mAccount.createCall(to));
clear();
}
}
......
......@@ -13,7 +13,9 @@ class PhoneLine : public QObject
Q_OBJECT
public:
PhoneLine(const Session &session, unsigned int line);
PhoneLine(const Session &session,
const Account &account,
unsigned int line);
~PhoneLine();
void call(const QString &to);
......@@ -115,6 +117,7 @@ signals:
private:
Session mSession;
Account mAccount;
Call *mCall;
QMutex mPhoneLineMutex;
unsigned int mLine;
......
......@@ -145,7 +145,7 @@ PhoneLineManagerImpl::setNbLines(unsigned int nb)
QMutexLocker guard(&mPhoneLinesMutex);
mPhoneLines.clear();
for(unsigned int i = 0; i < nb; i++) {
PhoneLine *p = new PhoneLine(*mSession, i + 1);
PhoneLine *p = new PhoneLine(*mSession, *mAccount, i + 1);
QObject::connect(p, SIGNAL(lineStatusChanged(const QString &)),
this, SIGNAL(lineStatusSet(const QString &)));
QObject::connect(p, SIGNAL(actionChanged(const QString &)),
......@@ -493,21 +493,21 @@ PhoneLineManagerImpl::clear()
}
void
PhoneLineManagerImpl::incomming(const QString &,
PhoneLineManagerImpl::incomming(const QString &accountId,
const QString &peer,
const QString &callId)
{
Call call(*mSession, callId, true);
Call call(mSession->id(), accountId, callId, true);
addCall(call, peer, "Incomming");
}
void
PhoneLineManagerImpl::addCall(const QString &,
PhoneLineManagerImpl::addCall(const QString &accountId,
const QString &callId,
const QString &peer,
const QString &state)
{
addCall(Call(*mSession, callId), peer, state);
addCall(Call(mSession->id(), accountId, callId), peer, state);
}
void
......
......@@ -21,6 +21,7 @@
#include <sstream>
#include "globals.h"
#include "CallManager.hpp"
#include "Request.hpp"
#include "Requester.hpp"
......@@ -93,14 +94,12 @@ CallRelatedRequest::CallRelatedRequest(const QString &sequenceId,
const QString &command,
const std::list< QString > &args)
: Request(sequenceId, command, args)
, mCallId(*args.begin())
{}
void
CallRelatedRequest::onError(const QString &code, const QString &message)
{
onError(Call(Requester::instance().getSessionIdFromSequenceId(getSequenceId()),
mCallId),
onError(CallManager::instance().getCall(mCallId),
code,
message);
}
......@@ -112,8 +111,7 @@ CallRelatedRequest::onError(Call, const QString &, const QString &)
void
CallRelatedRequest::onEntry(const QString &code, const QString &message)
{
onEntry(Call(Requester::instance().getSessionIdFromSequenceId(getSequenceId()),
mCallId),
onEntry(CallManager::instance().getCall(mCallId),
code,
message);
}
......@@ -125,8 +123,7 @@ CallRelatedRequest::onEntry(Call, const QString &, const QString &)
void
CallRelatedRequest::onSuccess(const QString &code, const QString &message)
{
onSuccess(Call(Requester::instance().getSessionIdFromSequenceId(getSequenceId()),
mCallId),
onSuccess(CallManager::instance().getCall(mCallId),
code,
message);
}
......
......@@ -20,12 +20,12 @@ SFLPhoneApp::SFLPhoneApp(int argc, char **argv)
PhoneLineManager::instance().setNbLines(NB_PHONELINES);
Requester::instance().registerObject< Request >(QString("playtone"));
Requester::instance().registerObject< Request >(QString("playdtmf"));
Requester::instance().registerObject< AccountRequest >(QString("call"));
Requester::instance().registerObject< EventRequest >(QString("getevents"));
Requester::instance().registerObject< CallStatusRequest >(QString("getcallstatus"));
Requester::instance().registerObject< PermanentRequest >(QString("answer"));
Requester::instance().registerObject< PermanentRequest >(QString("notavailable"));
Requester::instance().registerObject< PermanentRequest >(QString("refuse"));
Requester::instance().registerObject< PermanentRequest >(QString("call"));
Requester::instance().registerObject< PermanentRequest >(QString("hangup"));
Requester::instance().registerObject< TemporaryRequest >(QString("mute"));
Requester::instance().registerObject< TemporaryRequest >(QString("unmute"));
......
......@@ -102,8 +102,3 @@ Session::getDefaultAccount() const
return Account(mId, QString("mydefaultaccount"));
}
Call
Session::createCall() const
{
return Call(mId, Requester::instance().generateCallId());
}
......@@ -70,8 +70,6 @@ class Session
*/
void connect() const;
Call createCall() const;
QString id() const;
QString playTone() const;
......
......@@ -11,6 +11,8 @@ QT += network
# Input
HEADERS += Account.hpp \
CallManager.hpp \
CallManagerImpl.hpp \
Call.hpp \
CallStatus.hpp \
CallStatusFactory.hpp \
......@@ -46,6 +48,7 @@ HEADERS += Account.hpp \
ObjectPool.inl
SOURCES += Account.cpp \
Call.cpp \
CallManagerImpl.cpp \
CallStatus.cpp \
Event.cpp \
JPushButton.cpp \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment