call.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
  3. * Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
  4. *
  5. * Version: MPL 1.1
  6. *
  7. * The contents of this file are subject to the Mozilla Public License Version
  8. * 1.1 (the "License"); you may not use this file except in compliance with
  9. * the License. You may obtain a copy of the License at
  10. * http://www.mozilla.org/MPL/
  11. *
  12. * Software distributed under the License is distributed on an "AS IS" basis,
  13. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  14. * for the specific language governing rights and limitations under the
  15. * License.
  16. *
  17. * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
  18. *
  19. * The Initial Developer of the Original Code is
  20. * Anthony Minessale II <anthm@freeswitch.org>
  21. * Portions created by the Initial Developer are Copyright (C)
  22. * the Initial Developer. All Rights Reserved.
  23. *
  24. * Contributor(s):
  25. *
  26. * Joao Mesquita <jmesquita@freeswitch.org>
  27. *
  28. */
  29. #include "call.h"
  30. #include <QtGui>
  31. #include <fshost.h>
  32. Call::Call()
  33. {
  34. _answeredEpoch = 0;
  35. }
  36. switch_status_t Call::toggleHold(bool holdPressed)
  37. {
  38. if (_state != FSCOMM_CALL_STATE_ANSWERED) return SWITCH_STATUS_FALSE;
  39. switch_stream_handle_t stream = { 0 };
  40. SWITCH_STANDARD_STREAM(stream);
  41. QString holdStr;
  42. if (holdPressed)
  43. {
  44. holdStr = _channel.data()->getUuid();
  45. }
  46. else
  47. {
  48. holdStr = "off " + _channel.data()->getUuid();
  49. }
  50. switch_status_t st = switch_api_execute("uuid_hold", holdStr.toAscii().data(), NULL, &stream);
  51. switch_safe_free(stream.data);
  52. return st;
  53. }
  54. switch_status_t Call::toggleRecord(bool startRecord)
  55. {
  56. QDir conf_dir = QDir::home();
  57. QString result;
  58. switch_status_t status;
  59. if (startRecord)
  60. {
  61. _recording_filename = QString("%1/.fscomm/recordings/%2_%3.wav").arg(
  62. conf_dir.absolutePath(),
  63. QDateTime::currentDateTime().toString("yyyyMMddhhmmss"),
  64. getCidNumber());
  65. status = g_FSHost->sendCmd("uuid_record", QString("%1 start %2").arg(getUuid(), _recording_filename).toAscii().data(),&result);
  66. }
  67. else
  68. {
  69. switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Stopping call recording on call [%s]\n",
  70. getUuid().toAscii().data());
  71. status = g_FSHost->sendCmd("uuid_record", QString("%1 stop %2").arg(getUuid(), _recording_filename).toAscii().data(),&result);
  72. }
  73. return status;
  74. }
  75. void Call::sendDTMF(QString digit)
  76. {
  77. QString result;
  78. QString dtmf_string = QString("dtmf %1").arg(digit);
  79. if (g_FSHost->sendCmd("pa", dtmf_string.toAscii(), &result) == SWITCH_STATUS_FALSE) {
  80. switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not send DTMF digit %s on call[%s]", digit.toAscii().data(), getUuid().toAscii().data());
  81. QMessageBox::critical(0, QWidget::tr("DTMF Error"), QWidget::tr("There was an error sending DTMF, please report this bug."), QMessageBox::Ok);
  82. }
  83. }
  84. QTime Call::getCurrentStateTime()
  85. {
  86. qulonglong time = 0;
  87. if (_state == FSCOMM_CALL_STATE_ANSWERED)
  88. {
  89. time = _answeredEpoch;
  90. }
  91. else if(_state == FSCOMM_CALL_STATE_RINGING)
  92. {
  93. if (_direction == FSCOMM_CALL_DIRECTION_INBOUND)
  94. {
  95. time = _channel.data()->getCreatedEpoch();
  96. }
  97. else
  98. _otherLegChannel.data()->getProgressEpoch() == 0 ? time = _otherLegChannel.data()->getProgressMediaEpoch() : time = _otherLegChannel.data()->getProgressEpoch();
  99. }
  100. int now = QDateTime::fromTime_t(time).secsTo(QDateTime::currentDateTime());
  101. return QTime::fromString(QString::number(now), "s");
  102. }
  103. /*bool Call::transfer()
  104. {
  105. g_FSHost.sendCmd("uuid_bridge", "")
  106. }*/