Commit a9f3dc57 authored by Tristan Matthews's avatar Tristan Matthews

* #7127: apply astylerc to daemon and client.

99 % of these are just whitespace changes. Some unnecessary includes
removed as well
parent 58a31825
......@@ -5,12 +5,14 @@
# Savoir-faire Linux Inc
# http://www.sflphone.org
style=k&r # Kernighan & Ritchie style formatting/indenting uses linux bracket
indent=spaces=4 # Use spaces instead of tabs for indentation
indent-classes # Indent 'class' and 'struct' blocks so that the blocks 'public:', 'protected:' and 'private:' are indented
indent-switches # Indent 'switch' blocks so that the 'case X:' statements are indented in the switch block
break-blocks # Pad empty lines around header blocks (e.g. 'if', 'while'...).
style=stroustrup # stroustrup style http://astyle.sourceforge.net/astyle.html#_style=stroustrup
indent=spaces=4 # Use spaces instead of tabs for indentation
indent-classes # Indent 'class' and 'struct' blocks so that the blocks 'public:', 'protected:' and 'private:' are indented
indent-switches # Indent 'switch' blocks so that the 'case X:' statements are indented in the switch block
break-blocks # Pad empty lines around header blocks (e.g. 'if', 'while'...).
brackets=linux
unpad=paren
formatted
-d
unpad-paren # Remove unwanted space around parentheses
pad-header # Insert space padding after paren headers only (e.g. 'if', 'for', 'while'...)
formatted # only display files that have changed
recursive # recursively enter subdirs
suffix=none # don't create backup files (that's what version control is for)
......@@ -36,8 +36,7 @@
* Interface for both audio codecs as well as video codecs.
*/
namespace sfl {
class Codec
{
class Codec {
public:
Codec() {};
virtual ~Codec() {}
......
......@@ -33,18 +33,18 @@
#include "account.h"
#include "manager.h"
Account::Account (const std::string& accountID, const std::string &type) :
accountID_ (accountID)
, link_ (NULL)
, enabled_ (true)
, type_ (type)
, registrationState_ (Unregistered)
, codecOrder_ ()
, codecStr_ ("")
, ringtonePath_ ("/usr/share/sflphone/ringtones/konga.ul")
, ringtoneEnabled_ (true)
, displayName_ ("")
, userAgent_ ("SFLphone")
Account::Account(const std::string& accountID, const std::string &type) :
accountID_(accountID)
, link_(NULL)
, enabled_(true)
, type_(type)
, registrationState_(Unregistered)
, codecOrder_()
, codecStr_("")
, ringtonePath_("/usr/share/sflphone/ringtones/konga.ul")
, ringtoneEnabled_(true)
, displayName_("")
, userAgent_("SFLphone")
{
// Initialize the codec order, used when creating a new account
loadDefaultCodecs();
......@@ -54,7 +54,7 @@ Account::~Account()
{
}
void Account::setRegistrationState (const RegistrationState &state)
void Account::setRegistrationState(const RegistrationState &state)
{
if (state != registrationState_) {
registrationState_ = state;
......@@ -71,20 +71,20 @@ void Account::loadDefaultCodecs()
// Initialize codec
std::vector <std::string> codecList;
codecList.push_back ("0");
codecList.push_back ("3");
codecList.push_back ("8");
codecList.push_back ("9");
codecList.push_back ("110");
codecList.push_back ("111");
codecList.push_back ("112");
setActiveCodecs (codecList);
codecList.push_back("0");
codecList.push_back("3");
codecList.push_back("8");
codecList.push_back("9");
codecList.push_back("110");
codecList.push_back("111");
codecList.push_back("112");
setActiveCodecs(codecList);
}
void Account::setActiveCodecs (const std::vector <std::string> &list)
void Account::setActiveCodecs(const std::vector <std::string> &list)
{
// first clear the previously stored codecs
codecOrder_.clear();
......@@ -93,12 +93,12 @@ void Account::setActiveCodecs (const std::vector <std::string> &list)
// we used the CodecOrder vector to save the order.
for (std::vector<std::string>::const_iterator iter = list.begin(); iter != list.end();
++iter) {
int payload = std::atoi (iter->c_str());
codecOrder_.push_back ( (int) payload);
int payload = std::atoi(iter->c_str());
codecOrder_.push_back((int) payload);
}
// update the codec string according to new codec selection
codecStr_ = ManagerImpl::serialize (list);
codecStr_ = ManagerImpl::serialize(list);
}
std::string Account::mapStateNumberToString(RegistrationState state)
......
......@@ -143,12 +143,11 @@ static const char * const ringtonePathKey = "ringtonePath";
static const char * const ringtoneEnabledKey = "ringtoneEnabled";
static const char * const displayNameKey = "displayName";
class Account : public Serializable
{
class Account : public Serializable {
public:
Account (const std::string& accountID, const std::string &type);
Account(const std::string& accountID, const std::string &type);
/**
* Virtual destructor
......@@ -159,15 +158,15 @@ class Account : public Serializable
* Method called by the configuration engine to serialize instance's information
* into configuration file.
*/
virtual void serialize (Conf::YamlEmitter *emitter) = 0;
virtual void serialize(Conf::YamlEmitter *emitter) = 0;
/**
* Method called by the configuration engine to restore instance internal state
* from configuration file.
*/
virtual void unserialize (Conf::MappingNode *map) = 0;
virtual void unserialize(Conf::MappingNode *map) = 0;
virtual void setAccountDetails (std::map<std::string, std::string> details) = 0;
virtual void setAccountDetails(std::map<std::string, std::string> details) = 0;
virtual std::map<std::string, std::string> getAccountDetails() const = 0;
......@@ -213,7 +212,7 @@ class Account : public Serializable
return enabled_;
}
void setEnabled (bool enable) {
void setEnabled(bool enable) {
enabled_ = enable;
}
......@@ -221,31 +220,31 @@ class Account : public Serializable
* Set the registration state of the specified link
* @param state The registration state of underlying VoIPLink
*/
void setRegistrationState (const RegistrationState &state);
void setRegistrationState(const RegistrationState &state);
/* They should be treated like macro definitions by the C++ compiler */
std::string getUsername (void) const {
std::string getUsername(void) const {
return username_;
}
std::string getHostname (void) const {
std::string getHostname(void) const {
return hostname_;
}
void setHostname (const std::string &hostname) {
void setHostname(const std::string &hostname) {
hostname_ = hostname;
}
std::string getAlias (void) const {
std::string getAlias(void) const {
return alias_;
}
void setAlias (const std::string &alias) {
void setAlias(const std::string &alias) {
alias_ = alias;
}
std::string getType (void) const {
std::string getType(void) const {
return type_;
}
void setType (const std::string &type) {
void setType(const std::string &type) {
type_ = type;
}
......@@ -253,7 +252,7 @@ class Account : public Serializable
* Accessor to data structures
* @return CodecOrder& The list that reflects the user's choice
*/
const CodecOrder& getActiveCodecs (void) const {
const CodecOrder& getActiveCodecs(void) const {
return codecOrder_;
}
......@@ -261,40 +260,40 @@ class Account : public Serializable
* Update both the codec order structure and the codec string used for
* SDP offer and configuration respectively
*/
void setActiveCodecs (const std::vector <std::string>& list);
void setActiveCodecs(const std::vector <std::string>& list);
std::string getRingtonePath (void) const {
std::string getRingtonePath(void) const {
return ringtonePath_;
}
void setRingtonePath (const std::string &path) {
void setRingtonePath(const std::string &path) {
ringtonePath_ = path;
}
bool getRingtoneEnabled (void) const {
bool getRingtoneEnabled(void) const {
return ringtoneEnabled_;
}
void setRingtoneEnabled (bool enable) {
void setRingtoneEnabled(bool enable) {
ringtoneEnabled_ = enable;
}
std::string getDisplayName (void) const {
std::string getDisplayName(void) const {
return displayName_;
}
void setDisplayName (const std::string &name) {
void setDisplayName(const std::string &name) {
displayName_ = name;
}
std::string getMailBox (void) const {
std::string getMailBox(void) const {
return mailBox_;
}
void setMailBox (const std::string &mb) {
void setMailBox(const std::string &mb) {
mailBox_ = mb;
}
private:
// copy constructor
Account (const Account& rh);
Account(const Account& rh);
// assignment operator
Account& operator= (const Account& rh);
......@@ -303,10 +302,10 @@ class Account : public Serializable
* Helper function used to load the default codec order from the codec factory
* setActiveCodecs is called to sync both codecOrder_ and codecStr_
*/
void loadDefaultCodecs (void);
void loadDefaultCodecs(void);
protected:
static std::string mapStateNumberToString (RegistrationState state);
static std::string mapStateNumberToString(RegistrationState state);
/**
* Account ID are assign in constructor and shall not changed
......
......@@ -36,65 +36,64 @@
#include "managerimpl.h"
#include "dbus/configurationmanager.h"
class AlsaThread : public ost::Thread
{
class AlsaThread : public ost::Thread {
public:
AlsaThread (AlsaLayer *alsa);
AlsaThread(AlsaLayer *alsa);
~AlsaThread () {
~AlsaThread() {
terminate();
}
virtual void run (void);
virtual void run(void);
private:
AlsaThread (const AlsaThread& at);
AlsaThread(const AlsaThread& at);
AlsaThread& operator= (const AlsaThread& at);
AlsaLayer* alsa_;
};
AlsaThread::AlsaThread (AlsaLayer *alsa)
AlsaThread::AlsaThread(AlsaLayer *alsa)
: Thread(), alsa_(alsa)
{
setCancel (cancelDeferred);
setCancel(cancelDeferred);
}
/**
* Reimplementation of run()
*/
void AlsaThread::run (void)
void AlsaThread::run(void)
{
while (!testCancel()) {
alsa_->audioCallback();
Thread::sleep (20);
Thread::sleep(20);
}
}
// Constructor
AlsaLayer::AlsaLayer ()
: indexIn_ (audioPref.getCardin())
, indexOut_ (audioPref.getCardout())
, indexRing_ (audioPref.getCardring())
, playbackHandle_ (NULL)
, ringtoneHandle_ (NULL)
, captureHandle_ (NULL)
, audioPlugin_ (audioPref.getPlugin())
, IDSoundCards_ ()
, is_playback_prepared_ (false)
, is_capture_prepared_ (false)
, is_playback_running_ (false)
, is_capture_running_ (false)
, is_playback_open_ (false)
, is_capture_open_ (false)
, audioThread_ (NULL)
AlsaLayer::AlsaLayer()
: indexIn_(audioPref.getCardin())
, indexOut_(audioPref.getCardout())
, indexRing_(audioPref.getCardring())
, playbackHandle_(NULL)
, ringtoneHandle_(NULL)
, captureHandle_(NULL)
, audioPlugin_(audioPref.getPlugin())
, IDSoundCards_()
, is_playback_prepared_(false)
, is_capture_prepared_(false)
, is_playback_running_(false)
, is_capture_running_(false)
, is_playback_open_(false)
, is_capture_open_(false)
, audioThread_(NULL)
{
}
// Destructor
AlsaLayer::~AlsaLayer (void)
AlsaLayer::~AlsaLayer(void)
{
delete audioThread_;
delete audioThread_;
/* Then close the audio devices */
closeCaptureStream();
......@@ -106,6 +105,7 @@ bool AlsaLayer::openDevice(snd_pcm_t **pcm, const std::string &dev, snd_pcm_stre
{
static const int MAX_RETRIES = 100;
int err = snd_pcm_open(pcm, dev.c_str(), stream, 0);
// Retry if busy, since dmix plugin may not have released the device yet
for (int tries = 0; tries < MAX_RETRIES and err == -EBUSY; ++tries) {
usleep(10000);
......@@ -114,22 +114,22 @@ bool AlsaLayer::openDevice(snd_pcm_t **pcm, const std::string &dev, snd_pcm_stre
if (err < 0) {
_error("Alsa: couldn't open device %s : %s", dev.c_str(),
snd_strerror(err));
snd_strerror(err));
return false;
}
if (!alsa_set_params(*pcm)) {
snd_pcm_close(*pcm);
return false;
}
if (!alsa_set_params(*pcm)) {
snd_pcm_close(*pcm);
return false;
}
return true;
return true;
}
void
AlsaLayer::startStream (void)
AlsaLayer::startStream(void)
{
dcblocker_.reset();
dcblocker_.reset();
if (is_playback_running_ and is_capture_running_)
return;
......@@ -139,55 +139,57 @@ AlsaLayer::startStream (void)
std::string pcmc;
if (audioPlugin_ == PCM_DMIX_DSNOOP) {
pcmp = buildDeviceTopo (PCM_DMIX, indexOut_);
pcmr = buildDeviceTopo (PCM_DMIX, indexRing_);
pcmc = buildDeviceTopo (PCM_DSNOOP, indexIn_);
pcmp = buildDeviceTopo(PCM_DMIX, indexOut_);
pcmr = buildDeviceTopo(PCM_DMIX, indexRing_);
pcmc = buildDeviceTopo(PCM_DSNOOP, indexIn_);
} else {
pcmp = buildDeviceTopo (audioPlugin_, indexOut_);
pcmr = buildDeviceTopo (audioPlugin_, indexRing_);
pcmc = buildDeviceTopo (audioPlugin_, indexIn_);
pcmp = buildDeviceTopo(audioPlugin_, indexOut_);
pcmr = buildDeviceTopo(audioPlugin_, indexRing_);
pcmc = buildDeviceTopo(audioPlugin_, indexIn_);
}
if (not is_capture_open_) {
is_capture_open_ = openDevice(&captureHandle_, pcmc, SND_PCM_STREAM_CAPTURE);
is_capture_open_ = openDevice(&captureHandle_, pcmc, SND_PCM_STREAM_CAPTURE);
if (not is_capture_open_)
Manager::instance().getDbusManager()->getConfigurationManager()->errorAlert(ALSA_CAPTURE_DEVICE);
}
if (not is_playback_open_) {
is_playback_open_ = openDevice(&playbackHandle_, pcmp, SND_PCM_STREAM_PLAYBACK);
if (not is_playback_open_)
is_playback_open_ = openDevice(&playbackHandle_, pcmp, SND_PCM_STREAM_PLAYBACK);
if (not is_playback_open_)
Manager::instance().getDbusManager()->getConfigurationManager()->errorAlert(ALSA_PLAYBACK_DEVICE);
if (getIndexOut() != getIndexRing())
if (!openDevice(&ringtoneHandle_, pcmr, SND_PCM_STREAM_PLAYBACK))
Manager::instance().getDbusManager()->getConfigurationManager()->errorAlert(ALSA_PLAYBACK_DEVICE);
if (getIndexOut() != getIndexRing())
if (!openDevice(&ringtoneHandle_, pcmr, SND_PCM_STREAM_PLAYBACK))
Manager::instance().getDbusManager()->getConfigurationManager()->errorAlert(ALSA_PLAYBACK_DEVICE);
}
prepareCaptureStream ();
preparePlaybackStream ();
prepareCaptureStream();
preparePlaybackStream();
startCaptureStream ();
startPlaybackStream ();
startCaptureStream();
startPlaybackStream();
flushMain();
flushUrgent();
if (audioThread_ == NULL) {
audioThread_ = new AlsaThread (this);
audioThread_->start();
audioThread_ = new AlsaThread(this);
audioThread_->start();
}
isStarted_ = true;
}
void
AlsaLayer::stopStream (void)
AlsaLayer::stopStream(void)
{
isStarted_ = false;
delete audioThread_;
audioThread_ = NULL;
delete audioThread_;
audioThread_ = NULL;
closeCaptureStream();
closePlaybackStream();
......@@ -220,37 +222,37 @@ AlsaLayer::stopStream (void)
err_code; \
})
void AlsaLayer::stopCaptureStream (void)
void AlsaLayer::stopCaptureStream(void)
{
if (captureHandle_ && ALSA_CALL(snd_pcm_drop (captureHandle_), "couldn't stop capture") >= 0) {
is_capture_running_ = false;
is_capture_prepared_ = false;
if (captureHandle_ && ALSA_CALL(snd_pcm_drop(captureHandle_), "couldn't stop capture") >= 0) {
is_capture_running_ = false;
is_capture_prepared_ = false;
}
}
void AlsaLayer::closeCaptureStream (void)
void AlsaLayer::closeCaptureStream(void)
{
if (is_capture_prepared_ and is_capture_running_)
stopCaptureStream ();
stopCaptureStream();
if (is_capture_open_ && ALSA_CALL(snd_pcm_close (captureHandle_), "Couldn't close capture") >= 0)
is_capture_open_ = false;
if (is_capture_open_ && ALSA_CALL(snd_pcm_close(captureHandle_), "Couldn't close capture") >= 0)
is_capture_open_ = false;
}
void AlsaLayer::startCaptureStream (void)
void AlsaLayer::startCaptureStream(void)
{
if (captureHandle_ and not is_capture_running_)
if (ALSA_CALL(snd_pcm_start (captureHandle_), "Couldn't start capture") >= 0)
if (ALSA_CALL(snd_pcm_start(captureHandle_), "Couldn't start capture") >= 0)
is_capture_running_ = true;
}
void AlsaLayer::stopPlaybackStream (void)
void AlsaLayer::stopPlaybackStream(void)
{
if (ringtoneHandle_ and is_playback_running_)
ALSA_CALL(snd_pcm_drop(ringtoneHandle_), "Couldn't stop ringtone");
ALSA_CALL(snd_pcm_drop(ringtoneHandle_), "Couldn't stop ringtone");
if (playbackHandle_ and is_playback_running_) {
if (ALSA_CALL(snd_pcm_drop(playbackHandle_), "Couldn't stop playback") >= 0) {
if (ALSA_CALL(snd_pcm_drop(playbackHandle_), "Couldn't stop playback") >= 0) {
is_playback_running_ = false;
is_playback_prepared_ = false;
}
......@@ -258,14 +260,14 @@ void AlsaLayer::stopPlaybackStream (void)
}
void AlsaLayer::closePlaybackStream (void)
void AlsaLayer::closePlaybackStream(void)
{
if (is_playback_prepared_ and is_playback_running_)
stopPlaybackStream();
if (is_playback_open_) {
if (ringtoneHandle_)
ALSA_CALL(snd_pcm_close(ringtoneHandle_), "Couldn't stop ringtone");
ALSA_CALL(snd_pcm_close(ringtoneHandle_), "Couldn't stop ringtone");
if (ALSA_CALL(snd_pcm_close(playbackHandle_), "Coulnd't close playback") >= 0)
is_playback_open_ = false;
......@@ -273,28 +275,28 @@ void AlsaLayer::closePlaybackStream (void)
}
void AlsaLayer::startPlaybackStream (void)
void AlsaLayer::startPlaybackStream(void)
{
if (playbackHandle_ and not is_playback_running_)
if (ALSA_CALL(snd_pcm_start(playbackHandle_), "Couldn't start playback") >= 0)
if (ALSA_CALL(snd_pcm_start(playbackHandle_), "Couldn't start playback") >= 0)
is_playback_running_ = true;
}
void AlsaLayer::prepareCaptureStream (void)
void AlsaLayer::prepareCaptureStream(void)
{
if (is_capture_open_ and not is_capture_prepared_)
if (ALSA_CALL(snd_pcm_prepare(captureHandle_), "Couldn't prepare capture") >= 0)
if (ALSA_CALL(snd_pcm_prepare(captureHandle_), "Couldn't prepare capture") >= 0)
is_capture_prepared_ = true;
}
void AlsaLayer::preparePlaybackStream (void)
void AlsaLayer::preparePlaybackStream(void)
{
if (is_playback_open_ and not is_playback_prepared_)
if (ALSA_CALL(snd_pcm_prepare(playbackHandle_), "Couldn't prepare playback") >= 0)
if (ALSA_CALL(snd_pcm_prepare(playbackHandle_), "Couldn't prepare playback") >= 0)
is_playback_prepared_ = true;
}
bool AlsaLayer::alsa_set_params (snd_pcm_t *pcm_handle)
bool AlsaLayer::alsa_set_params(snd_pcm_t *pcm_handle)
{
#define TRY(call, error) do { \
if (ALSA_CALL(call, error) < 0) \
......@@ -308,27 +310,27 @@ bool AlsaLayer::alsa_set_params (snd_pcm_t *pcm_handle)
unsigned int periods = 4;
#define HW pcm_handle, hwparams /* hardware parameters */
TRY(snd_pcm_hw_params_any (HW), "hwparams init");
TRY(snd_pcm_hw_params_set_access (HW, SND_PCM_ACCESS_RW_INTERLEAVED), "access type");
TRY(snd_pcm_hw_params_set_format (HW, SND_PCM_FORMAT_S16_LE), "sample format");
TRY(snd_pcm_hw_params_set_rate_near (HW, &audioSampleRate_, NULL), "sample rate");
TRY(snd_pcm_hw_params_set_channels (HW, 1), "channel count");
TRY(snd_pcm_hw_params_set_period_size_near (HW, &periodSize, NULL), "period time");
TRY(snd_pcm_hw_params_set_periods_near (HW, &periods, NULL), "periods number");
TRY(snd_pcm_hw_params (HW), "hwparams");
TRY(snd_pcm_hw_params_any(HW), "hwparams init");
TRY(snd_pcm_hw_params_set_access(HW, SND_PCM_ACCESS_RW_INTERLEAVED), "access type");
TRY(snd_pcm_hw_params_set_format(HW, SND_PCM_FORMAT_S16_LE), "sample format");
TRY(snd_pcm_hw_params_set_rate_near(HW, &audioSampleRate_, NULL), "sample rate");
TRY(snd_pcm_hw_params_set_channels(HW, 1), "channel count");
TRY(snd_pcm_hw_params_set_period_size_near(HW, &periodSize, NULL), "period time");
TRY(snd_pcm_hw_params_set_periods_near(HW, &periods, NULL), "periods number");
TRY(snd_pcm_hw_params(HW), "hwparams");
#undef HW
_debug ("ALSA: %s using sampling rate %dHz",
(snd_pcm_stream(pcm_handle) == SND_PCM_STREAM_PLAYBACK) ? "playback" : "capture",
audioSampleRate_);
_debug("ALSA: %s using sampling rate %dHz",
(snd_pcm_stream(pcm_handle) == SND_PCM_STREAM_PLAYBACK) ? "playback" : "capture",
audioSampleRate_);
snd_pcm_sw_params_t *swparams = NULL;
snd_pcm_sw_params_alloca(&swparams);
#define SW pcm_handle, swparams /* software parameters */
snd_pcm_sw_params_current (SW);
TRY(snd_pcm_sw_params_set_start_threshold (SW, periodSize * 2), "start threshold");