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>
......
This diff is collapsed.
......@@ -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);
......
This diff is collapsed.
/*
* Copyright (C) 2004-2015 Savoir-Faire Linux Inc.
* Author: Pierre-Luc Beaudoin <pierre-luc.beaudoin@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
......@@ -32,7 +33,6 @@
#define __DBUSCLIENT_H__
#include "dring.h"
#include "noncopyable.h"
class DBusConfigurationManager;
class DBusCallManager;
......@@ -54,26 +54,24 @@ class DBusClient {
DBusClient(int sflphFlags, bool persistent);
~DBusClient();
int event_loop();
int exit();
int event_loop() noexcept;
int exit() noexcept;
private:
NON_COPYABLE(DBusClient);
int initLibrary(int sflphFlags);
void finiLibrary();
void finiLibrary() noexcept;
DBusCallManager* callManager_;
DBusConfigurationManager* configurationManager_;
std::unique_ptr<DBus::BusDispatcher> dispatcher_;
std::unique_ptr<DBus::DefaultTimeout> timeout_;
DBusPresenceManager* presenceManager_;
DBusInstance* instanceManager_;
DBus::BusDispatcher* dispatcher_;
std::unique_ptr<DBusCallManager> callManager_;
std::unique_ptr<DBusConfigurationManager> configurationManager_;
std::unique_ptr<DBusPresenceManager> presenceManager_;
std::unique_ptr<DBusInstance> instanceManager_;
#ifdef RING_VIDEO
DBusVideoManager *videoManager_;
std::unique_ptr<DBusVideoManager> videoManager_;
#endif
DBus::DefaultTimeout *timeout_;
};
#endif
......@@ -56,8 +56,6 @@
#pragma GCC diagnostic warning "-Wunused-but-set-variable"
#endif
#include <stdexcept>
class DBusConfigurationManager :
public cx::ring::Ring::ConfigurationManager_adaptor,
public DBus::IntrospectableAdaptor,
......@@ -67,30 +65,30 @@ class DBusConfigurationManager :
DBusConfigurationManager(DBus::Connection& connection);
// Methods
std::map< std::string, std::string > getAccountDetails(const std::string& accountID);
std::map<std::string, std::string> getAccountDetails(const std::string& accountID);
std::map<std::string, std::string> getVolatileAccountDetails(const std::string& accountID);
void setAccountDetails(const std::string& accountID, const std::map< std::string, std::string >& details);
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);
std::string addAccount(const std::map<std::string, std::string>& details);
void removeAccount(const std::string& accoundID);
std::vector< std::string > getAccountList();
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< std::string > getSupportedCiphers(const std::string& accountID);
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();
std::map<std::string, std::string> getTlsDefaultSettings();
std::vector<std::string> getSupportedCiphers(const std::string& accountID);
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();
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();
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();
......@@ -104,7 +102,6 @@ class DBusConfigurationManager :
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();
......@@ -119,12 +116,12 @@ class DBusConfigurationManager :
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::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);
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();
......@@ -132,8 +129,7 @@ class DBusConfigurationManager :
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);
std::map<std::string, std::string> validateCertificate(const std::string& accountId,
const std::string& certificate, const std::string& privateKey);
std::map<std::string, std::string> validateCertificate(const std::string& accountId, const std::string& certificate, const std::string& privateKey);
std::map<std::string, std::string> getCertificateDetails(const std::string& certificate);
};
......
......@@ -31,10 +31,10 @@
#include "dbusinstance.h"
DBusInstance::DBusInstance(DBus::Connection& connection,
const OnNoMoreClientFunc& onNoMoreClientFunc) :
DBus::ObjectAdaptor(connection, "/cx/ring/Ring/Instance"),
onNoMoreClientFunc_(onNoMoreClientFunc),
count_(0)
const OnNoMoreClientFunc& onNoMoreClientFunc)
: DBus::ObjectAdaptor(connection, "/cx/ring/Ring/Instance")
, onNoMoreClientFunc_(onNoMoreClientFunc)
, count_(0)
{}
void
......
......@@ -53,9 +53,8 @@ class DBusInstance :
public DBus::ObjectAdaptor
{
public:
typedef std::function<void ()> OnNoMoreClientFunc;
typedef std::function<void()> OnNoMoreClientFunc;
public:
DBusInstance(DBus::Connection& connection,
const OnNoMoreClientFunc& onNoMoreClientFunc);
......
......@@ -27,36 +27,40 @@
* shall include the source code for the parts of OpenSSL used as well
* as that of the covered work.
*/
#include "dring.h"
#include "dbuspresencemanager.h"
#include "presencemanager_interface.h"
DBusPresenceManager::DBusPresenceManager(DBus::Connection& connection)
: DBus::ObjectAdaptor(connection, "/cx/ring/Ring/PresenceManager")
{
}
{}
void DBusPresenceManager::publish(const std::string& accountID, const bool& status, const std::string& note)
void
DBusPresenceManager::publish(const std::string& accountID, const bool& status, const std::string& note)
{
ring_pres_publish(accountID, status, note);
DRing::publish(accountID, status, note);
}
void DBusPresenceManager::answerServerRequest(const std::string& uri, const bool& flag)
void
DBusPresenceManager::answerServerRequest(const std::string& uri, const bool& flag)
{
ring_pres_answer_server_request(uri, flag);
DRing::answerServerRequest(uri, flag);
}
void DBusPresenceManager::subscribeBuddy(const std::string& accountID, const std::string& uri, const bool& flag)
void
DBusPresenceManager::subscribeBuddy(const std::string& accountID, const std::string& uri, const bool& flag)
{
ring_pres_subscribe_buddy(accountID, uri, flag);
DRing::subscribeBuddy(accountID, uri, flag);
}
std::vector<std::map<std::string, std::string> > DBusPresenceManager::getSubscriptions(const std::string& accountID)
auto
DBusPresenceManager::getSubscriptions(const std::string& accountID) -> decltype(DRing::getSubscriptions(accountID))
{
return ring_pres_get_subscriptions(accountID);
return DRing::getSubscriptions(accountID);
}
void DBusPresenceManager::setSubscriptions(const std::string& accountID, const std::vector<std::string>& uris)
void
DBusPresenceManager::setSubscriptions(const std::string& accountID, const std::vector<std::string>& uris)
{
ring_pres_set_subscriptions(accountID, uris);
DRing::setSubscriptions(accountID, uris);
}
......@@ -53,8 +53,6 @@
#pragma GCC diagnostic warning "-Wunused-but-set-variable"
#endif
#include <stdexcept>
class DBusPresenceManager :
public cx::ring::Ring::PresenceManager_adaptor,
public DBus::IntrospectableAdaptor,
......@@ -67,7 +65,7 @@ class DBusPresenceManager :
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);
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);
};
......
......@@ -27,76 +27,90 @@
* shall include the source code for the parts of OpenSSL used as well
* as that of the covered work.
*/
#include "dring.h"
#include "dbusvideomanager.h"
#include "managerimpl.h"
#include "manager.h"
#include "client/videomanager.h"
DBusVideoManager::DBusVideoManager(DBus::Connection& connection)
: DBus::ObjectAdaptor(connection, "/cx/ring/Ring/VideoManager")
{
}
{}
std::vector<std::map<std::string, std::string>> DBusVideoManager::getCodecs(const std::string& accountID)
auto
DBusVideoManager::getCodecs(const std::string& accountID) -> decltype(DRing::getCodecs(accountID))
{
return ring_video_get_codecs(accountID);
return DRing::getCodecs(accountID);
}
void DBusVideoManager::setCodecs(const std::string& accountID, const std::vector<std::map<std::string, std::string> > &details)
void
DBusVideoManager::setCodecs(const std::string& accountID, const std::vector<std::map<std::string, std::string>>& details)
{
ring_video_set_codecs(accountID, details);
DRing::setCodecs(accountID, details);
}
std::vector<std::string> DBusVideoManager::getDeviceList()
auto
DBusVideoManager::getDeviceList() -> decltype(DRing::getDeviceList())
{
return ring_video_get_device_list();
return DRing::getDeviceList();
}
std::map<std::string, std::map<std::string, std::vector<std::string>>> DBusVideoManager::getCapabilities(const std::string& name)
auto
DBusVideoManager::getCapabilities(const std::string& name) -> decltype(DRing::getCapabilities(name))
{
return ring_video_get_capabilities(name);
return DRing::getCapabilities(name);
}
std::map<std::string, std::string> DBusVideoManager::getSettings(const std::string& name)
auto
DBusVideoManager::getSettings(const std::string& name) -> decltype(DRing::getSettings(name))
{
return ring_video_get_settings(name);
return DRing::getSettings(name);
}
void DBusVideoManager::applySettings(const std::string& name, const std::map<std::string, std::string>& settings)
void
DBusVideoManager::applySettings(const std::string& name, const std::map<std::string, std::string>& settings)
{
ring_video_apply_settings(name, settings);
DRing::applySettings(name, settings);
}
void DBusVideoManager::setDefaultDevice(const std::string &dev)
void
DBusVideoManager::setDefaultDevice(const std::string& dev)
{
ring_video_set_default_device(dev);
DRing::setDefaultDevice(dev);
}
std::string DBusVideoManager::getDefaultDevice()
auto
DBusVideoManager::getDefaultDevice() -> decltype(DRing::getDefaultDevice())
{
return ring_video_get_default_device();
return DRing::getDefaultDevice();
}
std::string DBusVideoManager::getCurrentCodecName(const std::string &callID)
auto
DBusVideoManager::getCurrentCodecName(const std::string& callID) -> decltype(DRing::getCurrentCodecName(callID))
{
return ring_video_get_current_codec_name(callID);
return DRing::getCurrentCodecName(callID);
}
void DBusVideoManager::startCamera()
void
DBusVideoManager::startCamera()
{
ring_video_start_camera();
DRing::startCamera();
}
void DBusVideoManager::stopCamera()
void
DBusVideoManager::stopCamera()
{
ring_video_stop_camera();
DRing::stopCamera();
}
bool DBusVideoManager::switchInput(const std::string& resource)
auto
DBusVideoManager::switchInput(const std::string& resource) -> decltype(DRing::switchInput(resource))
{
return ring_video_switch_input(resource);
return DRing::switchInput(resource);
}
bool DBusVideoManager::hasCameraStarted()
auto
DBusVideoManager::hasCameraStarted() -> decltype(DRing::hasCameraStarted())
{
return ring_video_is_camera_started();
return DRing::hasCameraStarted();
}
......@@ -52,26 +52,25 @@
#pragma GCC diagnostic warning "-Wunused-but-set-variable"
#endif
#include <stdexcept>
class DBusVideoManager :
public cx::ring::Ring::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);
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);
void setDefaultDevice(const std::string& dev);
std::string getDefaultDevice();
std::string getCurrentCodecName(const std::string &callID);
std::string getCurrentCodecName(const std::string& callID);
void startCamera();
void stopCamera();
bool switchInput(const std::string& resource);
......
......@@ -41,14 +41,17 @@
static int ringFlags = 0;
static std::unique_ptr<DBusClient> dbusClient;
static void print_title()
static void
print_title()
{
std::cout << "Ring Daemon " << ring_version() <<
", by Savoir-Faire Linux 2004-2015" << std::endl <<
"http://www.sflphone.org/" << std::endl;
std::cout
<< "Ring Daemon " << DRing::version()
<< ", by Savoir-Faire Linux 2004-2015" << std::endl
<< "http://www.sflphone.org/" << std::endl;
}
static void print_usage()
static void
print_usage()
{
std::cout << std::endl <<
"-c, --console \t- Log in console (instead of syslog)" << std::endl <<
......@@ -60,12 +63,9 @@ static void print_usage()
// 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)
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'},
......@@ -76,16 +76,16 @@ static bool parse_args(int argc, char *argv[], bool &persistent)
{0, 0, 0, 0} /* Sentinel */
};
int consoleFlag = false;
int debugFlag = false;
int helpFlag = false;
int versionFlag = false;
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) {
switch (getopt_long(argc, argv, "dcphv", long_options, &option_index)) {
case 'd':
debugFlag = true;
break;
......@@ -107,49 +107,51 @@ static bool parse_args(int argc, char *argv[], bool &persistent)
versionFlag = true;
break;
case -1: // end of the options
default:
break;
}
}
bool quit = false;
if (helpFlag) {
print_usage();
quit = true;
} else if (versionFlag) {
return true;
}
if (versionFlag) {
// We've always print the title/version, so we can just exit
quit = true;
} else {
if (consoleFlag) {
ringFlags |= RING_FLAG_CONSOLE_LOG;
}
if (debugFlag) {
ringFlags |= RING_FLAG_DEBUG;
}
return true;
}
return quit;
if (consoleFlag)
ringFlags |= DRing::DRING_FLAG_CONSOLE_LOG;
if (debugFlag)
ringFlags |= DRing::DRING_FLAG_DEBUG;
return false;
}
static int run()
static int
run()
{
if (dbusClient) {
if (dbusClient)
return dbusClient->event_loop();
}
return 1;
}
static void interrupt()
static void
interrupt()
{
if (dbusClient) {
if (dbusClient)
dbusClient->exit();
}
}
static void signal_handler(int code)
static void
signal_handler(int code)
{
std::cerr << "Caught signal " << strsignal(code)
<< ", terminating..." << std::endl;
<< ", terminating..." << std::endl;
// Unset signal handlers
signal(SIGHUP, SIG_DFL);
......@@ -159,13 +161,12 @@ static void signal_handler(int code)
interrupt();
}
int main(int argc, char *argv [])
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::string programName {argv[0]};
std::vector<char> writable(programName.size() + 1);
std::copy(programName.begin(), programName.end(), writable.begin());
......@@ -179,13 +180,12 @@ int main(int argc, char *argv [])
print_title();
bool persistent = false;
if (parse_args(argc, argv, persistent))
return 0;
// initialize client/library
try {
dbusClient = std::unique_ptr<DBusClient>(new DBusClient(ringFlags, persistent));
dbusClient.reset(new DBusClient {ringFlags, persistent});
} catch (const std::exception& ex) {
std::cerr << "One does not simply initialize the DBus client: " << ex.what() << std::endl;
return 1;
......@@ -201,10 +201,5 @@ int main(int argc, char *argv [])
std::cerr << "Warning: built with video support" << std::endl;
#endif
ret = run();
// terminate client/library
dbusClient = nullptr;
return ret;
return run();
}
......@@ -37,18 +37,26 @@
#include <string>
#include "dring.h"
#include "callmanager_interface.h"
#include "configurationmanager_interface.h"
#include "presencemanager_interface.h"
#ifdef RING_VIDEO
#include "videomanager_interface.h"
#endif
#include "fileutils.h"
static int sflphFlags = 0;
static int ringFlags = 0;
static void print_title()
static void
print_title()
{
std::cout << "Ring Daemon " << ring_version() <<
", by Savoir-Faire Linux 2004-2015" << std::endl <<
"http://www.sflphone.org/" << std::endl;
std::cout << "Ring Daemon " << DRing::version()
<< ", by Savoir-Faire Linux 2004-2015" << std::endl
<< "http://www.sflphone.org/" << std::endl;
}
static void print_usage()
static void
print_usage()
{
std::cout << std::endl <<
"-c, --console \t- Log in console (instead of syslog)" << std::endl <<
......@@ -60,12 +68,9 @@ static void print_usage()
// 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)
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'},
......@@ -76,16 +81,16 @@ static bool parse_args(int argc, char *argv[], bool &persistent)
{0, 0, 0, 0} /* Sentinel */
};
int consoleFlag = false;
int debugFlag = false;
int helpFlag = false;
int versionFlag = false;
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) {
switch (getopt_long(argc, argv, "dcphv", long_options, &option_index)) {
case 'd':
debugFlag = true;
break;
......@@ -107,86 +112,63 @@ static bool parse_args(int argc, char *argv[], bool &persistent)
versionFlag = true;
break;
case -1: // end of the options