mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-18 03:28:07 +00:00
Create custom responses deriving from the Response class.
This commit is contained in:
parent
b831b132a7
commit
ddd1a0f72e
12 changed files with 145 additions and 188 deletions
|
|
@ -2,82 +2,82 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
class AdaptiveBufferCompensationCommandPrivate {
|
||||
class AdaptiveBufferCompensationResponse : public Response {
|
||||
public:
|
||||
enum StreamType {
|
||||
AudioStream,
|
||||
VideoStream
|
||||
VideoStream,
|
||||
AllStreams
|
||||
};
|
||||
|
||||
void outputAdaptiveBufferCompensation(Daemon *app, ostringstream &ost, StreamType type);
|
||||
void outputAdaptiveBufferCompensations(Daemon *app, ostringstream &ost);
|
||||
AdaptiveBufferCompensationResponse(LinphoneCore *core, StreamType type);
|
||||
|
||||
private:
|
||||
void outputAdaptiveBufferCompensation(LinphoneCore *core, ostringstream &ost, const char *header, bool_t value);
|
||||
};
|
||||
|
||||
void AdaptiveBufferCompensationCommandPrivate::outputAdaptiveBufferCompensation(Daemon* app, ostringstream& ost, StreamType type) {
|
||||
AdaptiveBufferCompensationResponse::AdaptiveBufferCompensationResponse(LinphoneCore *core, StreamType type) : Response() {
|
||||
bool enabled = false;
|
||||
ostringstream ost;
|
||||
switch (type) {
|
||||
case AudioStream:
|
||||
enabled = linphone_core_audio_adaptive_jittcomp_enabled(app->getCore());
|
||||
ost << "Audio: ";
|
||||
enabled = linphone_core_audio_adaptive_jittcomp_enabled(core);
|
||||
outputAdaptiveBufferCompensation(core, ost, "Audio", enabled);
|
||||
break;
|
||||
case VideoStream:
|
||||
enabled = linphone_core_video_adaptive_jittcomp_enabled(app->getCore());
|
||||
ost << "Video: ";
|
||||
enabled = linphone_core_video_adaptive_jittcomp_enabled(core);
|
||||
outputAdaptiveBufferCompensation(core, ost, "Video", enabled);
|
||||
break;
|
||||
case AllStreams:
|
||||
enabled = linphone_core_audio_adaptive_jittcomp_enabled(core);
|
||||
outputAdaptiveBufferCompensation(core, ost, "Audio", enabled);
|
||||
enabled = linphone_core_video_adaptive_jittcomp_enabled(core);
|
||||
outputAdaptiveBufferCompensation(core, ost, "Video", enabled);
|
||||
break;
|
||||
}
|
||||
if (enabled) {
|
||||
setBody(ost.str().c_str());
|
||||
}
|
||||
|
||||
void AdaptiveBufferCompensationResponse::outputAdaptiveBufferCompensation(LinphoneCore *core, ostringstream &ost, const char *header, bool_t value) {
|
||||
ost << header << ": ";
|
||||
if (value) {
|
||||
ost << "enabled\n";
|
||||
} else {
|
||||
ost << "disabled\n";
|
||||
}
|
||||
}
|
||||
|
||||
void AdaptiveBufferCompensationCommandPrivate::outputAdaptiveBufferCompensations(Daemon* app, ostringstream& ost)
|
||||
{
|
||||
outputAdaptiveBufferCompensation(app, ost, AdaptiveBufferCompensationCommandPrivate::AudioStream);
|
||||
outputAdaptiveBufferCompensation(app, ost, AdaptiveBufferCompensationCommandPrivate::VideoStream);
|
||||
}
|
||||
|
||||
AdaptiveBufferCompensationCommand::AdaptiveBufferCompensationCommand() :
|
||||
DaemonCommand("adaptive-jitter-compensation", "adaptive-jitter-compensation [<stream>] [enable|disable]",
|
||||
"Enable or disable adaptive buffer compensation respectively with the 'enable' and 'disable' parameters for the specified stream, "
|
||||
"return the status of the use of adaptive buffer compensation without parameter.\n"
|
||||
"<stream> must be one of these values: audio, video."),
|
||||
d(new AdaptiveBufferCompensationCommandPrivate()) {
|
||||
}
|
||||
|
||||
AdaptiveBufferCompensationCommand::~AdaptiveBufferCompensationCommand() {
|
||||
delete d;
|
||||
"<stream> must be one of these values: audio, video.") {
|
||||
}
|
||||
|
||||
void AdaptiveBufferCompensationCommand::exec(Daemon *app, const char *args) {
|
||||
string stream;
|
||||
string state;
|
||||
istringstream ist(args);
|
||||
ostringstream ost;
|
||||
ist >> stream;
|
||||
if (ist.fail()) {
|
||||
d->outputAdaptiveBufferCompensations(app, ost);
|
||||
app->sendResponse(Response(ost.str().c_str(), Response::Ok));
|
||||
app->sendResponse(AdaptiveBufferCompensationResponse(app->getCore(), AdaptiveBufferCompensationResponse::AllStreams));
|
||||
} else {
|
||||
ist >> state;
|
||||
if (ist.fail()) {
|
||||
if (stream.compare("audio") == 0) {
|
||||
d->outputAdaptiveBufferCompensation(app, ost, AdaptiveBufferCompensationCommandPrivate::AudioStream);
|
||||
app->sendResponse(Response(ost.str().c_str(), Response::Ok));
|
||||
app->sendResponse(AdaptiveBufferCompensationResponse(app->getCore(), AdaptiveBufferCompensationResponse::AudioStream));
|
||||
} else if (stream.compare("video") == 0) {
|
||||
d->outputAdaptiveBufferCompensation(app, ost, AdaptiveBufferCompensationCommandPrivate::VideoStream);
|
||||
app->sendResponse(Response(ost.str().c_str(), Response::Ok));
|
||||
app->sendResponse(AdaptiveBufferCompensationResponse(app->getCore(), AdaptiveBufferCompensationResponse::VideoStream));
|
||||
} else {
|
||||
app->sendResponse(Response("Incorrect stream parameter.", Response::Error));
|
||||
}
|
||||
} else {
|
||||
AdaptiveBufferCompensationCommandPrivate::StreamType type;
|
||||
AdaptiveBufferCompensationResponse::StreamType type;
|
||||
bool enabled;
|
||||
if (stream.compare("audio") == 0) {
|
||||
type = AdaptiveBufferCompensationCommandPrivate::AudioStream;
|
||||
type = AdaptiveBufferCompensationResponse::AudioStream;
|
||||
} else if (stream.compare("video") == 0) {
|
||||
type = AdaptiveBufferCompensationCommandPrivate::VideoStream;
|
||||
type = AdaptiveBufferCompensationResponse::VideoStream;
|
||||
} else {
|
||||
app->sendResponse(Response("Incorrect stream parameter.", Response::Error));
|
||||
return;
|
||||
|
|
@ -90,16 +90,12 @@ void AdaptiveBufferCompensationCommand::exec(Daemon *app, const char *args) {
|
|||
app->sendResponse(Response("Incorrect parameter.", Response::Error));
|
||||
return;
|
||||
}
|
||||
switch (type) {
|
||||
case AdaptiveBufferCompensationCommandPrivate::AudioStream:
|
||||
linphone_core_enable_audio_adaptive_jittcomp(app->getCore(), enabled);
|
||||
break;
|
||||
case AdaptiveBufferCompensationCommandPrivate::VideoStream:
|
||||
linphone_core_enable_video_adaptive_jittcomp(app->getCore(), enabled);
|
||||
break;
|
||||
if (type == AdaptiveBufferCompensationResponse::AudioStream) {
|
||||
linphone_core_enable_audio_adaptive_jittcomp(app->getCore(), enabled);
|
||||
} else if (type == AdaptiveBufferCompensationResponse::VideoStream) {
|
||||
linphone_core_enable_video_adaptive_jittcomp(app->getCore(), enabled);
|
||||
}
|
||||
d->outputAdaptiveBufferCompensation(app, ost, type);
|
||||
app->sendResponse(Response(ost.str().c_str(), Response::Ok));
|
||||
app->sendResponse(AdaptiveBufferCompensationResponse(app->getCore(), AdaptiveBufferCompensationResponse::AllStreams));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,15 +3,10 @@
|
|||
|
||||
#include "../daemon.h"
|
||||
|
||||
class AdaptiveBufferCompensationCommandPrivate;
|
||||
|
||||
class AdaptiveBufferCompensationCommand: public DaemonCommand {
|
||||
public:
|
||||
AdaptiveBufferCompensationCommand();
|
||||
~AdaptiveBufferCompensationCommand();
|
||||
virtual void exec(Daemon *app, const char *args);
|
||||
private:
|
||||
AdaptiveBufferCompensationCommandPrivate *d;
|
||||
};
|
||||
|
||||
#endif //COMMAND_ADAPTIVE_BUFFER_COMPENSATION_H_
|
||||
|
|
|
|||
|
|
@ -2,13 +2,14 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
class FirewallPolicyCommandPrivate {
|
||||
class FirewallPolicyResponse : public Response {
|
||||
public:
|
||||
void outputFirewallPolicy(Daemon *app, ostringstream &ost);
|
||||
FirewallPolicyResponse(LinphoneCore *core);
|
||||
};
|
||||
|
||||
void FirewallPolicyCommandPrivate::outputFirewallPolicy(Daemon* app, ostringstream& ost) {
|
||||
LinphoneFirewallPolicy policy = linphone_core_get_firewall_policy(app->getCore());
|
||||
FirewallPolicyResponse::FirewallPolicyResponse(LinphoneCore *core) : Response() {
|
||||
ostringstream ost;
|
||||
LinphoneFirewallPolicy policy = linphone_core_get_firewall_policy(core);
|
||||
ost << "Type: ";
|
||||
switch (policy) {
|
||||
case LinphonePolicyNoFirewall:
|
||||
|
|
@ -16,17 +17,18 @@ void FirewallPolicyCommandPrivate::outputFirewallPolicy(Daemon* app, ostringstre
|
|||
break;
|
||||
case LinphonePolicyUseNatAddress:
|
||||
ost << "nat\n";
|
||||
ost << "Address: " << linphone_core_get_nat_address(app->getCore()) << "\n";
|
||||
ost << "Address: " << linphone_core_get_nat_address(core) << "\n";
|
||||
break;
|
||||
case LinphonePolicyUseStun:
|
||||
ost << "stun\n";
|
||||
ost << "Address: " << linphone_core_get_stun_server(app->getCore()) << "\n";
|
||||
ost << "Address: " << linphone_core_get_stun_server(core) << "\n";
|
||||
break;
|
||||
case LinphonePolicyUseIce:
|
||||
ost << "ice\n";
|
||||
ost << "Address: " << linphone_core_get_stun_server(app->getCore()) << "\n";
|
||||
ost << "Address: " << linphone_core_get_stun_server(core) << "\n";
|
||||
break;
|
||||
}
|
||||
setBody(ost.str().c_str());
|
||||
}
|
||||
|
||||
FirewallPolicyCommand::FirewallPolicyCommand() :
|
||||
|
|
@ -34,12 +36,7 @@ FirewallPolicyCommand::FirewallPolicyCommand() :
|
|||
"Set the firewall policy if type is set, otherwise return the used firewall policy.\n"
|
||||
"<type> must be one of these values: none, nat, stun, ice.\n"
|
||||
"<address> must be specified for the 'nat' and 'stun' types. "
|
||||
"It represents the public address of the gateway for the 'nat' type and the STUN server address for the 'stun' and 'ice' types."),
|
||||
d(new FirewallPolicyCommandPrivate()) {
|
||||
}
|
||||
|
||||
FirewallPolicyCommand::~FirewallPolicyCommand() {
|
||||
delete d;
|
||||
"It represents the public address of the gateway for the 'nat' type and the STUN server address for the 'stun' and 'ice' types.") {
|
||||
}
|
||||
|
||||
void FirewallPolicyCommand::exec(Daemon *app, const char *args) {
|
||||
|
|
@ -48,9 +45,7 @@ void FirewallPolicyCommand::exec(Daemon *app, const char *args) {
|
|||
istringstream ist(args);
|
||||
ist >> type;
|
||||
if (ist.eof() && (type.length() == 0)) {
|
||||
ostringstream ost;
|
||||
d->outputFirewallPolicy(app, ost);
|
||||
app->sendResponse(Response(ost.str().c_str(), Response::Ok));
|
||||
app->sendResponse(FirewallPolicyResponse(app->getCore()));
|
||||
} else if (ist.fail()) {
|
||||
app->sendResponse(Response("Incorrect type parameter.", Response::Error));
|
||||
} else {
|
||||
|
|
@ -85,8 +80,6 @@ void FirewallPolicyCommand::exec(Daemon *app, const char *args) {
|
|||
} else if ((policy == LinphonePolicyUseStun) || (policy == LinphonePolicyUseIce)) {
|
||||
linphone_core_set_stun_server(app->getCore(), address.c_str());
|
||||
}
|
||||
ostringstream ost;
|
||||
d->outputFirewallPolicy(app, ost);
|
||||
app->sendResponse(Response(ost.str().c_str(), Response::Ok));
|
||||
app->sendResponse(FirewallPolicyResponse(app->getCore()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,15 +3,10 @@
|
|||
|
||||
#include "../daemon.h"
|
||||
|
||||
class FirewallPolicyCommandPrivate;
|
||||
|
||||
class FirewallPolicyCommand: public DaemonCommand {
|
||||
public:
|
||||
FirewallPolicyCommand();
|
||||
~FirewallPolicyCommand();
|
||||
virtual void exec(Daemon *app, const char *args);
|
||||
private:
|
||||
FirewallPolicyCommandPrivate *d;
|
||||
};
|
||||
|
||||
#endif //COMMAND_FIREWALL_POLICY_H_
|
||||
|
|
|
|||
|
|
@ -2,29 +2,26 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
class IPv6CommandPrivate {
|
||||
class IPv6Response : public Response {
|
||||
public:
|
||||
void outputIPv6(Daemon *app, ostringstream &ost);
|
||||
IPv6Response(LinphoneCore *core);
|
||||
};
|
||||
|
||||
void IPv6CommandPrivate::outputIPv6(Daemon* app, ostringstream& ost) {
|
||||
bool ipv6_enabled = linphone_core_ipv6_enabled(app->getCore()) == TRUE ? true : false;
|
||||
IPv6Response::IPv6Response(LinphoneCore *core) : Response() {
|
||||
ostringstream ost;
|
||||
bool ipv6_enabled = linphone_core_ipv6_enabled(core) == TRUE ? true : false;
|
||||
ost << "State: ";
|
||||
if (ipv6_enabled) {
|
||||
ost << "enabled\n";
|
||||
} else {
|
||||
ost << "disabled\n";
|
||||
}
|
||||
setBody(ost.str().c_str());
|
||||
}
|
||||
|
||||
IPv6Command::IPv6Command() :
|
||||
DaemonCommand("ipv6", "ipv6 [enable|disable]",
|
||||
"Enable or disable IPv6 respectively with the 'enable' and 'disable' parameters, return the status of the use of IPv6 without parameter."),
|
||||
d(new IPv6CommandPrivate()) {
|
||||
}
|
||||
|
||||
IPv6Command::~IPv6Command() {
|
||||
delete d;
|
||||
"Enable or disable IPv6 respectively with the 'enable' and 'disable' parameters, return the status of the use of IPv6 without parameter.") {
|
||||
}
|
||||
|
||||
void IPv6Command::exec(Daemon *app, const char *args) {
|
||||
|
|
@ -32,9 +29,7 @@ void IPv6Command::exec(Daemon *app, const char *args) {
|
|||
istringstream ist(args);
|
||||
ist >> status;
|
||||
if (ist.fail()) {
|
||||
ostringstream ost;
|
||||
d->outputIPv6(app, ost);
|
||||
app->sendResponse(Response(ost.str().c_str(), Response::Ok));
|
||||
app->sendResponse(IPv6Response(app->getCore()));
|
||||
} else {
|
||||
if (status.compare("enable") == 0) {
|
||||
linphone_core_enable_ipv6(app->getCore(), TRUE);
|
||||
|
|
@ -44,8 +39,6 @@ void IPv6Command::exec(Daemon *app, const char *args) {
|
|||
app->sendResponse(Response("Incorrect parameter.", Response::Error));
|
||||
return;
|
||||
}
|
||||
ostringstream ost;
|
||||
d->outputIPv6(app, ost);
|
||||
app->sendResponse(Response(ost.str().c_str(), Response::Ok));
|
||||
app->sendResponse(IPv6Response(app->getCore()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,15 +3,10 @@
|
|||
|
||||
#include "../daemon.h"
|
||||
|
||||
class IPv6CommandPrivate;
|
||||
|
||||
class IPv6Command: public DaemonCommand {
|
||||
public:
|
||||
IPv6Command();
|
||||
~IPv6Command();
|
||||
virtual void exec(Daemon *app, const char *args);
|
||||
private:
|
||||
IPv6CommandPrivate *d;
|
||||
};
|
||||
|
||||
#endif //COMMAND_IPV6_H_
|
||||
|
|
|
|||
|
|
@ -2,13 +2,14 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
class MediaEncryptionCommandPrivate {
|
||||
class MediaEncryptionResponse : public Response {
|
||||
public:
|
||||
void outputMediaEncryption(Daemon *app, ostringstream &ost);
|
||||
MediaEncryptionResponse(LinphoneCore *core);
|
||||
};
|
||||
|
||||
void MediaEncryptionCommandPrivate::outputMediaEncryption(Daemon* app, ostringstream& ost) {
|
||||
LinphoneMediaEncryption encryption = linphone_core_get_media_encryption(app->getCore());
|
||||
MediaEncryptionResponse::MediaEncryptionResponse(LinphoneCore *core) : Response() {
|
||||
LinphoneMediaEncryption encryption = linphone_core_get_media_encryption(core);
|
||||
ostringstream ost;
|
||||
ost << "Encryption: ";
|
||||
switch (encryption) {
|
||||
case LinphoneMediaEncryptionNone:
|
||||
|
|
@ -21,16 +22,12 @@ void MediaEncryptionCommandPrivate::outputMediaEncryption(Daemon* app, ostringst
|
|||
ost << "zrtp\n";
|
||||
break;
|
||||
}
|
||||
setBody(ost.str().c_str());
|
||||
}
|
||||
|
||||
MediaEncryptionCommand::MediaEncryptionCommand() :
|
||||
DaemonCommand("media-encryption", "media-encryption [none|srtp|zrtp]",
|
||||
"Set the media encryption policy if a parameter is given, otherwise return the media encrytion in use."),
|
||||
d(new MediaEncryptionCommandPrivate()) {
|
||||
}
|
||||
|
||||
MediaEncryptionCommand::~MediaEncryptionCommand() {
|
||||
delete d;
|
||||
"Set the media encryption policy if a parameter is given, otherwise return the media encrytion in use.") {
|
||||
}
|
||||
|
||||
void MediaEncryptionCommand::exec(Daemon *app, const char *args) {
|
||||
|
|
@ -38,9 +35,7 @@ void MediaEncryptionCommand::exec(Daemon *app, const char *args) {
|
|||
istringstream ist(args);
|
||||
ist >> encryption_str;
|
||||
if (ist.eof() && (encryption_str.length() == 0)) {
|
||||
ostringstream ost;
|
||||
d->outputMediaEncryption(app, ost);
|
||||
app->sendResponse(Response(ost.str().c_str(), Response::Ok));
|
||||
app->sendResponse(MediaEncryptionResponse(app->getCore()));
|
||||
} else if (ist.fail()) {
|
||||
app->sendResponse(Response("Incorrect parameter.", Response::Error));
|
||||
} else {
|
||||
|
|
@ -56,8 +51,6 @@ void MediaEncryptionCommand::exec(Daemon *app, const char *args) {
|
|||
return;
|
||||
}
|
||||
linphone_core_set_media_encryption(app->getCore(), encryption);
|
||||
ostringstream ost;
|
||||
d->outputMediaEncryption(app, ost);
|
||||
app->sendResponse(Response(ost.str().c_str(), Response::Ok));
|
||||
app->sendResponse(MediaEncryptionResponse(app->getCore()));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,15 +3,10 @@
|
|||
|
||||
#include "../daemon.h"
|
||||
|
||||
class MediaEncryptionCommandPrivate;
|
||||
|
||||
class MediaEncryptionCommand: public DaemonCommand {
|
||||
public:
|
||||
MediaEncryptionCommand();
|
||||
~MediaEncryptionCommand();
|
||||
virtual void exec(Daemon *app, const char *args);
|
||||
private:
|
||||
MediaEncryptionCommandPrivate *d;
|
||||
};
|
||||
|
||||
#endif //COMMAND_MEDIA_ENCRYPTION_H_
|
||||
|
|
|
|||
|
|
@ -2,63 +2,76 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
enum PortType {
|
||||
SIPPort,
|
||||
AudioRTPPort,
|
||||
VideoRTPPort
|
||||
};
|
||||
|
||||
enum Protocol {
|
||||
UDPProtocol,
|
||||
TCPProtocol,
|
||||
TLSProtocol
|
||||
};
|
||||
|
||||
class PortCommandPrivate {
|
||||
class PortResponse : public Response {
|
||||
public:
|
||||
void outputPort(Daemon *app, ostringstream &ost, PortType type);
|
||||
void outputPorts(Daemon *app, ostringstream &ost);
|
||||
enum PortType {
|
||||
SIPPort,
|
||||
AudioRTPPort,
|
||||
VideoRTPPort,
|
||||
AllPorts
|
||||
};
|
||||
|
||||
PortResponse(LinphoneCore *core, PortType type);
|
||||
|
||||
private:
|
||||
void outputSIPPort(LinphoneCore *core, ostringstream &ost);
|
||||
void outputAudioRTPPort(LinphoneCore *core, ostringstream &ost);
|
||||
void outputVideoRTPPort(LinphoneCore *core, ostringstream &ost);
|
||||
};
|
||||
|
||||
void PortCommandPrivate::outputPort(Daemon* app, ostringstream& ost, PortType type) {
|
||||
PortResponse::PortResponse(LinphoneCore *core, PortResponse::PortType type) : Response() {
|
||||
ostringstream ost;
|
||||
switch (type) {
|
||||
case SIPPort:
|
||||
LCSipTransports transports;
|
||||
linphone_core_get_sip_transports(app->getCore(), &transports);
|
||||
ost << "SIP: ";
|
||||
if (transports.udp_port > 0) {
|
||||
ost << transports.udp_port << " UDP\n";
|
||||
} else if (transports.tcp_port > 0) {
|
||||
ost << transports.tcp_port << " TCP\n";
|
||||
} else {
|
||||
ost << transports.tls_port << " TLS\n";
|
||||
}
|
||||
outputSIPPort(core, ost);
|
||||
break;
|
||||
case AudioRTPPort:
|
||||
ost << "Audio RTP: " << linphone_core_get_audio_port(app->getCore()) << "\n";
|
||||
outputAudioRTPPort(core, ost);
|
||||
break;
|
||||
case VideoRTPPort:
|
||||
ost << "Video RTP: " << linphone_core_get_video_port(app->getCore()) << "\n";
|
||||
outputVideoRTPPort(core, ost);
|
||||
break;
|
||||
case AllPorts:
|
||||
outputSIPPort(core, ost);
|
||||
outputAudioRTPPort(core, ost);
|
||||
outputVideoRTPPort(core, ost);
|
||||
break;
|
||||
}
|
||||
setBody(ost.str().c_str());
|
||||
}
|
||||
|
||||
void PortResponse::outputSIPPort(LinphoneCore *core, ostringstream &ost) {
|
||||
LCSipTransports transports;
|
||||
linphone_core_get_sip_transports(core, &transports);
|
||||
ost << "SIP: ";
|
||||
if (transports.udp_port > 0) {
|
||||
ost << transports.udp_port << " UDP\n";
|
||||
} else if (transports.tcp_port > 0) {
|
||||
ost << transports.tcp_port << " TCP\n";
|
||||
} else {
|
||||
ost << transports.tls_port << " TLS\n";
|
||||
}
|
||||
}
|
||||
|
||||
void PortCommandPrivate::outputPorts(Daemon* app, ostringstream& ost) {
|
||||
outputPort(app, ost, SIPPort);
|
||||
outputPort(app, ost, AudioRTPPort);
|
||||
outputPort(app, ost, VideoRTPPort);
|
||||
void PortResponse::outputAudioRTPPort(LinphoneCore *core, ostringstream &ost) {
|
||||
ost << "Audio RTP: " << linphone_core_get_audio_port(core) << "\n";
|
||||
}
|
||||
|
||||
void PortResponse::outputVideoRTPPort(LinphoneCore *core, ostringstream &ost) {
|
||||
ost << "Video RTP: " << linphone_core_get_video_port(core) << "\n";
|
||||
}
|
||||
|
||||
PortCommand::PortCommand() :
|
||||
DaemonCommand("port", "port [<type>] [<port>] [<protocol>]",
|
||||
"Set the port to use for type if port is set, otherwise return the port used for type if specified or all the used ports if no type is specified.\n"
|
||||
"<type> must be one of these values: sip, audio, video.\n"
|
||||
"<protocol> should be defined only for sip port and have one of these values: udp, tcp, tls."),
|
||||
d(new PortCommandPrivate()) {
|
||||
}
|
||||
|
||||
PortCommand::~PortCommand() {
|
||||
delete d;
|
||||
"<protocol> should be defined only for sip port and have one of these values: udp, tcp, tls.") {
|
||||
}
|
||||
|
||||
void PortCommand::exec(Daemon *app, const char *args) {
|
||||
|
|
@ -68,22 +81,18 @@ void PortCommand::exec(Daemon *app, const char *args) {
|
|||
ostringstream ost;
|
||||
ist >> type;
|
||||
if (ist.eof() && (type.length() == 0)) {
|
||||
d->outputPorts(app, ost);
|
||||
app->sendResponse(Response(ost.str().c_str(), Response::Ok));
|
||||
app->sendResponse(PortResponse(app->getCore(), PortResponse::AllPorts));
|
||||
} else if (ist.fail()) {
|
||||
app->sendResponse(Response("Incorrect type parameter.", Response::Error));
|
||||
} else {
|
||||
ist >> port;
|
||||
if (ist.fail()) {
|
||||
if (type.compare("sip") == 0) {
|
||||
d->outputPort(app, ost, SIPPort);
|
||||
app->sendResponse(Response(ost.str().c_str(), Response::Ok));
|
||||
app->sendResponse(PortResponse(app->getCore(), PortResponse::SIPPort));
|
||||
} else if (type.compare("audio") == 0) {
|
||||
d->outputPort(app, ost, AudioRTPPort);
|
||||
app->sendResponse(Response(ost.str().c_str(), Response::Ok));
|
||||
app->sendResponse(PortResponse(app->getCore(), PortResponse::AudioRTPPort));
|
||||
} else if (type.compare("video") == 0) {
|
||||
d->outputPort(app, ost, VideoRTPPort);
|
||||
app->sendResponse(Response(ost.str().c_str(), Response::Ok));
|
||||
app->sendResponse(PortResponse(app->getCore(), PortResponse::VideoRTPPort));
|
||||
} else {
|
||||
app->sendResponse(Response("Incorrect type parameter.", Response::Error));
|
||||
}
|
||||
|
|
@ -118,16 +127,13 @@ void PortCommand::exec(Daemon *app, const char *args) {
|
|||
break;
|
||||
}
|
||||
linphone_core_set_sip_transports(app->getCore(), &transports);
|
||||
d->outputPort(app, ost, SIPPort);
|
||||
app->sendResponse(Response(ost.str().c_str(), Response::Ok));
|
||||
app->sendResponse(PortResponse(app->getCore(), PortResponse::SIPPort));
|
||||
} else if (type.compare("audio") == 0) {
|
||||
linphone_core_set_audio_port(app->getCore(), port);
|
||||
d->outputPort(app, ost, AudioRTPPort);
|
||||
app->sendResponse(Response(ost.str().c_str(), Response::Ok));
|
||||
app->sendResponse(PortResponse(app->getCore(), PortResponse::AudioRTPPort));
|
||||
} else if (type.compare("video") == 0) {
|
||||
linphone_core_set_video_port(app->getCore(), port);
|
||||
d->outputPort(app, ost, VideoRTPPort);
|
||||
app->sendResponse(Response(ost.str().c_str(), Response::Ok));
|
||||
app->sendResponse(PortResponse(app->getCore(), PortResponse::VideoRTPPort));
|
||||
} else {
|
||||
app->sendResponse(Response("Incorrect type parameter.", Response::Error));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,15 +3,10 @@
|
|||
|
||||
#include "../daemon.h"
|
||||
|
||||
class PortCommandPrivate;
|
||||
|
||||
class PortCommand: public DaemonCommand {
|
||||
public:
|
||||
PortCommand();
|
||||
~PortCommand();
|
||||
virtual void exec(Daemon *app, const char *args);
|
||||
private:
|
||||
PortCommandPrivate *d;
|
||||
};
|
||||
|
||||
#endif //COMMAND_PORT_H_
|
||||
|
|
|
|||
|
|
@ -2,23 +2,35 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
class PtimeCommandPrivate {
|
||||
class PtimeResponse : public Response {
|
||||
public:
|
||||
void outputPtime(Daemon *app, ostringstream &ost, int ms);
|
||||
enum Direction {
|
||||
Upload,
|
||||
Download,
|
||||
BothDirections
|
||||
};
|
||||
PtimeResponse(LinphoneCore *core, Direction dir);
|
||||
};
|
||||
|
||||
void PtimeCommandPrivate::outputPtime(Daemon* app, ostringstream& ost, int ms) {
|
||||
ost << "Value: " << ms << "\n";
|
||||
PtimeResponse::PtimeResponse(LinphoneCore *core, Direction dir) : Response() {
|
||||
ostringstream ost;
|
||||
switch (dir) {
|
||||
case Upload:
|
||||
ost << "Upload: " << linphone_core_get_upload_ptime(core) << "\n";
|
||||
break;
|
||||
case Download:
|
||||
ost << "Download: " << linphone_core_get_download_ptime(core) << "\n";
|
||||
break;
|
||||
case BothDirections:
|
||||
ost << "Upload: " << linphone_core_get_upload_ptime(core) << "\n";
|
||||
ost << "Download: " << linphone_core_get_download_ptime(core) << "\n";
|
||||
break;
|
||||
}
|
||||
setBody(ost.str().c_str());
|
||||
}
|
||||
|
||||
PtimeCommand::PtimeCommand() :
|
||||
DaemonCommand("ptime", "ptime [up|down] <ms>", "Set the upload or download ptime if ms is defined, otherwise return the current value of the ptime."),
|
||||
d(new PtimeCommandPrivate()) {
|
||||
}
|
||||
|
||||
PtimeCommand::~PtimeCommand()
|
||||
{
|
||||
delete d;
|
||||
DaemonCommand("ptime", "ptime [up|down] <ms>", "Set the upload or download ptime if ms is defined, otherwise return the current value of the ptime.") {
|
||||
}
|
||||
|
||||
void PtimeCommand::exec(Daemon *app, const char *args) {
|
||||
|
|
@ -27,7 +39,7 @@ void PtimeCommand::exec(Daemon *app, const char *args) {
|
|||
istringstream ist(args);
|
||||
ist >> direction;
|
||||
if (ist.fail()) {
|
||||
app->sendResponse(Response("Missing/Incorrect parameter(s).", Response::Error));
|
||||
app->sendResponse(PtimeResponse(app->getCore(), PtimeResponse::BothDirections));
|
||||
} else {
|
||||
if (direction.compare("up") == 0) {
|
||||
if (!ist.eof()) {
|
||||
|
|
@ -37,10 +49,7 @@ void PtimeCommand::exec(Daemon *app, const char *args) {
|
|||
}
|
||||
linphone_core_set_upload_ptime(app->getCore(), ms);
|
||||
}
|
||||
ms = linphone_core_get_upload_ptime(app->getCore());
|
||||
ostringstream ost;
|
||||
d->outputPtime(app, ost, ms);
|
||||
app->sendResponse(Response(ost.str().c_str(), Response::Ok));
|
||||
app->sendResponse(PtimeResponse(app->getCore(), PtimeResponse::Upload));
|
||||
} else if (direction.compare("down") == 0) {
|
||||
if (!ist.eof()) {
|
||||
ist >> ms;
|
||||
|
|
@ -49,10 +58,7 @@ void PtimeCommand::exec(Daemon *app, const char *args) {
|
|||
}
|
||||
linphone_core_set_download_ptime(app->getCore(), ms);
|
||||
}
|
||||
ms = linphone_core_get_download_ptime(app->getCore());
|
||||
ostringstream ost;
|
||||
d->outputPtime(app, ost, ms);
|
||||
app->sendResponse(Response(ost.str().c_str(), Response::Ok));
|
||||
app->sendResponse(PtimeResponse(app->getCore(), PtimeResponse::Download));
|
||||
} else {
|
||||
app->sendResponse(Response("Missing/Incorrect parameter(s).", Response::Error));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,15 +3,10 @@
|
|||
|
||||
#include "../daemon.h"
|
||||
|
||||
class PtimeCommandPrivate;
|
||||
|
||||
class PtimeCommand: public DaemonCommand {
|
||||
public:
|
||||
PtimeCommand();
|
||||
~PtimeCommand();
|
||||
virtual void exec(Daemon *app, const char *args);
|
||||
private:
|
||||
PtimeCommandPrivate *d;
|
||||
};
|
||||
|
||||
#endif //COMMAND_PTIME_H_
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue