提交 3ed45189 authored 作者: Joao Mesquita's avatar Joao Mesquita

Use more SharedPointers to make our lives easier.

上级 b9d5c62b
......@@ -32,7 +32,9 @@
#include <fshost.h>
Call::Call()
{}
{
_answeredEpoch = 0;
}
switch_status_t Call::toggleRecord(bool startRecord)
{
......@@ -70,6 +72,23 @@ void Call::sendDTMF(QString digit)
QTime Call::getCurrentStateTime()
{
int now = QDateTime::fromTime_t(_answered_epoch).secsTo(QDateTime::currentDateTime());
qulonglong time = 0;
if (_state == FSCOMM_CALL_STATE_ANSWERED)
{
time = _answeredEpoch;
}
else if(_state == FSCOMM_CALL_STATE_RINGING)
{
if (_direction == FSCOMM_CALL_DIRECTION_INBOUND)
{
/* TODO: DOESNT WORK - How do I get what time it started to ring? */
_channel.data()->getProgressEpoch() == 0 ? time = _channel.data()->getProgressMediaEpoch() : time = _channel.data()->getProgressEpoch();
}
else
_otherLegChannel.data()->getProgressEpoch() == 0 ? time = _otherLegChannel.data()->getProgressMediaEpoch() : time = _otherLegChannel.data()->getProgressEpoch();
}
int now = QDateTime::fromTime_t(time).secsTo(QDateTime::currentDateTime());
return QTime::fromString(QString::number(now), "s");
}
......@@ -72,7 +72,7 @@ public:
bool isActive() { return _isActive == true; }
switch_status_t toggleRecord(bool);
void sendDTMF(QString digit);
void setAnsweredEpoch(qulonglong time) { _answered_epoch = time/1000000; }
void setAnsweredEpoch(qulonglong time) { _answeredEpoch = time/1000000; }
QTime getCurrentStateTime();
private:
......@@ -85,7 +85,7 @@ private:
bool _isActive;
QString _recording_filename;
fscomm_call_state_t _state;
qulonglong _answered_epoch;
qulonglong _answeredEpoch;
};
Q_DECLARE_METATYPE(Call)
......
......@@ -3,4 +3,6 @@
Channel::Channel(QString uuid):
_uuid(uuid)
{
_progressEpoch = 0;
_progressMediaEpoch = 0;
}
......@@ -16,14 +16,22 @@ public:
void setDestinatinonNumber(QString destinationNumber) { _destinationNumber = destinationNumber; }
QString getDestinationNumber() { return _destinationNumber; }
int getPaCallId() { return _pa_call_id; }
int getPaCallId() { return _paCallId; }
void setPaCallId(int paCallId) { _paCallId = paCallId;}
void setProgressEpoch(qulonglong time) { _progressEpoch = time/1000000; }
qulonglong getProgressEpoch() { return _progressEpoch; }
void setProgressMediaEpoch(qulonglong time) { _progressMediaEpoch = time/1000000; }
qulonglong getProgressMediaEpoch() { return _progressMediaEpoch; }
private:
QString _uuid;
QString _cidName;
QString _cidNumber;
QString _destinationNumber;
int _pa_call_id;
int _paCallId;
qulonglong _progressEpoch;
qulonglong _progressMediaEpoch;
};
Q_DECLARE_METATYPE(Channel)
......
差异被折叠。
......@@ -44,7 +44,7 @@ Q_OBJECT
public:
explicit FSHost(QObject *parent = 0);
switch_status_t sendCmd(const char *cmd, const char *args, QString *res);
void generalEventHandler(switch_event_t *event);
void generalEventHandler(QSharedPointer<switch_event_t>event);
QSharedPointer<Call> getCallByUUID(QString uuid) { return _active_calls.value(uuid); }
QSharedPointer<Call> getCurrentActiveCall();
QList<QSharedPointer<Account> > getAccounts() { return _accounts.values(); }
......@@ -84,28 +84,29 @@ private slots:
private:
/* Helper methods */
void createFolders();
void printEventHeaders(switch_event_t *event);
void printEventHeaders(QSharedPointer<switch_event_t>event);
/*FSM State handlers*/
/** Channel Related*/
void eventChannelCreate(switch_event_t *event, QString uuid);
void eventChannelAnswer(switch_event_t *event, QString uuid);
void eventChannelState(switch_event_t *event, QString uuid);
void eventChannelExecute(switch_event_t *event, QString uuid);
void eventChannelExecuteComplete(switch_event_t *event, QString uuid);
void eventChannelOutgoing(switch_event_t *event, QString uuid);
void eventChannelOriginate(switch_event_t *event, QString uuid);
void eventChannelProgressMedia(switch_event_t *event, QString uuid);
void eventChannelBridge(switch_event_t *event, QString uuid);
void eventChannelHangup(switch_event_t *event, QString uuid);
void eventChannelUnbridge(switch_event_t *event, QString uuid);
void eventChannelHangupComplete(switch_event_t *event, QString uuid);
void eventChannelDestroy(switch_event_t *event, QString uuid);
void eventChannelCreate(QSharedPointer<switch_event_t> event, QString uuid);
void eventChannelAnswer(QSharedPointer<switch_event_t> event, QString uuid);
void eventChannelState(QSharedPointer<switch_event_t>event, QString uuid);
void eventChannelExecute(QSharedPointer<switch_event_t>event, QString uuid);
void eventChannelExecuteComplete(QSharedPointer<switch_event_t>event, QString uuid);
void eventChannelOutgoing(QSharedPointer<switch_event_t>event, QString uuid);
void eventChannelOriginate(QSharedPointer<switch_event_t>event, QString uuid);
void eventChannelProgress(QSharedPointer<switch_event_t>event, QString uuid);
void eventChannelProgressMedia(QSharedPointer<switch_event_t>event, QString uuid);
void eventChannelBridge(QSharedPointer<switch_event_t>event, QString uuid);
void eventChannelHangup(QSharedPointer<switch_event_t>event, QString uuid);
void eventChannelUnbridge(QSharedPointer<switch_event_t>event, QString uuid);
void eventChannelHangupComplete(QSharedPointer<switch_event_t>event, QString uuid);
void eventChannelDestroy(QSharedPointer<switch_event_t>event, QString uuid);
/** Others*/
void eventCodec(switch_event_t *event, QString uuid);
void eventCallUpdate(switch_event_t *event, QString uuid);
void eventRecvInfo(switch_event_t *event, QString uuid);
void eventCodec(QSharedPointer<switch_event_t>event, QString uuid);
void eventCallUpdate(QSharedPointer<switch_event_t>event, QString uuid);
void eventRecvInfo(QSharedPointer<switch_event_t>event, QString uuid);
/* Structures to keep track of things */
QHash<QString, QSharedPointer<Call> > _active_calls;
......@@ -125,9 +126,9 @@ static void eventHandlerCallback(switch_event_t *event)
{
switch_event_t *clone = NULL;
if (switch_event_dup(&clone, event) == SWITCH_STATUS_SUCCESS) {
g_FSHost.generalEventHandler(clone);
QSharedPointer<switch_event_t> e(clone);
g_FSHost.generalEventHandler(e);
}
switch_safe_free(clone);
}
#endif // FSHOST_H
......@@ -133,7 +133,7 @@ void MainWindow::updateCallTimers()
QSharedPointer<Call> call = g_FSHost.getCallByUUID(item->data(Qt::UserRole).toString());
QTime time = call.data()->getCurrentStateTime();
item->setText(time.toString("hh:mm:ss"));
item->setTextAlignment(Qt::AlignRight);
item->setTextAlignment(Qt::AlignRight|Qt::AlignVCenter);
}
}
......@@ -267,7 +267,6 @@ void MainWindow::makeCall()
switch_core_set_variable("fscomm_caller_id_name", cidName.toAscii().data());
switch_core_set_variable("fscomm_caller_id_num", cidNum.toAscii().data());
qDebug() << "Name:" << cidName << "Num:" << cidNum;
}
if (ok && !dialstring.isEmpty())
......@@ -396,12 +395,18 @@ void MainWindow::ringing(QSharedPointer<Call> call)
if (item->data(Qt::UserRole).toString() == call.data()->getUuid())
{
item->setText(tr("Ringing"));
if (call.data()->getDirection() == FSCOMM_CALL_DIRECTION_INBOUND)
ui->textEdit->setText(QString("Call from %1 (%2)").arg(call.data()->getCidName(), call.data()->getCidNumber()));
else
ui->textEdit->setText(QString("Call to %1 is ringing.").arg(call.data()->getDestinationNumber()));
return;
}
}
if (call.data()->getDirection() == FSCOMM_CALL_DIRECTION_INBOUND)
ui->textEdit->setText(QString("Call from %1 (%2)").arg(call.data()->getCidName(), call.data()->getCidNumber()));
else
ui->textEdit->setText(QString("Call to %1 is ringing.").arg(call.data()->getDestinationNumber()));
ui->tableCalls->setRowCount(ui->tableCalls->rowCount()+1);
QTableWidgetItem *item0 = new QTableWidgetItem(QString("%1 (%2)").arg(call.data()->getCidName(), call.data()->getCidNumber()));
......@@ -521,7 +526,7 @@ void MainWindow::hungup(QSharedPointer<Call> call)
}
else
{
ui->textEdit->setText(tr("Call with %1 hungup.").arg(call.data()->getCidNumber()));
ui->textEdit->setText(tr("Call with %1 hungup.").arg(call.data()->getDestinationNumber()));
}
/* TODO: Will cause problems if 2 calls are received at the same time */
ui->recoredCallBtn->setEnabled(false);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论