diff --git a/src/gui/official/Account.cpp b/src/gui/official/Account.cpp index 932d46b6639b714c539501ae088ed9a3784729fe..944e5adaecd62d747f4e97a68877261fd870eb6d 100644 --- a/src/gui/official/Account.cpp +++ b/src/gui/official/Account.cpp @@ -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); +} + + diff --git a/src/gui/official/Account.hpp b/src/gui/official/Account.hpp index b81250934f9710cb19ddfc1a82a0242377979fc9..32a98ef272c0b4e3372bbc574697dafd7e811a9c 100644 --- a/src/gui/official/Account.hpp +++ b/src/gui/official/Account.hpp @@ -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(); /** diff --git a/src/gui/official/Call.cpp b/src/gui/official/Call.cpp index 8055930461952ce2cab8b70ca22922763d95447d..792709544a7074eca8c4ce7f3d5420b90a5a5934 100644 --- a/src/gui/official/Call.cpp +++ b/src/gui/official/Call.cpp @@ -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() { diff --git a/src/gui/official/Call.hpp b/src/gui/official/Call.hpp index 9739247797b2a302073192f8ee1d3043d8ce0507..018b424f8c7131c55c778d3a899c7e518ef16f24 100644 --- a/src/gui/official/Call.hpp +++ b/src/gui/official/Call.hpp @@ -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. */ diff --git a/src/gui/official/CallManager.hpp b/src/gui/official/CallManager.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8eff2b2f687d4bbb45e5501d1db259ea672c77df --- /dev/null +++ b/src/gui/official/CallManager.hpp @@ -0,0 +1,30 @@ +/** + * 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 + diff --git a/src/gui/official/CallManagerImpl.cpp b/src/gui/official/CallManagerImpl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..abb00c0a575c2fee5f23bb93dfe6875efe39d348 --- /dev/null +++ b/src/gui/official/CallManagerImpl.cpp @@ -0,0 +1,61 @@ +/** + * 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; +} diff --git a/src/gui/official/CallManagerImpl.hpp b/src/gui/official/CallManagerImpl.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c71c496e6bb7aca96c45e2ba444fd855447a545f --- /dev/null +++ b/src/gui/official/CallManagerImpl.hpp @@ -0,0 +1,49 @@ +/** + * 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 diff --git a/src/gui/official/PhoneLine.cpp b/src/gui/official/PhoneLine.cpp index ef514ce937ab8a036356494d9c52baebe47679cd..6e590ac8bfdabfdccb9ad683db9a827731884641 100644 --- a/src/gui/official/PhoneLine.cpp +++ b/src/gui/official/PhoneLine.cpp @@ -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(); } } diff --git a/src/gui/official/PhoneLine.hpp b/src/gui/official/PhoneLine.hpp index 1fa152f5a3f30db8cf9c2ecd24130b9817def694..247fc136b7a8ea4491e12840e83dacab26c7c5f2 100644 --- a/src/gui/official/PhoneLine.hpp +++ b/src/gui/official/PhoneLine.hpp @@ -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; diff --git a/src/gui/official/PhoneLineManagerImpl.cpp b/src/gui/official/PhoneLineManagerImpl.cpp index 010adfdd4855ca5937786972a427266a84d33b23..c723e85328fb318258ec9e321b819bc12f11eb53 100644 --- a/src/gui/official/PhoneLineManagerImpl.cpp +++ b/src/gui/official/PhoneLineManagerImpl.cpp @@ -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 diff --git a/src/gui/official/Request.cpp b/src/gui/official/Request.cpp index 3a4c355c1814528357a4bfa2695c47ee4cfab777..77a7079d6680878a605a1577d7686dff9e774c3c 100644 --- a/src/gui/official/Request.cpp +++ b/src/gui/official/Request.cpp @@ -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); } diff --git a/src/gui/official/SFLPhoneApp.cpp b/src/gui/official/SFLPhoneApp.cpp index f2920111617fdcd9953f29a732b903fa0125d81b..5bf8200ec9fa2297f192d3b4bb9019992aca5ffb 100644 --- a/src/gui/official/SFLPhoneApp.cpp +++ b/src/gui/official/SFLPhoneApp.cpp @@ -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")); diff --git a/src/gui/official/Session.cpp b/src/gui/official/Session.cpp index 2be43df8205ebcb9c533dc6f04ed09e2368b8adf..3762dbb1f052f4565f3e7fe1936cca753701f290 100644 --- a/src/gui/official/Session.cpp +++ b/src/gui/official/Session.cpp @@ -102,8 +102,3 @@ Session::getDefaultAccount() const return Account(mId, QString("mydefaultaccount")); } -Call -Session::createCall() const -{ - return Call(mId, Requester::instance().generateCallId()); -} diff --git a/src/gui/official/Session.hpp b/src/gui/official/Session.hpp index 8cabdea1334b5dd0272905e09b38eaf36b9bcc3c..912ede862867c8612a560afc0e4a187eb15383ba 100644 --- a/src/gui/official/Session.hpp +++ b/src/gui/official/Session.hpp @@ -70,8 +70,6 @@ class Session */ void connect() const; - Call createCall() const; - QString id() const; QString playTone() const; diff --git a/src/gui/official/sflphone.pro b/src/gui/official/sflphone.pro index 0e660ce07ebba3725783fffe3dd5e7947b1335a1..7532baeb5d1d3e2ce0ca1bdb7d2c1b1dd86c4ffc 100644 --- a/src/gui/official/sflphone.pro +++ b/src/gui/official/sflphone.pro @@ -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 \