fshost.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. #ifndef FSHOST_H
  30. #define FSHOST_H
  31. #include <QThread>
  32. #include <QColor>
  33. #include <QHash>
  34. #include <QSharedPointer>
  35. #include <switch.h>
  36. #include "call.h"
  37. #include "channel.h"
  38. #include "account.h"
  39. #include "fscomm.h"
  40. static void eventHandlerCallback(switch_event_t *);
  41. static switch_status_t loggerHandler(const switch_log_node_t *, switch_log_level_t);
  42. class FSHost : public QThread
  43. {
  44. Q_OBJECT
  45. public:
  46. explicit FSHost(QObject *parent = 0);
  47. switch_status_t sendCmd(const char *cmd, const char *args, QString *res);
  48. void generalEventHandler(QSharedPointer<switch_event_t>event);
  49. void generalLoggerHandler(QSharedPointer<switch_log_node_t>node, switch_log_level_t level);
  50. void printEventHeaders(QSharedPointer<switch_event_t>event);
  51. QSharedPointer<Call> getCallByUUID(QString uuid) { return _active_calls.value(uuid); }
  52. QSharedPointer<Call> getCurrentActiveCall();
  53. QList<QSharedPointer<Account> > getAccounts() { return _accounts.values(); }
  54. QSharedPointer<Account> getAccountByUUID(QString uuid);
  55. QSharedPointer<Account> getCurrentDefaultAccount();
  56. QSharedPointer<Account> getAccountByName(QString accStr);
  57. void accountReloadCmd(QSharedPointer<Account> acc);
  58. QBool isModuleLoaded(QString);
  59. protected:
  60. void run(void);
  61. signals:
  62. /* Status signals */
  63. void coreLoadingError(QString);
  64. void loadingModules(QString, int, QColor);
  65. void loadedModule(QString, QString);
  66. void ready(void);
  67. /* Logging signals */
  68. void eventLog(QSharedPointer<switch_log_node_t>, switch_log_level_t);
  69. void newEvent(QSharedPointer<switch_event_t>);
  70. /* Call signals */
  71. void ringing(QSharedPointer<Call>);
  72. void answered(QSharedPointer<Call>);
  73. void newOutgoingCall(QSharedPointer<Call>);
  74. void callFailed(QSharedPointer<Call>);
  75. void hungup(QSharedPointer<Call>);
  76. /* Account signals */
  77. void accountStateChange(QSharedPointer<Account>);
  78. void newAccount(QSharedPointer<Account>);
  79. void delAccount(QSharedPointer<Account>);
  80. private slots:
  81. /* We need to wait for the gateway deletion before reloading it */
  82. void accountReloadSlot(QSharedPointer<Account>);
  83. void minimalModuleLoaded(QString, QString);
  84. private:
  85. /* Helper methods */
  86. void createFolders();
  87. /*FSM State handlers*/
  88. /** Channel Related*/
  89. void eventChannelCreate(QSharedPointer<switch_event_t> event, QString uuid);
  90. void eventChannelAnswer(QSharedPointer<switch_event_t> event, QString uuid);
  91. void eventChannelState(QSharedPointer<switch_event_t>event, QString uuid);
  92. void eventChannelExecute(QSharedPointer<switch_event_t>event, QString uuid);
  93. void eventChannelExecuteComplete(QSharedPointer<switch_event_t>event, QString uuid);
  94. void eventChannelOutgoing(QSharedPointer<switch_event_t>event, QString uuid);
  95. void eventChannelOriginate(QSharedPointer<switch_event_t>event, QString uuid);
  96. void eventChannelProgress(QSharedPointer<switch_event_t>event, QString uuid);
  97. void eventChannelProgressMedia(QSharedPointer<switch_event_t>event, QString uuid);
  98. void eventChannelBridge(QSharedPointer<switch_event_t>event, QString uuid);
  99. void eventChannelHangup(QSharedPointer<switch_event_t>event, QString uuid);
  100. void eventChannelUnbridge(QSharedPointer<switch_event_t>event, QString uuid);
  101. void eventChannelHangupComplete(QSharedPointer<switch_event_t>event, QString uuid);
  102. void eventChannelDestroy(QSharedPointer<switch_event_t>event, QString uuid);
  103. /** Others*/
  104. void eventCodec(QSharedPointer<switch_event_t>event, QString uuid);
  105. void eventCallUpdate(QSharedPointer<switch_event_t>event, QString uuid);
  106. void eventRecvInfo(QSharedPointer<switch_event_t>event, QString uuid);
  107. /* Structures to keep track of things */
  108. QHash<QString, QSharedPointer<Call> > _active_calls;
  109. QHash<QString, QSharedPointer<Account> > _accounts;
  110. QHash<QString, QSharedPointer<Channel> > _channels;
  111. QList<QString> _reloading_Accounts;
  112. QList<QString> _loadedModules;
  113. };
  114. extern FSHost *g_FSHost;
  115. #endif // FSHOST_H