From 36a2a7bdc39331a6520dcbd1d57c1270de73a130 Mon Sep 17 00:00:00 2001 From: Philippe Proulx <philippe.proulx@savoirfairelinux.com> Date: Fri, 23 May 2014 14:53:49 -0400 Subject: [PATCH] Librarize daemon and create daemon app Refs:# 48032 --- daemon/Makefile.am | 2 +- daemon/bin/Makefile.am | 11 + daemon/{src/client => bin}/dbus/Makefile.am | 49 +- .../dbus/callmanager-introspec.xml | 0 .../dbus/configurationmanager-introspec.xml | 0 daemon/{src/client => bin}/dbus/dbus_cpp.h | 0 daemon/bin/dbus/dbuscallmanager.cpp | 243 ++++++ daemon/bin/dbus/dbuscallmanager.h | 110 +++ daemon/bin/dbus/dbusclient.cpp | 552 ++++++++++++ daemon/bin/dbus/dbusclient.h | 139 ++++ daemon/bin/dbus/dbusconfigurationmanager.cpp | 368 ++++++++ daemon/bin/dbus/dbusconfigurationmanager.h | 138 +++ .../dbus/dbusinstance.cpp} | 24 +- .../instance.h => bin/dbus/dbusinstance.h} | 31 +- .../dbus/dbuspresencemanager.cpp} | 45 +- .../dbus/dbuspresencemanager.h} | 51 +- daemon/bin/dbus/dbusvideomanager.cpp | 102 +++ daemon/bin/dbus/dbusvideomanager.h | 81 ++ .../dbus/instance-introspec.xml | 0 .../dbus/org.sflphone.SFLphone.service.in | 0 .../dbus/presencemanager-introspec.xml | 0 .../dbus/videomanager-introspec.xml | 0 daemon/bin/main.cpp | 215 +++++ daemon/configure.ac | 51 +- daemon/globals.mak | 1 - daemon/src/Makefile.am | 23 +- daemon/src/client/Makefile.am | 26 +- .../src/client/android/JavaJNI2CJNI_Load.py | 85 -- daemon/src/client/android/callmanager.i | 403 --------- daemon/src/client/android/callmanager_jni.cpp | 152 ---- .../src/client/android/configurationmanager.i | 184 ---- .../android/configurationmanager_jni.cpp | 80 -- daemon/src/client/android/jni-xml2cpp.py | 85 -- daemon/src/client/android/jni_callbacks.h | 39 - daemon/src/client/android/jni_interface.i | 92 -- daemon/src/client/android/managerimpl.i | 58 -- .../client/android/presencemanager_jni.cpp | 52 -- .../client/android/sflphoneservice.c.template | 73 -- daemon/src/client/callmanager.cpp | 172 ++++ daemon/src/client/callmanager.h | 57 +- daemon/src/client/callmanager_stub.cpp | 149 ---- daemon/src/client/client.cpp | 46 +- daemon/src/client/client.h | 23 - daemon/src/client/configurationmanager.cpp | 66 ++ daemon/src/client/configurationmanager.h | 51 +- .../src/client/configurationmanager_stub.cpp | 77 -- daemon/src/client/dbus/README | 24 - daemon/src/client/dbus/callmanager_dbus.cpp | 35 - daemon/src/client/dbus/client.cpp | 219 ----- .../client/dbus/configurationmanager_dbus.cpp | 56 -- daemon/src/client/dbus/networkmanager_proxy.h | 73 -- .../dbus/org.freedesktop.NetworkManager.xml | 15 - .../src/client/dbus/presencemanager_dbus.cpp | 41 - daemon/src/client/dbus/videomanager_dbus.cpp | 43 - daemon/src/client/presencemanager.cpp | 41 + daemon/src/client/presencemanager.h | 73 +- daemon/src/client/presencemanager_stub.cpp | 59 -- daemon/src/client/videomanager.cpp | 32 + daemon/src/client/videomanager.h | 52 +- daemon/src/client/videomanager_stub.cpp | 88 -- daemon/src/main.cpp | 207 ----- daemon/src/managerimpl.cpp | 16 - daemon/src/managerimpl.h | 9 - daemon/src/sflphone.h | 285 +++++++ daemon/src/sflphone_api.cpp | 785 ++++++++++++++++++ daemon/test/Makefile.am | 2 +- 66 files changed, 3569 insertions(+), 2792 deletions(-) create mode 100644 daemon/bin/Makefile.am rename daemon/{src/client => bin}/dbus/Makefile.am (57%) rename daemon/{src/client => bin}/dbus/callmanager-introspec.xml (100%) rename daemon/{src/client => bin}/dbus/configurationmanager-introspec.xml (100%) rename daemon/{src/client => bin}/dbus/dbus_cpp.h (100%) create mode 100644 daemon/bin/dbus/dbuscallmanager.cpp create mode 100644 daemon/bin/dbus/dbuscallmanager.h create mode 100644 daemon/bin/dbus/dbusclient.cpp create mode 100644 daemon/bin/dbus/dbusclient.h create mode 100644 daemon/bin/dbus/dbusconfigurationmanager.cpp create mode 100644 daemon/bin/dbus/dbusconfigurationmanager.h rename daemon/{src/client/dbus/instance.cpp => bin/dbus/dbusinstance.cpp} (76%) rename daemon/{src/client/dbus/instance.h => bin/dbus/dbusinstance.h} (78%) rename daemon/{src/client/dbus/networkmanager.cpp => bin/dbus/dbuspresencemanager.cpp} (56%) rename daemon/{src/client/dbus/networkmanager.h => bin/dbus/dbuspresencemanager.h} (52%) create mode 100644 daemon/bin/dbus/dbusvideomanager.cpp create mode 100644 daemon/bin/dbus/dbusvideomanager.h rename daemon/{src/client => bin}/dbus/instance-introspec.xml (100%) rename daemon/{src/client => bin}/dbus/org.sflphone.SFLphone.service.in (100%) rename daemon/{src/client => bin}/dbus/presencemanager-introspec.xml (100%) rename daemon/{src/client => bin}/dbus/videomanager-introspec.xml (100%) create mode 100644 daemon/bin/main.cpp delete mode 100755 daemon/src/client/android/JavaJNI2CJNI_Load.py delete mode 100644 daemon/src/client/android/callmanager.i delete mode 100644 daemon/src/client/android/callmanager_jni.cpp delete mode 100644 daemon/src/client/android/configurationmanager.i delete mode 100644 daemon/src/client/android/configurationmanager_jni.cpp delete mode 100755 daemon/src/client/android/jni-xml2cpp.py delete mode 100644 daemon/src/client/android/jni_callbacks.h delete mode 100644 daemon/src/client/android/jni_interface.i delete mode 100644 daemon/src/client/android/managerimpl.i delete mode 100644 daemon/src/client/android/presencemanager_jni.cpp delete mode 100644 daemon/src/client/android/sflphoneservice.c.template delete mode 100644 daemon/src/client/callmanager_stub.cpp delete mode 100644 daemon/src/client/configurationmanager_stub.cpp delete mode 100644 daemon/src/client/dbus/README delete mode 100644 daemon/src/client/dbus/callmanager_dbus.cpp delete mode 100644 daemon/src/client/dbus/client.cpp delete mode 100644 daemon/src/client/dbus/configurationmanager_dbus.cpp delete mode 100644 daemon/src/client/dbus/networkmanager_proxy.h delete mode 100644 daemon/src/client/dbus/org.freedesktop.NetworkManager.xml delete mode 100644 daemon/src/client/dbus/presencemanager_dbus.cpp delete mode 100644 daemon/src/client/dbus/videomanager_dbus.cpp delete mode 100644 daemon/src/client/presencemanager_stub.cpp delete mode 100644 daemon/src/client/videomanager_stub.cpp delete mode 100644 daemon/src/main.cpp create mode 100644 daemon/src/sflphone.h create mode 100644 daemon/src/sflphone_api.cpp diff --git a/daemon/Makefile.am b/daemon/Makefile.am index 6584a5c0f2..61ce4a43bd 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -19,7 +19,7 @@ unittest: endif ACLOCAL_AMFLAGS = -I m4 -SUBDIRS = src ringtones man $(TESTS_DIR) doc +SUBDIRS = src ringtones man $(TESTS_DIR) doc bin EXTRA_DIST = m4/libtool.m4 \ m4/lt~obsolete.m4 \ diff --git a/daemon/bin/Makefile.am b/daemon/bin/Makefile.am new file mode 100644 index 0000000000..2598f639e0 --- /dev/null +++ b/daemon/bin/Makefile.am @@ -0,0 +1,11 @@ +SUBDIRS=dbus + +libexecdir=$(libdir)/sflphone +libexec_PROGRAMS = sflphoned + +sflphoned_SOURCES = main.cpp + +sflphoned_CXXFLAGS=-I$(top_srcdir)/src ${DBUSCPP_CFLAGS} \ + -DTOP_BUILDDIR=\"$$(cd "$(top_builddir)"; pwd)\" + +sflphoned_LDADD = ${DBUSCPP_LIBS} dbus/libclient_dbus.la $(top_builddir)/src/libsflphone.la diff --git a/daemon/src/client/dbus/Makefile.am b/daemon/bin/dbus/Makefile.am similarity index 57% rename from daemon/src/client/dbus/Makefile.am rename to daemon/bin/dbus/Makefile.am index 2e3b46364f..813902966d 100644 --- a/daemon/src/client/dbus/Makefile.am +++ b/daemon/bin/dbus/Makefile.am @@ -3,66 +3,57 @@ include $(top_srcdir)/globals.mak noinst_LTLIBRARIES = libclient_dbus.la BUILT_SOURCES= \ - callmanager-glue.h \ - configurationmanager-glue.h \ - instance-glue.h + dbuscallmanager.adaptor.h \ + dbusconfigurationmanager.adaptor.h \ + dbusinstance.adaptor.h if SFL_PRESENCE -BUILT_SOURCES+=presencemanager-glue.h -presencemanager-glue.h: presencemanager-introspec.xml Makefile.am +BUILT_SOURCES+=dbuspresencemanager.adaptor.h +dbuspresencemanager.adaptor.h: presencemanager-introspec.xml Makefile.am dbusxx-xml2cpp $< --adaptor=$@ endif if SFL_VIDEO -BUILT_SOURCES+=videomanager-glue.h -videomanager-glue.h: videomanager-introspec.xml Makefile.am +BUILT_SOURCES+=dbusvideomanager.adaptor.h +dbusvideomanager.adaptor.h: videomanager-introspec.xml Makefile.am dbusxx-xml2cpp $< --adaptor=$@ endif # Rule to generate the binding headers -callmanager-glue.h: callmanager-introspec.xml Makefile.am +dbuscallmanager.adaptor.h: callmanager-introspec.xml Makefile.am dbusxx-xml2cpp $< --adaptor=$@ # Rule to generate the binding headers -configurationmanager-glue.h: configurationmanager-introspec.xml Makefile.am +dbusconfigurationmanager.adaptor.h: configurationmanager-introspec.xml Makefile.am dbusxx-xml2cpp $< --adaptor=$@ # Rule to generate the binding headers -instance-glue.h: instance-introspec.xml Makefile.am +dbusinstance.adaptor.h: instance-introspec.xml Makefile.am dbusxx-xml2cpp $< --adaptor=$@ libclient_dbus_la_SOURCES = \ - callmanager_dbus.cpp \ - configurationmanager_dbus.cpp \ - instance.cpp \ - client.cpp + dbuscallmanager.cpp \ + dbusconfigurationmanager.cpp \ + dbusinstance.cpp \ + dbusclient.cpp \ + dbusinstance.h \ + dbus_cpp.h \ + $(BUILT_SOURCES) if SFL_PRESENCE -libclient_dbus_la_SOURCES += presencemanager_dbus.cpp +libclient_dbus_la_SOURCES += dbuspresencemanager.cpp endif if SFL_VIDEO -libclient_dbus_la_SOURCES += videomanager_dbus.cpp -endif - -if USE_NETWORKMANAGER -libclient_dbus_la_SOURCES += networkmanager.cpp -NETWORKMANAGER=-DUSE_NETWORKMANAGER +libclient_dbus_la_SOURCES += dbusvideomanager.cpp endif libclient_dbus_la_CXXFLAGS = -I../ \ + -I$(top_srcdir)/src \ -DPREFIX=\"$(prefix)\" \ -DPROGSHAREDIR=\"${datadir}/sflphone\" \ - $(NETWORKMANAGER) \ $(DBUSCPP_CFLAGS) -noinst_HEADERS = \ - instance.h \ - networkmanager_proxy.h \ - networkmanager.h \ - dbus_cpp.h \ - $(BUILT_SOURCES) - # Dbus service file servicedir = $(datadir)/dbus-1/services service_in_files = org.sflphone.SFLphone.service.in diff --git a/daemon/src/client/dbus/callmanager-introspec.xml b/daemon/bin/dbus/callmanager-introspec.xml similarity index 100% rename from daemon/src/client/dbus/callmanager-introspec.xml rename to daemon/bin/dbus/callmanager-introspec.xml diff --git a/daemon/src/client/dbus/configurationmanager-introspec.xml b/daemon/bin/dbus/configurationmanager-introspec.xml similarity index 100% rename from daemon/src/client/dbus/configurationmanager-introspec.xml rename to daemon/bin/dbus/configurationmanager-introspec.xml diff --git a/daemon/src/client/dbus/dbus_cpp.h b/daemon/bin/dbus/dbus_cpp.h similarity index 100% rename from daemon/src/client/dbus/dbus_cpp.h rename to daemon/bin/dbus/dbus_cpp.h diff --git a/daemon/bin/dbus/dbuscallmanager.cpp b/daemon/bin/dbus/dbuscallmanager.cpp new file mode 100644 index 0000000000..764c721440 --- /dev/null +++ b/daemon/bin/dbus/dbuscallmanager.cpp @@ -0,0 +1,243 @@ +/* + * Copyright (C) 2004-2013 Savoir-Faire Linux Inc. + * Author: Philippe Proulx <philippe.proulx@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Additional permission under GNU GPL version 3 section 7: + * + * If you modify this program, or any covered work, by linking or + * combining it with the OpenSSL project's OpenSSL library (or a + * modified version of that library), containing parts covered by the + * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. + * grants you additional permission to convey the resulting work. + * Corresponding Source for a non-source form of such a combination + * shall include the source code for the parts of OpenSSL used as well + * as that of the covered work. + */ +#include <iostream> +#include <sflphone.h> + +#include "dbuscallmanager.h" + +DBusCallManager::DBusCallManager(DBus::Connection& connection) + : DBus::ObjectAdaptor(connection, "/org/sflphone/SFLphone/CallManager") +{ +} + +bool DBusCallManager::placeCall(const std::string& accountID, const std::string& callID, const std::string& to) +{ + return sflph_call_place(accountID, callID, to); +} + +bool DBusCallManager::refuse(const std::string& callID) +{ + return sflph_call_refuse(callID); +} + +bool DBusCallManager::accept(const std::string& callID) +{ + return sflph_call_accept(callID); +} + +bool DBusCallManager::hangUp(const std::string& callID) +{ + return sflph_call_hang_up(callID); +} + +bool DBusCallManager::hold(const std::string& callID) +{ + return sflph_call_hold(callID); +} + +bool DBusCallManager::unhold(const std::string& callID) +{ + return sflph_call_unhold(callID); +} + +bool DBusCallManager::transfer(const std::string& callID, const std::string& to) +{ + return sflph_call_transfer(callID, to); +} + +bool DBusCallManager::attendedTransfer(const std::string& transferID, const std::string& targetID) +{ + return sflph_call_attended_transfer(transferID, targetID); +} + +std::map< std::string, std::string > DBusCallManager::getCallDetails(const std::string& callID) +{ + return sflph_call_get_call_details(callID); +} + +std::vector< std::string > DBusCallManager::getCallList() +{ + return sflph_call_get_call_list(); +} + +void DBusCallManager::removeConference(const std::string& conference_id) +{ + sflph_call_remove_conference(conference_id); +} + +bool DBusCallManager::joinParticipant(const std::string& sel_callID, const std::string& drag_callID) +{ + return sflph_call_join_participant(sel_callID, drag_callID); +} + +void DBusCallManager::createConfFromParticipantList(const std::vector< std::string >& participants) +{ + sflph_call_create_conf_from_participant_list(participants); +} + +bool DBusCallManager::isConferenceParticipant(const std::string& call_id) +{ + return sflph_call_is_conference_participant(call_id); +} + +bool DBusCallManager::addParticipant(const std::string& callID, const std::string& confID) +{ + return sflph_call_add_participant(callID, confID); +} + +bool DBusCallManager::addMainParticipant(const std::string& confID) +{ + return sflph_call_add_main_participant(confID); +} + +bool DBusCallManager::detachParticipant(const std::string& callID) +{ + return sflph_call_detach_participant(callID); +} + +bool DBusCallManager::joinConference(const std::string& sel_confID, const std::string& drag_confID) +{ + return sflph_call_join_conference(sel_confID, drag_confID); +} + +bool DBusCallManager::hangUpConference(const std::string& confID) +{ + return sflph_call_hang_up_conference(confID); +} + +bool DBusCallManager::holdConference(const std::string& confID) +{ + return sflph_call_hold_conference(confID); +} + +bool DBusCallManager::unholdConference(const std::string& confID) +{ + return sflph_call_unhold_conference(confID); +} + +std::vector<std::string> DBusCallManager::getConferenceList() +{ + return sflph_call_get_conference_list(); +} + +std::vector<std::string> DBusCallManager::getParticipantList(const std::string& confID) +{ + return sflph_call_get_participant_list(confID); +} + +std::vector<std::string> DBusCallManager::getDisplayNames(const std::string& confID) +{ + return sflph_call_get_display_names(confID); +} + +std::string DBusCallManager::getConferenceId(const std::string& callID) +{ + return sflph_call_get_conference_id(callID); +} + +std::map<std::string, std::string> DBusCallManager::getConferenceDetails(const std::string& callID) +{ + return sflph_call_get_conference_details(callID); +} + +bool DBusCallManager::startRecordedFilePlayback(const std::string& filepath) +{ + return sflph_call_play_recorded_file(filepath); +} + +void DBusCallManager::stopRecordedFilePlayback(const std::string& filepath) +{ + sflph_call_stop_recorded_file(filepath); +} + +bool DBusCallManager::toggleRecording(const std::string& callID) +{ + return sflph_call_toggle_recording(callID); +} + +void DBusCallManager::setRecording(const std::string& callID) +{ + sflph_call_set_recording(callID); +} + +void DBusCallManager::recordPlaybackSeek(const double& value) +{ + sflph_call_record_playback_seek(value); +} + +bool DBusCallManager::getIsRecording(const std::string& callID) +{ + return sflph_call_is_recording(callID); +} + +std::string DBusCallManager::getCurrentAudioCodecName(const std::string& callID) +{ + return sflph_call_get_current_audio_codec_name(callID); +} + +void DBusCallManager::playDTMF(const std::string& key) +{ + sflph_call_play_dtmf(key); +} + +void DBusCallManager::startTone(const int32_t& start, const int32_t& type) +{ + sflph_call_start_tone(start, type); +} + +void DBusCallManager::setSASVerified(const std::string& callID) +{ + sflph_call_set_sas_verified(callID); +} + +void DBusCallManager::resetSASVerified(const std::string& callID) +{ + sflph_call_reset_sas_verified(callID); +} + +void DBusCallManager::setConfirmGoClear(const std::string& callID) +{ + sflph_call_set_confirm_go_clear(callID); +} + +void DBusCallManager::requestGoClear(const std::string& callID) +{ + sflph_call_request_go_clear(callID); +} + +void DBusCallManager::acceptEnrollment(const std::string& callID, const bool& accepted) +{ + sflph_call_accept_enrollment(callID, accepted); +} + +void DBusCallManager::sendTextMessage(const std::string& callID, const std::string& message) +{ + sflph_call_send_text_message(callID, message); +} diff --git a/daemon/bin/dbus/dbuscallmanager.h b/daemon/bin/dbus/dbuscallmanager.h new file mode 100644 index 0000000000..fbe5f00a80 --- /dev/null +++ b/daemon/bin/dbus/dbuscallmanager.h @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2004-2013 Savoir-Faire Linux Inc. + * Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Additional permission under GNU GPL version 3 section 7: + * + * If you modify this program, or any covered work, by linking or + * combining it with the OpenSSL project's OpenSSL library (or a + * modified version of that library), containing parts covered by the + * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. + * grants you additional permission to convey the resulting work. + * Corresponding Source for a non-source form of such a combination + * shall include the source code for the parts of OpenSSL used as well + * as that of the covered work. + */ + +#ifndef __SFL_CALLMANAGER_H__ +#define __SFL_CALLMANAGER_H__ + +#include <vector> +#include <map> +#include <string> + +#include "dbus_cpp.h" + +#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 6 +/* This warning option only exists for gcc 4.6.0 and greater. */ +#pragma GCC diagnostic ignored "-Wunused-but-set-variable" +#endif + +#pragma GCC diagnostic ignored "-Wignored-qualifiers" +#pragma GCC diagnostic ignored "-Wunused-parameter" +#include "dbuscallmanager.adaptor.h" +#pragma GCC diagnostic warning "-Wignored-qualifiers" +#pragma GCC diagnostic warning "-Wunused-parameter" + +#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 6 +/* This warning option only exists for gcc 4.6.0 and greater. */ +#pragma GCC diagnostic warning "-Wunused-but-set-variable" +#endif + +#include <stdexcept> + +class DBusCallManager : + public org::sflphone::SFLphone::CallManager_adaptor, + public DBus::IntrospectableAdaptor, + public DBus::ObjectAdaptor +{ + public: + DBusCallManager(DBus::Connection& connection); + + // Methods + bool placeCall(const std::string& accountID, const std::string& callID, const std::string& to); + bool refuse(const std::string& callID); + bool accept(const std::string& callID); + bool hangUp(const std::string& callID); + bool hold(const std::string& callID); + bool unhold(const std::string& callID); + bool transfer(const std::string& callID, const std::string& to); + bool attendedTransfer(const std::string& transferID, const std::string& targetID); + std::map< std::string, std::string > getCallDetails(const std::string& callID); + std::vector< std::string > getCallList(); + void removeConference(const std::string& conference_id); + bool joinParticipant(const std::string& sel_callID, const std::string& drag_callID); + void createConfFromParticipantList(const std::vector< std::string >& participants); + bool isConferenceParticipant(const std::string& call_id); + bool addParticipant(const std::string& callID, const std::string& confID); + bool addMainParticipant(const std::string& confID); + bool detachParticipant(const std::string& callID); + bool joinConference(const std::string& sel_confID, const std::string& drag_confID); + bool hangUpConference(const std::string& confID); + bool holdConference(const std::string& confID); + bool unholdConference(const std::string& confID); + std::vector<std::string> getConferenceList(); + std::vector<std::string> getParticipantList(const std::string& confID); + std::vector<std::string> getDisplayNames(const std::string& confID); + std::string getConferenceId(const std::string& callID); + std::map<std::string, std::string> getConferenceDetails(const std::string& callID); + bool startRecordedFilePlayback(const std::string& filepath); + void stopRecordedFilePlayback(const std::string& filepath); + bool toggleRecording(const std::string& callID); + void setRecording(const std::string& callID); + void recordPlaybackSeek(const double& value); + bool getIsRecording(const std::string& callID); + std::string getCurrentAudioCodecName(const std::string& callID); + void playDTMF(const std::string& key); + void startTone(const int32_t& start, const int32_t& type); + void setSASVerified(const std::string& callID); + void resetSASVerified(const std::string& callID); + void setConfirmGoClear(const std::string& callID); + void requestGoClear(const std::string& callID); + void acceptEnrollment(const std::string& callID, const bool& accepted); + void sendTextMessage(const std::string& callID, const std::string& message); +}; + +#endif // __SFL_CALLMANAGER_H__ diff --git a/daemon/bin/dbus/dbusclient.cpp b/daemon/bin/dbus/dbusclient.cpp new file mode 100644 index 0000000000..1ad25ab7ab --- /dev/null +++ b/daemon/bin/dbus/dbusclient.cpp @@ -0,0 +1,552 @@ +/* + * Copyright (C) 2014 Savoir-Faire Linux Inc. + * Author: Philippe Proulx <philippe.proulx@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Additional permission under GNU GPL version 3 section 7: + * + * If you modify this program, or any covered work, by linking or + * combining it with the OpenSSL project's OpenSSL library (or a + * modified version of that library), containing parts covered by the + * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. + * grants you additional permission to convey the resulting work. + * Corresponding Source for a non-source form of such a combination + * shall include the source code for the parts of OpenSSL used as well + * as that of the covered work. + */ +#include <cstdlib> +#include <iostream> +#include <cstring> +#include <stdexcept> +#include <sflphone.h> + +#include "dbusclient.h" +#include "dbus_cpp.h" + +#include "dbusinstance.h" +#include "dbuscallmanager.h" +#include "dbusconfigurationmanager.h" + +#ifdef SFL_PRESENCE +#include "dbuspresencemanager.h" +#endif + +#ifdef SFL_VIDEO +#include "dbusvideomanager.h" +#endif + +struct EventCallback : DBus::Callback_Base<void, DBus::DefaultTimeout&> +{ + EventCallback(const std::function<void()> &func) : + callback_(func) + {} + + void call(DBus::DefaultTimeout &) const + { + callback_(); + } + +private: + std::function<void()> callback_; +}; + +DBusClient* DBusClient::_lastDbusClient = nullptr; + +DBusClient::DBusClient(int sflphFlags, bool persistent) : + callManager_(nullptr) + , configurationManager_(nullptr) +#ifdef SFL_PRESENCE + , presenceManager_(nullptr) +#endif + , instanceManager_(nullptr) + , dispatcher_(new DBus::BusDispatcher) +#ifdef SFL_VIDEO + , videoManager_(nullptr) +#endif +{ + try { + DBus::_init_threading(); + DBus::default_dispatcher = dispatcher_; + + // timeout and expired are deleted internally by dispatcher_'s + // destructor, so we must NOT delete them ourselves. + DBus::DefaultTimeout *timeout = new DBus::DefaultTimeout(10 /* ms */, + true, + dispatcher_); + // Poll for SIP/IAX events + timeout->expired = new EventCallback(sflph_poll_events); + + DBus::Connection sessionConnection(DBus::Connection::SessionBus()); + sessionConnection.request_name("org.sflphone.SFLphone"); + + callManager_ = new DBusCallManager(sessionConnection); + configurationManager_ = new DBusConfigurationManager(sessionConnection); + +#ifdef SFL_PRESENCE + presenceManager_ = new DBusPresenceManager(sessionConnection); +#endif + + DBusInstance::OnNoMoreClientFunc onNoMoreClientFunc; + + if (!persistent) { + onNoMoreClientFunc = [this] () { + this->exit(); + }; + } + + instanceManager_ = new DBusInstance(sessionConnection, onNoMoreClientFunc); + +#ifdef SFL_VIDEO + videoManager_ = new DBusVideoManager(sessionConnection); +#endif + } catch (const DBus::Error &err) { + throw std::runtime_error("cannot initialize DBus stuff"); + } + + auto ret = initLibrary(sflphFlags); + + if (ret < 0) { + throw std::runtime_error("cannot initialize libsflphone"); + } + + instanceManager_->started(); +} + +DBusClient::~DBusClient() +{ +#ifdef SFL_VIDEO + delete videoManager_; +#endif + + delete instanceManager_; + +#ifdef SFL_PRESENCE + delete presenceManager_; +#endif + + delete configurationManager_; + delete callManager_; + delete dispatcher_; + + finiLibrary(); +} + +int DBusClient::initLibrary(int sflphFlags) +{ + if (!DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient = this; + } + + // Call event handlers + sflph_call_ev_handlers callEvHandlers = { + DBusClient::callOnStateChange, + DBusClient::callOnTransferFail, + DBusClient::callOnTransferSuccess, + DBusClient::callOnRecordPlaybackStopped, + DBusClient::callOnVoiceMailNotify, + DBusClient::callOnIncomingMessage, + DBusClient::callOnIncomingCall, + DBusClient::callOnRecordPlaybackFilepath, + DBusClient::callOnConferenceCreated, + DBusClient::callOnConferenceChanged, + DBusClient::callOnUpdatePlaybackScale, + DBusClient::callOnConferenceRemove, + DBusClient::callOnNewCall, + DBusClient::callOnSipCallStateChange, + DBusClient::callOnRecordStateChange, + DBusClient::callOnSecureSdesOn, + DBusClient::callOnSecureSdesOff, + DBusClient::callOnSecureZrtpOn, + DBusClient::callOnSecureZrtpOff, + DBusClient::callOnShowSas, + DBusClient::callOnZrtpNotSuppOther, + DBusClient::callOnZrtpNegotiationFail, + DBusClient::callOnRtcpReceiveReport, + }; + + // Configuration event handlers + sflph_config_ev_handlers configEvHandlers = { + DBusClient::configOnVolumeChange, + DBusClient::configOnAccountsChange, + DBusClient::configOnHistoryChange, + DBusClient::configOnStunStatusFail, + DBusClient::configOnRegistrationStateChange, + DBusClient::configOnSipRegistrationStateChange, + DBusClient::configOnError, + }; + +#ifdef SFL_PRESENCE + // Presence event handlers + sflph_pres_ev_handlers presEvHandlers = { + DBusClient::presOnNewServerSubscriptionRequest, + DBusClient::presOnServerError, + DBusClient::presOnNewBuddyNotification, + DBusClient::presOnSubscriptionStateChange, + }; +#endif // SFL_PRESENCE + +#ifdef SFL_VIDEO + // Video event handlers + sflph_video_ev_handlers videoEvHandlers = { + DBusClient::videoOnDeviceEvent, + DBusClient::videoOnStartDecoding, + DBusClient::videoOnStopDecoding, + }; +#endif // SFL_VIDEO + + // All event handlers + sflph_ev_handlers evHandlers; + std::memset(std::addressof(evHandlers), 0, sizeof(evHandlers)); + + evHandlers.call_ev_handlers = callEvHandlers; + evHandlers.config_ev_handlers = configEvHandlers; + +#ifdef SFL_PRESENCE + evHandlers.pres_ev_handlers = presEvHandlers; +#endif // SFL_PRESENCE + +#ifdef SFL_VIDEO + evHandlers.video_ev_handlers = videoEvHandlers; +#endif // SFL_VIDEO + + // Initialize now + return sflph_init(&evHandlers, static_cast<sflph_init_flag>(sflphFlags)); +} + +void DBusClient::finiLibrary() +{ + sflph_fini(); +} + +int DBusClient::event_loop() +{ + try { + dispatcher_->enter(); + } catch (const DBus::Error &err) { + std::cerr << "quitting: " << err.name() << ": " << err.what() << std::endl; + return 1; + } catch (const std::exception &err) { + std::cerr << "quitting: " << err.what() << std::endl; + return 1; + } + + return 0; +} + +int DBusClient::exit() +{ + // Avoid libsflphone events from now on + DBusClient::_lastDbusClient = nullptr; + + try { + dispatcher_->leave(); + } catch (const DBus::Error &err) { + std::cerr << "quitting: " << err.name() << ": " << err.what() << std::endl; + return 1; + } catch (const std::exception &err) { + std::cerr << "quitting: " << err.what() << std::endl; + return 1; + } + + return 0; +} + +DBusCallManager* DBusClient::getCallManager() +{ + return callManager_; +} + +DBusConfigurationManager* DBusClient::getConfigurationManager() +{ + return configurationManager_; +} + +#ifdef SFL_PRESENCE +DBusPresenceManager* DBusClient::getPresenceManager() +{ + return presenceManager_; +} +#endif + +#ifdef SFL_VIDEO +DBusVideoManager* DBusClient::getVideoManager() +{ + return videoManager_; +} +#endif + +void DBusClient::callOnStateChange(const std::string& call_id, const std::string& state) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getCallManager()->callStateChanged(call_id, state); + } +} + +void DBusClient::callOnTransferFail(void) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getCallManager()->transferFailed(); + } +} + +void DBusClient::callOnTransferSuccess(void) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getCallManager()->transferSucceeded(); + } +} + +void DBusClient::callOnRecordPlaybackStopped(const std::string& path) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getCallManager()->recordPlaybackStopped(path); + } +} + +void DBusClient::callOnVoiceMailNotify(const std::string& call_id, int nd_msg) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getCallManager()->voiceMailNotify(call_id, nd_msg); + } +} + +void DBusClient::callOnIncomingMessage(const std::string& id, const std::string& from, const std::string& msg) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getCallManager()->incomingMessage(id, from, msg); + } +} + +void DBusClient::callOnIncomingCall(const std::string& account_id, const std::string& call_id, const std::string& from) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getCallManager()->incomingCall(account_id, call_id, from); + } +} + +void DBusClient::callOnRecordPlaybackFilepath(const std::string& id, const std::string& filename) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getCallManager()->recordPlaybackFilepath(id, filename); + } +} + +void DBusClient::callOnConferenceCreated(const std::string& conf_id) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getCallManager()->conferenceCreated(conf_id); + } +} + +void DBusClient::callOnConferenceChanged(const std::string& conf_id, const std::string& state) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getCallManager()->conferenceChanged(conf_id, state); + } +} + +void DBusClient::callOnUpdatePlaybackScale(const std::string& filepath, int position, int scale) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getCallManager()->updatePlaybackScale(filepath, position, scale); + } +} + +void DBusClient::callOnConferenceRemove(const std::string& conf_id) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getCallManager()->conferenceRemoved(conf_id); + } +} + +void DBusClient::callOnNewCall(const std::string& account_id, const std::string& call_id, const std::string& to) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getCallManager()->newCallCreated(account_id, call_id, to); + } +} + +void DBusClient::callOnSipCallStateChange(const std::string& call_id, const std::string& state, int code) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getCallManager()->sipCallStateChanged(call_id, state, code); + } +} + +void DBusClient::callOnRecordStateChange(const std::string& call_id, int state) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getCallManager()->recordingStateChanged(call_id, state); + } +} + +void DBusClient::callOnSecureSdesOn(const std::string& call_id) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getCallManager()->secureSdesOn(call_id); + } +} + +void DBusClient::callOnSecureSdesOff(const std::string& call_id) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getCallManager()->secureSdesOff(call_id); + } +} + +void DBusClient::callOnSecureZrtpOn(const std::string& call_id, const std::string& cipher) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getCallManager()->secureZrtpOn(call_id, cipher); + } +} + +void DBusClient::callOnSecureZrtpOff(const std::string& call_id) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getCallManager()->secureZrtpOff(call_id); + } +} + +void DBusClient::callOnShowSas(const std::string& call_id, const std::string& sas, int verified) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getCallManager()->showSAS(call_id, sas, verified); + } +} + +void DBusClient::callOnZrtpNotSuppOther(const std::string& call_id) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getCallManager()->zrtpNotSuppOther(call_id); + } +} + +void DBusClient::callOnZrtpNegotiationFail(const std::string& call_id, const std::string& reason, const std::string& severity) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getCallManager()->zrtpNegotiationFailed(call_id, reason, severity); + } +} + +void DBusClient::callOnRtcpReceiveReport(const std::string& call_id, const std::map<std::string, int>& stats) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getCallManager()->onRtcpReportReceived(call_id, stats); + } +} + +void DBusClient::configOnVolumeChange(const std::string& device, int value) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getConfigurationManager()->volumeChanged(device, value); + } +} + +void DBusClient::configOnAccountsChange(void) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getConfigurationManager()->accountsChanged(); + } +} + +void DBusClient::configOnHistoryChange(void) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getConfigurationManager()->historyChanged(); + } +} + +void DBusClient::configOnStunStatusFail(const std::string& account_id) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getConfigurationManager()->stunStatusFailure(account_id); + } +} + +void DBusClient::configOnRegistrationStateChange(const std::string& account_id, int state) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getConfigurationManager()->registrationStateChanged(account_id, state); + } +} + +void DBusClient::configOnSipRegistrationStateChange(const std::string& account_id, const std::string& state, int code) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getConfigurationManager()->sipRegistrationStateChanged(account_id, state, code); + } +} + +void DBusClient::configOnError(int alert) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getConfigurationManager()->errorAlert(alert); + } +} + +#ifdef SFL_PRESENCE +void DBusClient::presOnNewServerSubscriptionRequest(const std::string& remote) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getPresenceManager()->newServerSubscriptionRequest(remote); + } +} + +void DBusClient::presOnServerError(const std::string& account_id, const std::string& error, const std::string& msg) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getPresenceManager()->serverError(account_id, error, msg); + } +} + +void DBusClient::presOnNewBuddyNotification(const std::string& account_id, const std::string& buddy_uri, int status, const std::string& line_status) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getPresenceManager()->newBuddyNotification(account_id, buddy_uri, status, line_status); + } +} + +void DBusClient::presOnSubscriptionStateChange(const std::string& account_id, const std::string& buddy_uri, int state) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getPresenceManager()->subscriptionStateChanged(account_id, buddy_uri, state); + } +} +#endif // SFL_PRESENCE + +#ifdef SFL_VIDEO +void DBusClient::videoOnDeviceEvent(void) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getVideoManager()->deviceEvent(); + } +} + +void DBusClient::videoOnStartDecoding(const std::string& id, const std::string& shm_path, int w, int h, bool is_mixer) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getVideoManager()->startedDecoding(id, shm_path, w, h, is_mixer); + } +} + +void DBusClient::videoOnStopDecoding(const std::string& id, const std::string& shm_path, bool is_mixer) +{ + if (DBusClient::_lastDbusClient) { + DBusClient::_lastDbusClient->getVideoManager()->stoppedDecoding(id, shm_path, is_mixer); + } +} +#endif // SFL_VIDEO diff --git a/daemon/bin/dbus/dbusclient.h b/daemon/bin/dbus/dbusclient.h new file mode 100644 index 0000000000..3cc3685678 --- /dev/null +++ b/daemon/bin/dbus/dbusclient.h @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2004-2013 Savoir-Faire Linux Inc. + * Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Additional permission under GNU GPL version 3 section 7: + * + * If you modify this program, or any covered work, by linking or + * combining it with the OpenSSL project's OpenSSL library (or a + * modified version of that library), containing parts covered by the + * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. + * grants you additional permission to convey the resulting work. + * Corresponding Source for a non-source form of such a combination + * shall include the source code for the parts of OpenSSL used as well + * as that of the covered work. + */ + +#ifndef __DBUSCLIENT_H__ +#define __DBUSCLIENT_H__ + +#include <sflphone.h> + +class DBusConfigurationManager; +class DBusCallManager; +class DBusNetworkManager; +class DBusInstance; + +#ifdef SFL_PRESENCE +class DBusPresenceManager; +#endif + +#ifdef SFL_VIDEO +class DBusVideoManager; +#endif + +namespace DBus { + class BusDispatcher; +} + +class DBusClient { + public: + DBusClient(int sflphFlags, bool persistent); + ~DBusClient(); + + DBusCallManager* getCallManager(); + DBusConfigurationManager* getConfigurationManager(); + +#ifdef SFL_PRESENCE + DBusPresenceManager* getPresenceManager(); +#endif + +#ifdef SFL_VIDEO + DBusVideoManager* getVideoManager(); +#endif + + int event_loop(); + int exit(); + + private: + int initLibrary(int sflphFlags); + void finiLibrary(); + + private: + static DBusClient* _lastDbusClient; + + static void callOnStateChange(const std::string& call_id, const std::string& state); + static void callOnTransferFail(void); + static void callOnTransferSuccess(void); + static void callOnRecordPlaybackStopped(const std::string& path); + static void callOnVoiceMailNotify(const std::string& call_id, int nd_msg); + static void callOnIncomingMessage(const std::string& id, const std::string& from, const std::string& msg); + static void callOnIncomingCall(const std::string& account_id, const std::string& call_id, const std::string& from); + static void callOnRecordPlaybackFilepath(const std::string& id, const std::string& filename); + static void callOnConferenceCreated(const std::string& conf_id); + static void callOnConferenceChanged(const std::string& conf_id, const std::string& state); + static void callOnUpdatePlaybackScale(const std::string& filepath, int position, int scale); + static void callOnConferenceRemove(const std::string& conf_id); + static void callOnNewCall(const std::string& account_id, const std::string& call_id, const std::string& to); + static void callOnSipCallStateChange(const std::string& call_id, const std::string& state, int code); + static void callOnRecordStateChange(const std::string& call_id, int state); + static void callOnSecureSdesOn(const std::string& call_id); + static void callOnSecureSdesOff(const std::string& call_id); + static void callOnSecureZrtpOn(const std::string& call_id, const std::string& cipher); + static void callOnSecureZrtpOff(const std::string& call_id); + static void callOnShowSas(const std::string& call_id, const std::string& sas, int verified); + static void callOnZrtpNotSuppOther(const std::string& call_id); + static void callOnZrtpNegotiationFail(const std::string& call_id, const std::string& reason, const std::string& severity); + static void callOnRtcpReceiveReport(const std::string& call_id, const std::map<std::string, int>& stats); + static void configOnVolumeChange(const std::string& device, int value); + static void configOnAccountsChange(void); + static void configOnHistoryChange(void); + static void configOnStunStatusFail(const std::string& account_id); + static void configOnRegistrationStateChange(const std::string& account_id, int state); + static void configOnSipRegistrationStateChange(const std::string& account_id, const std::string& state, int code); + static void configOnError(int alert); + +#ifdef SFL_PRESENCE + static void presOnNewServerSubscriptionRequest(const std::string& remote); + static void presOnServerError(const std::string& account_id, const std::string& error, const std::string& msg); + static void presOnNewBuddyNotification(const std::string& account_id, const std::string& buddy_uri, int status, const std::string& line_status); + static void presOnSubscriptionStateChange(const std::string& account_id, const std::string& buddy_uri, int state); +#endif // SFL_PRESENCE + +#ifdef SFL_VIDEO + static void videoOnDeviceEvent(void); + static void videoOnStartDecoding(const std::string& id, const std::string& shm_path, int w, int h, bool is_mixer); + static void videoOnStopDecoding(const std::string& id, const std::string& shm_path, bool is_mixer); +#endif // SFL_VIDEO + + private: + DBusCallManager* callManager_; + DBusConfigurationManager* configurationManager_; + +#ifdef SFL_PRESENCE + DBusPresenceManager* presenceManager_; +#endif + + DBusInstance* instanceManager_; + DBus::BusDispatcher* dispatcher_; + +#ifdef SFL_VIDEO + DBusVideoManager *videoManager_; +#endif +}; + +#endif diff --git a/daemon/bin/dbus/dbusconfigurationmanager.cpp b/daemon/bin/dbus/dbusconfigurationmanager.cpp new file mode 100644 index 0000000000..a8a1063dc9 --- /dev/null +++ b/daemon/bin/dbus/dbusconfigurationmanager.cpp @@ -0,0 +1,368 @@ +/* + * Copyright (C) 2004-2013 Savoir-Faire Linux Inc. + * Author: Philippe Proulx <philippe.proulx@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Additional permission under GNU GPL version 3 section 7: + * + * If you modify this program, or any covered work, by linking or + * combining it with the OpenSSL project's OpenSSL library (or a + * modified version of that library), containing parts covered by the + * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. + * grants you additional permission to convey the resulting work. + * Corresponding Source for a non-source form of such a combination + * shall include the source code for the parts of OpenSSL used as well + * as that of the covered work. + */ +#include <iostream> +#include <sflphone.h> + +#include "dbusconfigurationmanager.h" + +DBusConfigurationManager::DBusConfigurationManager(DBus::Connection& connection) + : DBus::ObjectAdaptor(connection, "/org/sflphone/SFLphone/ConfigurationManager") +{ +} + +std::map<std::string, std::string> DBusConfigurationManager::getAccountDetails(const std::string& accountID) +{ + return sflph_config_get_account_details(accountID); +} + +void DBusConfigurationManager::setAccountDetails(const std::string& accountID, const std::map< std::string, std::string >& details) +{ + sflph_config_set_account_details(accountID, details); +} + +std::map<std::string, std::string> DBusConfigurationManager::getAccountTemplate() +{ + return sflph_config_get_account_template(); +} + +std::string DBusConfigurationManager::addAccount(const std::map< std::string, std::string >& details) +{ + return sflph_config_add_account(details); +} + +void DBusConfigurationManager::removeAccount(const std::string& accountID) +{ + sflph_config_remove_account(accountID); +} + +std::vector< std::string > DBusConfigurationManager::getAccountList() +{ + return sflph_config_get_account_list(); +} + +void DBusConfigurationManager::sendRegister(const std::string& accountID, const bool& enable) +{ + sflph_config_send_register(accountID, enable); +} + +void DBusConfigurationManager::registerAllAccounts(void) +{ + sflph_config_register_all_accounts(); +} + +std::map< std::string, std::string > DBusConfigurationManager::getTlsSettingsDefault() +{ + return sflph_config_get_tls_default_settings(); +} + +std::vector< int32_t > DBusConfigurationManager::getAudioCodecList() +{ + return sflph_config_get_audio_codec_list(); +} + +std::vector< std::string > DBusConfigurationManager::getSupportedTlsMethod() +{ + return sflph_config_get_supported_tls_method(); +} + +std::vector< std::string > DBusConfigurationManager::getAudioCodecDetails(const int32_t& payload) +{ + return sflph_config_get_audio_codec_details(payload); +} + +std::vector< int32_t > DBusConfigurationManager::getActiveAudioCodecList(const std::string& accountID) +{ + return sflph_config_get_active_audio_codec_list(accountID); +} + +void DBusConfigurationManager::setActiveAudioCodecList(const std::vector< std::string >& list, const std::string& accountID) +{ + sflph_config_set_active_audio_codec_list(list, accountID); +} + +std::vector< std::string > DBusConfigurationManager::getAudioPluginList() +{ + return sflph_config_get_audio_plugin_list(); +} + +void DBusConfigurationManager::setAudioPlugin(const std::string& audioPlugin) +{ + sflph_config_set_audio_plugin(audioPlugin); +} + +std::vector< std::string > DBusConfigurationManager::getAudioOutputDeviceList() +{ + return sflph_config_get_audio_output_device_list(); +} + +void DBusConfigurationManager::setAudioOutputDevice(const int32_t& index) +{ + sflph_config_set_audio_output_device(index); +} + +void DBusConfigurationManager::setAudioInputDevice(const int32_t& index) +{ + sflph_config_set_audio_input_device(index); +} + +void DBusConfigurationManager::setAudioRingtoneDevice(const int32_t& index) +{ + sflph_config_set_audio_ringtone_device(index); +} + +std::vector< std::string > DBusConfigurationManager::getAudioInputDeviceList() +{ + return sflph_config_get_audio_input_device_list(); +} + +std::vector< std::string > DBusConfigurationManager::getCurrentAudioDevicesIndex() +{ + return sflph_config_get_current_audio_devices_index(); +} + +int32_t DBusConfigurationManager::getAudioInputDeviceIndex(const std::string& name) +{ + return sflph_config_get_audio_input_device_index(name); +} + +int32_t DBusConfigurationManager::getAudioOutputDeviceIndex(const std::string& name) +{ + return sflph_config_get_audio_output_device_index(name); +} + +std::string DBusConfigurationManager::getCurrentAudioOutputPlugin() +{ + return sflph_config_get_current_audio_output_plugin(); +} + +bool DBusConfigurationManager::getNoiseSuppressState() +{ + return sflph_config_get_noise_suppress_state(); +} + +void DBusConfigurationManager::setNoiseSuppressState(const bool& state) +{ + sflph_config_set_noise_suppress_state(state); +} + +bool DBusConfigurationManager::isAgcEnabled() +{ + return sflph_config_is_agc_enabled(); +} + +void DBusConfigurationManager::setAgcState(const bool& enabled) +{ + sflph_config_enable_agc(enabled); +} + +void DBusConfigurationManager::muteDtmf(const bool& mute) +{ + sflph_config_mute_dtmf(mute); +} + +bool DBusConfigurationManager::isDtmfMuted() +{ + return sflph_config_is_dtmf_muted(); +} + +bool DBusConfigurationManager::isCaptureMuted() +{ + return sflph_config_is_capture_muted(); +} + +void DBusConfigurationManager::muteCapture(const bool& mute) +{ + sflph_config_mute_capture(mute); +} + +bool DBusConfigurationManager::isPlaybackMuted() +{ + return sflph_config_is_playback_muted(); +} + +void DBusConfigurationManager::mutePlayback(const bool& mute) +{ + sflph_config_mute_playback(mute); +} + +std::map<std::string, std::string> DBusConfigurationManager::getRingtoneList() +{ + return sflph_config_get_ringtone_list(); +} + +std::string DBusConfigurationManager::getAudioManager() +{ + return sflph_config_get_audio_manager(); +} + +bool DBusConfigurationManager::setAudioManager(const std::string& api) +{ + return sflph_config_set_audio_manager(api); +} + +std::vector<std::string> DBusConfigurationManager::getSupportedAudioManagers() +{ + return sflph_config_get_supported_audio_managers(); +} + +int32_t DBusConfigurationManager::isIax2Enabled() +{ + return sflph_config_is_iax2_enabled(); +} + +std::string DBusConfigurationManager::getRecordPath() +{ + return sflph_config_get_record_path(); +} + +void DBusConfigurationManager::setRecordPath(const std::string& recPath) +{ + sflph_config_set_record_path(recPath); +} + +bool DBusConfigurationManager::getIsAlwaysRecording() +{ + return sflph_config_is_always_recording(); +} + +void DBusConfigurationManager::setIsAlwaysRecording(const bool& rec) +{ + sflph_config_set_always_recording(rec); +} + +void DBusConfigurationManager::setHistoryLimit(const int32_t& days) +{ + sflph_config_set_history_limit(days); +} + +int32_t DBusConfigurationManager::getHistoryLimit() +{ + return sflph_config_get_history_limit(); +} + +void DBusConfigurationManager::clearHistory() +{ + sflph_config_clear_history(); +} + +void DBusConfigurationManager::setAccountsOrder(const std::string& order) +{ + sflph_config_set_accounts_order(order); +} + +std::map<std::string, std::string> DBusConfigurationManager::getHookSettings() +{ + return sflph_config_get_hook_settings(); +} + +void DBusConfigurationManager::setHookSettings(const std::map<std::string, std::string>& settings) +{ + sflph_config_set_hook_settings(settings); +} + +std::vector<std::map<std::string, std::string> > DBusConfigurationManager::getHistory() +{ + return sflph_config_get_history(); +} + +std::map<std::string, std::string> DBusConfigurationManager::getTlsSettings() +{ + return sflph_config_get_tls_settings(); +} + +void DBusConfigurationManager::setTlsSettings(const std::map< std::string, std::string >& details) +{ + sflph_config_set_tls_settings(details); +} + +std::map< std::string, std::string > DBusConfigurationManager::getIp2IpDetails() +{ + return sflph_config_get_ip2ip_details(); +} + +std::vector< std::map< std::string, std::string > > DBusConfigurationManager::getCredentials(const std::string& accountID) +{ + return sflph_config_get_credentials(accountID); +} + +void DBusConfigurationManager::setCredentials(const std::string& accountID, const std::vector< std::map< std::string, std::string > >& details) +{ + sflph_config_set_credentials(accountID, details); +} + +std::string DBusConfigurationManager::getAddrFromInterfaceName(const std::string& interface) +{ + return sflph_config_get_addr_from_interface_name(interface); +} + +std::vector<std::string> DBusConfigurationManager::getAllIpInterface() +{ + return sflph_config_get_all_ip_interface(); +} + +std::vector<std::string> DBusConfigurationManager::getAllIpInterfaceByName() +{ + return sflph_config_get_all_ip_interface_by_name(); +} + +std::map<std::string, std::string> DBusConfigurationManager::getShortcuts() +{ + return sflph_config_get_shortcuts(); +} + +void DBusConfigurationManager::setShortcuts(const std::map<std::string, std::string> &shortcutsMap) +{ + sflph_config_set_shortcuts(shortcutsMap); +} + +void DBusConfigurationManager::setVolume(const std::string& device, const double& value) +{ + sflph_config_set_volume(device, value); +} + +double DBusConfigurationManager::getVolume(const std::string& device) +{ + return sflph_config_get_volume(device); +} + +bool DBusConfigurationManager::checkForPrivateKey(const std::string& pemPath) +{ + return sflph_config_check_for_private_key(pemPath); +} + +bool DBusConfigurationManager::checkCertificateValidity(const std::string& caPath, const std::string& pemPath) +{ + return sflph_config_check_certificate_validity(caPath, pemPath); +} + +bool DBusConfigurationManager::checkHostnameCertificate(const std::string& host, const std::string& port) +{ + return sflph_config_check_hostname_certificate(host, port); +} diff --git a/daemon/bin/dbus/dbusconfigurationmanager.h b/daemon/bin/dbus/dbusconfigurationmanager.h new file mode 100644 index 0000000000..dac651db18 --- /dev/null +++ b/daemon/bin/dbus/dbusconfigurationmanager.h @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2004-2013 Savoir-Faire Linux Inc. + * Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com> + * Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com> + * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> + * Author: Guillaume Carmel-Archambault <guillaume.carmel-archambault@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Additional permission under GNU GPL version 3 section 7: + * + * If you modify this program, or any covered work, by linking or + * combining it with the OpenSSL project's OpenSSL library (or a + * modified version of that library), containing parts covered by the + * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. + * grants you additional permission to convey the resulting work. + * Corresponding Source for a non-source form of such a combination + * shall include the source code for the parts of OpenSSL used as well + * as that of the covered work. + */ + +#ifndef __SFL_DBUSCONFIGURATIONMANAGER_H__ +#define __SFL_DBUSCONFIGURATIONMANAGER_H__ + +#include <vector> +#include <map> +#include <string> + +#include "dbus_cpp.h" + +#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 6 +/* This warning option only exists for gcc 4.6.0 and greater. */ +#pragma GCC diagnostic ignored "-Wunused-but-set-variable" +#endif + +#pragma GCC diagnostic ignored "-Wignored-qualifiers" +#pragma GCC diagnostic ignored "-Wunused-parameter" +#include "dbusconfigurationmanager.adaptor.h" +#pragma GCC diagnostic warning "-Wignored-qualifiers" +#pragma GCC diagnostic warning "-Wunused-parameter" + +#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 6 +/* This warning option only exists for gcc 4.6.0 and greater. */ +#pragma GCC diagnostic warning "-Wunused-but-set-variable" +#endif + +#include <stdexcept> + +class DBusConfigurationManager : + public org::sflphone::SFLphone::ConfigurationManager_adaptor, + public DBus::IntrospectableAdaptor, + public DBus::ObjectAdaptor +{ + public: + DBusConfigurationManager(DBus::Connection& connection); + + // Methods + std::map< std::string, std::string > getAccountDetails(const std::string& accountID); + void setAccountDetails(const std::string& accountID, const std::map< std::string, std::string >& details); + std::map<std::string, std::string> getAccountTemplate(); + std::string addAccount(const std::map< std::string, std::string >& details); + void removeAccount(const std::string& accoundID); + std::vector< std::string > getAccountList(); + void sendRegister(const std::string& accoundID, const bool& enable); + void registerAllAccounts(void); + std::map< std::string, std::string > getTlsSettingsDefault(); + std::vector< int32_t > getAudioCodecList(); + std::vector< std::string > getSupportedTlsMethod(); + std::vector< std::string > getAudioCodecDetails(const int32_t& payload); + std::vector< int32_t > getActiveAudioCodecList(const std::string& accountID); + void setActiveAudioCodecList(const std::vector< std::string >& list, const std::string& accountID); + std::vector< std::string > getAudioPluginList(); + void setAudioPlugin(const std::string& audioPlugin); + std::vector< std::string > getAudioOutputDeviceList(); + void setAudioOutputDevice(const int32_t& index); + void setAudioInputDevice(const int32_t& index); + void setAudioRingtoneDevice(const int32_t& index); + std::vector< std::string > getAudioInputDeviceList(); + std::vector< std::string > getCurrentAudioDevicesIndex(); + int32_t getAudioInputDeviceIndex(const std::string& name); + int32_t getAudioOutputDeviceIndex(const std::string& name); + std::string getCurrentAudioOutputPlugin(); + bool getNoiseSuppressState(); + void setNoiseSuppressState(const bool& state); + bool isAgcEnabled(); + void setAgcState(const bool& enabled); + void muteDtmf(const bool& mute); + bool isDtmfMuted(); + bool isCaptureMuted(); + void muteCapture(const bool& mute); + bool isPlaybackMuted(); + void mutePlayback(const bool& mute); + std::map<std::string, std::string> getRingtoneList(); + std::string getAudioManager(); + bool setAudioManager(const std::string& api); + std::vector<std::string> getSupportedAudioManagers(); + int32_t isIax2Enabled(); + std::string getRecordPath(); + void setRecordPath(const std::string& recPath); + bool getIsAlwaysRecording(); + void setIsAlwaysRecording(const bool& rec); + void setHistoryLimit(const int32_t& days); + int32_t getHistoryLimit(); + void clearHistory(); + void setAccountsOrder(const std::string& order); + std::map<std::string, std::string> getHookSettings(); + void setHookSettings(const std::map<std::string, std::string>& settings); + std::vector<std::map<std::string, std::string> > getHistory(); + std::map<std::string, std::string> getTlsSettings(); + void setTlsSettings(const std::map< std::string, std::string >& details); + std::map< std::string, std::string > getIp2IpDetails(); + std::vector< std::map< std::string, std::string > > getCredentials(const std::string& accountID); + void setCredentials(const std::string& accountID, const std::vector< std::map< std::string, std::string > >& details); + std::string getAddrFromInterfaceName(const std::string& interface); + std::vector<std::string> getAllIpInterface(); + std::vector<std::string> getAllIpInterfaceByName(); + std::map<std::string, std::string> getShortcuts(); + void setShortcuts(const std::map<std::string, std::string> &shortcutsMap); + void setVolume(const std::string& device, const double& value); + double getVolume(const std::string& device); + bool checkForPrivateKey(const std::string& pemPath); + bool checkCertificateValidity(const std::string& caPath, const std::string& pemPath); + bool checkHostnameCertificate(const std::string& host, const std::string& port); +}; + +#endif // __SFL_DBUSCONFIGURATIONMANAGER_H__ diff --git a/daemon/src/client/dbus/instance.cpp b/daemon/bin/dbus/dbusinstance.cpp similarity index 76% rename from daemon/src/client/dbus/instance.cpp rename to daemon/bin/dbus/dbusinstance.cpp index f7018ab54d..b99d2cddd1 100644 --- a/daemon/src/client/dbus/instance.cpp +++ b/daemon/bin/dbus/dbusinstance.cpp @@ -28,27 +28,29 @@ * as that of the covered work. */ #include "global.h" -#include "instance.h" -#include "../manager.h" +#include "dbusinstance.h" -Instance::Instance(DBus::Connection& connection) : +DBusInstance::DBusInstance(DBus::Connection& connection, + const OnNoMoreClientFunc& onNoMoreClientFunc) : DBus::ObjectAdaptor(connection, "/org/sflphone/SFLphone/Instance"), - count(0) + onNoMoreClientFunc_(onNoMoreClientFunc), + count_(0) {} void -Instance::Register(const int32_t& pid UNUSED, - const std::string& name UNUSED) +DBusInstance::Register(const int32_t& pid UNUSED, + const std::string& name UNUSED) { - ++count; + ++count_; } void -Instance::Unregister(const int32_t& pid UNUSED) +DBusInstance::Unregister(const int32_t& pid UNUSED) { - --count; + --count_; - if (count <= 0) - Manager::instance().getClient()->onLastUnregister(); + if (count_ <= 0 && onNoMoreClientFunc_) { + onNoMoreClientFunc_(); + } } diff --git a/daemon/src/client/dbus/instance.h b/daemon/bin/dbus/dbusinstance.h similarity index 78% rename from daemon/src/client/dbus/instance.h rename to daemon/bin/dbus/dbusinstance.h index c3abe3e1b4..1d5716c0cb 100644 --- a/daemon/src/client/dbus/instance.h +++ b/daemon/bin/dbus/dbusinstance.h @@ -28,8 +28,10 @@ * as that of the covered work. */ -#ifndef INSTANCE_H -#define INSTANCE_H +#ifndef __SFL_DBUSINSTANCE_H__ +#define __SFL_DBUSINSTANCE_H__ + +#include <functional> #if __GNUC__ >= 4 && __GNUC_MINOR__ >= 6 #pragma GCC diagnostic ignored "-Wunused-but-set-variable" @@ -38,28 +40,31 @@ #pragma GCC diagnostic ignored "-Wignored-qualifiers" #pragma GCC diagnostic ignored "-Wunused-parameter" -#include "instance-glue.h" +#include "dbusinstance.adaptor.h" #pragma GCC diagnostic warning "-Wignored-qualifiers" #pragma GCC diagnostic warning "-Wunused-parameter" #if __GNUC__ >= 4 && __GNUC_MINOR__ >= 6 #pragma GCC diagnostic warning "-Wunused-but-set-variable" #endif -class Instance - : public org::sflphone::SFLphone::Instance_adaptor, - public DBus::IntrospectableAdaptor, - public DBus::ObjectAdaptor { - private: - int count; +class DBusInstance : + public org::sflphone::SFLphone::Instance_adaptor, + public DBus::IntrospectableAdaptor, + public DBus::ObjectAdaptor +{ + public: + typedef std::function<void ()> OnNoMoreClientFunc; public: - Instance(DBus::Connection& connection); - static const char* SERVER_PATH; + DBusInstance(DBus::Connection& connection, + const OnNoMoreClientFunc& onNoMoreClientFunc); void Register(const int32_t& pid, const std::string& name); void Unregister(const int32_t& pid); - int32_t getRegistrationCount(); + private: + OnNoMoreClientFunc onNoMoreClientFunc_; + int count_; }; -#endif // INSTANCE_H +#endif // __SFL_DBUSINSTANCE_H__ diff --git a/daemon/src/client/dbus/networkmanager.cpp b/daemon/bin/dbus/dbuspresencemanager.cpp similarity index 56% rename from daemon/src/client/dbus/networkmanager.cpp rename to daemon/bin/dbus/dbuspresencemanager.cpp index f84b71517b..0b2b577e54 100644 --- a/daemon/src/client/dbus/networkmanager.cpp +++ b/daemon/bin/dbus/dbuspresencemanager.cpp @@ -1,6 +1,6 @@ /* * Copyright (C) 2004-2013 Savoir-Faire Linux Inc. - * Author: Julien Bonjean <julien.bonjean@savoirfairelinux.com> + * Author: Philippe Proulx <philippe.proulx@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,37 +27,36 @@ * shall include the source code for the parts of OpenSSL used as well * as that of the covered work. */ +#include <sflphone.h> -#include "networkmanager.h" -#include "../manager.h" -#include "array_size.h" -#include "logger.h" +#include "dbuspresencemanager.h" -static const -char *stateAsString(uint32_t state) +DBusPresenceManager::DBusPresenceManager(DBus::Connection& connection) + : DBus::ObjectAdaptor(connection, "/org/sflphone/SFLphone/PresenceManager") { - static const char * STATES[] = {"unknown", "asleep", "connecting", - "connected", "disconnected"}; +} - const size_t idx = state < ARRAYSIZE(STATES) ? state : 0; - return STATES[idx]; +void DBusPresenceManager::publish(const std::string& accountID, const bool& status, const std::string& note) +{ + sflph_pres_publish(accountID, status, note); } -void NetworkManager::StateChanged(const uint32_t &state) +void DBusPresenceManager::answerServerRequest(const std::string& uri, const bool& flag) { - WARN("Network state changed: %s", stateAsString(state)); + sflph_pres_answer_server_request(uri, flag); } -void NetworkManager::PropertiesChanged(const std::map<std::string, ::DBus::Variant> &argin0) +void DBusPresenceManager::subscribeBuddy(const std::string& accountID, const std::string& uri, const bool& flag) { - WARN("Properties changed: "); - for (const auto &item : argin0) - WARN("%s", item.first.c_str()); - Manager::instance().registerAccounts(); + sflph_pres_subscribe_buddy(accountID, uri, flag); } -NetworkManager::NetworkManager(DBus::Connection &connection, - const DBus::Path &dbus_path, - const char *destination) : - DBus::ObjectProxy(connection, dbus_path, destination) -{} +std::vector<std::map<std::string, std::string> > DBusPresenceManager::getSubscriptions(const std::string& accountID) +{ + return sflph_pres_get_subscriptions(accountID); +} + +void DBusPresenceManager::setSubscriptions(const std::string& accountID, const std::vector<std::string>& uris) +{ + sflph_pres_set_subscriptions(accountID, uris); +} diff --git a/daemon/src/client/dbus/networkmanager.h b/daemon/bin/dbus/dbuspresencemanager.h similarity index 52% rename from daemon/src/client/dbus/networkmanager.h rename to daemon/bin/dbus/dbuspresencemanager.h index ab0e8f82c5..2c2cfa3f82 100644 --- a/daemon/src/client/dbus/networkmanager.h +++ b/daemon/bin/dbus/dbuspresencemanager.h @@ -1,6 +1,6 @@ /* - * Copyright (C) 2004-2013 Savoir-Faire Linux Inc. - * Author: Julien Bonjean <julien.bonjean@savoirfairelinux.com> + * Copyright (C) 2013 Savoir-Faire Linux Inc. + * Author: Patrick Keroulas <patrick.keroulas@savoirfairelinux.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -28,22 +28,47 @@ * as that of the covered work. */ -#ifndef NETWORKMANAGER_H_ -#define NETWORKMANAGER_H_ +#ifndef __SFL_DBUSPRESENCEMANAGER_H__ +#define __SFL_DBUSPRESENCEMANAGER_H__ + +#include <vector> +#include <map> +#include <string> + +#include "dbus_cpp.h" + +#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 6 +/* This warning option only exists for gcc 4.6.0 and greater. */ +#pragma GCC diagnostic ignored "-Wunused-but-set-variable" +#endif #pragma GCC diagnostic ignored "-Wignored-qualifiers" #pragma GCC diagnostic ignored "-Wunused-parameter" -#include "networkmanager_proxy.h" +#include "dbuspresencemanager.adaptor.h" #pragma GCC diagnostic warning "-Wignored-qualifiers" #pragma GCC diagnostic warning "-Wunused-parameter" -class NetworkManager : public org::freedesktop::NetworkManager_proxy, - public DBus::IntrospectableProxy, - // cppcheck-suppress unusedFunction - public DBus::ObjectProxy { +#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 6 +/* This warning option only exists for gcc 4.6.0 and greater. */ +#pragma GCC diagnostic warning "-Wunused-but-set-variable" +#endif + +#include <stdexcept> + +class DBusPresenceManager : + public org::sflphone::SFLphone::PresenceManager_adaptor, + public DBus::IntrospectableAdaptor, + public DBus::ObjectAdaptor +{ public: - NetworkManager(DBus::Connection &, const DBus::Path &, const char*); - void StateChanged(const uint32_t &state); - void PropertiesChanged(const std::map<std::string, ::DBus::Variant> &argin0); + DBusPresenceManager(DBus::Connection& connection); + + // Methods + void publish(const std::string& accountID, const bool& status, const std::string& note); + void answerServerRequest(const std::string& uri, const bool& flag); + void subscribeBuddy(const std::string& accountID, const std::string& uri, const bool& flag); + std::vector<std::map<std::string, std::string> > getSubscriptions(const std::string& accountID); + void setSubscriptions(const std::string& accountID, const std::vector<std::string>& uris); }; -#endif + +#endif // __SFL_DBUSPRESENCEMANAGER_H__ diff --git a/daemon/bin/dbus/dbusvideomanager.cpp b/daemon/bin/dbus/dbusvideomanager.cpp new file mode 100644 index 0000000000..e394e2ea50 --- /dev/null +++ b/daemon/bin/dbus/dbusvideomanager.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2004-2013 Savoir-Faire Linux Inc. + * Author: Philippe Proulx <philippe.proulx@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Additional permission under GNU GPL version 3 section 7: + * + * If you modify this program, or any covered work, by linking or + * combining it with the OpenSSL project's OpenSSL library (or a + * modified version of that library), containing parts covered by the + * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. + * grants you additional permission to convey the resulting work. + * Corresponding Source for a non-source form of such a combination + * shall include the source code for the parts of OpenSSL used as well + * as that of the covered work. + */ +#include <sflphone.h> + +#include "dbusvideomanager.h" + +DBusVideoManager::DBusVideoManager(DBus::Connection& connection) + : DBus::ObjectAdaptor(connection, "/org/sflphone/SFLphone/VideoManager") +{ +} + +std::vector<std::map<std::string, std::string>> DBusVideoManager::getCodecs(const std::string& accountID) +{ + return sflph_video_get_codecs(accountID); +} + +void DBusVideoManager::setCodecs(const std::string& accountID, const std::vector<std::map<std::string, std::string> > &details) +{ + sflph_video_set_codecs(accountID, details); +} + +std::vector<std::string> DBusVideoManager::getDeviceList() +{ + return sflph_video_get_device_list(); +} + +std::map<std::string, std::map<std::string, std::vector<std::string>>> DBusVideoManager::getCapabilities(const std::string& name) +{ + return sflph_video_get_capabilities(name); +} + +std::map<std::string, std::string> DBusVideoManager::getSettings(const std::string& name) +{ + return sflph_video_get_settings(name); +} + +void DBusVideoManager::applySettings(const std::string& name, const std::map<std::string, std::string>& settings) +{ + sflph_video_apply_settings(name, settings); +} + +void DBusVideoManager::setDefaultDevice(const std::string &dev) +{ + sflph_video_set_default_device(dev); +} + +std::string DBusVideoManager::getDefaultDevice() +{ + return sflph_video_get_default_device(); +} + +std::string DBusVideoManager::getCurrentCodecName(const std::string &callID) +{ + return sflph_video_get_current_codec_name(callID); +} + +void DBusVideoManager::startCamera() +{ + sflph_video_start_camera(); +} + +void DBusVideoManager::stopCamera() +{ + sflph_video_stop_camera(); +} + +bool DBusVideoManager::switchInput(const std::string& resource) +{ + return sflph_video_switch_input(resource); +} + +bool DBusVideoManager::hasCameraStarted() +{ + return sflph_video_is_camera_started(); +} diff --git a/daemon/bin/dbus/dbusvideomanager.h b/daemon/bin/dbus/dbusvideomanager.h new file mode 100644 index 0000000000..df69a51697 --- /dev/null +++ b/daemon/bin/dbus/dbusvideomanager.h @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2012-2013 Savoir-Faire Linux Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Additional permission under GNU GPL version 3 section 7: + * + * If you modify this program, or any covered work, by linking or + * combining it with the OpenSSL project's OpenSSL library (or a + * modified version of that library), containing parts covered by the + * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. + * grants you additional permission to convey the resulting work. + * Corresponding Source for a non-source form of such a combination + * shall include the source code for the parts of OpenSSL used as well + * as that of the covered work. + */ + +#ifndef __SFL_DBUSVIDEOMANAGER_H__ +#define __SFL_DBUSVIDEOMANAGER_H__ + +#include <vector> +#include <map> +#include <string> + +#include "dbus_cpp.h" + +#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 6 +/* This warning option only exists for gcc 4.6.0 and greater. */ +#pragma GCC diagnostic ignored "-Wunused-but-set-variable" +#endif + +#pragma GCC diagnostic ignored "-Wignored-qualifiers" +#pragma GCC diagnostic ignored "-Wunused-parameter" +#include "dbusvideomanager.adaptor.h" +#pragma GCC diagnostic warning "-Wignored-qualifiers" +#pragma GCC diagnostic warning "-Wunused-parameter" + +#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 6 +/* This warning option only exists for gcc 4.6.0 and greater. */ +#pragma GCC diagnostic warning "-Wunused-but-set-variable" +#endif + +#include <stdexcept> + +class DBusVideoManager : + public org::sflphone::SFLphone::VideoManager_adaptor, + public DBus::IntrospectableAdaptor, + public DBus::ObjectAdaptor +{ + public: + DBusVideoManager(DBus::Connection& connection); + + // Methods + std::vector<std::map<std::string, std::string>> getCodecs(const std::string& accountID); + void setCodecs(const std::string& accountID, const std::vector<std::map<std::string, std::string> > &details); + std::vector<std::string> getDeviceList(); + std::map<std::string, std::map<std::string, std::vector<std::string>>> getCapabilities(const std::string& name); + std::map<std::string, std::string> getSettings(const std::string& name); + void applySettings(const std::string& name, const std::map<std::string, std::string>& settings); + void setDefaultDevice(const std::string &dev); + std::string getDefaultDevice(); + std::string getCurrentCodecName(const std::string &callID); + void startCamera(); + void stopCamera(); + bool switchInput(const std::string& resource); + bool hasCameraStarted(); +}; + +#endif // __SFL_DBUSVIDEOMANAGER_H__ diff --git a/daemon/src/client/dbus/instance-introspec.xml b/daemon/bin/dbus/instance-introspec.xml similarity index 100% rename from daemon/src/client/dbus/instance-introspec.xml rename to daemon/bin/dbus/instance-introspec.xml diff --git a/daemon/src/client/dbus/org.sflphone.SFLphone.service.in b/daemon/bin/dbus/org.sflphone.SFLphone.service.in similarity index 100% rename from daemon/src/client/dbus/org.sflphone.SFLphone.service.in rename to daemon/bin/dbus/org.sflphone.SFLphone.service.in diff --git a/daemon/src/client/dbus/presencemanager-introspec.xml b/daemon/bin/dbus/presencemanager-introspec.xml similarity index 100% rename from daemon/src/client/dbus/presencemanager-introspec.xml rename to daemon/bin/dbus/presencemanager-introspec.xml diff --git a/daemon/src/client/dbus/videomanager-introspec.xml b/daemon/bin/dbus/videomanager-introspec.xml similarity index 100% rename from daemon/src/client/dbus/videomanager-introspec.xml rename to daemon/bin/dbus/videomanager-introspec.xml diff --git a/daemon/bin/main.cpp b/daemon/bin/main.cpp new file mode 100644 index 0000000000..0690343b2a --- /dev/null +++ b/daemon/bin/main.cpp @@ -0,0 +1,215 @@ +/* + * Copyright (C) 2004-2013 Savoir-Faire Linux Inc. + * Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com> + * Author: Yan Morin <yan.morin@savoirfairelinux.com> + * Author: Laurielle Lea <laurielle.lea@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Additional permission under GNU GPL version 3 section 7: + * + * If you modify this program, or any covered work, by linking or + * combining it with the OpenSSL project's OpenSSL library (or a + * modified version of that library), containing parts covered by the + * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. + * grants you additional permission to convey the resulting work. + * Corresponding Source for a non-source form of such a combination + * shall include the source code for the parts of OpenSSL used as well + * as that of the covered work. + */ +#include <iostream> +#include <thread> +#include <cstring> +#include <signal.h> +#include <getopt.h> + +#include "dbus/dbusclient.h" + +static int sflphFlags = 0; +static std::unique_ptr<DBusClient> dbusClient; + +static void print_title() +{ + std::cout << "SFLphone Daemon " << VERSION << + ", by Savoir-Faire Linux 2004-2014" << std::endl << + "http://www.sflphone.org/" << std::endl; +} + +static void print_usage() +{ + std::cout << std::endl << + "-c, --console \t- Log in console (instead of syslog)" << std::endl << + "-d, --debug \t- Debug mode (more verbose)" << std::endl << + "-p, --persistent \t- Stay alive after client quits" << std::endl << + "-h, --help \t- Print help" << std::endl; +} + +// Parse command line arguments, setting debug options or printing a help +// message accordingly. +// returns true if we should quit (i.e. help was printed), false otherwise +static bool parse_args(int argc, char *argv[], bool &persistent) +{ + int consoleFlag = false; + int debugFlag = false; + int helpFlag = false; + int versionFlag = false; + static const struct option long_options[] = { + /* These options set a flag. */ + {"debug", no_argument, NULL, 'd'}, + {"console", no_argument, NULL, 'c'}, + {"persistent", no_argument, NULL, 'p'}, + {"help", no_argument, NULL, 'h'}, + {"version", no_argument, NULL, 'v'}, + {0, 0, 0, 0} /* Sentinel */ + }; + + while (true) { + /* getopt_long stores the option index here. */ + int option_index = 0; + int c = getopt_long(argc, argv, "dcphv", long_options, &option_index); + + /* Detect the end of the options. */ + if (c == -1) + break; + + switch (c) { + case 'd': + debugFlag = true; + break; + + case 'c': + consoleFlag = true; + break; + + case 'p': + persistent = true; + break; + + case 'h': + case '?': + helpFlag = true; + break; + + case 'v': + versionFlag = true; + break; + + default: + break; + } + } + + bool quit = false; + if (helpFlag) { + print_usage(); + quit = true; + } else if (versionFlag) { + // We've always print the title/version, so we can just exit + quit = true; + } else { + if (consoleFlag) { + sflphFlags |= SFLPH_FLAG_CONSOLE_LOG; + } + if (debugFlag) { + sflphFlags |= SFLPH_FLAG_DEBUG; + } + } + return quit; +} + +static int run() +{ + if (dbusClient) { + return dbusClient->event_loop(); + } + + return 1; +} + +static void interrupt() +{ + if (dbusClient) { + dbusClient->exit(); + } +} + +static void signal_handler(int code) +{ + // Unset signal handlers + signal(SIGHUP, SIG_DFL); + signal(SIGINT, SIG_DFL); + signal(SIGTERM, SIG_DFL); + + // Stop manager in new thread since we don't know what + // this handler is interrupting (e.g. a mutex might be held in the + // interrupted function) + std::thread th([code] { + interrupt(); + std::cerr << "Caught signal " << strsignal(code) + << ", terminating..." << std::endl; + }); + + // Detach thread and leave signal handler so that interrupted thread + // can continue + th.detach(); +} + +int main(int argc, char *argv []) +{ + int ret; + + // make a copy as we don't want to modify argv[0], copy it to a vector to + // guarantee that memory is correctly managed/exception safe + std::string programName(argv[0]); + std::vector<char> writable(programName.size() + 1); + std::copy(programName.begin(), programName.end(), writable.begin()); + +#ifdef TOP_BUILDDIR + if (!getenv("CODECS_PATH")) + setenv("CODECS_PATH", TOP_BUILDDIR "/src/audio/codecs", 1); +#endif + + print_title(); + + bool persistent = false; + + if (parse_args(argc, argv, persistent)) + return 0; + + // initialize client/library + try { + dbusClient = std::unique_ptr<DBusClient>(new DBusClient(sflphFlags, persistent)); + } catch (const std::exception& ex) { + std::cerr << "One does not simply initialize the DBus client: " << ex.what() << std::endl; + return 1; + } + + // TODO: Block signals for all threads but the main thread, decide how/if we should + // handle other signals + signal(SIGINT, signal_handler); + signal(SIGHUP, signal_handler); + signal(SIGTERM, signal_handler); + +#ifdef SFL_VIDEO + std::cerr << "Warning: built with video support" << std::endl; +#endif + + ret = run(); + + // terminate client/library + dbusClient = nullptr; + + return ret; +} diff --git a/daemon/configure.ac b/daemon/configure.ac index 82bac7338d..7c3efee038 100644 --- a/daemon/configure.ac +++ b/daemon/configure.ac @@ -237,6 +237,28 @@ AS_IF([test "x$enable_coverage" = "xyes"], [ CXXFLAGS="${CXXFLAGS} --coverage" LDFLAGS="${LDFLAGS} --coverage"]) +# DBUSCPP +dnl Check for dbuscpp, the C++ bindings for D-Bus +AC_ARG_WITH([dbus], + [AS_HELP_STRING([--without-dbus], [disable support for dbus])], + [], + [with_dbus=yes]) +AS_IF([test "x$with_dbus" = "xyes"], [ + PKG_CHECK_MODULES(DBUSCPP, dbus-c++-1,, AC_MSG_WARN([Missing dbus development files])) + AC_CONFIG_FILES([bin/Makefile \ + bin/dbus/Makefile]) + + AC_CHECK_PROG(HAVE_DBUSXML2CPP, dbusxx-xml2cpp, true, false) + if test "x$HAVE_DBUSXML2CPP" = "xfalse"; then + AC_MSG_ERROR([dbusxx-xml2cpp not found]) + fi + + AS_IF([test "x$CLANG" = "xyes"], [ + AC_MSG_ERROR([dbus does not compile when clang is used, rerun with --without-dbus]) + ]); +]); + + dnl Video is default-enabled AC_ARG_ENABLE([video], AS_HELP_STRING([--disable-video], [Disable video])) @@ -258,8 +280,9 @@ AS_IF([test "x$enable_video" != "xno"], PKG_CHECK_MODULES(UDEV, libudev,, AC_MSG_ERROR([Missing libudev development files])) ], - [AM_CONDITIONAL(SFL_VIDEO, false)]); - + [ + AM_CONDITIONAL(SFL_VIDEO, false) + ]); LIBCCRTP_MIN_VERSION=1.3.0 PKG_CHECK_MODULES([CCRTP], [libccrtp] >= ${LIBCCRTP_MIN_VERSION},, [ @@ -309,30 +332,6 @@ AC_DEFINE_UNQUOTED([HAVE_ZRTP], `if test "x$with_zrtp" = "xyes"; then echo 1; el AC_DEFINE_UNQUOTED([HAVE_ZRTP_CONFIGURE], `if test "x$with_zrtp_configure" = "xyes"; then echo 1; else echo 0; fi`, [Define if you have zrtp >= 2.3.0]) AM_CONDITIONAL(BUILD_ZRTP, test "x$with_zrtp" = "xyes" ) -# DBUSCPP -dnl Check for dbuscpp, the C++ bindings for D-Bus -AC_ARG_WITH([dbus], - [AS_HELP_STRING([--without-dbus], [disable support for dbus])], - [], - [with_dbus=yes]) -AS_IF([test "x$with_dbus" = "xyes"], [ - PKG_CHECK_MODULES(DBUSCPP, dbus-c++-1,, AC_MSG_WARN([Missing dbus development files])) - AC_CONFIG_FILES([src/client/dbus/Makefile \ - doc/dbus-api/Makefile]) - - AC_CHECK_PROG(HAVE_DBUSXML2CPP, dbusxx-xml2cpp, true, false) - if test "x$HAVE_DBUSXML2CPP" = "xfalse"; then - AC_MSG_ERROR([dbusxx-xml2cpp not found]) - fi - - AS_IF([test "x$CLANG" = "xyes"], [ - AC_MSG_ERROR([dbus does not compile when clang is used, rerun with --without-dbus]) - ]); -]); - -AC_DEFINE_UNQUOTED([HAVE_DBUS], `if test "x$with_dbus" = "xyes"; then echo 1; else echo 0; fi`, [Define if you have dbus support]) -AM_CONDITIONAL(USE_DBUS, test "x$with_dbus" = "xyes" ) - # Instant Messaging # required dependency(ies): libxpat AC_ARG_WITH([instant_messaging], diff --git a/daemon/globals.mak b/daemon/globals.mak index f9eaaf7c57..8e2764ec54 100644 --- a/daemon/globals.mak +++ b/daemon/globals.mak @@ -26,7 +26,6 @@ AM_CPPFLAGS = \ -I$(src)/src/config \ -I$(src)/test \ $(SIP_CFLAGS) \ - @DBUSCPP_CFLAGS@ \ -DPREFIX=\"$(prefix)\" \ -DPROGSHAREDIR=\"${datadir}/sflphone\" \ -DCODECS_DIR=\""$(sflcodecdir)"\" \ diff --git a/daemon/src/Makefile.am b/daemon/src/Makefile.am index 0522bbb09c..4a4db89f65 100644 --- a/daemon/src/Makefile.am +++ b/daemon/src/Makefile.am @@ -1,8 +1,5 @@ include ../globals.mak -libexecdir=$(libdir)/sflphone -libexec_PROGRAMS = sflphoned - if SFL_VIDEO SFL_VIDEO_SUBDIR = video SFL_VIDEO_LIBS=./video/libvideo.la \ @@ -32,16 +29,11 @@ endif SUBDIRS = client audio config hooks history sip $(IAX_SUBDIR) $(INSTANT_MESSAGING_SUBDIR) $(SFL_VIDEO_SUBDIR) -sflphoned_SOURCES = main.cpp - -sflphoned_CXXFLAGS = \ - -DPREFIX=\"$(prefix)\" -DPROGSHAREDIR=\"${datadir}/sflphone\" $(IAX_CXXFLAG) $(NETWORKMANAGER) \ - -DVERSION=\"$(VERSION)\" - # libsflphone -sflphoned_LDADD = ./libsflphone.la $(YAML_LIBS) $(IAX_LIB) -noinst_LTLIBRARIES = libsflphone.la +include_HEADERS = sflphone.h + +lib_LTLIBRARIES = libsflphone.la libsflphone_la_LIBADD = \ ./sip/libsiplink.la \ @@ -60,7 +52,8 @@ libsflphone_la_LDFLAGS = \ @SAMPLERATE_LIBS@ \ @SNDFILE_LIBS@ \ $(TLS_LIB) \ - @DBUSCPP_LIBS@ + @UUID_LIBS@ \ + @YAML_LIBS@ libsflphone_la_CFLAGS = \ @ZRTPCPP_CFLAGS@ \ @@ -70,7 +63,7 @@ libsflphone_la_CFLAGS = \ @PULSEAUDIO_CFLAGS@ \ @SAMPLERATE_CFLAGS@ \ $(TLS_CFLAGS) \ - @DBUSCPP_CFLAGS@ + @UUID_CFLAGS@ libsflphone_la_SOURCES = conference.cpp \ account_factory.cpp \ @@ -105,4 +98,6 @@ libsflphone_la_SOURCES = conference.cpp \ array_size.h \ account_schema.h \ registration_states.h \ - map_utils.h + map_utils.h \ + sflphone.h \ + sflphone_api.cpp diff --git a/daemon/src/client/Makefile.am b/daemon/src/client/Makefile.am index 3c7c389495..a1691d3d55 100644 --- a/daemon/src/client/Makefile.am +++ b/daemon/src/client/Makefile.am @@ -8,39 +8,19 @@ noinst_HEADERS = callmanager.h \ if SFL_PRESENCE PRESENCE_SRC = presencemanager.cpp -PRESENCE_STUB = presencemanager_stub.cpp noinst_HEADERS += presencemanager.h endif if SFL_VIDEO VIDEO_SRC = videomanager.cpp -VIDEO_STUB = videomanager_stub.cpp noinst_HEADERS += videomanager.h endif -if USE_ANDROID -SUBDIRS=android - -libclient_la_LIBADD = android/libclient_android.la -else -if USE_DBUS -SUBDIRS=dbus - -libclient_la_LIBADD = dbus/libclient_dbus.la -else -STUB_SRC = client.cpp \ - callmanager_stub.cpp \ - configurationmanager_stub.cpp \ - $(PRESENCE_STUB) \ - $(VIDEO_STUB) -endif -endif # USE_ANDROID - -libclient_la_SOURCES = callmanager.cpp \ +libclient_la_SOURCES = client.cpp \ + callmanager.cpp \ configurationmanager.cpp \ $(PRESENCE_SRC) \ - $(VIDEO_SRC) \ - $(STUB_SRC) + $(VIDEO_SRC) libclient_la_CXXFLAGS = -I./ \ -DPREFIX=\"$(prefix)\" \ diff --git a/daemon/src/client/android/JavaJNI2CJNI_Load.py b/daemon/src/client/android/JavaJNI2CJNI_Load.py deleted file mode 100755 index 941f0664c3..0000000000 --- a/daemon/src/client/android/JavaJNI2CJNI_Load.py +++ /dev/null @@ -1,85 +0,0 @@ -#!/usr/bin/python -import getopt, sys -import re -from string import Template - -def type_to_signature(itype): - if len(itype) > 2: - if itype[-2:] == '[]': - return "[%s" % type_to_signature(itype[:-2]) - if itype == "int": - return "I" - if itype == "long": - return "J" - if itype == "void": - return "V" - if itype == "boolean": - return "Z" - if itype == "byte": - return "B" - if itype == "char": - return "C" - if itype == "short": - return "S" - if itype == "float": - return "F" - if itype == "double": - return "D" - if itype == "String": - return "Ljava/lang/String;" - if itype == "Object": - return "Ljava/lang/Object;" - return "Lorg/sflphone/service/%s;" % itype - -def parse_java_file(input_stream, package, module): - outputs = [] - package_prefix = "Java_%s_%sJNI" % (package.replace(".", "_"), module) - for line in input_stream: - definition = re.match(r'.*public final static native ([^\( ]*) ([^\)]*)\(([^)]*)\).*',line) - if definition is not None: - retour = definition.group(1) - name = definition.group(2) - args = definition.group(3) - args_sigs = [] - args_frags = args.split(',') - for args_frag in args_frags: - argf = re.match(r'(\b)?([^ ]+) .*', args_frag.strip()) - if argf is not None: - args_sigs.append(type_to_signature(argf.group(2))) - sig = "(%s)%s" % (''.join(args_sigs), type_to_signature(retour)) - outputs.append("{\"%s\", \"%s\", (void*)& %s_%s}" % (name, sig, package_prefix, name.replace('_', '_1'))) - return outputs - -def render_to_template(defs, template_string): - template = Template(template_string) - return template.substitute(defs= ",\r\n".join(defs) ) - - -if __name__ == "__main__": - try: - opts, args = getopt.getopt(sys.argv[1:], "i:o:t:m:p:", ["input=", "output=", "template=", "module=", "package="]) - except getopt.GetoptError, err: - # print help information and exit: - print str(err) # will print something like "option -a not recognized" - sys.exit(2) - input_stream = None - output_file = None - template_string = None - package = "" - module = "" - for o, a in opts: - if o in ("-i", "--input"): - input_stream = open(a) - if o in ("-o", "--output"): - output_file = open(a, "w") - if o in ("-t", "--template"): - template_string = open(a).read() - if o in ("-m", "--module"): - module = a - if o in ("-p", "--package"): - package = a - - defs = parse_java_file(input_stream, package, module) - output_file.write(render_to_template(defs, template_string)) - output_file.close() - input_stream.close() diff --git a/daemon/src/client/android/callmanager.i b/daemon/src/client/android/callmanager.i deleted file mode 100644 index a1d168f31c..0000000000 --- a/daemon/src/client/android/callmanager.i +++ /dev/null @@ -1,403 +0,0 @@ -/* - * Copyright (C) 2004-2013 Savoir-Faire Linux Inc. - * Author: Emeric Vigier <emeric.vigier@savoirfairelinux.com> - * Alexandre Lision <alexnadre.L@savoirfairelinux.com> - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * Additional permission under GNU GPL version 3 section 7: - * - * If you modify this program, or any covered work, by linking or - * combining it with the OpenSSL project's OpenSSL library (or a - * modified version of that library), containing parts covered by the - * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. - * grants you additional permission to convey the resulting work. - * Corresponding Source for a non-source form of such a combination - * shall include the source code for the parts of OpenSSL used as well - * as that of the covered work. - */ - -%header %{ - -#include "client/callmanager.h" - - -typedef struct callmanager_callback -{ - void (*on_new_call_created)(const std::string& accountID, - const std::string& callID, - const std::string& to); - - void (*on_call_state_changed)(const std::string& callID, - const std::string& state); - - void (*on_incoming_call)(const std::string& accountID, - const std::string& callID, - const std::string& from); - - void (*on_transfer_state_changed) (const std::string& result); - - void (*on_conference_created) (const std::string& confID); - - void (*on_conference_removed) (const std::string& confID); - - void (*on_conference_state_changed) (const std::string& confID, - const std::string& state); - - void (*on_incoming_message) (const std::string& ID, - const std::string& from, - const std::string& msg); - - void (*on_record_playback_filepath) (const std::string& id, - const std::string& filename); - - void (*on_recording_state_changed) (const std::string& callID, - const bool& state); - - void (*newPresSubClientNotification) (const std::string& uri, - const std::string& basic, - const std::string& note); - - void (*newPresSubServerRequest) (const std::string& remote); - - void (*on_secure_sdes_on) (const std::string& callID); - - void (*on_secure_sdes_off) (const std::string& callID); - - void (*on_secure_zrtp_on) (const std::string& callID, - const std::string& cipher); - - void (*on_secure_zrtp_off) (const std::string& callID); - - void (*on_show_sas) (const std::string& callID, - const std::string& sas, - const bool& verified); - - void (*on_zrtp_not_supported) (const std::string& callID); - - void (*on_zrtp_negociation_failed) (const std::string& callID, - const std::string& reason, - const std::string& severity); - - void (*on_rtcp_report_received) (const std::string& callID, - const std::map<std::string, int>& stats); - -} callmanager_callback_t; - - -class Callback { -public: - virtual ~Callback() {} - - virtual void on_new_call_created(const std::string& arg1, - const std::string& arg2, - const std::string& arg3) {} - - virtual void on_call_state_changed(const std::string& arg1, - const std::string& arg2) {} - - virtual void on_incoming_call(const std::string& arg1, - const std::string& arg2, - const std::string& arg3) {} - - virtual void on_transfer_state_changed (const std::string& arg1) {} - - virtual void on_conference_created (const std::string& arg1) {} - - virtual void on_conference_removed (const std::string& arg1) {} - - virtual void on_conference_state_changed (const std::string& arg1, - const std::string& arg2) {} - - virtual void on_incoming_message(const std::string& ID, - const std::string& from, - const std::string& msg) {} - - virtual void on_record_playback_filepath(const std::string& id, - const std::string& filename) {} - - virtual void on_recording_state_changed(const std::string& callID, - const bool& state) {} - - virtual void newPresSubClientNotification(const std::string& uri, - const std::string& basic, - const std::string& note) {} - - virtual void newPresSubServerRequest(const std::string& remote) {} - - virtual void on_secure_sdes_on(const std::string& callID) {} - - virtual void on_secure_sdes_off(const std::string& callID) {} - - virtual void on_secure_zrtp_on(const std::string& callID, - const std::string& cipher) {} - - virtual void on_secure_zrtp_off(const std::string& callID) {} - - virtual void on_show_sas(const std::string& callID, - const std::string& sas, - const bool& verified) {} - - virtual void on_zrtp_not_supported(const std::string& callID) {} - - virtual void on_zrtp_negociation_failed(const std::string& callID, - const std::string& reason, - const std::string& severity) {} - - virtual void on_rtcp_report_received (const std::string& callID, - const std::map<std::string, int>& stats) {} -}; - - -static Callback* registeredCallbackObject = NULL; - -void on_new_call_created_wrapper (const std::string& accountID, - const std::string& callID, - const std::string& to) { - registeredCallbackObject->on_new_call_created(accountID, callID, to); -} - -void on_call_state_changed_wrapper(const std::string& callID, - const std::string& state) { - registeredCallbackObject->on_call_state_changed(callID, state); -} - -void on_incoming_call_wrapper (const std::string& accountID, - const std::string& callID, - const std::string& from) { - registeredCallbackObject->on_incoming_call(accountID, callID, from); -} - -void on_transfer_state_changed_wrapper (const std::string& result) { - registeredCallbackObject->on_transfer_state_changed(result); -} - -void on_conference_created_wrapper (const std::string& confID) { - registeredCallbackObject->on_conference_created(confID); -} - -void on_conference_removed_wrapper (const std::string& confID) { - registeredCallbackObject->on_conference_removed(confID); -} - -void on_conference_state_changed_wrapper (const std::string& confID, - const std::string& state) { - registeredCallbackObject->on_conference_state_changed(confID, state); -} - -void on_incoming_message_wrapper(const std::string& ID, const std::string& from, const std::string& msg) { - registeredCallbackObject->on_incoming_message(ID, from, msg); -} - -void on_record_playback_filepath_wrapper(const std::string& id, const std::string& filename) { - registeredCallbackObject->on_record_playback_filepath(id, filename); -} - -void on_recording_state_changed_wrapper(const std::string& callID, const bool& state) { - registeredCallbackObject->on_recording_state_changed(callID, state); -} - -void on_newPresSubClientNotification_wrapper(const std::string& uri, const std::string& basic, const std::string& note) { - registeredCallbackObject->newPresSubClientNotification(uri, basic, note); -} - -void on_newPresSubServerRequest_wrapper(const std::string& remote) { - registeredCallbackObject->newPresSubServerRequest(remote); -} - -void on_secure_sdes_on_wrapper(const std::string& callID){ - registeredCallbackObject->on_secure_sdes_on(callID); -} - -void on_secure_sdes_off_wrapper(const std::string& callID) { - registeredCallbackObject->on_secure_sdes_off(callID); -} - -void on_secure_zrtp_on_wrapper(const std::string& callID,const std::string& cipher){ - registeredCallbackObject->on_secure_zrtp_on(callID, cipher); -} - -void on_secure_zrtp_off_wrapper(const std::string& callID){ - registeredCallbackObject->on_secure_zrtp_off(callID); -} - -void on_show_sas_wrapper(const std::string& callID, const std::string& sas, const bool& verified){ - registeredCallbackObject->on_show_sas(callID, sas, verified); -} - -void on_zrtp_not_supported_wrapper(const std::string& callID){ - registeredCallbackObject->on_zrtp_not_supported(callID); -} - -void on_zrtp_negociation_failed_wrapper(const std::string& callID, const std::string& reason, const std::string& severity){ - registeredCallbackObject->on_zrtp_negociation_failed(callID, reason, severity); -} - -void on_rtcp_report_received_wrapper (const std::string& callID, const std::map<std::string, int>& stats){ - registeredCallbackObject->on_rtcp_report_received(callID, stats); -} - -static struct callmanager_callback wrapper_callback_struct = { - &on_new_call_created_wrapper, - &on_call_state_changed_wrapper, - &on_incoming_call_wrapper, - &on_transfer_state_changed_wrapper, - &on_conference_created_wrapper, - &on_conference_removed_wrapper, - &on_conference_state_changed_wrapper, - &on_incoming_message_wrapper, - &on_record_playback_filepath_wrapper, - &on_recording_state_changed_wrapper, - &on_newPresSubClientNotification_wrapper, - &on_newPresSubServerRequest_wrapper, - &on_secure_sdes_on_wrapper, - &on_secure_sdes_off_wrapper, - &on_secure_zrtp_on_wrapper, - &on_secure_zrtp_off_wrapper, - &on_show_sas_wrapper, - &on_zrtp_not_supported_wrapper, - &on_zrtp_negociation_failed_wrapper, - &on_rtcp_report_received_wrapper -}; - -void setCallbackObject(Callback* callback) { - registeredCallbackObject = callback; -} - -%} - -%feature("director") Callback; - -class CallManager { -public: - bool placeCall(const std::string& accountID, const std::string& callID, const std::string& to); - - bool refuse(const std::string& callID); - bool accept(const std::string& callID); - bool hangUp(const std::string& callID); - bool hold(const std::string& callID); - bool unhold(const std::string& callID); - bool transfer(const std::string& callID, const std::string& to); - bool attendedTransfer(const std::string& transferID, const std::string& targetID); - std::map< std::string, std::string > getCallDetails(const std::string& callID); - std::vector< std::string > getCallList(); - - /* Conference related methods */ - void removeConference(const std::string& conference_id); - bool joinParticipant(const std::string& sel_callID, const std::string& drag_callID); - void createConfFromParticipantList(const std::vector< std::string >& participants); - bool isConferenceParticipant(const std::string& call_id); - bool addParticipant(const std::string& callID, const std::string& confID); - bool addMainParticipant(const std::string& confID); - bool detachParticipant(const std::string& callID); - bool joinConference(const std::string& sel_confID, const std::string& drag_confID); - bool hangUpConference(const std::string& confID); - bool holdConference(const std::string& confID); - bool unholdConference(const std::string& confID); - std::vector<std::string> getConferenceList(); - std::vector<std::string> getParticipantList(const std::string& confID); - std::string getConferenceId(const std::string& callID); - std::map<std::string, std::string> getConferenceDetails(const std::string& callID); - - /* File Playback methods */ - bool startRecordedFilePlayback(const std::string& filepath); - void stopRecordedFilePlayback(const std::string& filepath); - - /* General audio methods */ - bool toggleRecording(const std::string& callID); - void recordPlaybackSeek(const double& value); - bool getIsRecording(const std::string& callID); - std::string getCurrentAudioCodecName(const std::string& callID); - void playDTMF(const std::string& key); - void startTone(const int32_t& start, const int32_t& type); - - /* Security related methods */ - void setSASVerified(const std::string& callID); - void resetSASVerified(const std::string& callID); - void setConfirmGoClear(const std::string& callID); - void requestGoClear(const std::string& callID); - void acceptEnrollment(const std::string& callID, const bool& accepted); - - /* Instant messaging */ - void sendTextMessage(const std::string& callID, const std::string& message); -}; - -class Callback { -public: - virtual ~Callback(); - - virtual void on_new_call_created(const std::string& arg1, - const std::string& arg2, - const std::string& arg3); - - virtual void on_call_state_changed(const std::string& arg1, - const std::string& arg2); - - virtual void on_incoming_call(const std::string& arg1, - const std::string& arg2, - const std::string& arg3); - - virtual void on_transfer_state_changed(const std::string& arg1); - - virtual void on_conference_created(const std::string& arg1); - - virtual void on_conference_removed(const std::string& arg1); - - virtual void on_conference_state_changed(const std::string& arg1, - const std::string& arg2); - - virtual void on_incoming_message(const std::string& ID, - const std::string& from, - const std::string& msg); - - virtual void on_record_playback_filepath(const std::string& id, - const std::string& filename); - - virtual void on_recording_state_changed(const std::string& callID, - const bool& state); - - virtual void newPresSubClientNotification(const std::string& uri, - const std::string& basic, - const std::string& note); - - virtual void newPresSubServerRequest(const std::string& remote); - - virtual void on_secure_sdes_on(const std::string& callID); - - virtual void on_secure_sdes_off(const std::string& callID); - - virtual void on_secure_zrtp_on(const std::string& callID, - const std::string& cipher); - - virtual void on_secure_zrtp_off(const std::string& callID); - - virtual void on_show_sas(const std::string& callID, - const std::string& sas, - const bool& verified); - - virtual void on_zrtp_not_supported(const std::string& callID); - - virtual void on_zrtp_negociation_failed(const std::string& callID, - const std::string& reason, - const std::string& severity); - - virtual void on_rtcp_report_received (const std::string& callID, - const std::map<std::string, int>& stats); -}; - -static Callback* registeredCallbackObject = NULL; - -void setCallbackObject(Callback* callback) { - registeredCallbackObject = callback; -} diff --git a/daemon/src/client/android/callmanager_jni.cpp b/daemon/src/client/android/callmanager_jni.cpp deleted file mode 100644 index 4adbad1b59..0000000000 --- a/daemon/src/client/android/callmanager_jni.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (C) 2004-2013 Savoir-Faire Linux Inc. - * Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com> - * Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com> - * Author: Emeric Vigier <emeric.vigier@savoirfairelinux.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * Additional permission under GNU GPL version 3 section 7: - * - * If you modify this program, or any covered work, by linking or - * combining it with the OpenSSL project's OpenSSL library (or a - * modified version of that library), containing parts covered by the - * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. - * grants you additional permission to convey the resulting work. - * Corresponding Source for a non-source form of such a combination - * shall include the source code for the parts of OpenSSL used as well - * as that of the covered work. - */ - -#include "client/callmanager.h" -#include "jni_callbacks.h" - -CallManager::CallManager() -{} - -void CallManager::callStateChanged(const std::string& callID, const std::string& state) -{ - on_call_state_changed_wrapper(callID, state); -} - -void CallManager::transferFailed() -{ - -} - -void CallManager::transferSucceeded() -{ - -} - -void CallManager::recordPlaybackStopped(const std::string& path) -{ - -} - -void CallManager::voiceMailNotify(const std::string& callID, const int32_t& nd_msg) -{ - -} - -void CallManager::incomingMessage(const std::string& ID, const std::string& from, const std::string& msg) -{ - on_incoming_message_wrapper(ID, from, msg); -} - -void CallManager::incomingCall(const std::string& accountID, const std::string& callID, const std::string& from) -{ - on_incoming_call_wrapper(accountID, callID, from); -} - -void CallManager::recordPlaybackFilepath(const std::string& id, const std::string& filename) -{ - on_record_playback_filepath_wrapper(id, filename); -} - -void CallManager::conferenceCreated(const std::string& confID) -{ - on_conference_created_wrapper(confID); -} - -void CallManager::conferenceChanged(const std::string& confID,const std::string& state) -{ - on_conference_state_changed_wrapper(confID, state); -} - -void CallManager::conferenceRemoved(const std::string& confID) -{ - on_conference_removed_wrapper(confID); -} - -void CallManager::newCallCreated(const std::string& accountID, const std::string& callID, const std::string& to) -{ - on_new_call_created_wrapper(accountID, callID, to); -} - -void CallManager::sipCallStateChanged(const std::string& accoundID, const std::string& state, const int32_t& code) -{ - -} - -void CallManager::recordingStateChanged(const std::string& callID, const bool& state) -{ - on_recording_state_changed_wrapper(callID, state); -} - -void CallManager::updatePlaybackScale(const std::string&, const int32_t&, const int32_t&) -{ - -} - -void CallManager::secureSdesOn(std::string const& callID) -{ - on_secure_sdes_on_wrapper(callID); -} - -void CallManager::secureSdesOff(std::string const& callID) -{ - on_secure_sdes_off_wrapper(callID); -} - -void CallManager::secureZrtpOn(const std::string& callID, const std::string& cipher) -{ - on_secure_zrtp_on_wrapper(callID, cipher); -} - -void CallManager::secureZrtpOff(const std::string& callID) -{ - on_secure_zrtp_off_wrapper(callID); -} - -void CallManager::showSAS(const std::string& callID, const std::string& sas, const bool& verified) -{ - on_show_sas_wrapper(callID, sas, verified); -} - -void CallManager::zrtpNotSuppOther(const std::string& callID) -{ - on_zrtp_not_supported_wrapper(callID); -} - -void CallManager::zrtpNegotiationFailed(const std::string& callID, const std::string& reason, const std::string& severity) -{ - on_zrtp_negociation_failed_wrapper(callID, reason, severity); -} - -void CallManager::onRtcpReportReceived(const std::string& callID, const std::map<std::string, int>& stats) -{ - on_rtcp_report_received_wrapper(callID, stats); -} diff --git a/daemon/src/client/android/configurationmanager.i b/daemon/src/client/android/configurationmanager.i deleted file mode 100644 index 329ab0ce23..0000000000 --- a/daemon/src/client/android/configurationmanager.i +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Copyright (C) 2004-2013 Savoir-Faire Linux Inc. - * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * Additional permission under GNU GPL version 3 section 7: - * - * If you modify this program, or any covered work, by linking or - * combining it with the OpenSSL project's OpenSSL library (or a - * modified version of that library), containing parts covered by the - * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. - * grants you additional permission to convey the resulting work. - * Corresponding Source for a non-source form of such a combination - * shall include the source code for the parts of OpenSSL used as well - * as that of the covered work. - */ - -%header %{ -#include "client/configurationmanager.h" - -typedef struct configurationmanager_callback -{ - void (*on_accounts_changed)(void); - void (*on_account_state_changed)(const std::string& accountID, const int32_t& state); - void (*on_account_state_changed_with_code)(const std::string& accountID, const std::string& state, const int32_t& code); - std::vector<int32_t> (*get_hardware_audio_format)(void); -} configurationmanager_callback_t; - - -class ConfigurationCallback { -public: - virtual ~ConfigurationCallback() {} - virtual void on_accounts_changed(void) {} - virtual void on_account_state_changed(const std::string& accountID, const int32_t& state) {} - virtual void on_account_state_changed_with_code(const std::string& accountID, const std::string& state, const int32_t& code) {} - virtual std::vector<int32_t> get_hardware_audio_format(void) {} -}; - -static ConfigurationCallback *registeredConfigurationCallbackObject = NULL; - -void on_accounts_changed_wrapper (void) { - registeredConfigurationCallbackObject->on_accounts_changed(); -} - -void on_account_state_changed_wrapper (const std::string& accountID, const int32_t& state) { - registeredConfigurationCallbackObject->on_account_state_changed(accountID, state); -} - -void on_account_state_changed_with_code_wrapper (const std::string& accountID, const std::string& state, const int32_t& code) { - registeredConfigurationCallbackObject->on_account_state_changed_with_code(accountID, state, code); -} - -std::vector<int32_t> get_hardware_audio_format_wrapper(void) { - return registeredConfigurationCallbackObject->get_hardware_audio_format(); -} - -static struct configurationmanager_callback wrapper_configurationcallback_struct = { - &on_accounts_changed_wrapper, - &on_account_state_changed_wrapper, - &on_account_state_changed_with_code_wrapper, - &get_hardware_audio_format_wrapper -}; - -void setConfigurationCallbackObject(ConfigurationCallback *callback) { - registeredConfigurationCallbackObject = callback; -} - -%} - -%feature("director") ConfigurationCallback; - -class ConfigurationManager { -public: - std::map< std::string, std::string > getAccountDetails(const std::string& accountID); - void setAccountDetails(const std::string& accountID, const std::map< std::string, std::string >& details); - std::map<std::string, std::string> getAccountTemplate(); - std::string addAccount(const std::map< std::string, std::string >& details); - void removeAccount(const std::string& accountID); - std::vector< std::string > getAccountList(); - void sendRegister(const std::string& accountID, const bool& enable); - void registerAllAccounts(void); - - std::map< std::string, std::string > getTlsSettingsDefault(); - - std::vector< int32_t > getAudioCodecList(); - std::vector< std::string > getSupportedTlsMethod(); - std::vector< std::string > getAudioCodecDetails(const int32_t& payload); - std::vector< int32_t > getActiveAudioCodecList(const std::string& accountID); - - void setActiveAudioCodecList(const std::vector< std::string >& list, const std::string& accountID); - - std::vector< std::string > getAudioPluginList(); - void setAudioPlugin(const std::string& audioPlugin); - std::vector< std::string > getAudioOutputDeviceList(); - void setAudioOutputDevice(const int32_t& index); - void setAudioInputDevice(const int32_t& index); - void setAudioRingtoneDevice(const int32_t& index); - std::vector< std::string > getAudioInputDeviceList(); - std::vector< std::string > getCurrentAudioDevicesIndex(); - int32_t getAudioInputDeviceIndex(const std::string& name); - int32_t getAudioOutputDeviceIndex(const std::string& name); - std::string getCurrentAudioOutputPlugin(); - bool getNoiseSuppressState(); - void setNoiseSuppressState(const bool& state); - bool isAgcEnabled(); - void setAgcState(const bool& state); - bool isDtmfMuted(); - void muteDtmf(const bool& mute); - bool isCaptureMuted(); - void muteCapture(const bool& mute); - bool isPlaybackMuted(); - void mutePlayback(const bool& mute); - void setVolume(const std::string& device, const double& value); - double getVolume(const std::string& device); - - std::map<std::string, std::string> getRingtoneList(); - - std::string getAudioManager(); - bool setAudioManager(const std::string& api); - - int32_t isIax2Enabled(); - std::string getRecordPath(); - void setRecordPath(const std::string& recPath); - bool getIsAlwaysRecording(); - void setIsAlwaysRecording(const bool& rec); - - void setHistoryLimit(const int32_t& days); - int32_t getHistoryLimit(); - void clearHistory(); - - void setAccountsOrder(const std::string& order); - - std::map<std::string, std::string> getHookSettings(); - void setHookSettings(const std::map<std::string, std::string>& settings); - - std::vector<std::map<std::string, std::string> > getHistory(); - - std::map<std::string, std::string> getTlsSettings(); - void setTlsSettings(const std::map< std::string, std::string >& details); - std::map< std::string, std::string > getIp2IpDetails(); - - std::vector< std::map< std::string, std::string > > getCredentials(const std::string& accountID); - void setCredentials(const std::string& accountID, const std::vector< std::map< std::string, std::string > >& details); - - std::string getAddrFromInterfaceName(const std::string& interface); - - std::vector<std::string> getAllIpInterface(); - std::vector<std::string> getAllIpInterfaceByName(); - - std::map<std::string, std::string> getShortcuts(); - void setShortcuts(const std::map<std::string, std::string> &shortcutsMap); - - bool checkForPrivateKey(const std::string& pemPath); - bool checkCertificateValidity(const std::string& caPath, const std::string& pemPath); - bool checkHostnameCertificate(const std::string& host, const std::string& port); - -}; - -class ConfigurationCallback { -public: - virtual ~ConfigurationCallback(); - virtual void on_accounts_changed(void); - virtual void on_account_state_changed(const std::string& accountID, const int32_t& state); - virtual void on_account_state_changed_with_code(const std::string& accountID, const std::string& state, const int32_t& code); - virtual std::vector<int32_t> get_hardware_audio_format(void); -}; - -static ConfigurationCallback *registeredConfigurationCallbackObject = NULL; - -void setConfigurationCallbackObject(ConfigurationCallback *callback) { - registeredConfigurationCallbackObject = callback; -} diff --git a/daemon/src/client/android/configurationmanager_jni.cpp b/daemon/src/client/android/configurationmanager_jni.cpp deleted file mode 100644 index 5a9ab957e4..0000000000 --- a/daemon/src/client/android/configurationmanager_jni.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010, 2011 Savoir-Faire Linux Inc. - * Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com> - * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> - * Author: Guillaume Carmel-Archambault <guillaume.carmel-archambault@savoirfairelinux.com> - * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * Additional permission under GNU GPL version 3 section 7: - * - * If you modify this program, or any covered work, by linking or - * combining it with the OpenSSL project's OpenSSL library (or a - * modified version of that library), containing parts covered by the - * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. - * grants you additional permission to convey the resulting work. - * Corresponding Source for a non-source form of such a combination - * shall include the source code for the parts of OpenSSL used as well - * as that of the covered work. - */ - -#include "client/configurationmanager.h" -#include "jni_callbacks.h" - -ConfigurationManager::ConfigurationManager() {} - -void ConfigurationManager::accountsChanged() -{ - on_accounts_changed_wrapper(); -} - -void ConfigurationManager::historyChanged() -{ - -} - -void ConfigurationManager::stunStatusFailure(const std::string& accountID) -{ - -} - -void ConfigurationManager::volumeChanged(const std::string&, const int&) -{ -} - -void ConfigurationManager::registrationStateChanged(const std::string& accountID, int const& state) -{ - on_account_state_changed_wrapper(accountID, state); -} - -void ConfigurationManager::sipRegistrationStateChanged(const std::string& accountID, const std::string& state, const int32_t& code) -{ - on_account_state_changed_with_code_wrapper(accountID, state, code); -} - -void ConfigurationManager::errorAlert(const int & /*alert*/) -{ -} - -std::vector< int32_t > ConfigurationManager::getHardwareAudioFormat() -{ - return get_hardware_audio_format_wrapper(); -} - -std::vector<std::string> ConfigurationManager::getSupportedAudioManagers() -{ - return {"opensl"}; -} diff --git a/daemon/src/client/android/jni-xml2cpp.py b/daemon/src/client/android/jni-xml2cpp.py deleted file mode 100755 index 067f488d3f..0000000000 --- a/daemon/src/client/android/jni-xml2cpp.py +++ /dev/null @@ -1,85 +0,0 @@ -#!/usr/bin/python - -# -# PACKAGE DEPENDENCIES: python python-lxml -# - -#import easy to use xml parser called minidom: -from lxml import etree -#from copy import deepcopy -from lxml import objectify -import re, sys, getopt - -def rreplace(s, old, new, occurrence): - li = s.rsplit(old, occurrence) - return new.join(li) - -def usage(): - print "jni-xml2cpp.py --file <file> | -i <file>" - -# main -inputfile = "./dbus/callmanager-introspec.xml" -outputfile = "./dbus/callmanager-jni.h" -try: - opts, args = getopt.getopt(sys.argv[1:], "hi:o:", ["help", "input=", "output="]) -except getopt.GetoptError, err: - usage() - print str(err) - #print opts - sys.exit(2) - -for opt, arg in opts: - if opt in ("-h", "--help"): - usage() - sys.exit(0) - elif opt in ("-i", "--input"): - inputfile = arg - elif opt in ("-o", "--output"): - outputfile = arg - else: - print "error: argument not recognized" - sys.exit(3) - -print "inputfile = %s" % (inputfile) -print "outputfile = %s" % (outputfile) -source = "".join(args) - -# lxml.objectify -# FIXME relative path -cm_obj_tree = objectify.parse(inputfile) -cm_obj_root = cm_obj_tree.getroot() -# http://www.skymind.com/~ocrow/python_string/ -# method 4: list of strings -prototype = [] -# iteration on methods -for meth in cm_obj_root.interface.iter(tag="method"): -# iteration on arguments - prototype.append(meth.get("name")) - prototype.append("(") - for argum in meth.iter(tag="arg"): - name = argum.get("name") - typ = argum.get("type") -# FIXME - if typ == 's': - prototype.append("string %s, " % (name)) - elif typ == 'i': - prototype.append("int %s, " % (name)) - elif typ == 'd': - prototype.append("unsigned int %s, " % (name)) - elif typ == 'as': - prototype.append("std::vector< std::string > &%s, " % (name)) - else: - prototype.append("void %s, " % (name)) - prototype.append(");\n") - -# starting from the end of string, -# replace the first and 1-only comma by nothing -#rreplace(prototype[tostring(), ',', '', 1) - -p = re.compile(", \);") -prototypes = p.sub(");", ''.join(prototype)) - -# FIXME relative path -outfile = open(outputfile, "w") -outfile.write(prototypes) -outfile.close() diff --git a/daemon/src/client/android/jni_callbacks.h b/daemon/src/client/android/jni_callbacks.h deleted file mode 100644 index acc6539b00..0000000000 --- a/daemon/src/client/android/jni_callbacks.h +++ /dev/null @@ -1,39 +0,0 @@ - - - - -extern struct callmanager_callback wrapper_callback_struct; -void on_new_call_created_wrapper (const std::string& accountID, - const std::string& callID, - const std::string& to); -void on_call_state_changed_wrapper(const std::string& callID, - const std::string& to); -void on_incoming_call_wrapper (const std::string& accountID, - const std::string& callID, - const std::string& from); -void on_transfer_state_changed_wrapper (const std::string& result); - -void on_conference_created_wrapper (const std::string& confID); -void on_conference_removed_wrapper (const std::string& confID); -void on_conference_state_changed_wrapper(const std::string& confID,const std::string& state); -void on_incoming_message_wrapper(const std::string& ID, const std::string& from, const std::string& msg); -void on_newPresSubClientNotification_wrapper(const std::string& uri, const std::string& basic, const std::string& note); -void on_newPresSubServerRequest_wrapper(const std::string& remote); - -void on_secure_sdes_on_wrapper(const std::string& callID); -void on_secure_sdes_off_wrapper(const std::string& callID); -void on_secure_zrtp_on_wrapper(const std::string& callID,const std::string& cipher); -void on_secure_zrtp_off_wrapper(const std::string& callID); -void on_show_sas_wrapper(const std::string& callID, const std::string& sas, const bool& verified); -void on_zrtp_not_supported_wrapper(const std::string& callID); -void on_zrtp_negociation_failed_wrapper(const std::string& callID, const std::string& reason, const std::string& severity); -void on_rtcp_report_received_wrapper(const std::string& callID, const std::map<std::basic_string<char>, int>& stats); - -extern struct configurationmanager_callback wrapper_configurationcallback_struct; -extern void on_accounts_changed_wrapper (); -extern void on_account_state_changed_wrapper (const std::string& accoundID, int const& state); -extern void on_account_state_changed_with_code_wrapper (const std::string& accoundID, const std::string& state, const int32_t& code); -extern std::vector<int> get_hardware_audio_format_wrapper(); - -void on_record_playback_filepath_wrapper(const std::string& id, const std::string& filename); -void on_recording_state_changed_wrapper(const std::string& callID, const bool& state); diff --git a/daemon/src/client/android/jni_interface.i b/daemon/src/client/android/jni_interface.i deleted file mode 100644 index 0021f977d6..0000000000 --- a/daemon/src/client/android/jni_interface.i +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (C) 2004-2013 Savoir-Faire Linux Inc. - * Author: Emeric Vigier <emeric.vigier@savoirfairelinux.com> - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * Additional permission under GNU GPL version 3 section 7: - * - * If you modify this program, or any covered work, by linking or - * combining it with the OpenSSL project's OpenSSL library (or a - * modified version of that library), containing parts covered by the - * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. - * grants you additional permission to convey the resulting work. - * Corresponding Source for a non-source form of such a combination - * shall include the source code for the parts of OpenSSL used as well - * as that of the covered work. - */ - -/* File : jni_interface.i */ -%module (directors="1") SFLPhoneservice - -#define SWIG_JAVA_ATTACH_CURRENT_THREAD_AS_DAEMON -%include "typemaps.i" -%include "std_string.i" /* std::string typemaps */ -%include "enums.swg" -%include "arrays_java.i"; -%include "carrays.i"; -%include "std_map.i"; -%include "std_vector.i"; -%include "stdint.i"; - -/* void* shall be handled as byte arrays */ -%typemap(jni) void * "void *" -%typemap(jtype) void * "byte[]" -%typemap(jstype) void * "byte[]" -%typemap(javain) void * "$javainput" -%typemap(in) void * %{ - $1 = $input; -%} -%typemap(javadirectorin) void * "$jniinput" -%typemap(out) void * %{ - $result = $1; -%} -%typemap(javaout) void * { - return $jnicall; -} - -namespace std { - %template(StringMap) map<string, string>; - %template(StringVect) vector<string>; - %template(VectMap) vector< map<string,string> >; - %template(IntegerMap) map<string,int>; - %template(IntVect) vector<int32_t>; -} - -/* not parsed by SWIG but needed by generated C files */ -%header %{ - -#include <logger.h> - -%} - -%inline %{ -/* some functions that need to be declared in *_wrap.cpp - * that are not declared elsewhere in the c++ code - */ -%} - -/* parsed by SWIG to generate all the glue */ -/* %include "../managerimpl.h" */ -/* %include <client/callmanager.h> */ - -//%constant struct callmanager_callback* WRAPPER_CALLBACK_STRUCT = &wrapper_callback_struct; - -%include "managerimpl.i" -%include "callmanager.i" -%include "configurationmanager.i" - -#ifndef SWIG -/* some bad declarations */ -#endif diff --git a/daemon/src/client/android/managerimpl.i b/daemon/src/client/android/managerimpl.i deleted file mode 100644 index 357d416f44..0000000000 --- a/daemon/src/client/android/managerimpl.i +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2004-2013 Savoir-Faire Linux Inc. - * Author: Emeric Vigier <emeric.vigier@savoirfairelinux.com> - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * Additional permission under GNU GPL version 3 section 7: - * - * If you modify this program, or any covered work, by linking or - * combining it with the OpenSSL project's OpenSSL library (or a - * modified version of that library), containing parts covered by the - * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. - * grants you additional permission to convey the resulting work. - * Corresponding Source for a non-source form of such a combination - * shall include the source code for the parts of OpenSSL used as well - * as that of the covered work. - */ - -/* %nodefaultctor ManagerImpl; -%nodefaultdtor ManagerImpl; */ -%header %{ -#include <managerimpl.h> -namespace Manager { -extern ManagerImpl& instance(); -} -%} - -class ManagerImpl { -public: - void init(const std::string &config_file); - void setPath(const std::string &path); - void pollEvents(); - void finish(); -}; - -//%rename(Manager_instance) Manager::instance; - -namespace Manager { - -ManagerImpl& Manager::instance() -{ - // Meyers singleton - static ManagerImpl instance_; - return instance_; -} - -} diff --git a/daemon/src/client/android/presencemanager_jni.cpp b/daemon/src/client/android/presencemanager_jni.cpp deleted file mode 100644 index 9a0b197dd8..0000000000 --- a/daemon/src/client/android/presencemanager_jni.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2013 Savoir-Faire Linux Inc. - * Author: Patrick Keroulas <patrick.keroulas@savoirfairelinux.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Additional permission under GNU GPL version 3 section 7: - * - * If you modify this program, or any covered work, by linking or - * combining it with the OpenSSL project's OpenSSL library (or a - * modified version of that library), containing parts covered by the - * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. - * grants you additional permission to convey the resulting work. - * Corresponding Source for a non-source form of such a combination - * shall include the source code for the parts of OpenSSL used as well - * as that of the covered work. - */ - -#include "client/presencemanager.h" - -PresenceManager::PresenceManager() -{} - -void -PresenceManager::newBuddyNotification(const std::string& accountID, const std::string& buddyUri, - const bool& status, const std::string& lineStatus) -{} - -void -PresenceManager::subscriptionStateChanged(const std::string& accountID, const std::string& buddyUri, - const bool& state) -{} - -void -PresenceManager::newServerSubscriptionRequest(const std::string& remote) -{} - -void -PresenceManager::serverError(const std::string& accountID, const std::string& error, const std::string& msg) -{} diff --git a/daemon/src/client/android/sflphoneservice.c.template b/daemon/src/client/android/sflphoneservice.c.template deleted file mode 100644 index f409e3f488..0000000000 --- a/daemon/src/client/android/sflphoneservice.c.template +++ /dev/null @@ -1,73 +0,0 @@ -#include "logger.h" - -JavaVM *gJavaVM; -const char *ksflphoneservicePath = "org/sflphone/service/SFLPhoneserviceJNI"; - -void deinitClassHelper(JNIEnv *env, jobject obj) { - INFO("deinitClassHelper"); - - /* delete cached object instances */ - env->DeleteGlobalRef(obj); - INFO("deinitClassHelper: object %x deleted", obj); -} - -JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) { - JNIEnv *env; - jclass clazz; - jint r; - - INFO("JNI_OnLoad"); - - //Assume it is c++ - r = vm->GetEnv ((void **) &env, JNI_VERSION_1_6); - if (r != JNI_OK) { - ERROR("JNI_OnLoad: failed to get the environment using GetEnv()"); - return -1; - } - INFO("JNI_Onload: GetEnv %p", env); - - clazz = env->FindClass (ksflphoneservicePath); - if (!clazz) { - ERROR("JNI_Onload: whoops, %s class not found!", ksflphoneservicePath); - } - gJavaVM = vm; - INFO("JNI_Onload: JavaVM %p", gJavaVM); - - /* put instances of class object we need into cache */ - //initClassHelper(env, kManagerPath, &gManagerObject); - - JNINativeMethod methods[] = { - - $defs - - }; - - r = env->RegisterNatives (clazz, methods, (int) (sizeof(methods) / sizeof(methods[0]))); - return JNI_VERSION_1_6; -} - -void JNI_OnUnLoad(JavaVM* vm, void* reserved) { - JNIEnv* env; - jclass clazz; - - INFO("JNI_OnUnLoad"); - - /* get env */ - if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) { - ERROR("JNI_OnUnLoad: failed to get the environment using GetEnv()"); - return; - } - INFO("JNI_OnUnLoad: GetEnv %p", env); - - /* Get jclass with env->FindClass */ - clazz = env->FindClass(ksflphoneservicePath); - if (!clazz) { - ERROR("JNI_OnUnLoad: whoops, %s class not found!", ksflphoneservicePath); - } - - /* remove instances of class object we need into cache */ - //deinitClassHelper(env, gManagerObject); - - env->UnregisterNatives(clazz); - INFO("JNI_OnUnLoad: Native functions unregistered"); -} diff --git a/daemon/src/client/callmanager.cpp b/daemon/src/client/callmanager.cpp index 375fd15208..c1c8b8e02f 100644 --- a/daemon/src/client/callmanager.cpp +++ b/daemon/src/client/callmanager.cpp @@ -29,6 +29,7 @@ * as that of the covered work. */ #include <vector> +#include <cstring> #include "global.h" #include "callmanager.h" @@ -45,6 +46,16 @@ #include "logger.h" #include "manager.h" +CallManager::CallManager() +{ + std::memset(std::addressof(evHandlers_), 0, sizeof(evHandlers_)); +} + +void CallManager::registerEvHandlers(struct sflph_call_ev_handlers* evHandlers) +{ + evHandlers_ = *evHandlers; +} + bool CallManager::placeCall(const std::string& accountID, const std::string& callID, const std::string& to) @@ -383,3 +394,164 @@ CallManager::sendTextMessage(const std::string& callID, const std::string& messa ERROR("Could not send \"%s\" text message to %s since SFLphone daemon does not support it, please recompile with instant messaging support", message.c_str(), callID.c_str()); #endif } + +void CallManager::callStateChanged(const std::string& callID, const std::string& state) +{ + if (evHandlers_.on_state_change) { + evHandlers_.on_state_change(callID, state); + } +} + +void CallManager::transferFailed() +{ + if (evHandlers_.on_transfer_fail) { + evHandlers_.on_transfer_fail(); + } +} + +void CallManager::transferSucceeded() +{ + if (evHandlers_.on_transfer_success) { + evHandlers_.on_transfer_success(); + } +} + +void CallManager::recordPlaybackStopped(const std::string& path) +{ + if (evHandlers_.on_record_playback_stopped) { + evHandlers_.on_record_playback_stopped(path); + } +} + +void CallManager::voiceMailNotify(const std::string& callID, const int32_t& nd_msg) +{ + if (evHandlers_.on_voice_mail_notify) { + evHandlers_.on_voice_mail_notify(callID, nd_msg); + } +} + +void CallManager::incomingMessage(const std::string& ID, const std::string& from, const std::string& msg) +{ + if (evHandlers_.on_incoming_message) { + evHandlers_.on_incoming_message(ID, from, msg); + } +} + +void CallManager::incomingCall(const std::string& accountID, const std::string& callID, const std::string& from) +{ + if (evHandlers_.on_incoming_call) { + evHandlers_.on_incoming_call(accountID, callID, from); + } +} + +void CallManager::recordPlaybackFilepath(const std::string& id, const std::string& filename) +{ + if (evHandlers_.on_record_playback_filepath) { + evHandlers_.on_record_playback_filepath(id, filename); + } +} + +void CallManager::conferenceCreated(const std::string& confID) +{ + if (evHandlers_.on_conference_created) { + evHandlers_.on_conference_created(confID); + } +} + +void CallManager::conferenceChanged(const std::string& confID,const std::string& state) +{ + if (evHandlers_.on_conference_changed) { + evHandlers_.on_conference_changed(confID, state); + } +} + +void CallManager::updatePlaybackScale(const std::string& filepath, const int32_t& position, const int32_t& scale) +{ + if (evHandlers_.on_update_playback_scale) { + evHandlers_.on_update_playback_scale(filepath, position, scale); + } +} + +void CallManager::conferenceRemoved(const std::string& confID) +{ + if (evHandlers_.on_conference_remove) { + evHandlers_.on_conference_remove(confID); + } +} + +void CallManager::newCallCreated(const std::string& accountID, const std::string& callID, const std::string& to) +{ + if (evHandlers_.on_new_call) { + evHandlers_.on_new_call(accountID, callID, to); + } +} + +void CallManager::sipCallStateChanged(const std::string& callID, const std::string& state, const int32_t& code) +{ + if (evHandlers_.on_sip_call_state_change) { + evHandlers_.on_sip_call_state_change(callID, state, code); + } +} + +void CallManager::recordingStateChanged(const std::string& callID, const bool& state) +{ + if (evHandlers_.on_record_state_change) { + evHandlers_.on_record_state_change(callID, state); + } +} + +void CallManager::secureSdesOn(const std::string& callID) +{ + if (evHandlers_.on_secure_sdes_on) { + evHandlers_.on_secure_sdes_on(callID); + } +} + +void CallManager::secureSdesOff(const std::string& callID) +{ + if (evHandlers_.on_secure_sdes_off) { + evHandlers_.on_secure_sdes_off(callID); + } +} + +void CallManager::secureZrtpOn(const std::string& callID, const std::string& cipher) +{ + if (evHandlers_.on_secure_zrtp_on) { + evHandlers_.on_secure_zrtp_on(callID, cipher); + } +} + +void CallManager::secureZrtpOff(const std::string& callID) +{ + if (evHandlers_.on_secure_zrtp_off) { + evHandlers_.on_secure_zrtp_off(callID); + } +} + +void CallManager::showSAS(const std::string& callID, const std::string& sas, const bool& verified) +{ + if (evHandlers_.on_show_sas) { + evHandlers_.on_show_sas(callID, sas, verified); + } +} + +void CallManager::zrtpNotSuppOther(const std::string& callID) +{ + if (evHandlers_.on_zrtp_not_supp_other) { + evHandlers_.on_zrtp_not_supp_other(callID); + } +} + +void CallManager::zrtpNegotiationFailed(const std::string& callID, const std::string& reason, const std::string& severity) +{ + if (evHandlers_.on_zrtp_negotiation_fail) { + evHandlers_.on_zrtp_negotiation_fail(callID, reason, severity); + } +} + +void CallManager::onRtcpReportReceived(const std::string& callID, const std::map<std::string, int>& stats) +{ + if (evHandlers_.on_rtcp_receive_report) { + evHandlers_.on_rtcp_receive_report(callID, stats); + } +} diff --git a/daemon/src/client/callmanager.h b/daemon/src/client/callmanager.h index 312710a9d3..8070afabdf 100644 --- a/daemon/src/client/callmanager.h +++ b/daemon/src/client/callmanager.h @@ -35,34 +35,12 @@ #include "config.h" #endif -#if HAVE_DBUS - -#include "dbus/dbus_cpp.h" - -#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 6 -/* This warning option only exists for gcc 4.6.0 and greater. */ -#pragma GCC diagnostic ignored "-Wunused-but-set-variable" -#endif - -#pragma GCC diagnostic ignored "-Wignored-qualifiers" -#pragma GCC diagnostic ignored "-Wunused-parameter" -#include "dbus/callmanager-glue.h" -#pragma GCC diagnostic warning "-Wignored-qualifiers" -#pragma GCC diagnostic warning "-Wunused-parameter" - -#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 6 -/* This warning option only exists for gcc 4.6.0 and greater. */ -#pragma GCC diagnostic warning "-Wunused-but-set-variable" -#endif - -#else -// these includes normally come with DBus C++ -#include <vector> +#include <stdexcept> #include <map> +#include <vector> #include <string> -#endif // HAVE_DBUS -#include <stdexcept> +#include "sflphone.h" class CallManagerException: public std::runtime_error { public: @@ -75,24 +53,13 @@ class AudioZrtpSession; } class CallManager -#if HAVE_DBUS - : public org::sflphone::SFLphone::CallManager_adaptor, - public DBus::IntrospectableAdaptor, - public DBus::ObjectAdaptor -#endif { public: - -#if HAVE_DBUS - CallManager(DBus::Connection& connection); -#else CallManager(); -#endif - - /* methods exported by this interface, - * you will have to implement them in your ObjectAdaptor - */ + void registerEvHandlers(struct sflph_call_ev_handlers* evHandlers); + // Methods + public: /* Call related methods */ bool placeCall(const std::string& accountID, const std::string& callID, const std::string& to); @@ -150,9 +117,8 @@ class CallManager void sendTextMessage(const std::string& callID, const std::string& message); void sendTextMessage(const std::string& callID, const std::string& message, const std::string& from); - /* the following signals must be implemented manually for any - * platform or configuration that does not supply dbus */ -#if !HAVE_DBUS + // Signals + public: void callStateChanged(const std::string& callID, const std::string& state); void transferFailed(); @@ -188,13 +154,16 @@ class CallManager void zrtpNegotiationFailed(const std::string& callID, const std::string& arg2, const std::string& arg3); void onRtcpReportReceived(const std::string& callID, const std::map<std::string, int>& stats); -#endif // !HAVE_DBUS -private: + private: #if HAVE_ZRTP sfl::AudioZrtpSession * getAudioZrtpSession(const std::string& callID); #endif + + private: + // Event handlers; needed by the library API + struct sflph_call_ev_handlers evHandlers_; }; #endif//CALLMANAGER_H diff --git a/daemon/src/client/callmanager_stub.cpp b/daemon/src/client/callmanager_stub.cpp deleted file mode 100644 index 3f9ace06d8..0000000000 --- a/daemon/src/client/callmanager_stub.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (C) 2014 Savoir-Faire Linux Inc. - * Author: Vittorio Giovara <vittorio.giovara@savoirfairelinux.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * Additional permission under GNU GPL version 3 section 7: - * - * If you modify this program, or any covered work, by linking or - * combining it with the OpenSSL project's OpenSSL library (or a - * modified version of that library), containing parts covered by the - * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. - * grants you additional permission to convey the resulting work. - * Corresponding Source for a non-source form of such a combination - * shall include the source code for the parts of OpenSSL used as well - * as that of the covered work. - */ - -#warning Using a stub file will produce a non working application - -#include "client/callmanager.h" - -CallManager::CallManager() -{} - -void CallManager::callStateChanged(const std::string& callID, - const std::string& state) -{ -} - -void CallManager::transferFailed() -{ -} - -void CallManager::transferSucceeded() -{ -} - -void CallManager::recordPlaybackStopped(const std::string& path) -{ -} - -void CallManager::voiceMailNotify(const std::string& callID, - const int32_t& nd_msg) -{ -} - -void CallManager::incomingMessage(const std::string& ID, - const std::string& from, - const std::string& msg) -{ -} - -void CallManager::incomingCall(const std::string& accountID, - const std::string& callID, - const std::string& from) -{ -} - -void CallManager::recordPlaybackFilepath(const std::string& id, - const std::string& filename) -{ -} - -void CallManager::conferenceCreated(const std::string& confID) -{ -} - -void CallManager::conferenceChanged(const std::string& confID, - const std::string& state) -{ -} - -void CallManager::conferenceRemoved(const std::string& confID) -{ -} - -void CallManager::newCallCreated(const std::string& accountID, - const std::string& callID, - const std::string& to) -{ -} - -void CallManager::sipCallStateChanged(const std::string& accoundID, - const std::string& state, - const int32_t& code) -{ -} - -void CallManager::recordingStateChanged(const std::string& callID, - const bool& state) -{ -} - -void CallManager::updatePlaybackScale(const std::string& callID, - const int32_t&, - const int32_t&) -{ -} - -void CallManager::secureSdesOn(std::string const& callID) -{ -} - -void CallManager::secureSdesOff(std::string const& callID) -{ -} - -void CallManager::secureZrtpOn(const std::string& callID, - const std::string& cipher) -{ -} - -void CallManager::secureZrtpOff(const std::string& callID) -{ -} - -void CallManager::showSAS(const std::string& callID, - const std::string& sas, - const bool& verified) -{ -} - -void CallManager::zrtpNotSuppOther(const std::string& callID) -{ -} - -void CallManager::zrtpNegotiationFailed(const std::string& callID, - const std::string& reason, - const std::string& severity) -{ -} - -void CallManager::onRtcpReportReceived(const std::string& callID, - const std::map<std::string, int>& stats) -{ -} diff --git a/daemon/src/client/client.cpp b/daemon/src/client/client.cpp index b418e31a04..862313a171 100644 --- a/daemon/src/client/client.cpp +++ b/daemon/src/client/client.cpp @@ -28,28 +28,30 @@ * as that of the covered work. */ -/* Note: this file is compiled only when dbus is not available */ - #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include "client/client.h" -#include "client/callmanager.h" -#include "client/configurationmanager.h" -#include "client/presencemanager.h" +#include "client.h" +#include "callmanager.h" +#include "configurationmanager.h" + +#ifdef SFL_PRESENCE +#include "presencemanager.h" +#endif // SFL_PRESENCE + +#ifdef SFL_PRESENCE +#include "videomanager.h" +#endif // SFL_PRESENCE -Client::Client() : callManager_(new CallManager) +Client::Client() : + callManager_(new CallManager) , configurationManager_(new ConfigurationManager) #ifdef SFL_PRESENCE , presenceManager_(new PresenceManager) #endif -#if HAVE_DBUS - , instanceManager_(0) - , dispatcher_(0) -#endif #ifdef SFL_VIDEO - , videoManager_(0) + , videoManager_(new VideoManager) #endif #ifdef USE_NETWORKMANAGER , networkManager_(0) @@ -63,10 +65,6 @@ Client::~Client() #endif #ifdef SFL_VIDEO delete videoManager_; -#endif -#if HAVE_DBUS - delete dispatcher_; - delete instanceManager_; #endif delete configurationManager_; #ifdef SFL_PRESENCE @@ -75,22 +73,6 @@ Client::~Client() delete callManager_; } -int Client::event_loop() -{ - return 0; -} - -void -Client::registerCallback(const std::function<void()> &callback) -{ - -} - -int Client::exit() -{ - return 0; -} - CallManager * Client::getCallManager() { return callManager_; diff --git a/daemon/src/client/client.h b/daemon/src/client/client.h index 04d3e36538..042be941af 100644 --- a/daemon/src/client/client.h +++ b/daemon/src/client/client.h @@ -49,14 +49,6 @@ class PresenceManager; class VideoManager; #endif -#include <functional> - -#if HAVE_DBUS -namespace DBus { - class BusDispatcher; -} -#endif - class Client { public: Client(); @@ -74,16 +66,6 @@ class Client { VideoManager* getVideoManager(); #endif - int event_loop(); - int exit(); - // DBus provides our event loop - void registerCallback(const std::function<void()> &callback); - -#if HAVE_DBUS - void onLastUnregister(); - void setPersistent(bool p) { isPersistent_ = p; } -#endif - private: NON_COPYABLE(Client); CallManager* callManager_; @@ -91,11 +73,6 @@ class Client { #ifdef SFL_PRESENCE PresenceManager* presenceManager_; #endif -#if HAVE_DBUS - Instance* instanceManager_; - DBus::BusDispatcher* dispatcher_; - bool isPersistent_ = false; -#endif #ifdef SFL_VIDEO VideoManager *videoManager_; #endif diff --git a/daemon/src/client/configurationmanager.cpp b/daemon/src/client/configurationmanager.cpp index 4e567f4b02..17c77907de 100644 --- a/daemon/src/client/configurationmanager.cpp +++ b/daemon/src/client/configurationmanager.cpp @@ -36,6 +36,7 @@ #include <cerrno> #include <sstream> +#include <cstring> #include "configurationmanager.h" #include "account_schema.h" @@ -50,6 +51,16 @@ #include "history/historynamecache.h" #include "audio/audiolayer.h" +ConfigurationManager::ConfigurationManager() +{ + std::memset(std::addressof(evHandlers_), 0, sizeof(evHandlers_)); +} + +void ConfigurationManager::registerEvHandlers(struct sflph_config_ev_handlers* evHandlers) +{ + evHandlers_ = *evHandlers; +} + std::map<std::string, std::string> ConfigurationManager::getIp2IpDetails() { const auto account = Manager::instance().getIP2IPAccount(); @@ -577,3 +588,58 @@ bool ConfigurationManager::checkHostnameCertificate(const std::string& host, return false; #endif } + + +void ConfigurationManager::volumeChanged(const std::string& device, const int& value) +{ + if (evHandlers_.on_volume_change) { + evHandlers_.on_volume_change(device, value); + } +} + +void ConfigurationManager::accountsChanged() +{ + if (evHandlers_.on_accounts_change) { + evHandlers_.on_accounts_change(); + } +} + +void ConfigurationManager::historyChanged() +{ + if (evHandlers_.on_history_change) { + evHandlers_.on_history_change(); + } +} + +void ConfigurationManager::stunStatusFailure(const std::string& accountID) +{ + if (evHandlers_.on_stun_status_fail) { + evHandlers_.on_stun_status_fail(accountID); + } +} + +void ConfigurationManager::registrationStateChanged(const std::string& accountID, int const& state) +{ + if (evHandlers_.on_registration_state_change) { + evHandlers_.on_registration_state_change(accountID, state); + } +} + +void ConfigurationManager::sipRegistrationStateChanged(const std::string& accountID, const std::string& state, const int32_t& code) +{ + if (evHandlers_.on_sip_registration_state_change) { + evHandlers_.on_sip_registration_state_change(accountID, state, code); + } +} + +void ConfigurationManager::errorAlert(const int& alert) +{ + if (evHandlers_.on_error) { + evHandlers_.on_error(alert); + } +} + +std::vector< int32_t > ConfigurationManager::getHardwareAudioFormat() +{ + return std::vector<int32_t> {}; +} diff --git a/daemon/src/client/configurationmanager.h b/daemon/src/client/configurationmanager.h index 96467ca5cb..db75fa4a8a 100644 --- a/daemon/src/client/configurationmanager.h +++ b/daemon/src/client/configurationmanager.h @@ -38,46 +38,20 @@ #include "config.h" #endif -#if HAVE_DBUS - -#include "dbus/dbus_cpp.h" - -#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 6 -#pragma GCC diagnostic ignored "-Wunused-but-set-variable" -#endif - -#pragma GCC diagnostic ignored "-Wignored-qualifiers" -#pragma GCC diagnostic ignored "-Wunused-parameter" -#pragma GCC diagnostic ignored "-Weffc++" -#include "dbus/configurationmanager-glue.h" -#pragma GCC diagnostic warning "-Wignored-qualifiers" -#pragma GCC diagnostic warning "-Wunused-parameter" -#pragma GCC diagnostic warning "-Weffc++" - -#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 6 -#pragma GCC diagnostic warning "-Wunused-but-set-variable" -#endif - -#else -// these includes normally come with DBus C++ #include <vector> #include <map> #include <string> -#endif // HAVE_DBUS + +#include "sflphone.h" class ConfigurationManager -#if HAVE_DBUS - : public org::sflphone::SFLphone::ConfigurationManager_adaptor, - public DBus::IntrospectableAdaptor, - public DBus::ObjectAdaptor -#endif { public: -#if HAVE_DBUS - ConfigurationManager(DBus::Connection& connection); -#else ConfigurationManager(); -#endif + void registerEvHandlers(struct sflph_config_ev_handlers* evHandlers); + + // Methods + public: std::map< std::string, std::string > getAccountDetails(const std::string& accountID); void setAccountDetails(const std::string& accountID, const std::map< std::string, std::string >& details); std::map<std::string, std::string> getAccountTemplate(); @@ -125,7 +99,6 @@ class ConfigurationManager std::string getAudioManager(); bool setAudioManager(const std::string& api); - std::vector<std::string> getSupportedAudioManagers(); int32_t isIax2Enabled(); std::string getRecordPath(); @@ -171,9 +144,8 @@ class ConfigurationManager bool checkHostnameCertificate(const std::string& host, const std::string& port); - /* the following signals must be implemented manually for any - * platform or configuration that does not supply dbus */ -#if !HAVE_DBUS + // Signals + public: void volumeChanged(const std::string& device, const int& value); void accountsChanged(); @@ -186,8 +158,11 @@ class ConfigurationManager void sipRegistrationStateChanged(const std::string&, const std::string&, const int32_t&); void errorAlert(const int& alert); - std::vector< int32_t > getHardwareAudioFormat(); -#endif // !HAVE_DBUS + std::vector< int32_t > getHardwareAudioFormat(); + + private: + // Event handlers; needed by the library API + struct sflph_config_ev_handlers evHandlers_; }; #endif //CONFIGURATIONMANAGER_H diff --git a/daemon/src/client/configurationmanager_stub.cpp b/daemon/src/client/configurationmanager_stub.cpp deleted file mode 100644 index 331559f03f..0000000000 --- a/daemon/src/client/configurationmanager_stub.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2014 Savoir-Faire Linux Inc. - * Author: Vittorio Giovara <vittorio.giovara@savoirfairelinux.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * Additional permission under GNU GPL version 3 section 7: - * - * If you modify this program, or any covered work, by linking or - * combining it with the OpenSSL project's OpenSSL library (or a - * modified version of that library), containing parts covered by the - * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. - * grants you additional permission to convey the resulting work. - * Corresponding Source for a non-source form of such a combination - * shall include the source code for the parts of OpenSSL used as well - * as that of the covered work. - */ - -#warning Using a stub file will produce a non working application - -#include "client/configurationmanager.h" - -ConfigurationManager::ConfigurationManager() {} - -void ConfigurationManager::accountsChanged() -{ -} - -void ConfigurationManager::historyChanged() -{ -} - -void ConfigurationManager::stunStatusFailure(const std::string& accountID) -{ -} - -void ConfigurationManager::volumeChanged(const std::string&, - const int&) -{ -} - -void ConfigurationManager::registrationStateChanged(const std::string& accountID, - int const& state) -{ -} - -void ConfigurationManager::sipRegistrationStateChanged(const std::string& accountID, - const std::string& state, - const int32_t& code) -{ -} - -void ConfigurationManager::errorAlert(const int& alertmsg) -{ -} - -std::vector< int32_t > ConfigurationManager::getHardwareAudioFormat() -{ - return std::vector<int32_t>(); -} - -std::vector<std::string> ConfigurationManager::getSupportedAudioManagers() -{ - return {"STUB"}; -} diff --git a/daemon/src/client/dbus/README b/daemon/src/client/dbus/README deleted file mode 100644 index 45fdf4b41a..0000000000 --- a/daemon/src/client/dbus/README +++ /dev/null @@ -1,24 +0,0 @@ -To build a new dbus interface: - -1. Define the API with a xml file. -2. Generate the glue.h header by running "dbusxx-xml2cpp file.xml --adaptor=file.h" -3. Inheritate from that glue.h class in your code. - -Examples: -dbusxx-xml2cpp callmanager-introspec.xml --adaptor=callmanager-glue.h -dbusxx-xml2cpp configurationmanager-introspec.xml --adaptor=configurationmanager-glue.h -dbusxx-xml2cpp contactmanager-introspec.xml --adaptor=contactmanager-glue.h - -dbusxx-xml2cpp instance-introspec.xml --adaptor=instance-glue.h - -Warning : depending on the dbusxx-xml2cpp version used, it can generate buggy code - -code generated - -::DBus::IntrospectedInterface *const introspect() const - -instead of - -::DBus::IntrospectedInterface *introspect() const - -This issue is dealt with in make-swig.sh diff --git a/daemon/src/client/dbus/callmanager_dbus.cpp b/daemon/src/client/dbus/callmanager_dbus.cpp deleted file mode 100644 index 15822036e8..0000000000 --- a/daemon/src/client/dbus/callmanager_dbus.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2004-2013 Savoir-Faire Linux Inc. - * Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com> - * Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Additional permission under GNU GPL version 3 section 7: - * - * If you modify this program, or any covered work, by linking or - * combining it with the OpenSSL project's OpenSSL library (or a - * modified version of that library), containing parts covered by the - * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. - * grants you additional permission to convey the resulting work. - * Corresponding Source for a non-source form of such a combination - * shall include the source code for the parts of OpenSSL used as well - * as that of the covered work. - */ -#include "callmanager.h" - -CallManager::CallManager(DBus::Connection& connection) - : DBus::ObjectAdaptor(connection, "/org/sflphone/SFLphone/CallManager") -{} diff --git a/daemon/src/client/dbus/client.cpp b/daemon/src/client/dbus/client.cpp deleted file mode 100644 index 5f46cf846b..0000000000 --- a/daemon/src/client/dbus/client.cpp +++ /dev/null @@ -1,219 +0,0 @@ -/* - * Copyright (C) 2004-2013 Savoir-Faire Linux Inc. - * Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Additional permission under GNU GPL version 3 section 7: - * - * If you modify this program, or any covered work, by linking or - * combining it with the OpenSSL project's OpenSSL library (or a - * modified version of that library), containing parts covered by the - * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. - * grants you additional permission to convey the resulting work. - * Corresponding Source for a non-source form of such a combination - * shall include the source code for the parts of OpenSSL used as well - * as that of the covered work. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <cstdlib> -#include "client/client.h" -#include "global.h" -#include "manager.h" -#include "logger.h" -#include "instance.h" - -#include "dbus_cpp.h" - -#include "callmanager.h" -#include "configurationmanager.h" -#include "networkmanager.h" - -#ifdef SFL_PRESENCE -#include "presencemanager.h" -#endif - -#ifdef SFL_VIDEO -#include "videomanager.h" -#endif - -struct EventCallback : DBus::Callback_Base<void, DBus::DefaultTimeout&> -{ - EventCallback(const std::function<void()> &func) : - callback_(func) - {} - - void call(DBus::DefaultTimeout &) const - { - callback_(); - } - -private: - std::function<void()> callback_; -}; - -Client::Client() : callManager_(0) - , configurationManager_(0) -#ifdef SFL_PRESENCE - , presenceManager_(0) -#endif - , instanceManager_(0) - , dispatcher_(new DBus::BusDispatcher) -#ifdef SFL_VIDEO - , videoManager_(0) -#endif -#ifdef USE_NETWORKMANAGER - , networkManager_(0) -#endif -{ - try { - DEBUG("DBUS init threading"); - DBus::_init_threading(); - DEBUG("DBUS instantiate default dispatcher"); - DBus::default_dispatcher = dispatcher_; - - DEBUG("DBUS session connection to session bus"); - DBus::Connection sessionConnection(DBus::Connection::SessionBus()); - DEBUG("DBUS request org.sflphone.SFLphone from session connection"); - sessionConnection.request_name("org.sflphone.SFLphone"); - - DEBUG("DBUS create call manager from session connection"); - callManager_ = new CallManager(sessionConnection); - DEBUG("DBUS create configuration manager from session connection"); - configurationManager_ = new ConfigurationManager(sessionConnection); - DEBUG("DBUS create presence manager from session connection"); - -#ifdef SFL_PRESENCE - presenceManager_ = new PresenceManager(sessionConnection); - DEBUG("DBUS create instance manager from session connection"); -#endif - instanceManager_ = new Instance(sessionConnection); - -#ifdef SFL_VIDEO - videoManager_ = new VideoManager(sessionConnection); -#endif - -#ifdef USE_NETWORKMANAGER - DEBUG("DBUS system connection to system bus"); - DBus::Connection systemConnection(DBus::Connection::SystemBus()); - DEBUG("DBUS create the network manager from the system bus"); - networkManager_ = new NetworkManager(systemConnection, "/org/freedesktop/NetworkManager", ""); -#endif - - } catch (const DBus::Error &err) { - ERROR("%s: %s, exiting\n", err.name(), err.what()); - ::exit(EXIT_FAILURE); - } - - DEBUG("DBUS registration done"); - instanceManager_->started(); -} - -Client::~Client() -{ -#ifdef USE_NETWORKMANAGER - delete networkManager_; -#endif -#ifdef SFL_VIDEO - delete videoManager_; -#endif - delete instanceManager_; -#ifdef SFL_PRESENCE - delete presenceManager_; -#endif - delete configurationManager_; - delete callManager_; - delete dispatcher_; -} - -void -Client::registerCallback(const std::function<void()> &callback) -{ - // timeout and expired are deleted internally by dispatcher_'s - // destructor, so we must NOT delete them ourselves. - DBus::DefaultTimeout *timeout = new DBus::DefaultTimeout(10 /* ms */, - true, - dispatcher_); - timeout->expired = new EventCallback(callback); -} - - -int Client::event_loop() -{ - try { - dispatcher_->enter(); - } catch (const DBus::Error &err) { - ERROR("%s: %s, quitting\n", err.name(), err.what()); - return 1; - } catch (const std::exception &err) { - ERROR("%s: quitting\n", err.what()); - return 1; - } - - return 0; -} - -int Client::exit() -{ - try { - dispatcher_->leave(); - } catch (const DBus::Error &err) { - ERROR("%s: %s, quitting\n", err.name(), err.what()); - return 1; - } catch (const std::exception &err) { - ERROR("%s: quitting\n", err.what()); - return 1; - } - return 0; -} - -CallManager * -Client::getCallManager() -{ - return callManager_; -} - -ConfigurationManager * -Client::getConfigurationManager() -{ - return configurationManager_; -} - -#ifdef SFL_PRESENCE -PresenceManager * -Client::getPresenceManager() -{ - return presenceManager_; -} -#endif - -#ifdef SFL_VIDEO -VideoManager* -Client::getVideoManager() -{ - return videoManager_; -} -#endif - -void -Client::onLastUnregister() -{ - if (not isPersistent_) - exit(); -} diff --git a/daemon/src/client/dbus/configurationmanager_dbus.cpp b/daemon/src/client/dbus/configurationmanager_dbus.cpp deleted file mode 100644 index ee3b0fc00d..0000000000 --- a/daemon/src/client/dbus/configurationmanager_dbus.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2004-2013 Savoir-Faire Linux Inc. - * Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com> - * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> - * Author: Guillaume Carmel-Archambault <guillaume.carmel-archambault@savoirfairelinux.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Additional permission under GNU GPL version 3 section 7: - * - * If you modify this program, or any covered work, by linking or - * combining it with the OpenSSL project's OpenSSL library (or a - * modified version of that library), containing parts covered by the - * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. - * grants you additional permission to convey the resulting work. - * Corresponding Source for a non-source form of such a combination - * shall include the source code for the parts of OpenSSL used as well - * as that of the covered work. - */ - -#include "configurationmanager.h" -#include "global.h" - -static const char* SERVER_PATH = "/org/sflphone/SFLphone/ConfigurationManager"; - -ConfigurationManager::ConfigurationManager(DBus::Connection& connection) : - DBus::ObjectAdaptor(connection, SERVER_PATH) -{} - -std::vector<std::string> -ConfigurationManager::getSupportedAudioManagers() -{ - return { -#if HAVE_ALSA - ALSA_API_STR, -#endif -#if HAVE_PULSE - PULSEAUDIO_API_STR, -#endif -#if HAVE_JACK - JACK_API_STR, -#endif - }; -} diff --git a/daemon/src/client/dbus/networkmanager_proxy.h b/daemon/src/client/dbus/networkmanager_proxy.h deleted file mode 100644 index 56ee150934..0000000000 --- a/daemon/src/client/dbus/networkmanager_proxy.h +++ /dev/null @@ -1,73 +0,0 @@ - -/* - * This file was automatically generated by dbusxx-xml2cpp; DO NOT EDIT! - */ - -#ifndef __dbusxx__networkmanager_proxy_h__PROXY_MARSHAL_H -#define __dbusxx__networkmanager_proxy_h__PROXY_MARSHAL_H - -#include "dbus_cpp.h" - -namespace org { -namespace freedesktop { - -class NetworkManager_proxy - : public ::DBus::InterfaceProxy { - public: - - NetworkManager_proxy() - : ::DBus::InterfaceProxy("org.freedesktop.NetworkManager") { - connect_signal(NetworkManager_proxy, StateChanged, _StateChanged_stub); - connect_signal(NetworkManager_proxy, PropertiesChanged, _PropertiesChanged_stub); - } - - public: - - /* properties exported by this interface */ - public: - - /* methods exported by this interface, - * this functions will invoke the corresponding methods on the remote objects - */ - std::vector< ::DBus::Path > GetDevices() { - ::DBus::CallMessage call; - call.member("GetDevices"); - ::DBus::Message ret = invoke_method(call); - ::DBus::MessageIter ri = ret.reader(); - - std::vector< ::DBus::Path > argout; - ri >> argout; - return argout; - } - - - public: - - /* signal handlers for this interface - */ - virtual void StateChanged(const uint32_t& argin0) = 0; - virtual void PropertiesChanged(const std::map< std::string, ::DBus::Variant >& argin0) = 0; - - private: - - /* unmarshalers (to unpack the DBus message before calling the actual signal handler) - */ - void _StateChanged_stub(const ::DBus::SignalMessage &sig) { - ::DBus::MessageIter ri = sig.reader(); - - uint32_t arg0; - ri >> arg0; - StateChanged(arg0); - } - void _PropertiesChanged_stub(const ::DBus::SignalMessage &sig) { - ::DBus::MessageIter ri = sig.reader(); - - std::map< std::string, ::DBus::Variant > arg0; - ri >> arg0; - PropertiesChanged(arg0); - } -}; - -} -} -#endif //__dbusxx__networkmanager_proxy_h__PROXY_MARSHAL_H diff --git a/daemon/src/client/dbus/org.freedesktop.NetworkManager.xml b/daemon/src/client/dbus/org.freedesktop.NetworkManager.xml deleted file mode 100644 index a98db8123b..0000000000 --- a/daemon/src/client/dbus/org.freedesktop.NetworkManager.xml +++ /dev/null @@ -1,15 +0,0 @@ -<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" -"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> -<node> - <interface name="org.freedesktop.NetworkManager"> - <method name="GetDevices"> - <arg name="devices" type="ao" direction="out"/> - </method> - <signal name="StateChanged"> - <arg type="u"/> - </signal> - <signal name="PropertiesChanged"> - <arg type="a{sv}"/> - </signal> - </interface> -</node> diff --git a/daemon/src/client/dbus/presencemanager_dbus.cpp b/daemon/src/client/dbus/presencemanager_dbus.cpp deleted file mode 100644 index ff4ab40eb6..0000000000 --- a/daemon/src/client/dbus/presencemanager_dbus.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2013 Savoir-Faire Linux Inc. - * Author: Patrick Keroulas <patrick.keroulas@savoirfairelinux.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Additional permission under GNU GPL version 3 section 7: - * - * If you modify this program, or any covered work, by linking or - * combining it with the OpenSSL project's OpenSSL library (or a - * modified version of that library), containing parts covered by the - * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. - * grants you additional permission to convey the resulting work. - * Corresponding Source for a non-source form of such a combination - * shall include the source code for the parts of OpenSSL used as well - * as that of the covered work. - */ - -#include "presencemanager.h" - -constexpr static const char* SERVER_PATH = "/org/sflphone/SFLphone/PresenceManager"; -constexpr static const char* STATUS_KEY = "Status"; -constexpr static const char* LINESTATUS_KEY = "LineStatus"; -constexpr static const char* ONLINE_KEY = "Online"; -constexpr static const char* OFFLINE_KEY = "Offline"; - -PresenceManager::PresenceManager(DBus::Connection& connection) : - DBus::ObjectAdaptor(connection, SERVER_PATH) -{} diff --git a/daemon/src/client/dbus/videomanager_dbus.cpp b/daemon/src/client/dbus/videomanager_dbus.cpp deleted file mode 100644 index 5a245c3b62..0000000000 --- a/daemon/src/client/dbus/videomanager_dbus.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2004-2014 Savoir-Faire Linux Inc. - * Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@savoirfairelinux.com> - * Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> - * Author: Guillaume Carmel-Archambault <guillaume.carmel-archambault@savoirfairelinux.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Additional permission under GNU GPL version 3 section 7: - * - * If you modify this program, or any covered work, by linking or - * combining it with the OpenSSL project's OpenSSL library (or a - * modified version of that library), containing parts covered by the - * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. - * grants you additional permission to convey the resulting work. - * Corresponding Source for a non-source form of such a combination - * shall include the source code for the parts of OpenSSL used as well - * as that of the covered work. - */ - -#include "videomanager.h" -#include "video/libav_utils.h" -#include "video/video_input.h" -#include "video/video_device_monitor.h" - -VideoManager::VideoManager(DBus::Connection& connection) : - DBus::ObjectAdaptor(connection, "/org/sflphone/SFLphone/VideoManager") -{ - // initialize libav libraries - libav_utils::sfl_avcodec_init(); -} diff --git a/daemon/src/client/presencemanager.cpp b/daemon/src/client/presencemanager.cpp index 32e2578e3f..1defbc60f5 100644 --- a/daemon/src/client/presencemanager.cpp +++ b/daemon/src/client/presencemanager.cpp @@ -36,6 +36,7 @@ #include <cerrno> #include <sstream> +#include <cstring> #include "logger.h" #include "manager.h" @@ -48,6 +49,16 @@ constexpr static const char* LINESTATUS_KEY = "LineStatus"; constexpr static const char* ONLINE_KEY = "Online"; constexpr static const char* OFFLINE_KEY = "Offline"; +PresenceManager::PresenceManager() +{ + std::memset(std::addressof(evHandlers_), 0, sizeof(evHandlers_)); +} + +void PresenceManager::registerEvHandlers(struct sflph_pres_ev_handlers* evHandlers) +{ + evHandlers_ = *evHandlers; +} + /** * Un/subscribe to buddySipUri for an accountID */ @@ -169,3 +180,33 @@ PresenceManager::setSubscriptions(const std::string& accountID, const std::vecto for (const auto &u : uris) pres->subscribeClient(u, true); } + +void PresenceManager::newServerSubscriptionRequest(const std::string& remote) +{ + if (evHandlers_.on_new_server_subscription_request) { + evHandlers_.on_new_server_subscription_request(remote); + } +} + +void PresenceManager::serverError(const std::string& accountID, const std::string& error, const std::string& msg) +{ + if (evHandlers_.on_server_error) { + evHandlers_.on_server_error(accountID, error, msg); + } +} + +void PresenceManager::newBuddyNotification(const std::string& accountID, const std::string& buddyUri, + const bool& status, const std::string& lineStatus) +{ + if (evHandlers_.on_new_buddy_notification) { + evHandlers_.on_new_buddy_notification(accountID, buddyUri, status, lineStatus); + } +} + +void PresenceManager::subscriptionStateChanged(const std::string& accountID, const std::string& buddyUri, + const bool& state) +{ + if (evHandlers_.on_subscription_state_change) { + evHandlers_.on_subscription_state_change(accountID, buddyUri, state); + } +} diff --git a/daemon/src/client/presencemanager.h b/daemon/src/client/presencemanager.h index 3aaaaed17b..60063f3c0e 100644 --- a/daemon/src/client/presencemanager.h +++ b/daemon/src/client/presencemanager.h @@ -35,65 +35,38 @@ #include "config.h" #endif -#if HAVE_DBUS - -#include "dbus/dbus_cpp.h" - -#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 6 -#pragma GCC diagnostic ignored "-Wunused-but-set-variable" -#endif - -#pragma GCC diagnostic ignored "-Wignored-qualifiers" -#pragma GCC diagnostic ignored "-Wunused-parameter" -#pragma GCC diagnostic ignored "-Weffc++" -#include "dbus/presencemanager-glue.h" -#pragma GCC diagnostic warning "-Wignored-qualifiers" -#pragma GCC diagnostic warning "-Wunused-parameter" -#pragma GCC diagnostic warning "-Weffc++" - -#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 6 -#pragma GCC diagnostic warning "-Wunused-but-set-variable" -#endif - -#else -// these includes normally come with DBus C++ #include <vector> -#include <map> #include <string> -#endif // HAVE_DBUS + +#include "sflphone.h" class PresenceManager -#if HAVE_DBUS - : public org::sflphone::SFLphone::PresenceManager_adaptor, - public DBus::IntrospectableAdaptor, - public DBus::ObjectAdaptor -#endif { public: -#if HAVE_DBUS - PresenceManager(DBus::Connection& connection); -#else PresenceManager(); -#endif + void registerEvHandlers(struct sflph_pres_ev_handlers* evHandlers); - /* the following signals must be implemented manually for any - * platform or configuration that does not supply dbus */ -#if !HAVE_DBUS - void newServerSubscriptionRequest(const std::string& remote); - void serverError(const std::string& accountID, const std::string& error, const std::string& msg); - void newBuddyNotification(const std::string& accountID, const std::string& buddyUri, - const bool& status, const std::string& lineStatus); - void subscriptionStateChanged(const std::string& accountID, const std::string& buddyUri, - const bool& state); -#endif // !HAVE_DBUS + // Methods + public: + /* Presence subscription/Notification. */ + void publish(const std::string& accountID, const bool& status, const std::string& note); + void answerServerRequest(const std::string& uri, const bool& flag); + void subscribeBuddy(const std::string& accountID, const std::string& uri, const bool& flag); + std::vector<std::map<std::string, std::string> > getSubscriptions(const std::string& accountID); + void setSubscriptions(const std::string& accountID, const std::vector<std::string>& uris); - /* Presence subscription/Notification. */ - void publish(const std::string& accountID, const bool& status, const std::string& note); - void answerServerRequest(const std::string& uri, const bool& flag); - void subscribeBuddy(const std::string& accountID, const std::string& uri, const bool& flag); - std::vector<std::map<std::string, std::string> > getSubscriptions(const std::string& accountID); - void setSubscriptions(const std::string& accountID, const std::vector<std::string>& uris); + // Signals + public: + void newServerSubscriptionRequest(const std::string& remote); + void serverError(const std::string& accountID, const std::string& error, const std::string& msg); + void newBuddyNotification(const std::string& accountID, const std::string& buddyUri, + const bool& status, const std::string& lineStatus); + void subscriptionStateChanged(const std::string& accountID, const std::string& buddyUri, + const bool& state); + private: + // Event handlers; needed by the library API + struct sflph_pres_ev_handlers evHandlers_; }; -#endif //CONFIGURATIONMANAGER_H +#endif //PRESENCEINT_H diff --git a/daemon/src/client/presencemanager_stub.cpp b/daemon/src/client/presencemanager_stub.cpp deleted file mode 100644 index ee817f260c..0000000000 --- a/daemon/src/client/presencemanager_stub.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2013 Savoir-Faire Linux Inc. - * Author: Patrick Keroulas <patrick.keroulas@savoirfairelinux.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Additional permission under GNU GPL version 3 section 7: - * - * If you modify this program, or any covered work, by linking or - * combining it with the OpenSSL project's OpenSSL library (or a - * modified version of that library), containing parts covered by the - * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. - * grants you additional permission to convey the resulting work. - * Corresponding Source for a non-source form of such a combination - * shall include the source code for the parts of OpenSSL used as well - * as that of the covered work. - */ - -#warning Using a stub file will produce a non working application - -#include "client/presencemanager.h" - -PresenceManager::PresenceManager() -{} - -void PresenceManager::newBuddyNotification(const std::string& accountID, - const std::string& buddyUri, - const bool& status, - const std::string& lineStatus) -{ -} - -void PresenceManager::subscriptionStateChanged(const std::string& accountID, - const std::string& buddyUri, - const bool& state) -{ -} - -void PresenceManager::newServerSubscriptionRequest(const std::string& remote) -{ -} - -void PresenceManager::serverError(const std::string& accountID, - const std::string& error, - const std::string& msg) -{ -} diff --git a/daemon/src/client/videomanager.cpp b/daemon/src/client/videomanager.cpp index 82582c22e0..106cccdf7f 100644 --- a/daemon/src/client/videomanager.cpp +++ b/daemon/src/client/videomanager.cpp @@ -38,6 +38,17 @@ #include "logger.h" #include "manager.h" +VideoManager::VideoManager() +{ + std::memset(std::addressof(evHandlers_), 0, sizeof(evHandlers_)); + libav_utils::sfl_avcodec_init(); +} + +void VideoManager::registerEvHandlers(struct sflph_video_ev_handlers* evHandlers) +{ + evHandlers_ = *evHandlers; +} + sfl_video::VideoDeviceMonitor & VideoManager::getVideoDeviceMonitor() { @@ -155,3 +166,24 @@ VideoManager::getCurrentCodecName(const std::string & /*callID*/) { return ""; } + +void VideoManager::deviceEvent() +{ + if (evHandlers_.on_device_event) { + evHandlers_.on_device_event(); + } +} + +void VideoManager::startedDecoding(const std::string &id, const std::string& shmPath, int w, int h, bool isMixer) +{ + if (evHandlers_.on_start_decoding) { + evHandlers_.on_start_decoding(id, shmPath, w, h, isMixer); + } +} + +void VideoManager::stoppedDecoding(const std::string &id, const std::string& shmPath, bool isMixer) +{ + if (evHandlers_.on_stop_decoding) { + evHandlers_.on_stop_decoding(id, shmPath, isMixer); + } +} diff --git a/daemon/src/client/videomanager.h b/daemon/src/client/videomanager.h index 18e449aff7..ef0787ebed 100644 --- a/daemon/src/client/videomanager.h +++ b/daemon/src/client/videomanager.h @@ -34,38 +34,18 @@ #include "config.h" #endif -#if HAVE_DBUS -#include "dbus/dbus_cpp.h" - -#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 6 -/* This warning option only exists for gcc 4.6.0 and greater. */ -#pragma GCC diagnostic ignored "-Wunused-but-set-variable" -#endif - -#pragma GCC diagnostic ignored "-Wignored-qualifiers" -#pragma GCC diagnostic ignored "-Wunused-parameter" -#include "dbus/videomanager-glue.h" -#pragma GCC diagnostic warning "-Wignored-qualifiers" -#pragma GCC diagnostic warning "-Wunused-parameter" - -#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 6 -/* This warning option only exists for gcc 4.6.0 and greater. */ -#pragma GCC diagnostic warning "-Wunused-but-set-variable" -#endif - -#endif // HAVE_DBUS - #include <memory> // for weak/shared_ptr +#include <vector> +#include <map> +#include <string> + #include "video/video_device_monitor.h" #include "video/video_base.h" #include "video/video_input.h" +#include "sflphone.h" + class VideoManager -#if HAVE_DBUS - : public org::sflphone::SFLphone::VideoManager_adaptor, - public DBus::IntrospectableAdaptor, - public DBus::ObjectAdaptor -#endif { private: /* VideoManager acts as a cache of the active VideoInput. @@ -81,13 +61,12 @@ class VideoManager sfl_video::VideoDeviceMonitor videoDeviceMonitor_ = {}; public: -#if HAVE_DBUS - VideoManager(DBus::Connection& connection); -#else VideoManager(); -#endif + void registerEvHandlers(struct sflph_video_ev_handlers* evHandlers); sfl_video::VideoDeviceMonitor& getVideoDeviceMonitor(); + // Methods + public: std::vector<std::map<std::string, std::string> > getCodecs(const std::string& accountID); @@ -124,13 +103,14 @@ class VideoManager bool switchToCamera(); std::shared_ptr<sfl_video::VideoFrameActiveWriter> getVideoCamera(); - /* the following signals must be implemented manually for any - * platform or configuration that does not supply dbus */ -#if !HAVE_DBUS + // Signals + public: void deviceEvent(); - void startedDecoding(const std::string &id, const std::string, int w, int h); - void stoppedDecoding(const std::string &id, const std::string); -#endif // !HAVE_DBUS + void startedDecoding(const std::string &id, const std::string& shmPath, int w, int h, bool isMixer); + void stoppedDecoding(const std::string &id, const std::string& shmPath, bool isMixer); + + private: + struct sflph_video_ev_handlers evHandlers_; }; #endif // VIDEOMANAGER_H_ diff --git a/daemon/src/client/videomanager_stub.cpp b/daemon/src/client/videomanager_stub.cpp deleted file mode 100644 index b61a692711..0000000000 --- a/daemon/src/client/videomanager_stub.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright (C) 2013 Savoir-Faire Linux Inc. - * Author: Patrick Keroulas <patrick.keroulas@savoirfairelinux.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Additional permission under GNU GPL version 3 section 7: - * - * If you modify this program, or any covered work, by linking or - * combining it with the OpenSSL project's OpenSSL library (or a - * modified version of that library), containing parts covered by the - * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. - * grants you additional permission to convey the resulting work. - * Corresponding Source for a non-source form of such a combination - * shall include the source code for the parts of OpenSSL used as well - * as that of the covered work. - */ - -#warning Using a stub file will produce a non working application - -#include "client/videomanager.h" - -VideoManager::VideoManager() -{} - -VideoDeviceMonitor& VideoManager::getVideoDeviceMonitor() -{ -} - -void VideoManager::deviceEvent() -{ -} - -void VideoManager::startedDecoding(const std::string &id, const std::string, - int w, int h) -{ -} - -void VideoManager::stoppedDecoding(const std::string &id, const std::string) -{ -} - -VideoCapabilities -VideoManager::getCapabilities(const std::string& name); -{ - return VideoCapabilities(); -} - -std::map<std::string, std::string> VideoManager::getSettings(const std::string& name) -{ - return std::map<std::string, std::string>(); -} - -void -VideoManager::applySettings(const std::string& name, - std::map<std::string, std::string> settings) -{ -} - -bool VideoManager::hasCameraStarted() -{ - return false; -} - -void VideoManager::startCamera() -{ -} - -void VideoManager::stopCamera() -{ -} - -std::weak_ptr<sfl_video::VideoFrameActiveWriter> VideoManager::getVideoCamera() -{ - return std::weak_ptr<sfl_video::VideoFrameActiveWriter>(); -} diff --git a/daemon/src/main.cpp b/daemon/src/main.cpp deleted file mode 100644 index 4142b361be..0000000000 --- a/daemon/src/main.cpp +++ /dev/null @@ -1,207 +0,0 @@ -/* - * Copyright (C) 2004-2013 Savoir-Faire Linux Inc. - * Author: Alexandre Bourget <alexandre.bourget@savoirfairelinux.com> - * Author: Yan Morin <yan.morin@savoirfairelinux.com> - * Author: Laurielle Lea <laurielle.lea@savoirfairelinux.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Additional permission under GNU GPL version 3 section 7: - * - * If you modify this program, or any covered work, by linking or - * combining it with the OpenSSL project's OpenSSL library (or a - * modified version of that library), containing parts covered by the - * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. - * grants you additional permission to convey the resulting work. - * Corresponding Source for a non-source form of such a combination - * shall include the source code for the parts of OpenSSL used as well - * as that of the covered work. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <iostream> -#include <thread> -#include <signal.h> -#include <getopt.h> -#include "fileutils.h" -#include "logger.h" -#include "manager.h" - -static void -print_title() -{ - std::cout << "SFLphone Daemon " << VERSION << - ", by Savoir-Faire Linux 2004-2014" << std::endl << - "http://www.sflphone.org/" << std::endl; -} - -static void -print_usage() -{ - std::cout << std::endl << - "-c, --console \t- Log in console (instead of syslog)" << std::endl << - "-d, --debug \t- Debug mode (more verbose)" << std::endl << - "-p, --persistent \t- Stay alive after client quits" << std::endl << - "-h, --help \t- Print help" << std::endl; -} - -// Parse command line arguments, setting debug options or printing a help -// message accordingly. -// returns true if we should quit (i.e. help was printed), false otherwise -static bool -parse_args(int argc, char *argv[], bool &persistent) -{ - int consoleFlag = false; - int debugFlag = false; - int helpFlag = false; - int versionFlag = false; - static const struct option long_options[] = { - /* These options set a flag. */ - {"debug", no_argument, NULL, 'd'}, - {"console", no_argument, NULL, 'c'}, - {"persistent", no_argument, NULL, 'p'}, - {"help", no_argument, NULL, 'h'}, - {"version", no_argument, NULL, 'v'}, - {0, 0, 0, 0} /* Sentinel */ - }; - - while (true) { - /* getopt_long stores the option index here. */ - int option_index = 0; - int c = getopt_long(argc, argv, "dcphv", long_options, &option_index); - - /* Detect the end of the options. */ - if (c == -1) - break; - - switch (c) { - case 'd': - debugFlag = true; - break; - - case 'c': - consoleFlag = true; - break; - - case 'p': - persistent = true; - break; - - case 'h': - case '?': - helpFlag = true; - break; - - case 'v': - versionFlag = true; - break; - - default: - break; - } - } - - bool quit = false; - if (helpFlag) { - print_usage(); - quit = true; - } else if (versionFlag) { - // We've always print the title/version, so we can just exit - quit = true; - } else { - setConsoleLog(consoleFlag); - setDebugMode(debugFlag); - } - return quit; -} - -static void -signal_handler(int code) -{ - // Unset signal handlers - signal(SIGHUP, SIG_DFL); - signal(SIGINT, SIG_DFL); - signal(SIGTERM, SIG_DFL); - - // Stop manager in new thread since we don't know what - // this handler is interrupting (e.g. a mutex might be held in the - // interrupted function) - std::thread th([code] { - Manager::instance().interrupt(); - std::cerr << "Caught signal " << strsignal(code) - << ", terminating..." << std::endl; - }); - - // Detach thread and leave signal handler so that interrupted thread - // can continue - th.detach(); -} - -int -main(int argc, char *argv []) -{ - // make a copy as we don't want to modify argv[0], copy it to a vector to - // guarantee that memory is correctly managed/exception safe - std::string programName(argv[0]); - std::vector<char> writable(programName.size() + 1); - std::copy(programName.begin(), programName.end(), writable.begin()); - - fileutils::set_program_dir(writable.data()); - - print_title(); - bool persistent = false; - - if (parse_args(argc, argv, persistent)) - return 0; - - fileutils::FileHandle f(fileutils::create_pidfile()); - if (f.fd == -1) { - std::cerr << "An " PACKAGE_NAME << - " instance is already running, quitting..." << std::endl; - return 1; - } - - try { - Manager::instance().init(""); - } catch (const std::exception &e) { - std::cerr << e.what() << std::endl; - return 1; - } catch (...) { - std::cerr << "An exception occured when initializing " PACKAGE << - std::endl; - return 1; - } - - // TODO: Block signals for all threads but the main thread, decide how/if we should - // handle other signals - signal(SIGINT, signal_handler); - signal(SIGHUP, signal_handler); - signal(SIGTERM, signal_handler); - - int ret = 0; -#ifdef SFL_VIDEO - WARN("Built with video support"); -#endif -#if HAVE_DBUS - Manager::instance().getClient()->setPersistent(persistent); -#endif - ret = Manager::instance().run(); - Manager::instance().finish(); - - return ret; -} diff --git a/daemon/src/managerimpl.cpp b/daemon/src/managerimpl.cpp index b74883c56c..1b09b8e04f 100644 --- a/daemon/src/managerimpl.cpp +++ b/daemon/src/managerimpl.cpp @@ -237,22 +237,6 @@ ManagerImpl::setPath(const std::string &path) history_.setPath(path); } -int -ManagerImpl::run() -{ - DEBUG("Starting client event loop"); - - client_.registerCallback(std::bind(&ManagerImpl::pollEvents, std::ref(*this))); - - return client_.event_loop(); -} - -int -ManagerImpl::interrupt() -{ - return client_.exit(); -} - void ManagerImpl::finish() { diff --git a/daemon/src/managerimpl.h b/daemon/src/managerimpl.h index cdb9c88dae..412e4d0c85 100644 --- a/daemon/src/managerimpl.h +++ b/daemon/src/managerimpl.h @@ -126,15 +126,6 @@ class ManagerImpl { void setPath(const std::string &path); - /** - * Enter mainloop - */ - int run(); - /** - * Interrupt mainloop - */ - int interrupt(); - /* * Terminate all threads and exit DBus loop */ diff --git a/daemon/src/sflphone.h b/daemon/src/sflphone.h new file mode 100644 index 0000000000..ebb11b0f11 --- /dev/null +++ b/daemon/src/sflphone.h @@ -0,0 +1,285 @@ +/* + * Copyright (C) 2014 Savoir-Faire Linux Inc. + * Author: Philippe Proulx <philippe.proulx@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Additional permission under GNU GPL version 3 section 7: + * + * If you modify this program, or any covered work, by linking or + * combining it with the OpenSSL project's OpenSSL library (or a + * modified version of that library), containing parts covered by the + * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. + * grants you additional permission to convey the resulting work. + * Corresponding Source for a non-source form of such a combination + * shall include the source code for the parts of OpenSSL used as well + * as that of the covered work. + */ +#ifndef SFLPHONE_H +#define SFLPHONE_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <vector> +#include <string> +#include <map> + +/* presence events */ +#ifdef SFL_PRESENCE +struct sflph_pres_ev_handlers +{ + void (*on_new_server_subscription_request)(const std::string& remote); + void (*on_server_error)(const std::string& account_id, const std::string& error, const std::string& msg); + void (*on_new_buddy_notification)(const std::string& account_id, const std::string& buddy_uri, int status, const std::string& line_status); + void (*on_subscription_state_change)(const std::string& account_id, const std::string& buddy_uri, int state); +}; +#endif /* SFL_PRESENCE */ + +/* configuration events */ +struct sflph_config_ev_handlers +{ + void (*on_volume_change)(const std::string& device, int value); + void (*on_accounts_change)(void); + void (*on_history_change)(void); + void (*on_stun_status_fail)(const std::string& account_id); + void (*on_registration_state_change)(const std::string& account_id, int state); + void (*on_sip_registration_state_change)(const std::string& account_id, const std::string& state, int code); + void (*on_error)(int alert); +}; + +/* call events */ +struct sflph_call_ev_handlers +{ + void (*on_state_change)(const std::string& call_id, const std::string& state); + void (*on_transfer_fail)(void); + void (*on_transfer_success)(void); + void (*on_record_playback_stopped)(const std::string& path); + void (*on_voice_mail_notify)(const std::string& call_id, int nd_msg); + void (*on_incoming_message)(const std::string& id, const std::string& from, const std::string& msg); + void (*on_incoming_call)(const std::string& account_id, const std::string& call_id, const std::string& from); + void (*on_record_playback_filepath)(const std::string& id, const std::string& filename); + void (*on_conference_created)(const std::string& conf_id); + void (*on_conference_changed)(const std::string& conf_id, const std::string& state); + void (*on_update_playback_scale)(const std::string& filepath, int position, int scale); + void (*on_conference_remove)(const std::string& conf_id); + void (*on_new_call)(const std::string& account_id, const std::string& call_id, const std::string& to); + void (*on_sip_call_state_change)(const std::string& call_id, const std::string& state, int code); + void (*on_record_state_change)(const std::string& call_id, int state); + void (*on_secure_sdes_on)(const std::string& call_id); + void (*on_secure_sdes_off)(const std::string& call_id); + void (*on_secure_zrtp_on)(const std::string& call_id, const std::string& cipher); + void (*on_secure_zrtp_off)(const std::string& call_id); + void (*on_show_sas)(const std::string& call_id, const std::string& sas, int verified); + void (*on_zrtp_not_supp_other)(const std::string& call_id); + void (*on_zrtp_negotiation_fail)(const std::string& call_id, const std::string& reason, const std::string& severity); + void (*on_rtcp_receive_report)(const std::string& call_id, const std::map<std::string, int>& stats); +}; + +/* video events */ +#ifdef SFL_VIDEO +struct sflph_video_ev_handlers +{ + void (*on_device_event)(void); + void (*on_start_decoding)(const std::string& id, const std::string& shm_path, int w, int h, bool is_mixer); + void (*on_stop_decoding)(const std::string& id, const std::string& shm_path, bool is_mixer); +}; +#endif /* SFL_VIDEO */ + +/* all handlers */ +struct sflph_ev_handlers +{ + struct sflph_call_ev_handlers call_ev_handlers; + struct sflph_config_ev_handlers config_ev_handlers; + +#ifdef SFL_PRESENCE + struct sflph_pres_ev_handlers pres_ev_handlers; +#endif /* SFL_PRESENCE */ + +#ifdef SFL_VIDEO + struct sflph_video_ev_handlers video_ev_handlers; +#endif /* SFL_VIDEO */ +}; + +/* error codes returned by functions of this API */ +enum sflph_error { + SFLPH_ERR_MANAGER_INIT, + SFLPH_ERR_UNKNOWN, +}; + +/* flags for initialization */ +enum sflph_init_flag { + SFLPH_FLAG_DEBUG = 1, + SFLPH_FLAG_CONSOLE_LOG = 2, +}; + +/** + * Initializes libsflphone. + * + * @param ev_handlers Event handlers + * @param flags Flags to customize this initialization + * @returns 0 if successful or a negative error code + */ +int sflph_init(struct sflph_ev_handlers* ev_handlers, enum sflph_init_flag flags); + +/** + * Finalizes libsflphone, freeing any resource allocated by the library. + */ +void sflph_fini(void); + +/** + * Poll for SIP/IAX events + */ +void sflph_poll_events(void); + +/* call API */ +bool sflph_call_place(const std::string& account_id, const std::string& call_id, const std::string& to); +bool sflph_call_refuse(const std::string& call_id); +bool sflph_call_accept(const std::string& call_id); +bool sflph_call_hang_up(const std::string& call_id); +bool sflph_call_hold(const std::string& call_id); +bool sflph_call_unhold(const std::string& call_id); +bool sflph_call_transfer(const std::string& call_id, const std::string& to); +bool sflph_call_attended_transfer(const std::string& transfer_id, const std::string& target_id); +std::map<std::string, std::string> sflph_call_get_call_details(const std::string& call_id); +std::vector<std::string> sflph_call_get_call_list(void); +void sflph_call_remove_conference(const std::string& conf_id); +bool sflph_call_join_participant(const std::string& sel_call_id, const std::string& drag_call_id); +void sflph_call_create_conf_from_participant_list(const std::vector<std::string>& participants); +bool sflph_call_is_conference_participant(const std::string& call_id); +bool sflph_call_add_participant(const std::string& call_id, const std::string& conf_id); +bool sflph_call_add_main_participant(const std::string& conf_id); +bool sflph_call_detach_participant(const std::string& call_id); +bool sflph_call_join_conference(const std::string& sel_conf_id, const std::string& drag_conf_id); +bool sflph_call_hang_up_conference(const std::string& conf_id); +bool sflph_call_hold_conference(const std::string& conf_id); +bool sflph_call_unhold_conference(const std::string& conf_id); +std::vector<std::string> sflph_call_get_conference_list(void); +std::vector<std::string> sflph_call_get_participant_list(const std::string& conf_id); +std::vector<std::string> sflph_call_get_display_names(const std::string& conf_id); +std::string sflph_call_get_conference_id(const std::string& call_id); +std::map<std::string, std::string> sflph_call_get_conference_details(const std::string& call_id); +bool sflph_call_play_recorded_file(const std::string& path); +void sflph_call_stop_recorded_file(const std::string& path); +bool sflph_call_toggle_recording(const std::string& call_id); +void sflph_call_set_recording(const std::string& call_id); +void sflph_call_record_playback_seek(double pos); +bool sflph_call_is_recording(const std::string& call_id); +std::string sflph_call_get_current_audio_codec_name(const std::string& call_id); +void sflph_call_play_dtmf(const std::string& key); +void sflph_call_start_tone(int start, int type); +void sflph_call_set_sas_verified(const std::string& call_id); +void sflph_call_reset_sas_verified(const std::string& call_id); +void sflph_call_set_confirm_go_clear(const std::string& call_id); +void sflph_call_request_go_clear(const std::string& call_id); +void sflph_call_accept_enrollment(const std::string& call_id, bool accepted); +void sflph_call_send_text_message(const std::string& call_id, const std::string& message); + +/* configuration API */ +std::map<std::string, std::string> sflph_config_get_account_details(const std::string& account_id); +void sflph_config_set_account_details(const std::string& account_id, const std::map<std::string, std::string>& details); +std::map<std::string, std::string> sflph_config_get_account_template(void); +std::string sflph_config_add_account(const std::map<std::string, std::string>& details); +void sflph_config_remove_account(const std::string& account_id); +std::vector<std::string> sflph_config_get_account_list(void); +void sflph_config_send_register(const std::string& account_id, bool enable); +void sflph_config_register_all_accounts(void); +std::map<std::string, std::string> sflph_config_get_tls_default_settings(void); +std::vector<int> sflph_config_get_audio_codec_list(void); +std::vector<std::string> sflph_config_get_supported_tls_method(void); +std::vector<std::string> sflph_config_get_audio_codec_details(int payload); +std::vector<int> sflph_config_get_active_audio_codec_list(const std::string& account_id); +void sflph_config_set_active_audio_codec_list(const std::vector<std::string>& list, const std::string& account_id); +std::vector<std::string> sflph_config_get_audio_plugin_list(void); +void sflph_config_set_audio_plugin(const std::string& audio_plugin); +std::vector<std::string> sflph_config_get_audio_output_device_list(); +void sflph_config_set_audio_output_device(int index); +void sflph_config_set_audio_input_device(int index); +void sflph_config_set_audio_ringtone_device(int index); +std::vector<std::string> sflph_config_get_audio_input_device_list(void); +std::vector<std::string> sflph_config_get_current_audio_devices_index(void); +int sflph_config_get_audio_input_device_index(const std::string& name); +int sflph_config_get_audio_output_device_index(const std::string& name); +std::string sflph_config_get_current_audio_output_plugin(void); +bool sflph_config_get_noise_suppress_state(void); +void sflph_config_set_noise_suppress_state(bool state); +bool sflph_config_is_agc_enabled(void); +void sflph_config_enable_agc(bool enabled); +void sflph_config_mute_dtmf(bool mute); +bool sflph_config_is_dtmf_muted(void); +bool sflph_config_is_capture_muted(void); +void sflph_config_mute_capture(bool mute); +bool sflph_config_is_playback_muted(void); +void sflph_config_mute_playback(int mute); +std::map<std::string, std::string> sflph_config_get_ringtone_list(void); +std::string sflph_config_get_audio_manager(void); +bool sflph_config_set_audio_manager(const std::string& api); +std::vector<std::string> sflph_config_get_supported_audio_managers(void); +int sflph_config_is_iax2_enabled(void); +std::string sflph_config_get_record_path(void); +void sflph_config_set_record_path(const std::string& path); +bool sflph_config_is_always_recording(void); +void sflph_config_set_always_recording(bool rec); +void sflph_config_set_history_limit(int days); +int sflph_config_get_history_limit(void); +void sflph_config_clear_history(void); +void sflph_config_set_accounts_order(const std::string& order); +std::map<std::string, std::string> sflph_config_get_hook_settings(void); +void sflph_config_set_hook_settings(const std::map<std::string, std::string>& settings); +std::vector<std::map<std::string, std::string>> sflph_config_get_history(void); +std::map<std::string, std::string> sflph_config_get_tls_settings(); +void sflph_config_set_tls_settings(const std::map< std::string, std::string >& settings); +std::map<std::string, std::string> sflph_config_get_ip2ip_details(void); +std::vector<std::map<std::string, std::string>> sflph_config_get_credentials(const std::string& account_id); +void sflph_config_set_credentials(const std::string& account_id, const std::vector<std::map<std::string, std::string>>& details); +std::string sflph_config_get_addr_from_interface_name(const std::string& interface); +std::vector<std::string> sflph_config_get_all_ip_interface(void); +std::vector<std::string> sflph_config_get_all_ip_interface_by_name(void); +std::map<std::string, std::string> sflph_config_get_shortcuts(); +void sflph_config_set_shortcuts(const std::map<std::string, std::string>& shortcuts); +void sflph_config_set_volume(const std::string& device, double value); +double sflph_config_get_volume(const std::string& device); +bool sflph_config_check_for_private_key(const std::string& pem_path); +bool sflph_config_check_certificate_validity(const std::string& ca_path, const std::string& pem_path); +bool sflph_config_check_hostname_certificate(const std::string& host, const std::string& port); + +/* presence API */ +#ifdef SFL_PRESENCE +void sflph_pres_publish(const std::string& account_id, int status, const std::string& note); +void sflph_pres_answer_server_request(const std::string& uri, int flag); +void sflph_pres_subscribe_buddy(const std::string& account_id, const std::string& uri, int flag); +std::vector<std::map<std::string, std::string>> sflph_pres_get_subscriptions(const std::string& account_id); +void sflph_pres_set_subscriptions(const std::string& account_id, const std::vector<std::string>& uris); +#endif /* SFL_PRESENCE */ + +/* video API */ +#ifdef SFL_VIDEO +std::vector<std::map<std::string, std::string>> sflph_video_get_codecs(const std::string& account_id); +void sflph_video_set_codecs(const std::string& account_id, const std::vector<std::map<std::string, std::string>>& details); +std::vector<std::string> sflph_video_get_device_list(void); +std::map<std::string, std::map<std::string, std::vector<std::string>>> sflph_video_get_capabilities(const std::string& name); +std::map<std::string, std::string> sflph_video_get_settings(const std::string& name); +void sflph_video_set_default_device(const std::string& dev); +std::string sflph_video_get_default_device(void); +std::string sflph_video_get_current_codec_name(const std::string& call_id); +void sflph_video_start_camera(void); +void sflph_video_stop_camera(void); +bool sflph_video_switch_input(const std::string& resource); +bool sflph_video_is_camera_started(void); +void sflph_video_apply_settings(const std::string& name, const std::map<std::string, std::string>& settings); +#endif /* SFL_VIDEO */ + +#endif /* SFLPHONE_H */ diff --git a/daemon/src/sflphone_api.cpp b/daemon/src/sflphone_api.cpp new file mode 100644 index 0000000000..277d304877 --- /dev/null +++ b/daemon/src/sflphone_api.cpp @@ -0,0 +1,785 @@ +/* + * Copyright (C) 2014 Savoir-Faire Linux Inc. + * Author: Philippe Proulx <philippe.proulx@savoirfairelinux.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Additional permission under GNU GPL version 3 section 7: + * + * If you modify this program, or any covered work, by linking or + * combining it with the OpenSSL project's OpenSSL library (or a + * modified version of that library), containing parts covered by the + * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. + * grants you additional permission to convey the resulting work. + * Corresponding Source for a non-source form of such a combination + * shall include the source code for the parts of OpenSSL used as well + * as that of the covered work. + */ +#include <string> +#include <vector> +#include <map> +#include <cstdlib> + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "manager.h" +#include "managerimpl.h" +#include "logger.h" +#include "sflphone.h" +#include "client/callmanager.h" +#include "client/configurationmanager.h" + +#ifdef SFL_PRESENCE +#include "client/presencemanager.h" +#endif // SFL_PRESENCE + +#ifdef SFL_VIDEO +#include "client/videomanager.h" +#endif // SFL_VIDEO + +namespace { + // This manager pointer is only set after proper library initialization. + ManagerImpl* _manager = nullptr; + + CallManager* _getCallManager() + { + return _manager->getClient()->getCallManager(); + } + + ConfigurationManager* _getConfigurationManager() + { + return _manager->getClient()->getConfigurationManager(); + } + +#ifdef SFL_PRESENCE + PresenceManager* _getPresenceManager() + { + return _manager->getClient()->getPresenceManager(); + } +#endif // SFL_PRESENCE + +#ifdef SFL_VIDEO + VideoManager* _getVideoManager() + { + return _manager->getClient()->getVideoManager(); + } +#endif // SFL_VIDEO + + // User handlers of library events + struct sflph_ev_handlers _evHandlers; +} + +int sflph_init(struct sflph_ev_handlers* ev_handlers, enum sflph_init_flag flags) +{ + // Ignore initialization if already done + if (_manager) { + return 0; + } + + // Copy user event handlers + _evHandlers = *ev_handlers; + + // Handle flags + setDebugMode((flags & SFLPH_FLAG_DEBUG) ? true : false); + setConsoleLog((flags & SFLPH_FLAG_CONSOLE_LOG) ? true : false); + + // Create manager + try { + _manager = std::addressof(Manager::instance()); + } catch (...) { + return -SFLPH_ERR_MANAGER_INIT; + } + + // Register user event handlers + _getCallManager()->registerEvHandlers(&_evHandlers.call_ev_handlers); + _getConfigurationManager()->registerEvHandlers(&_evHandlers.config_ev_handlers); + +#ifdef SFL_PRESENCE + _getPresenceManager()->registerEvHandlers(&_evHandlers.pres_ev_handlers); +#endif // SFL_PRESENCE + +#ifdef SFL_VIDEO + _getVideoManager()->registerEvHandlers(&_evHandlers.video_ev_handlers); +#endif // SFL_VIDEO + + // Initialize manager now + try { + _manager->init(""); + } catch (...) { + _manager = nullptr; + return -SFLPH_ERR_MANAGER_INIT; + } + + return 0; +} + +void sflph_fini(void) +{ + // Ignore if not yet initialized + if (!_manager) { + return; + } + + // Finish manager + _manager->finish(); + _manager = nullptr; +} + +void sflph_poll_events() +{ + _manager->pollEvents(); +} + +bool sflph_call_place(const std::string& account_id, const std::string& call_id, const std::string& to) +{ + return _getCallManager()->placeCall(account_id, call_id, to); +} + +bool sflph_call_refuse(const std::string& call_id) +{ + return _getCallManager()->refuse(call_id); +} + +bool sflph_call_accept(const std::string& call_id) +{ + return _getCallManager()->accept(call_id); +} + +bool sflph_call_hang_up(const std::string& call_id) +{ + return _getCallManager()->hangUp(call_id); +} + +bool sflph_call_hold(const std::string& call_id) +{ + return _getCallManager()->hold(call_id); +} + +bool sflph_call_unhold(const std::string& call_id) +{ + return _getCallManager()->unhold(call_id); +} + +bool sflph_call_transfer(const std::string& call_id, const std::string& to) +{ + return _getCallManager()->transfer(call_id, to); +} + +bool sflph_call_attended_transfer(const std::string& transfer_id, const std::string& target_id) +{ + return _getCallManager()->attendedTransfer(transfer_id, target_id); +} + +std::map<std::string, std::string> sflph_call_get_call_details(const std::string& call_id) +{ + return _getCallManager()->getCallDetails(call_id); +} + +std::vector<std::string> sflph_call_get_call_list(void) +{ + return _getCallManager()->getCallList(); +} + +void sflph_call_remove_conference(const std::string& conf_id) +{ + _getCallManager()->removeConference(conf_id); +} + +bool sflph_call_join_participant(const std::string& sel_call_id, const std::string& drag_call_id) +{ + return _getCallManager()->joinParticipant(sel_call_id, drag_call_id); +} + +void sflph_call_create_conf_from_participant_list(const std::vector<std::string>& participants) +{ + _getCallManager()->createConfFromParticipantList(participants); +} + +bool sflph_call_is_conference_participant(const std::string& call_id) +{ + return _getCallManager()->isConferenceParticipant(call_id); +} + +bool sflph_call_add_participant(const std::string& call_id, const std::string& conf_id) +{ + return _getCallManager()->addParticipant(call_id, conf_id); +} + +bool sflph_call_add_main_participant(const std::string& conf_id) +{ + return _getCallManager()->addMainParticipant(conf_id); +} + +bool sflph_call_detach_participant(const std::string& call_id) +{ + return _getCallManager()->detachParticipant(call_id); +} + +bool sflph_call_join_conference(const std::string& sel_conf_id, const std::string& drag_conf_id) +{ + return _getCallManager()->joinConference(sel_conf_id, drag_conf_id); +} + +bool sflph_call_hang_up_conference(const std::string& conf_id) +{ + return _getCallManager()->hangUpConference(conf_id); +} + +bool sflph_call_hold_conference(const std::string& conf_id) +{ + return _getCallManager()->holdConference(conf_id); +} + +bool sflph_call_unhold_conference(const std::string& conf_id) +{ + return _getCallManager()->unholdConference(conf_id); +} + +std::vector<std::string> sflph_call_get_conference_list(void) +{ + return _getCallManager()->getConferenceList(); +} + +std::vector<std::string> sflph_call_get_participant_list(const std::string& conf_id) +{ + return _getCallManager()->getParticipantList(conf_id); +} + +std::vector<std::string> sflph_call_get_display_names(const std::string& conf_id) +{ + return _getCallManager()->getDisplayNames(conf_id); +} + +std::string sflph_call_get_conference_id(const std::string& call_id) +{ + return _getCallManager()->getConferenceId(call_id); +} + +std::map<std::string, std::string> sflph_call_get_conference_details(const std::string& call_id) +{ + return _getCallManager()->getConferenceDetails(call_id); +} + +bool sflph_call_play_recorded_file(const std::string& path) +{ + return _getCallManager()->startRecordedFilePlayback(path); +} + +void sflph_call_stop_recorded_file(const std::string& path) +{ + _getCallManager()->stopRecordedFilePlayback(path); +} + +bool sflph_call_toggle_recording(const std::string& call_id) +{ + return _getCallManager()->toggleRecording(call_id); +} + +void sflph_call_set_recording(const std::string& call_id) +{ + _getCallManager()->setRecording(call_id); +} + +void sflph_call_record_playback_seek(double pos) +{ + _getCallManager()->recordPlaybackSeek(pos); +} + +bool sflph_call_is_recording(const std::string& call_id) +{ + return _getCallManager()->getIsRecording(call_id); +} + +std::string sflph_call_get_current_audio_codec_name(const std::string& call_id) +{ + return _getCallManager()->getCurrentAudioCodecName(call_id); +} + +void sflph_call_play_dtmf(const std::string& key) +{ + _getCallManager()->playDTMF(key); +} + +void sflph_call_start_tone(int start, int type) +{ + _getCallManager()->startTone(start, type); +} + +void sflph_call_set_sas_verified(const std::string& call_id) +{ + _getCallManager()->setSASVerified(call_id); +} + +void sflph_call_reset_sas_verified(const std::string& call_id) +{ + _getCallManager()->resetSASVerified(call_id); +} + +void sflph_call_set_confirm_go_clear(const std::string& call_id) +{ + _getCallManager()->setConfirmGoClear(call_id); +} + +void sflph_call_request_go_clear(const std::string& call_id) +{ + _getCallManager()->requestGoClear(call_id); +} + +void sflph_call_accept_enrollment(const std::string& call_id, bool accepted) +{ + _getCallManager()->acceptEnrollment(call_id, accepted); +} + +void sflph_call_send_text_message(const std::string& call_id, const std::string& message) +{ + _getCallManager()->sendTextMessage(call_id, message); +} + +std::map<std::string, std::string> sflph_config_get_account_details(const std::string& account_id) +{ + return _getConfigurationManager()->getAccountDetails(account_id); +} + +void sflph_config_set_account_details(const std::string& account_id, const std::map<std::string, std::string>& details) +{ + _getConfigurationManager()->setAccountDetails(account_id, details); +} + +std::map<std::string, std::string> sflph_config_get_account_template(void) +{ + return _getConfigurationManager()->getAccountTemplate(); +} + +std::string sflph_config_add_account(const std::map<std::string, std::string>& details) +{ + return _getConfigurationManager()->addAccount(details); +} + +void sflph_config_remove_account(const std::string& account_id) +{ + _getConfigurationManager()->removeAccount(account_id); +} + +std::vector<std::string> sflph_config_get_account_list(void) +{ + return _getConfigurationManager()->getAccountList(); +} + +void sflph_config_send_register(const std::string& account_id, bool enable) +{ + _getConfigurationManager()->sendRegister(account_id, enable); +} + +void sflph_config_register_all_accounts(void) +{ + _getConfigurationManager()->registerAllAccounts(); +} + +std::map<std::string, std::string> sflph_config_get_tls_default_settings(void) +{ + return _getConfigurationManager()->getTlsSettingsDefault(); +} + +std::vector<int> sflph_config_get_audio_codec_list(void) +{ + return _getConfigurationManager()->getAudioCodecList(); +} + +std::vector<std::string> sflph_config_get_supported_tls_method(void) +{ + return _getConfigurationManager()->getSupportedTlsMethod(); +} + +std::vector<std::string> sflph_config_get_audio_codec_details(int payload) +{ + return _getConfigurationManager()->getAudioCodecDetails(payload); +} + +std::vector<int> sflph_config_get_active_audio_codec_list(const std::string& account_id) +{ + return _getConfigurationManager()->getActiveAudioCodecList(account_id); +} + +void sflph_config_set_active_audio_codec_list(const std::vector<std::string>& list, const std::string& account_id) +{ + _getConfigurationManager()->setActiveAudioCodecList(list, account_id); +} + +std::vector<std::string> sflph_config_get_audio_plugin_list(void) +{ + return _getConfigurationManager()->getAudioPluginList(); +} + +void sflph_config_set_audio_plugin(const std::string& audio_plugin) +{ + _getConfigurationManager()->setAudioPlugin(audio_plugin); +} + +std::vector<std::string> sflph_config_get_audio_output_device_list() +{ + return _getConfigurationManager()->getAudioOutputDeviceList(); +} + +void sflph_config_set_audio_output_device(int index) +{ + _getConfigurationManager()->setAudioOutputDevice(index); +} + +void sflph_config_set_audio_input_device(int index) +{ + _getConfigurationManager()->setAudioInputDevice(index); +} + +void sflph_config_set_audio_ringtone_device(int index) +{ + _getConfigurationManager()->setAudioRingtoneDevice(index); +} + +std::vector<std::string> sflph_config_get_audio_input_device_list(void) +{ + return _getConfigurationManager()->getAudioInputDeviceList(); +} + +std::vector<std::string> sflph_config_get_current_audio_devices_index(void) +{ + return _getConfigurationManager()->getCurrentAudioDevicesIndex(); +} + +int sflph_config_get_audio_input_device_index(const std::string& name) +{ + return _getConfigurationManager()->getAudioInputDeviceIndex(name); +} + +int sflph_config_get_audio_output_device_index(const std::string& name) +{ + return _getConfigurationManager()->getAudioOutputDeviceIndex(name); +} + +std::string sflph_config_get_current_audio_output_plugin(void) +{ + return _getConfigurationManager()->getCurrentAudioOutputPlugin(); +} + +bool sflph_config_get_noise_suppress_state(void) +{ + return _getConfigurationManager()->getNoiseSuppressState(); +} + +void sflph_config_set_noise_suppress_state(bool state) +{ + _getConfigurationManager()->setNoiseSuppressState(state); +} + +bool sflph_config_is_agc_enabled(void) +{ + return _getConfigurationManager()->isAgcEnabled(); +} + +void sflph_config_enable_agc(bool enabled) +{ + _getConfigurationManager()->setAgcState(enabled); +} + +void sflph_config_mute_dtmf(bool mute) +{ + _getConfigurationManager()->muteDtmf(mute); +} + +bool sflph_config_is_dtmf_muted(void) +{ + return _getConfigurationManager()->isDtmfMuted(); +} + +bool sflph_config_is_capture_muted(void) +{ + return _getConfigurationManager()->isCaptureMuted(); +} + +void sflph_config_mute_capture(bool mute) +{ + _getConfigurationManager()->muteCapture(mute); +} + +bool sflph_config_is_playback_muted(void) +{ + return _getConfigurationManager()->isPlaybackMuted(); +} + +void sflph_config_mute_playback(int mute) +{ + _getConfigurationManager()->mutePlayback(mute); +} + +std::map<std::string, std::string> sflph_config_get_ringtone_list(void) +{ + return _getConfigurationManager()->getRingtoneList(); +} + +std::string sflph_config_get_audio_manager(void) +{ + return _getConfigurationManager()->getAudioManager(); +} + +bool sflph_config_set_audio_manager(const std::string& api) +{ + return _getConfigurationManager()->setAudioManager(api); +} + +std::vector<std::string> sflph_config_get_supported_audio_managers(void) +{ + return { +#if HAVE_ALSA + ALSA_API_STR, +#endif +#if HAVE_PULSE + PULSEAUDIO_API_STR, +#endif +#if HAVE_JACK + JACK_API_STR, +#endif + }; +} + +int sflph_config_is_iax2_enabled(void) +{ + return _getConfigurationManager()->isIax2Enabled(); +} + +std::string sflph_config_get_record_path(void) +{ + return _getConfigurationManager()->getRecordPath(); +} + +void sflph_config_set_record_path(const std::string& path) +{ + _getConfigurationManager()->setRecordPath(path); +} + +bool sflph_config_is_always_recording(void) +{ + return _getConfigurationManager()->getIsAlwaysRecording(); +} + +void sflph_config_set_always_recording(bool rec) +{ + _getConfigurationManager()->setIsAlwaysRecording(rec); +} + +void sflph_config_set_history_limit(int days) +{ + _getConfigurationManager()->setHistoryLimit(days); +} + +int sflph_config_get_history_limit(void) +{ + return _getConfigurationManager()->getHistoryLimit(); +} + +void sflph_config_clear_history(void) +{ + _getConfigurationManager()->clearHistory(); +} + +void sflph_config_set_accounts_order(const std::string& order) +{ + _getConfigurationManager()->setAccountsOrder(order); +} + +std::map<std::string, std::string> sflph_config_get_hook_settings(void) +{ + return _getConfigurationManager()->getHookSettings(); +} + +void sflph_config_set_hook_settings(const std::map<std::string, std::string>& settings) +{ + _getConfigurationManager()->setHookSettings(settings); +} + +std::vector<std::map<std::string, std::string>> sflph_config_get_history(void) +{ + return _getConfigurationManager()->getHistory(); +} + +std::map<std::string, std::string> sflph_config_get_tls_settings() +{ + return _getConfigurationManager()->getTlsSettings(); +} + +void sflph_config_set_tls_settings(const std::map< std::string, std::string >& settings) +{ + _getConfigurationManager()->setTlsSettings(settings); +} + +std::map<std::string, std::string> sflph_config_get_ip2ip_details(void) +{ + return _getConfigurationManager()->getIp2IpDetails(); +} + +std::vector<std::map<std::string, std::string>> sflph_config_get_credentials(const std::string& account_id) +{ + return _getConfigurationManager()->getCredentials(account_id); +} + +void sflph_config_set_credentials(const std::string& account_id, const std::vector<std::map<std::string, std::string>>& details) +{ + _getConfigurationManager()->setCredentials(account_id, details); +} + +std::string sflph_config_get_addr_from_interface_name(const std::string& interface) +{ + return _getConfigurationManager()->getAddrFromInterfaceName(interface); +} + +std::vector<std::string> sflph_config_get_all_ip_interface(void) +{ + return _getConfigurationManager()->getAllIpInterface(); +} + +std::vector<std::string> sflph_config_get_all_ip_interface_by_name(void) +{ + return _getConfigurationManager()->getAllIpInterfaceByName(); +} + +std::map<std::string, std::string> sflph_config_get_shortcuts() +{ + return _getConfigurationManager()->getShortcuts(); +} + +void sflph_config_set_shortcuts(const std::map<std::string, std::string>& shortcuts) +{ + _getConfigurationManager()->setShortcuts(shortcuts); +} + +void sflph_config_set_volume(const std::string& device, double value) +{ + _getConfigurationManager()->setVolume(device, value); +} + +double sflph_config_get_volume(const std::string& device) +{ + return _getConfigurationManager()->getVolume(device); +} + +bool sflph_config_check_for_private_key(const std::string& pem_path) +{ + return _getConfigurationManager()->checkForPrivateKey(pem_path); +} + +bool sflph_config_check_certificate_validity(const std::string& ca_path, const std::string& pem_path) +{ + return _getConfigurationManager()->checkCertificateValidity(ca_path, pem_path); +} + +bool sflph_config_check_hostname_certificate(const std::string& host, const std::string& port) +{ + return _getConfigurationManager()->checkHostnameCertificate(host, port); +} + +#ifdef SFL_PRESENCE +void sflph_pres_publish(const std::string& account_id, int status, const std::string& note) +{ + _getPresenceManager()->publish(account_id, status, note); +} + +void sflph_pres_answer_server_request(const std::string& uri, int flag) +{ + _getPresenceManager()->answerServerRequest(uri, flag); +} + +void sflph_pres_subscribe_buddy(const std::string& account_id, const std::string& uri, int flag) +{ + _getPresenceManager()->subscribeBuddy(account_id, uri, flag); +} + +std::vector<std::map<std::string, std::string>> sflph_pres_get_subscriptions(const std::string& account_id) +{ + return _getPresenceManager()->getSubscriptions(account_id); +} + +void sflph_pres_set_subscriptions(const std::string& account_id, const std::vector<std::string>& uris) +{ + _getPresenceManager()->setSubscriptions(account_id, uris); +} +#endif // SFL_PRESENCE + +#ifdef SFL_VIDEO +std::vector<std::map<std::string, std::string>> sflph_video_get_codecs(const std::string& account_id) +{ + return _getVideoManager()->getCodecs(account_id); +} + +void sflph_video_set_codecs(const std::string& account_id, const std::vector<std::map<std::string, std::string>>& details) +{ + _getVideoManager()->setCodecs(account_id, details); +} + +std::vector<std::string> sflph_video_get_device_list(void) +{ + return _getVideoManager()->getDeviceList(); +} + +std::map<std::string, std::string> sflph_video_get_settings(const std::string& name) +{ + return _getVideoManager()->getSettings(name); +} + +void sflph_video_set_default_device(const std::string& dev) +{ + _getVideoManager()->setDefaultDevice(dev); +} + +std::string sflph_video_get_default_device(void) +{ + return _getVideoManager()->getDefaultDevice(); +} + +std::string sflph_video_get_current_codec_name(const std::string& call_id) +{ + return _getVideoManager()->getCurrentCodecName(call_id); +} + +void sflph_video_start_camera(void) +{ + _getVideoManager()->startCamera(); +} + +void sflph_video_stop_camera(void) +{ + _getVideoManager()->stopCamera(); +} + +bool sflph_video_switch_input(const std::string& resource) +{ + return _getVideoManager()->switchInput(resource); +} + +bool sflph_video_is_camera_started(void) +{ + return _getVideoManager()->hasCameraStarted(); +} + +void sflph_video_apply_settings(const std::string& name, const std::map<std::string, std::string>& settings) +{ + _getVideoManager()->applySettings(name, settings); +} + +std::map<std::string, std::map<std::string, std::vector<std::string>>> sflph_video_get_capabilities(const std::string& name) +{ + return _getVideoManager()->getCapabilities(name); +} + +#endif // SFL_VIDEO diff --git a/daemon/test/Makefile.am b/daemon/test/Makefile.am index 6dfb77eafa..015e942db5 100644 --- a/daemon/test/Makefile.am +++ b/daemon/test/Makefile.am @@ -6,7 +6,7 @@ check_PROGRAMS = test TESTS = run_tests.sh test_CXXFLAGS = -DWORKSPACE="$(top_srcdir)/test/" @PTHREAD_CFLAGS@ -test_LDADD = $(top_builddir)/src/libsflphone.la @ZRTPCPP_LIBS@ @LIBCRYPTO_LIBS@ @CPPUNIT_LIBS@ @YAML_LIBS@ +test_LDADD = $(top_builddir)/src/libsflphone.la $(top_builddir)/src/libsflphone_la-logger.lo @CPPUNIT_LIBS@ EXTRA_DIST = sflphoned-sample.yml history-sample.tpl run_tests.sh test_SOURCES = constants.h \ -- GitLab