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

we can process hangup events

parent 38fbeda8
Branches
Tags
No related merge requests found
......@@ -33,6 +33,9 @@ class Call
Call(const Session &session,
const std::string &callId);
std::string id()
{return mId;}
std::string call(const std::string &to);
/**
......
#include "globals.h"
#include "Event.hpp"
#include "PhoneLineManager.hpp"
Event::Event(const std::string &code,
const std::list< std::string > &args)
: mCode(code)
, mArgs(args)
{}
std::string
Event::toString()
{
std::string output(mCode);
for(std::list< std::string >::iterator pos = mArgs.begin();
pos != mArgs.end();
pos++) {
output += *pos;
}
return output;
}
HangupEvent::HangupEvent(const std::string &code,
const std::list< std::string > &args)
: Event(code, args)
{
if(args.size() != 0) {
mCallId = *args.begin();
}
}
void
HangupEvent::execute()
{
if(mCallId.size() > 0) {
_debug("Hangup Event received for call ID: %s.\n", mCallId.c_str());
PhoneLineManager::instance().hangup(mCallId);
}
else {
_debug("Event invalid: %s\n", toString().c_str());
}
}
/**
* 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 __EVENT_HPP__
#define __EVENT_HPP__
#include <list>
#include <string>
class Event
{
public:
Event(const std::string &code,
const std::list< std::string > &args);
virtual ~Event(){}
virtual void execute(){};
virtual std::string toString();
private:
std::string mCode;
std::list< std::string > mArgs;
};
class HangupEvent : public Event
{
public:
HangupEvent(const std::string &code,
const std::list< std::string > &args);
virtual void execute();
private:
std::string mCallId;
};
#endif
......@@ -140,3 +140,15 @@ PhoneLine::hangup()
unselect();
}
std::string
PhoneLine::getCallId()
{
std::string id;
if(mCall) {
id = mCall->id();
}
return id;
}
......@@ -20,6 +20,8 @@ public:
void hangup();
void hold();
std::string getCallId();
unsigned int line();
/**
......
#include <QMutexLocker>
#include <iostream>
#include <stdexcept>
#include "globals.h"
#include "PhoneLine.hpp"
#include "PhoneLineLocker.hpp"
#include "PhoneLineManager.hpp"
PhoneLineManager::PhoneLineManager(unsigned int nbLines)
: mAccount(mSession.getDefaultAccount())
, mCurrentLine(NULL)
{
for(unsigned int i = 0; i < nbLines; i++) {
mPhoneLines.push_back(new PhoneLine(mSession.createCall(),
i));
}
}
void
PhoneLineManager::selectAvailableLine()
{
PhoneLine *selectedLine = NULL;
mPhoneLinesMutex.lock();
unsigned int i = 0;
while(i < mPhoneLines.size() && !selectedLine) {
PhoneLineLocker guard(mPhoneLines[i]);
if(mPhoneLines[i]->isAvailable()) {
selectedLine = mPhoneLines[i];
}
else {
i++;
}
}
mPhoneLinesMutex.unlock();
if(selectedLine) {
selectLine(i);
}
}
PhoneLine *
PhoneLineManager::getPhoneLine(unsigned int line)
{
QMutexLocker guard(&mPhoneLinesMutex);
if(mPhoneLines.size() <= line) {
throw std::runtime_error("Trying to get an invalid Line");
}
return mPhoneLines[line];
}
void
PhoneLineManager::sendKey(Qt::Key c)
{
PhoneLine *selectedLine = NULL;
mCurrentLineMutex.lock();
selectedLine = mCurrentLine;
mCurrentLineMutex.unlock();
if(!selectedLine) {
selectAvailableLine();
mCurrentLineMutex.lock();
selectedLine = mCurrentLine;
mCurrentLineMutex.unlock();
}
if(selectedLine) {
PhoneLineLocker guard(selectedLine);
selectedLine->sendKey(c);
}
}
/**
* Warning: This function might 'cause a problem if
* we select 2 line in a very short time.
*/
void
PhoneLineManager::selectLine(unsigned int line)
{
PhoneLine *selectedLine = NULL;
// getting the wanted line;
{
mPhoneLinesMutex.lock();
if(mPhoneLines.size() > line) {
selectedLine = mPhoneLines[line];
}
mPhoneLinesMutex.unlock();
}
if(selectedLine != NULL) {
_debug("Line %d selected.\n", line);
mCurrentLineMutex.lock();
PhoneLine *oldLine = mCurrentLine;
mCurrentLine = selectedLine;
mCurrentLineMutex.unlock();
if(oldLine != selectedLine) {
if(oldLine != NULL) {
PhoneLineLocker guard(oldLine);
oldLine->unselect();
}
PhoneLineLocker guard(selectedLine);
selectedLine->select();
if(selectedLine->isAvailable()) {
mSession.sendTone();
}
}
}
else {
_debug("Tried to selected line %d, which appears to be invalid.\n", line);
}
}
void
PhoneLineManager::call(const QString &)
{
}
......@@ -81,6 +81,27 @@ PhoneLineManagerImpl::getPhoneLine(unsigned int line)
return mPhoneLines[line];
}
PhoneLine *
PhoneLineManagerImpl::getPhoneLine(const std::string &callId)
{
PhoneLine *selectedLine = NULL;
QMutexLocker guard(&mPhoneLinesMutex);
unsigned int i = 0;
while(i < mPhoneLines.size() &&
!selectedLine) {
if(mPhoneLines[i]->getCallId() == callId) {
selectedLine = mPhoneLines[i];
}
else {
i++;
}
}
return selectedLine;
}
void
PhoneLineManagerImpl::sendKey(Qt::Key c)
{
......@@ -187,6 +208,26 @@ PhoneLineManagerImpl::hangup()
}
}
void
PhoneLineManagerImpl::hangup(const std::string &callId)
{
PhoneLine *selectedLine = getPhoneLine(callId);
if(selectedLine) {
PhoneLineLocker guard(selectedLine);
selectedLine->hangup();
}
}
void
PhoneLineManagerImpl::hangup(unsigned int line)
{
PhoneLine *selectedLine = getPhoneLine(line);
if(selectedLine) {
PhoneLineLocker guard(selectedLine);
selectedLine->hangup();
}
}
void
PhoneLineManagerImpl::clear()
{
......
......@@ -24,9 +24,19 @@ public:
PhoneLineManagerImpl();
/**
* Will return the PhoneLine linked to the line
* number.
*/
PhoneLine *getPhoneLine(unsigned int line);
/**
* Will return the PhoneLine with the call ID.
* If there's no PhoneLine of call ID, it will
* return NULL.
*/
PhoneLine *getPhoneLine(const std::string &callId);
PhoneLine *getPhoneLine(unsigned int line);
PhoneLine *getCurrentLine();
void setNbLines(unsigned int line);
......@@ -51,6 +61,20 @@ public slots:
*/
void hangup();
/**
* This function will hanp up the line number given
* argument. Be aware that the first line is 1, not
* zero.
*/
void hangup(unsigned int line);
/**
* This function will hanp up the line with the
* following call ID. If there's no line with
* the call ID, it will do nothing.
*/
void hangup(const std::string &callId);
/**
* This function will make a call on the
* current line. If there's no selected
......
src/gui/official/images/clear_off.png

1.35 KiB

src/gui/official/images/clear_on.png

1.35 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment