diff --git a/daemon/Makefile.am b/daemon/Makefile.am index a2829100b..942fb1ea8 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -14,6 +14,7 @@ linphone_daemon_SOURCES=daemon.cc \ commands/call.cc \ commands/call-stats.cc \ commands/call-status.cc \ + commands/dtmf.cc \ commands/firewall-policy.cc \ commands/help.cc \ commands/ipv6.cc \ @@ -39,6 +40,7 @@ linphone_daemon_SOURCES=daemon.cc \ commands/call.h \ commands/call-stats.h \ commands/call-status.h \ + commands/dtmf.h \ commands/firewall-policy.h \ commands/help.h \ commands/ipv6.h \ diff --git a/daemon/commands/dtmf.cc b/daemon/commands/dtmf.cc new file mode 100644 index 000000000..97a87457a --- /dev/null +++ b/daemon/commands/dtmf.cc @@ -0,0 +1,26 @@ +#include "dtmf.h" + +using namespace std; + +DtmfCommand::DtmfCommand() : + DaemonCommand("dtmf", "dtmf ", "Generate a DTMF (one of: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, *, #.") { +} + +void DtmfCommand::exec(Daemon *app, const char *args) { + string digit_str; + char digit; + istringstream ist(args); + ist >> digit_str; + if (ist.fail()) { + app->sendResponse(Response("Missing digit parameter.", Response::Error)); + } else { + digit = digit_str.at(0); + if (isdigit(digit) || (digit == 'A') || (digit == 'B') || (digit == 'C') || (digit == 'D') || (digit == '*') || (digit == '#')) { + linphone_core_play_dtmf(app->getCore(), digit, 100); + linphone_core_send_dtmf(app->getCore(), digit); + app->sendResponse(Response()); + } else { + app->sendResponse(Response("Incorrect digit parameter.", Response::Error)); + } + } +} diff --git a/daemon/commands/dtmf.h b/daemon/commands/dtmf.h new file mode 100644 index 000000000..d1b6fc8cd --- /dev/null +++ b/daemon/commands/dtmf.h @@ -0,0 +1,12 @@ +#ifndef COMMAND_DTMF_H_ +#define COMMAND_DTMF_H_ + +#include "../daemon.h" + +class DtmfCommand: public DaemonCommand { +public: + DtmfCommand(); + virtual void exec(Daemon *app, const char *args); +}; + +#endif //COMMAND_DTMF_H_ diff --git a/daemon/daemon.cc b/daemon/daemon.cc index 897f34722..9e977f7f3 100644 --- a/daemon/daemon.cc +++ b/daemon/daemon.cc @@ -21,6 +21,7 @@ #include "commands/call.h" #include "commands/call-stats.h" #include "commands/call-status.h" +#include "commands/dtmf.h" #include "commands/firewall-policy.h" #include "commands/help.h" #include "commands/ipv6.h" @@ -314,6 +315,7 @@ void Daemon::initCommands() { mCommands.push_back(new UnregisterCommand()); mCommands.push_back(new CallCommand()); mCommands.push_back(new TerminateCommand()); + mCommands.push_back(new DtmfCommand()); mCommands.push_back(new PopEventCommand()); mCommands.push_back(new AnswerCommand()); mCommands.push_back(new CallStatusCommand());