void FSHost::run(void) { switch_core_flag_t flags = SCF_USE_SQL | SCF_USE_AUTO_NAT; const char *err = NULL; switch_bool_t console = SWITCH_FALSE; switch_status_t destroy_status; createFolders(); /* If you need to override configuration directories, you need to change them in the SWITCH_GLOBAL_dirs global structure */ qDebug() << "Initializing core..."; /* Initialize the core and load modules, that will startup FS completely */ if (switch_core_init(flags, console, &err) != SWITCH_STATUS_SUCCESS) { fprintf(stderr, "Failed to initialize FreeSWITCH's core: %s\n", err); emit coreLoadingError(err); } qDebug() << "Everything OK, Entering runtime loop ..."; if (switch_event_bind("FSHost", SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, eventHandlerCallback, NULL) != SWITCH_STATUS_SUCCESS) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n"); } emit loadingModules("Loading modules...", Qt::AlignRight|Qt::AlignBottom, Qt::blue); if (switch_core_init_and_modload(flags, console, &err) != SWITCH_STATUS_SUCCESS) { fprintf(stderr, "Failed to initialize FreeSWITCH's core: %s\n", err); emit coreLoadingError(err); } switch_log_bind_logger(loggerHandler, SWITCH_LOG_DEBUG, SWITCH_FALSE); emit ready(); /* Go into the runtime loop. If the argument is true, this basically sets runtime.running = 1 and loops while that is set * If its false, it initializes the libedit for the console, then does the same thing */ switch_core_runtime_loop(!console); fflush(stdout); switch_event_unbind_callback(eventHandlerCallback); /* When the runtime loop exits, its time to shutdown */ destroy_status = switch_core_destroy(); if (destroy_status == SWITCH_STATUS_SUCCESS) { qDebug() << "We have properly shutdown the core."; } }
void FSHost::createFolders() { /* Create directory structure for softphone with default configs */ QDir conf_dir = QDir::home(); if (!conf_dir.exists(".fscomm")) conf_dir.mkpath(".fscomm"); if (!conf_dir.exists(".fscomm/recordings")) conf_dir.mkpath(".fscomm/recordings"); if (!conf_dir.exists(".fscomm/sounds")) { conf_dir.mkpath(".fscomm/sounds"); QFile::copy(":/sounds/test.wav", QString("%1/.fscomm/sounds/test.wav").arg(QDir::homePath())); } if(!QFile::exists(QString("%1/.fscomm/conf/freeswitch.xml").arg(conf_dir.absolutePath()))) { conf_dir.mkdir(".fscomm/conf"); QFile rootXML(":/confs/freeswitch.xml"); QString dest = QString("%1/.fscomm/conf/freeswitch.xml").arg(conf_dir.absolutePath()); rootXML.copy(dest); } /* Set all directories to the home user directory */ if (conf_dir.cd(".fscomm")) { SWITCH_GLOBAL_dirs.conf_dir = (char *) malloc(strlen(QString("%1/conf").arg(conf_dir.absolutePath()).toAscii().constData()) + 1); if (!SWITCH_GLOBAL_dirs.conf_dir) { emit coreLoadingError("Cannot allocate memory for conf_dir."); } strcpy(SWITCH_GLOBAL_dirs.conf_dir, QString("%1/conf").arg(conf_dir.absolutePath()).toAscii().constData()); SWITCH_GLOBAL_dirs.log_dir = (char *) malloc(strlen(QString("%1/log").arg(conf_dir.absolutePath()).toAscii().constData()) + 1); if (!SWITCH_GLOBAL_dirs.log_dir) { emit coreLoadingError("Cannot allocate memory for log_dir."); } strcpy(SWITCH_GLOBAL_dirs.log_dir, QString("%1/log").arg(conf_dir.absolutePath()).toAscii().constData()); SWITCH_GLOBAL_dirs.run_dir = (char *) malloc(strlen(QString("%1/run").arg(conf_dir.absolutePath()).toAscii().constData()) + 1); if (!SWITCH_GLOBAL_dirs.run_dir) { emit coreLoadingError("Cannot allocate memory for run_dir."); } strcpy(SWITCH_GLOBAL_dirs.run_dir, QString("%1/run").arg(conf_dir.absolutePath()).toAscii().constData()); SWITCH_GLOBAL_dirs.db_dir = (char *) malloc(strlen(QString("%1/db").arg(conf_dir.absolutePath()).toAscii().constData()) + 1); if (!SWITCH_GLOBAL_dirs.db_dir) { emit coreLoadingError("Cannot allocate memory for db_dir."); } strcpy(SWITCH_GLOBAL_dirs.db_dir, QString("%1/db").arg(conf_dir.absolutePath()).toAscii().constData()); SWITCH_GLOBAL_dirs.script_dir = (char *) malloc(strlen(QString("%1/script").arg(conf_dir.absolutePath()).toAscii().constData()) + 1); if (!SWITCH_GLOBAL_dirs.script_dir) { emit coreLoadingError("Cannot allocate memory for script_dir."); } strcpy(SWITCH_GLOBAL_dirs.script_dir, QString("%1/script").arg(conf_dir.absolutePath()).toAscii().constData()); SWITCH_GLOBAL_dirs.htdocs_dir = (char *) malloc(strlen(QString("%1/htdocs").arg(conf_dir.absolutePath()).toAscii().constData()) + 1); if (!SWITCH_GLOBAL_dirs.htdocs_dir) { emit coreLoadingError("Cannot allocate memory for htdocs_dir."); } strcpy(SWITCH_GLOBAL_dirs.htdocs_dir, QString("%1/htdocs").arg(conf_dir.absolutePath()).toAscii().constData()); } }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), preferences(NULL), _consoleWindow(NULL), _stateDebugDialog(NULL) { ui->setupUi(this); /* Setup the taskbar icon */ sysTray = new QSystemTrayIcon(QIcon(":/images/taskbar_icon"), this); sysTray->setToolTip(tr("FSComm")); /* Connect DTMF buttons */ dialpadMapper = new QSignalMapper(this); connect(ui->dtmf0Btn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmf1Btn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmf2Btn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmf3Btn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmf4Btn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmf5Btn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmf6Btn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmf7Btn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmf8Btn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmf9Btn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmfABtn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmfBBtn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmfCBtn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmfDBtn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmfAstBtn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); connect(ui->dtmfPoundBtn, SIGNAL(clicked()), dialpadMapper, SLOT(map())); dialpadMapper->setMapping(ui->dtmf0Btn, QString("0")); dialpadMapper->setMapping(ui->dtmf1Btn, QString("1")); dialpadMapper->setMapping(ui->dtmf2Btn, QString("2")); dialpadMapper->setMapping(ui->dtmf3Btn, QString("3")); dialpadMapper->setMapping(ui->dtmf4Btn, QString("4")); dialpadMapper->setMapping(ui->dtmf5Btn, QString("5")); dialpadMapper->setMapping(ui->dtmf6Btn, QString("6")); dialpadMapper->setMapping(ui->dtmf7Btn, QString("7")); dialpadMapper->setMapping(ui->dtmf8Btn, QString("8")); dialpadMapper->setMapping(ui->dtmf9Btn, QString("9")); dialpadMapper->setMapping(ui->dtmfABtn, QString("A")); dialpadMapper->setMapping(ui->dtmfBBtn, QString("B")); dialpadMapper->setMapping(ui->dtmfCBtn, QString("C")); dialpadMapper->setMapping(ui->dtmfDBtn, QString("D")); dialpadMapper->setMapping(ui->dtmfAstBtn, QString("*")); dialpadMapper->setMapping(ui->dtmfPoundBtn, QString("#")); connect(dialpadMapper, SIGNAL(mapped(QString)), this, SLOT(sendDTMF(QString))); /* Connect events related to FreeSWITCH */ connect(g_FSHost, SIGNAL(ready()),this, SLOT(fshostReady())); connect(g_FSHost, SIGNAL(ringing(QSharedPointer<Call>)), this, SLOT(ringing(QSharedPointer<Call>))); connect(g_FSHost, SIGNAL(answered(QSharedPointer<Call>)), this, SLOT(answered(QSharedPointer<Call>))); connect(g_FSHost, SIGNAL(hungup(QSharedPointer<Call>)), this, SLOT(hungup(QSharedPointer<Call>))); connect(g_FSHost, SIGNAL(newOutgoingCall(QSharedPointer<Call>)), this, SLOT(newOutgoingCall(QSharedPointer<Call>))); connect(g_FSHost, SIGNAL(callFailed(QSharedPointer<Call>)), this, SLOT(callFailed(QSharedPointer<Call>))); connect(g_FSHost, SIGNAL(accountStateChange(QSharedPointer<Account>)), this, SLOT(accountStateChanged(QSharedPointer<Account>))); connect(g_FSHost, SIGNAL(newAccount(QSharedPointer<Account>)), this, SLOT(accountAdd(QSharedPointer<Account>))); connect(g_FSHost, SIGNAL(delAccount(QSharedPointer<Account>)), this, SLOT(accountDel(QSharedPointer<Account>))); connect(g_FSHost, SIGNAL(coreLoadingError(QString)), this, SLOT(coreLoadingError(QString))); /* Connect call commands */ connect(ui->newCallBtn, SIGNAL(clicked()), this, SLOT(makeCall())); connect(ui->answerBtn, SIGNAL(clicked()), this, SLOT(paAnswer())); connect(ui->hangupBtn, SIGNAL(clicked()), this, SLOT(paHangup())); connect(ui->recoredCallBtn, SIGNAL(toggled(bool)), SLOT(recordCall(bool))); connect(ui->btnHold, SIGNAL(toggled(bool)), this, SLOT(holdCall(bool))); /*connect(ui->btnTransfer, SIGNAL(clicked()), this, SLOT(transferCall()));*/ connect(ui->tableCalls, SIGNAL(itemDoubleClicked(QTableWidgetItem*)), this, SLOT(callTableDoubleClick(QTableWidgetItem*))); connect(ui->action_Preferences, SIGNAL(triggered()), this, SLOT(prefTriggered())); connect(ui->action_Exit, SIGNAL(triggered()), this, SLOT(close())); connect(ui->actionConsole, SIGNAL(triggered()), this, SLOT(debugConsoleTriggered())); connect(ui->actionEvents, SIGNAL(triggered()), this, SLOT(debugEventsTriggered())); connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(showAbout())); connect(ui->actionSetDefaultAccount, SIGNAL(triggered(bool)), this, SLOT(setDefaultAccount())); connect(sysTray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(sysTrayActivated(QSystemTrayIcon::ActivationReason))); /* Set the context menus */ ui->tableAccounts->addAction(ui->actionSetDefaultAccount); /* Set other properties */ ui->tableAccounts->horizontalHeader()->setStretchLastSection(true); /* Set the call timer */ callTimer = new QTimer(this); callTimer->setInterval(1000); connect(callTimer, SIGNAL(timeout()), this, SLOT(updateCallTimers())); callTimer->start(); }