diff --git a/daemon/Makefile.am b/daemon/Makefile.am index eb193418e..a2829100b 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -5,11 +5,10 @@ bin_PROGRAMS=linphone-daemon linphone-daemon-pipetest linphone_daemon_SOURCES=daemon.cc \ commands/adaptive-jitter-compensation.cc \ commands/answer.cc \ - commands/audio-codec-disable.cc \ - commands/audio-codec-enable.cc \ commands/audio-codec-get.cc \ commands/audio-codec-move.cc \ commands/audio-codec-set.cc \ + commands/audio-codec-toggle.cc \ commands/audio-stream-start.cc \ commands/audio-stream-stop.cc \ commands/call.cc \ @@ -31,11 +30,10 @@ linphone_daemon_SOURCES=daemon.cc \ daemon.h \ commands/adaptive-jitter-compensation.h \ commands/answer.h \ - commands/audio-codec-disable.h \ - commands/audio-codec-enable.h \ commands/audio-codec-get.h \ commands/audio-codec-move.h \ commands/audio-codec-set.h \ + commands/audio-codec-toggle.h \ commands/audio-stream-start.h \ commands/audio-stream-stop.h \ commands/call.h \ diff --git a/daemon/commands/audio-codec-disable.cc b/daemon/commands/audio-codec-disable.cc deleted file mode 100644 index 5fc28864b..000000000 --- a/daemon/commands/audio-codec-disable.cc +++ /dev/null @@ -1,49 +0,0 @@ -#include "audio-codec-disable.h" -#include "audio-codec-get.h" - -using namespace std; - -AudioCodecDisableCommand::AudioCodecDisableCommand() : - DaemonCommand("audio-codec-disable", "audio-codec-disable ", - "Disable an audio codec.\n" - " is of the form mime/rate/channels, eg. speex/16000/1") { -} - -void AudioCodecDisableCommand::exec(Daemon *app, const char *args) { - istringstream ist(args); - - if (ist.peek() == EOF) { - app->sendResponse(Response("Missing parameter.", Response::Error)); - } else { - string mime_type; - int ptnum = -1; - ist >> mime_type; - PayloadTypeParser parser(app->getCore(), mime_type, true); - if (!parser.successful()) { - app->sendResponse(Response("Incorrect mime type format.", Response::Error)); - return; - } - if (!parser.all()) ptnum = parser.payloadTypeNumber(); - - int index = 0; - for (const MSList *node = linphone_core_get_audio_codecs(app->getCore()); node != NULL; node = ms_list_next(node)) { - PayloadType *payload = reinterpret_cast(node->data); - if (parser.all()) { - linphone_core_enable_payload_type(app->getCore(), payload, false); - } else { - if (ptnum == linphone_core_get_payload_type_number(app->getCore(), payload)) { - linphone_core_enable_payload_type(app->getCore(), payload, false); - app->sendResponse(PayloadTypeResponse(app->getCore(), payload, index)); - return; - } - } - ++index; - } - if (parser.all()) { - AudioCodecGetCommand getCommand; - getCommand.exec(app, ""); - } else { - app->sendResponse(Response("Audio codec not found.", Response::Error)); - } - } -} diff --git a/daemon/commands/audio-codec-disable.h b/daemon/commands/audio-codec-disable.h deleted file mode 100644 index 040622c27..000000000 --- a/daemon/commands/audio-codec-disable.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef COMMAND_AUDIO_CODEC_DISABLE_H_ -#define COMMAND_AUDIO_CODEC_DISABLE_H_ - -#include "../daemon.h" - -class AudioCodecDisableCommand: public DaemonCommand { -public: - AudioCodecDisableCommand(); - virtual void exec(Daemon *app, const char *args); -}; - -#endif //COMMAND_AUDIO_CODEC_DISABLE_H_ diff --git a/daemon/commands/audio-codec-enable.h b/daemon/commands/audio-codec-enable.h deleted file mode 100644 index c2f410281..000000000 --- a/daemon/commands/audio-codec-enable.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef COMMAND_AUDIO_CODEC_ENABLE_H_ -#define COMMAND_AUDIO_CODEC_ENABLE_H_ - -#include "../daemon.h" - -class AudioCodecEnableCommand: public DaemonCommand { -public: - AudioCodecEnableCommand(); - virtual void exec(Daemon *app, const char *args); -}; - -#endif //COMMAND_AUDIO_CODEC_ENABLE_H_ diff --git a/daemon/commands/audio-codec-enable.cc b/daemon/commands/audio-codec-toggle.cc similarity index 59% rename from daemon/commands/audio-codec-enable.cc rename to daemon/commands/audio-codec-toggle.cc index 00a5c8dab..e5076c2d0 100644 --- a/daemon/commands/audio-codec-enable.cc +++ b/daemon/commands/audio-codec-toggle.cc @@ -1,15 +1,13 @@ -#include "audio-codec-enable.h" +#include "audio-codec-toggle.h" #include "audio-codec-get.h" using namespace std; -AudioCodecEnableCommand::AudioCodecEnableCommand() : - DaemonCommand("audio-codec-enable", "audio-codec-enable ", - "Enable an audio codec.\n" - " is of the form mime/rate/channels, eg. speex/16000/1") { +AudioCodecToggleCommand::AudioCodecToggleCommand(const char *name, const char *proto, const char *help, bool enable) : + DaemonCommand(name, proto, help), mEnable(enable) { } -void AudioCodecEnableCommand::exec(Daemon *app, const char *args) { +void AudioCodecToggleCommand::exec(Daemon *app, const char *args) { istringstream ist(args); if (ist.peek() == EOF) { @@ -29,10 +27,10 @@ void AudioCodecEnableCommand::exec(Daemon *app, const char *args) { for (const MSList *node = linphone_core_get_audio_codecs(app->getCore()); node != NULL; node = ms_list_next(node)) { PayloadType *payload = reinterpret_cast(node->data); if (parser.all()) { - linphone_core_enable_payload_type(app->getCore(), payload, true); + linphone_core_enable_payload_type(app->getCore(), payload, mEnable); } else { if (ptnum == linphone_core_get_payload_type_number(app->getCore(), payload)) { - linphone_core_enable_payload_type(app->getCore(), payload, true); + linphone_core_enable_payload_type(app->getCore(), payload, mEnable); app->sendResponse(PayloadTypeResponse(app->getCore(), payload, index)); return; } @@ -47,3 +45,15 @@ void AudioCodecEnableCommand::exec(Daemon *app, const char *args) { } } } + +AudioCodecEnableCommand::AudioCodecEnableCommand() : + AudioCodecToggleCommand("audio-codec-enable", "audio-codec-enable ", + "Enable an audio codec.\n" + " is of the form mime/rate/channels, eg. speex/16000/1", true) { +} + +AudioCodecDisableCommand::AudioCodecDisableCommand() : + AudioCodecToggleCommand("audio-codec-disable", "audio-codec-disable ", + "Disable an audio codec.\n" + " is of the form mime/rate/channels, eg. speex/16000/1", false) { +} \ No newline at end of file diff --git a/daemon/commands/audio-codec-toggle.h b/daemon/commands/audio-codec-toggle.h new file mode 100644 index 000000000..bce36dfa2 --- /dev/null +++ b/daemon/commands/audio-codec-toggle.h @@ -0,0 +1,24 @@ +#ifndef COMMAND_AUDIO_CODEC_TOGGLE_H_ +#define COMMAND_AUDIO_CODEC_TOGGLE_H_ + +#include "../daemon.h" + +class AudioCodecToggleCommand: public DaemonCommand { +public: + AudioCodecToggleCommand(const char *name, const char *proto, const char *help, bool enable); + virtual void exec(Daemon *app, const char *args); +protected: + bool mEnable; +}; + +class AudioCodecEnableCommand: public AudioCodecToggleCommand { +public: + AudioCodecEnableCommand(); +}; + +class AudioCodecDisableCommand: public AudioCodecToggleCommand { +public: + AudioCodecDisableCommand(); +}; + +#endif //COMMAND_AUDIO_CODEC_TOGGLE_H_ diff --git a/daemon/daemon.cc b/daemon/daemon.cc index 359aeea97..897f34722 100644 --- a/daemon/daemon.cc +++ b/daemon/daemon.cc @@ -14,9 +14,8 @@ #include "commands/answer.h" #include "commands/audio-codec-get.h" #include "commands/audio-codec-move.h" -#include "commands/audio-codec-enable.h" -#include "commands/audio-codec-disable.h" #include "commands/audio-codec-set.h" +#include "commands/audio-codec-toggle.h" #include "commands/audio-stream-start.h" #include "commands/audio-stream-stop.h" #include "commands/call.h"