Commit 5551a555 authored by Alexandre Lision's avatar Alexandre Lision Committed by Alexandre Lision

api: clean public interfaces

* remove preprocessor flags from public headers.
* split dring.h by manager types to let user include what he needs.
* simplify function relations.
* use namespace DRing for all exported API.
* implement a generic way to export daemon signal callbacks.
* C++11 and project CodingRules conformance.

Refs #65931

Change-Id: I1f1157f9d29e1798ddb27d46e8136bdcb01828dd
parent 5d96de7e
......@@ -622,7 +622,7 @@
</arg>
</method>
<method name="getTlsSettingsDefault" tp:name-for-bindings="getTlsSettingsDefault">
<method name="getTlsDefaultSettings" tp:name-for-bindings="getTlsDefaultSettings">
<annotation name="org.qtproject.QtDBus.QtTypeName.Out0" value="MapStringString"/>
<arg type="a{ss}" name="details" direction="out">
</arg>
......
......@@ -27,217 +27,256 @@
* shall include the source code for the parts of OpenSSL used as well
* as that of the covered work.
*/
#include <iostream>
#include "dring.h"
#include "dbuscallmanager.h"
#include "dring/callmanager_interface.h"
DBusCallManager::DBusCallManager(DBus::Connection& connection)
: DBus::ObjectAdaptor(connection, "/cx/ring/Ring/CallManager")
{
}
{}
bool DBusCallManager::placeCall(const std::string& accountID, const std::string& callID, const std::string& to)
auto
DBusCallManager::placeCall(const std::string& accountID, const std::string& callID, const std::string& to) -> decltype(DRing::placeCall(accountID, callID, to))
{
return ring_call_place(accountID, callID, to);
return DRing::placeCall(accountID, callID, to);
}
bool DBusCallManager::refuse(const std::string& callID)
auto
DBusCallManager::refuse(const std::string& callID) -> decltype(DRing::refuse(callID))
{
return ring_call_refuse(callID);
return DRing::refuse(callID);
}
bool DBusCallManager::accept(const std::string& callID)
auto
DBusCallManager::accept(const std::string& callID) -> decltype(DRing::accept(callID))
{
return ring_call_accept(callID);
return DRing::accept(callID);
}
bool DBusCallManager::hangUp(const std::string& callID)
auto
DBusCallManager::hangUp(const std::string& callID) -> decltype(DRing::hangUp(callID))
{
return ring_call_hang_up(callID);
return DRing::hangUp(callID);
}
bool DBusCallManager::hold(const std::string& callID)
auto
DBusCallManager::hold(const std::string& callID) -> decltype(DRing::hold(callID))
{
return ring_call_hold(callID);
return DRing::hold(callID);
}
bool DBusCallManager::unhold(const std::string& callID)
auto
DBusCallManager::unhold(const std::string& callID) -> decltype(DRing::unhold(callID))
{
return ring_call_unhold(callID);
return DRing::unhold(callID);
}
bool DBusCallManager::transfer(const std::string& callID, const std::string& to)
auto
DBusCallManager::transfer(const std::string& callID, const std::string& to) -> decltype(DRing::transfer(callID, to))
{
return ring_call_transfer(callID, to);
return DRing::transfer(callID, to);
}
bool DBusCallManager::attendedTransfer(const std::string& transferID, const std::string& targetID)
auto
DBusCallManager::attendedTransfer(const std::string& transferID, const std::string& targetID) -> decltype(DRing::attendedTransfer(transferID, targetID))
{
return ring_call_attended_transfer(transferID, targetID);
return DRing::attendedTransfer(transferID, targetID);
}
std::map< std::string, std::string > DBusCallManager::getCallDetails(const std::string& callID)
auto
DBusCallManager::getCallDetails(const std::string& callID) -> decltype(DRing::getCallDetails(callID))
{
return ring_call_get_call_details(callID);
return DRing::getCallDetails(callID);
}
std::vector< std::string > DBusCallManager::getCallList()
auto
DBusCallManager::getCallList() -> decltype(DRing::getCallList())
{
return ring_call_get_call_list();
return DRing::getCallList();
}
void DBusCallManager::removeConference(const std::string& conference_id)
void
DBusCallManager::removeConference(const std::string& conference_id)
{
ring_call_remove_conference(conference_id);
DRing::removeConference(conference_id);
}
bool DBusCallManager::joinParticipant(const std::string& sel_callID, const std::string& drag_callID)
auto
DBusCallManager::joinParticipant(const std::string& sel_callID, const std::string& drag_callID) -> decltype(DRing::joinParticipant(sel_callID, drag_callID))
{
return ring_call_join_participant(sel_callID, drag_callID);
return DRing::joinParticipant(sel_callID, drag_callID);
}
void DBusCallManager::createConfFromParticipantList(const std::vector< std::string >& participants)
void
DBusCallManager::createConfFromParticipantList(const std::vector< std::string >& participants)
{
ring_call_create_conf_from_participant_list(participants);
DRing::createConfFromParticipantList(participants);
}
bool DBusCallManager::isConferenceParticipant(const std::string& call_id)
auto
DBusCallManager::isConferenceParticipant(const std::string& call_id) -> decltype(DRing::isConferenceParticipant(call_id))
{
return ring_call_is_conference_participant(call_id);
return DRing::isConferenceParticipant(call_id);
}
bool DBusCallManager::addParticipant(const std::string& callID, const std::string& confID)
auto
DBusCallManager::addParticipant(const std::string& callID, const std::string& confID) -> decltype(DRing::addParticipant(callID, confID))
{
return ring_call_add_participant(callID, confID);
return DRing::addParticipant(callID, confID);
}
bool DBusCallManager::addMainParticipant(const std::string& confID)
auto
DBusCallManager::addMainParticipant(const std::string& confID) -> decltype(DRing::addMainParticipant(confID))
{
return ring_call_add_main_participant(confID);
return DRing::addMainParticipant(confID);
}
bool DBusCallManager::detachParticipant(const std::string& callID)
auto
DBusCallManager::detachParticipant(const std::string& callID) -> decltype(DRing::detachParticipant(callID))
{
return ring_call_detach_participant(callID);
return DRing::detachParticipant(callID);
}
bool DBusCallManager::joinConference(const std::string& sel_confID, const std::string& drag_confID)
auto
DBusCallManager::joinConference(const std::string& sel_confID, const std::string& drag_confID) -> decltype(DRing::joinConference(sel_confID, drag_confID))
{
return ring_call_join_conference(sel_confID, drag_confID);
return DRing::joinConference(sel_confID, drag_confID);
}
bool DBusCallManager::hangUpConference(const std::string& confID)
auto
DBusCallManager::hangUpConference(const std::string& confID) -> decltype(DRing::hangUpConference(confID))
{
return ring_call_hang_up_conference(confID);
return DRing::hangUpConference(confID);
}
bool DBusCallManager::holdConference(const std::string& confID)
auto
DBusCallManager::holdConference(const std::string& confID) -> decltype(DRing::holdConference(confID))
{
return ring_call_hold_conference(confID);
return DRing::holdConference(confID);
}
bool DBusCallManager::unholdConference(const std::string& confID)
auto
DBusCallManager::unholdConference(const std::string& confID) -> decltype(DRing::unholdConference(confID))
{
return ring_call_unhold_conference(confID);
return DRing::unholdConference(confID);
}
std::vector<std::string> DBusCallManager::getConferenceList()
auto
DBusCallManager::getConferenceList() -> decltype(DRing::getConferenceList())
{
return ring_call_get_conference_list();
return DRing::getConferenceList();
}
std::vector<std::string> DBusCallManager::getParticipantList(const std::string& confID)
auto
DBusCallManager::getParticipantList(const std::string& confID) -> decltype(DRing::getParticipantList(confID))
{
return ring_call_get_participant_list(confID);
return DRing::getParticipantList(confID);
}
std::vector<std::string> DBusCallManager::getDisplayNames(const std::string& confID)
auto
DBusCallManager::getDisplayNames(const std::string& confID) -> decltype(DRing::getDisplayNames(confID))
{
return ring_call_get_display_names(confID);
return DRing::getDisplayNames(confID);
}
std::string DBusCallManager::getConferenceId(const std::string& callID)
auto
DBusCallManager::getConferenceId(const std::string& callID) -> decltype(DRing::getConferenceId(callID))
{
return ring_call_get_conference_id(callID);
return DRing::getConferenceId(callID);
}
std::map<std::string, std::string> DBusCallManager::getConferenceDetails(const std::string& callID)
auto
DBusCallManager::getConferenceDetails(const std::string& callID) -> decltype(DRing::getConferenceDetails(callID))
{
return ring_call_get_conference_details(callID);
return DRing::getConferenceDetails(callID);
}
bool DBusCallManager::startRecordedFilePlayback(const std::string& filepath)
auto
DBusCallManager::startRecordedFilePlayback(const std::string& filepath) -> decltype(DRing::startRecordedFilePlayback(filepath))
{
return ring_call_play_recorded_file(filepath);
return DRing::startRecordedFilePlayback(filepath);
}
void DBusCallManager::stopRecordedFilePlayback(const std::string& filepath)
void
DBusCallManager::stopRecordedFilePlayback(const std::string& filepath)
{
ring_call_stop_recorded_file(filepath);
DRing::stopRecordedFilePlayback(filepath);
}
bool DBusCallManager::toggleRecording(const std::string& callID)
auto
DBusCallManager::toggleRecording(const std::string& callID) -> decltype(DRing::toggleRecording(callID))
{
return ring_call_toggle_recording(callID);
return DRing::toggleRecording(callID);
}
void DBusCallManager::setRecording(const std::string& callID)
void
DBusCallManager::setRecording(const std::string& callID)
{
ring_call_set_recording(callID);
DRing::setRecording(callID);
}
void DBusCallManager::recordPlaybackSeek(const double& value)
void
DBusCallManager::recordPlaybackSeek(const double& value)
{
ring_call_record_playback_seek(value);
DRing::recordPlaybackSeek(value);
}
bool DBusCallManager::getIsRecording(const std::string& callID)
auto
DBusCallManager::getIsRecording(const std::string& callID) -> decltype(DRing::getIsRecording(callID))
{
return ring_call_is_recording(callID);
return DRing::getIsRecording(callID);
}
std::string DBusCallManager::getCurrentAudioCodecName(const std::string& callID)
auto
DBusCallManager::getCurrentAudioCodecName(const std::string& callID) -> decltype(DRing::getCurrentAudioCodecName(callID))
{
return ring_call_get_current_audio_codec_name(callID);
return DRing::getCurrentAudioCodecName(callID);
}
void DBusCallManager::playDTMF(const std::string& key)
void
DBusCallManager::playDTMF(const std::string& key)
{
ring_call_play_dtmf(key);
DRing::playDTMF(key);
}
void DBusCallManager::startTone(const int32_t& start, const int32_t& type)
void
DBusCallManager::startTone(const int32_t& start, const int32_t& type)
{
ring_call_start_tone(start, type);
DRing::startTone(start, type);
}
void DBusCallManager::setSASVerified(const std::string& callID)
void
DBusCallManager::setSASVerified(const std::string& callID)
{
ring_call_set_sas_verified(callID);
DRing::setSASVerified(callID);
}
void DBusCallManager::resetSASVerified(const std::string& callID)
void
DBusCallManager::resetSASVerified(const std::string& callID)
{
ring_call_reset_sas_verified(callID);
DRing::resetSASVerified(callID);
}
void DBusCallManager::setConfirmGoClear(const std::string& callID)
void
DBusCallManager::setConfirmGoClear(const std::string& callID)
{
ring_call_set_confirm_go_clear(callID);
DRing::setConfirmGoClear(callID);
}
void DBusCallManager::requestGoClear(const std::string& callID)
void
DBusCallManager::requestGoClear(const std::string& callID)
{
ring_call_request_go_clear(callID);
DRing::requestGoClear(callID);
}
void DBusCallManager::acceptEnrollment(const std::string& callID, const bool& accepted)
void
DBusCallManager::acceptEnrollment(const std::string& callID, const bool& accepted)
{
ring_call_accept_enrollment(callID, accepted);
DRing::acceptEnrollment(callID, accepted);
}
void DBusCallManager::sendTextMessage(const std::string& callID, const std::string& message)
void
DBusCallManager::sendTextMessage(const std::string& callID, const std::string& message)
{
ring_call_send_text_message(callID, message);
DRing::sendTextMessage(callID, message);
}
......@@ -28,8 +28,8 @@
* as that of the covered work.
*/
#ifndef __RING_CALLMANAGER_H__
#define __RING_CALLMANAGER_H__
#ifndef __RING_DBUSCALLMANAGER_H__
#define __RING_DBUSCALLMANAGER_H__
#include <vector>
#include <map>
......@@ -72,8 +72,8 @@ class DBusCallManager :
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();
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);
......
/*
* Copyright (C) 2014 Savoir-Faire Linux Inc.
* Copyright (C) 2014-2015 Savoir-Faire Linux Inc.
* Author: Philippe Proulx <philippe.proulx@savoirfairelinux.com>
* Author: Guillaume Roguez <Guillaume.Roguez@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
......@@ -31,200 +32,181 @@
#include <iostream>
#include <cstring>
#include <stdexcept>
#include "dring.h"
#include "dbusclient.h"
#include "dbus_cpp.h"
#include "dbusinstance.h"
#include "callmanager_interface.h"
#include "dbuscallmanager.h"
#include "dbusconfigurationmanager.h"
#include "configurationmanager_interface.h"
#include "dbuspresencemanager.h"
#include "presencemanager_interface.h"
#ifdef RING_VIDEO
#include "dbusvideomanager.h"
#include "videomanager_interface.h"
#endif
struct EventCallback : DBus::Callback_Base<void, DBus::DefaultTimeout&>
class EventCallback :
public DBus::Callback_Base<void, DBus::DefaultTimeout&>
{
EventCallback(const std::function<void()> &func) :
callback_(func)
{}
public:
EventCallback(const std::function<void()>&& func)
: callback_ {std::forward<const std::function<void()>>(func)}
{}
void call(DBus::DefaultTimeout &) const
{
callback_();
}
void call(DBus::DefaultTimeout&) const {
callback_();
}
private:
std::function<void()> callback_;
private:
const std::function<void()> callback_;
};
DBusClient::DBusClient(int sflphFlags, bool persistent) :
callManager_(nullptr)
, configurationManager_(nullptr)
, presenceManager_(nullptr)
, instanceManager_(nullptr)
, dispatcher_(new DBus::BusDispatcher)
#ifdef RING_VIDEO
, videoManager_(nullptr)
#endif
, timeout_(nullptr)
DBusClient::DBusClient(int sflphFlags, bool persistent)
: dispatcher_(new DBus::BusDispatcher)
{
try {
DBus::_init_threading();
DBus::default_dispatcher = dispatcher_;
DBus::default_dispatcher = dispatcher_.get();
// timeout and expired are deleted internally by dispatcher_'s
// destructor, so we must NOT delete them ourselves.
timeout_ = new DBus::DefaultTimeout(10 /* ms */, true, dispatcher_);
// Poll for SIP/IAX events
timeout_->expired = new EventCallback(ring_poll_events);
timeout_.reset(new DBus::DefaultTimeout {10 /* ms */, true, dispatcher_.get()});
// Poll for Deamon events
timeout_->expired = new EventCallback {DRing::poll_events};
DBus::Connection sessionConnection(DBus::Connection::SessionBus());
DBus::Connection sessionConnection {DBus::Connection::SessionBus()};
sessionConnection.request_name("cx.ring.Ring");
callManager_ = new DBusCallManager(sessionConnection);
configurationManager_ = new DBusConfigurationManager(sessionConnection);
presenceManager_ = new DBusPresenceManager(sessionConnection);
callManager_.reset(new DBusCallManager {sessionConnection});
configurationManager_.reset(new DBusConfigurationManager {sessionConnection});
presenceManager_.reset(new DBusPresenceManager {sessionConnection});
DBusInstance::OnNoMoreClientFunc onNoMoreClientFunc;
if (!persistent)
onNoMoreClientFunc = [this] {this->exit();};
if (!persistent) {
onNoMoreClientFunc = [this] () {
this->exit();
};
}
instanceManager_ = new DBusInstance(sessionConnection, onNoMoreClientFunc);
instanceManager_.reset(new DBusInstance {sessionConnection, onNoMoreClientFunc});
#ifdef RING_VIDEO
videoManager_ = new DBusVideoManager(sessionConnection);
videoManager_.reset(new DBusVideoManager {sessionConnection});
#endif
} catch (const DBus::Error &err) {
throw std::runtime_error("cannot initialize DBus stuff");
throw std::runtime_error {"cannot initialize DBus stuff"};
}
auto ret = initLibrary(sflphFlags);
if (ret < 0) {
throw std::runtime_error("cannot initialize libring");
}
if (initLibrary(sflphFlags) < 0)
throw std::runtime_error {"cannot initialize libring"};
instanceManager_->started();
}
DBusClient::~DBusClient()
{
#ifdef RING_VIDEO
delete videoManager_;
#endif
delete instanceManager_;
delete presenceManager_;
delete configurationManager_;
delete callManager_;
delete dispatcher_;
dispatcher_.reset(); // force dispatcher reset first
}
int DBusClient::initLibrary(int sflphFlags)
{
using namespace std::placeholders;
using std::bind;
auto callM = callManager_; // just an alias
// Call event handlers
ring_call_ev_handlers callEvHandlers = {
bind(&DBusCallManager::callStateChanged, callM, _1, _2),
bind(&DBusCallManager::transferFailed, callM),
bind(&DBusCallManager::transferSucceeded, callM),
bind(&DBusCallManager::recordPlaybackStopped, callM, _1),
bind(&DBusCallManager::voiceMailNotify, callM, _1, _2),
bind(&DBusCallManager::incomingMessage, callM, _1, _2, _3),
bind(&DBusCallManager::incomingCall, callM, _1, _2, _3),
bind(&DBusCallManager::recordPlaybackFilepath, callM, _1, _2),
bind(&DBusCallManager::conferenceCreated, callM, _1),
bind(&DBusCallManager::conferenceChanged, callM, _1, _2),
bind(&DBusCallManager::updatePlaybackScale, callM, _1, _2, _3),
bind(&DBusCallManager::conferenceRemoved, callM, _1),
bind(&DBusCallManager::newCallCreated, callM, _1, _2, _3),
bind(&DBusCallManager::sipCallStateChanged, callM, _1, _2, _3),
bind(&DBusCallManager::recordingStateChanged, callM, _1, _2),
bind(&DBusCallManager::secureSdesOn, callM, _1),
bind(&DBusCallManager::secureSdesOff, callM, _1),
bind(&DBusCallManager::secureZrtpOn, callM, _1, _2),
bind(&DBusCallManager::secureZrtpOff, callM, _1),
bind(&DBusCallManager::showSAS, callM, _1, _2, _3),
bind(&DBusCallManager::zrtpNotSuppOther, callM, _1),
bind(&DBusCallManager::zrtpNegotiationFailed, callM, _1, _2, _3),
bind(&DBusCallManager::onRtcpReportReceived, callM, _1, _2)
};
auto confM = configurationManager_; // just an alias
// Configuration event handlers
ring_config_ev_handlers configEvHandlers = {
bind(&DBusConfigurationManager::volumeChanged, confM, _1, _2),
bind(&DBusConfigurationManager::accountsChanged, confM),
bind(&DBusConfigurationManager::historyChanged, confM),
bind(&DBusConfigurationManager::stunStatusFailure, confM, _1),
bind(&DBusConfigurationManager::registrationStateChanged, confM, _1, _2),
bind(&DBusConfigurationManager::sipRegistrationStateChanged, confM, _1, _2, _3),
bind(&DBusConfigurationManager::volatileAccountDetailsChanged, confM, _1, _2),
bind(&DBusConfigurationManager::errorAlert, confM, _1),
};
auto presM = presenceManager_;
// Presence event handlers