From 6385f6d41da6d98cfffa12d502a8daa46e86d10a Mon Sep 17 00:00:00 2001 From: Guillaume BIENKOWSKI Date: Thu, 2 Jan 2014 12:26:14 +0100 Subject: [PATCH] Added new commands to the linphone daemon executable. --- daemon/Makefile.am | 12 ++++++++++++ daemon/commands/call-mute.cc | 5 +++++ daemon/commands/call-mute.h | 10 ++++++++++ daemon/commands/call-pause.cc | 31 +++++++++++++++++++++++++++++++ daemon/commands/call-pause.h | 14 ++++++++++++++ daemon/commands/call-resume.cc | 5 +++++ daemon/commands/call-resume.h | 10 ++++++++++ daemon/commands/call-transfer.cc | 5 +++++ daemon/commands/call-transfer.h | 10 ++++++++++ daemon/commands/conference.cc | 5 +++++ daemon/commands/conference.h | 10 ++++++++++ daemon/commands/video.cc | 5 +++++ daemon/commands/video.h | 10 ++++++++++ daemon/daemon.cc | 21 +++++++++++++++++---- daemon/daemon.h | 22 ++++++++++++++++++---- 15 files changed, 167 insertions(+), 8 deletions(-) create mode 100644 daemon/commands/call-mute.cc create mode 100644 daemon/commands/call-mute.h create mode 100644 daemon/commands/call-pause.cc create mode 100644 daemon/commands/call-pause.h create mode 100644 daemon/commands/call-resume.cc create mode 100644 daemon/commands/call-resume.h create mode 100644 daemon/commands/call-transfer.cc create mode 100644 daemon/commands/call-transfer.h create mode 100644 daemon/commands/conference.cc create mode 100644 daemon/commands/conference.h create mode 100644 daemon/commands/video.cc create mode 100644 daemon/commands/video.h diff --git a/daemon/Makefile.am b/daemon/Makefile.am index db7e4e1eb..98bd350c1 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -15,6 +15,12 @@ linphone_daemon_SOURCES=daemon.cc \ commands/call.cc \ commands/call-stats.cc \ commands/call-status.cc \ + commands/call-pause.cc \ + commands/call-resume.cc \ + commands/call-mute.cc \ + commands/call-camera.cc \ + commands/call-transfer.cc \ + commands/conference.cc \ commands/dtmf.cc \ commands/firewall-policy.cc \ commands/help.cc \ @@ -46,6 +52,12 @@ linphone_daemon_SOURCES=daemon.cc \ commands/call.h \ commands/call-stats.h \ commands/call-status.h \ + commands/call-pause.h \ + commands/call-resume.h \ + commands/call-mute.h \ + commands/call-camera.h \ + commands/call-transfer.h \ + commands/conference.h \ commands/dtmf.h \ commands/firewall-policy.h \ commands/help.h \ diff --git a/daemon/commands/call-mute.cc b/daemon/commands/call-mute.cc new file mode 100644 index 000000000..cde7637b4 --- /dev/null +++ b/daemon/commands/call-mute.cc @@ -0,0 +1,5 @@ +#include "call-mute.h" + +CallMute::CallMute() +{ +} diff --git a/daemon/commands/call-mute.h b/daemon/commands/call-mute.h new file mode 100644 index 000000000..69612b299 --- /dev/null +++ b/daemon/commands/call-mute.h @@ -0,0 +1,10 @@ +#ifndef CALLMUTE_H +#define CALLMUTE_H + +class CallMute : public DaemonCommand +{ +public: + CallMute(); +}; + +#endif // CALLMUTE_H diff --git a/daemon/commands/call-pause.cc b/daemon/commands/call-pause.cc new file mode 100644 index 000000000..7145d0857 --- /dev/null +++ b/daemon/commands/call-pause.cc @@ -0,0 +1,31 @@ +#include "call-pause.h" + +CallPause::CallPause() +{ +} + +void CallPause::exec(Daemon* app, const char* args) +{ + LinphoneCore *lc = app->getCore(); + int cid; + LinphoneCall *call = NULL; + if (sscanf(args, "%i", &cid) == 1) { + call = app->findCall(cid); + if (call == NULL) { + app->sendResponse(Response("No call with such id.")); + return; + } + } else { + call = linphone_core_get_current_call(lc); + if (call == NULL) { + app->sendResponse(Response("No current call available.")); + return; + } + } + + if( linphone_core_pause_call(lc, call) == 0 ) { + app->sendResponse(Response("Call was paused", Response::Ok)); + } else { + app->sendResponse(Response("Error pausing call")); + } +} diff --git a/daemon/commands/call-pause.h b/daemon/commands/call-pause.h new file mode 100644 index 000000000..598eac2d5 --- /dev/null +++ b/daemon/commands/call-pause.h @@ -0,0 +1,14 @@ +#ifndef CALLPAUSE_H +#define CALLPAUSE_H + +#include "daemon.h" + +class CallPause : public DaemonCommand +{ +public: + CallPause(); + + virtual void exec(Daemon *app, const char *args); +}; + +#endif // CALLPAUSE_H diff --git a/daemon/commands/call-resume.cc b/daemon/commands/call-resume.cc new file mode 100644 index 000000000..f620df52d --- /dev/null +++ b/daemon/commands/call-resume.cc @@ -0,0 +1,5 @@ +#include "call-resume.h" + +CallResume::CallResume() +{ +} diff --git a/daemon/commands/call-resume.h b/daemon/commands/call-resume.h new file mode 100644 index 000000000..baed7968d --- /dev/null +++ b/daemon/commands/call-resume.h @@ -0,0 +1,10 @@ +#ifndef CALLRESUME_H +#define CALLRESUME_H + +class CallResume : public DaemonCommand +{ +public: + CallResume(); +}; + +#endif // CALLRESUME_H diff --git a/daemon/commands/call-transfer.cc b/daemon/commands/call-transfer.cc new file mode 100644 index 000000000..f2cb26880 --- /dev/null +++ b/daemon/commands/call-transfer.cc @@ -0,0 +1,5 @@ +#include "call-transfer.h" + +CallTransfer::CallTransfer() +{ +} diff --git a/daemon/commands/call-transfer.h b/daemon/commands/call-transfer.h new file mode 100644 index 000000000..11c884dee --- /dev/null +++ b/daemon/commands/call-transfer.h @@ -0,0 +1,10 @@ +#ifndef CALLTRANSFER_H +#define CALLTRANSFER_H + +class CallTransfer : public DaemonCommand +{ +public: + CallTransfer(); +}; + +#endif // CALLTRANSFER_H diff --git a/daemon/commands/conference.cc b/daemon/commands/conference.cc new file mode 100644 index 000000000..c9d51a9a0 --- /dev/null +++ b/daemon/commands/conference.cc @@ -0,0 +1,5 @@ +#include "conference.h" + +Conference::Conference() +{ +} diff --git a/daemon/commands/conference.h b/daemon/commands/conference.h new file mode 100644 index 000000000..db442c33d --- /dev/null +++ b/daemon/commands/conference.h @@ -0,0 +1,10 @@ +#ifndef CONFERENCE_H +#define CONFERENCE_H + +class Conference : public DaemonCommand +{ +public: + Conference(); +}; + +#endif // CONFERENCE_H diff --git a/daemon/commands/video.cc b/daemon/commands/video.cc new file mode 100644 index 000000000..d6e631e61 --- /dev/null +++ b/daemon/commands/video.cc @@ -0,0 +1,5 @@ +#include "call-camera.h" + +CallCamera::CallCamera() +{ +} diff --git a/daemon/commands/video.h b/daemon/commands/video.h new file mode 100644 index 000000000..b21089535 --- /dev/null +++ b/daemon/commands/video.h @@ -0,0 +1,10 @@ +#ifndef CALLCAMERA_H +#define CALLCAMERA_H + +class CallCamera : public DaemonCommand +{ +public: + CallCamera(); +}; + +#endif // CALLCAMERA_H diff --git a/daemon/daemon.cc b/daemon/daemon.cc index 84201448b..903d7d3e0 100644 --- a/daemon/daemon.cc +++ b/daemon/daemon.cc @@ -26,6 +26,12 @@ #include "commands/call.h" #include "commands/call-stats.h" #include "commands/call-status.h" +#include "commands/call-pause.h" +#include "commands/call-mute.h" +#include "commands/call-resume.h" +#include "commands/call-camera.h" +#include "commands/call-transfer.h" +#include "commands/conference.h" #include "commands/contact.h" #include "commands/dtmf.h" #include "commands/firewall-policy.h" @@ -186,7 +192,7 @@ CallStatsResponse::CallStatsResponse(Daemon *daemon, LinphoneCall *call, const L AudioStreamStatsResponse::AudioStreamStatsResponse(Daemon* daemon, AudioStream* stream, const LinphoneCallStats *stats, bool event) { const char *prefix = ""; - + ostringstream ostr; if (event) { ostr << "Event-type: audio-stream-stats\n"; @@ -201,9 +207,9 @@ AudioStreamStatsResponse::AudioStreamStatsResponse(Daemon* daemon, AudioStream* } else { prefix = ((stats->type == LINPHONE_CALL_STATS_AUDIO) ? "Audio-" : "Video-"); } - + printCallStatsHelper(ostr, stats, prefix); - + setBody(ostr.str().c_str()); } @@ -413,6 +419,12 @@ void Daemon::initCommands() { mCommands.push_back(new AnswerCommand()); mCommands.push_back(new CallStatusCommand()); mCommands.push_back(new CallStatsCommand()); + mCommands.push_back(new CallPause()); + mCommands.push_back(new CallMute()); + mCommands.push_back(new CallResume()); + mCommands.push_back(new CallTransfer()); + mCommands.push_back(new CallCamera()); + mCommands.push_back(new Conference()); mCommands.push_back(new AudioCodecGetCommand()); mCommands.push_back(new AudioCodecEnableCommand()); mCommands.push_back(new AudioCodecDisableCommand()); @@ -459,8 +471,9 @@ bool Daemon::pullEvent() { void Daemon::callStateChanged(LinphoneCall *call, LinphoneCallState state, const char *msg) { switch (state) { - case LinphoneCallOutgoingProgress: case LinphoneCallIncomingReceived: + linphone_call_enable_camera (call,mAutoVideo); + case LinphoneCallOutgoingProgress: case LinphoneCallIncomingEarlyMedia: case LinphoneCallConnected: case LinphoneCallStreamsRunning: diff --git a/daemon/daemon.h b/daemon/daemon.h index b8bc893e7..22d742266 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -93,6 +93,15 @@ public: mReason = msg; } } + Response(const std::string& msg, Status status = Error): + mStatus(status) { + if( status == Ok) { + mBody = msg; + } else { + mReason = msg; + } + } + void setStatus(Status st) { mStatus = st; } @@ -151,9 +160,9 @@ public: class PayloadTypeParser { public: PayloadTypeParser(LinphoneCore *core, const std::string &mime_type, bool accept_all = false); - inline bool all() { return mAll; }; - inline bool successful() { return mSuccesful; }; - inline int payloadTypeNumber() { return mPayloadTypeNumber; }; + inline bool all() { return mAll; } + inline bool successful() { return mSuccesful; } + inline int payloadTypeNumber() { return mPayloadTypeNumber; } private: bool mAll; bool mSuccesful; @@ -195,12 +204,16 @@ public: bool pullEvent(); int updateCallId(LinphoneCall *call); int updateProxyId(LinphoneProxyConfig *proxy); - inline int maxProxyId() { return mProxyIds; }; + inline int maxProxyId() { return mProxyIds; } int updateAudioStreamId(AudioStream *audio_stream); void dumpCommandsHelp(); void dumpCommandsHelpHtml(); void enableStatsEvents(bool enabled); void enableLSD(bool enabled); + + void setAutoVideo( bool enabled ){ mAutoVideo = enabled; } + inline bool autoVideo(){ return mAutoVideo; } + private: static void* iterateThread(void *arg); static void callStateChanged(LinphoneCore *lc, LinphoneCall *call, LinphoneCallState state, const char *msg); @@ -229,6 +242,7 @@ private: bool mRunning; bool mUseStatsEvents; FILE *mLogFile; + bool mAutoVideo; int mCallIds; int mProxyIds; int mAudioStreamIds;