Factorise audio-codec-enable and audio-codec-disable commands.

This commit is contained in:
Ghislain MARY 2012-08-28 15:14:21 +02:00
parent e3ffbce629
commit 7a5684917c
7 changed files with 45 additions and 87 deletions

View file

@ -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 \

View file

@ -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 <payload_type_number|mime_type|ALL>",
"Disable an audio codec.\n"
"<mime_type> 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<PayloadType*>(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));
}
}
}

View file

@ -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_

View file

@ -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_

View file

@ -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 <payload_type_number|mime_type|ALL>",
"Enable an audio codec.\n"
"<mime_type> 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<PayloadType*>(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 <payload_type_number|mime_type|ALL>",
"Enable an audio codec.\n"
"<mime_type> is of the form mime/rate/channels, eg. speex/16000/1", true) {
}
AudioCodecDisableCommand::AudioCodecDisableCommand() :
AudioCodecToggleCommand("audio-codec-disable", "audio-codec-disable <payload_type_number|mime_type|ALL>",
"Disable an audio codec.\n"
"<mime_type> is of the form mime/rate/channels, eg. speex/16000/1", false) {
}

View file

@ -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_

View file

@ -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"