Skip to content
Snippets Groups Projects
Commit 7fbf9713 authored by Alexandre Savard's avatar Alexandre Savard
Browse files
parents ced6c682 ea88c480
Branches
Tags
No related merge requests found
Showing
with 136 additions and 128 deletions
...@@ -6,10 +6,6 @@ AC_INIT([sflphone],[1.0.2],[sflphoneteam@savoirfairelinux.com],[sflphone]) ...@@ -6,10 +6,6 @@ AC_INIT([sflphone],[1.0.2],[sflphoneteam@savoirfairelinux.com],[sflphone])
AC_COPYRIGHT([[Copyright (c) Savoir-Faire Linux 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012]]) AC_COPYRIGHT([[Copyright (c) Savoir-Faire Linux 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012]])
AC_REVISION([$Revision$]) AC_REVISION([$Revision$])
AC_CANONICAL_BUILD
AC_CANONICAL_HOST
AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE AM_INIT_AUTOMAKE
AC_CONFIG_HEADERS([config.h]) AC_CONFIG_HEADERS([config.h])
...@@ -90,9 +86,6 @@ AC_DEFINE_UNQUOTED([RETSIGTYPE],[$ac_cv_type_signal],[Define as the return type ...@@ -90,9 +86,6 @@ AC_DEFINE_UNQUOTED([RETSIGTYPE],[$ac_cv_type_signal],[Define as the return type
AC_FUNC_STAT AC_FUNC_STAT
AC_FUNC_UTIME_NULL AC_FUNC_UTIME_NULL
AC_FUNC_VPRINTF AC_FUNC_VPRINTF
AC_CHECK_FUNCS([bzero floor gethostbyname gethrtime gettimeofday \
inet_ntoa memset mkdir pathconf pow regcomp select setlocale \
socket strchr strdup strerror strrchr strstr strtol utime])
dnl Check for GNU ccRTP dnl Check for GNU ccRTP
PKG_PROG_PKG_CONFIG PKG_PROG_PKG_CONFIG
......
...@@ -11,20 +11,8 @@ ASTYLERC="$(top_srcdir)/../astylerc" ...@@ -11,20 +11,8 @@ ASTYLERC="$(top_srcdir)/../astylerc"
indent="/usr/bin/astyle" indent="/usr/bin/astyle"
# for pjsip # for pjsip
PJSIP_LIBS= \ include $(src)/libs/pjproject/build.mak
-L$(src)/libs/pjproject/pjnath/lib/ \ PJSIP_LIBS=$(APP_LDFLAGS) $(APP_LDLIBS)
-L$(src)/libs/pjproject/pjsip/lib/ \
-L$(src)/libs/pjproject/pjlib/lib/ \
-L$(src)/libs/pjproject/pjlib-util/lib/ \
-L$(src)/libs/pjproject/pjmedia/lib/ \
-lpjnath-$(target) \
-lpjsua-$(target) \
-lpjsip-$(target) \
-lpjmedia-$(target) \
-lpjsip-simple-$(target) \
-lpjsip-ua-$(target) \
-lpjlib-util-$(target) \
-lpj-$(target)
SIP_CFLAGS=-I$(src)/libs/pjproject/pjsip/include \ SIP_CFLAGS=-I$(src)/libs/pjproject/pjsip/include \
-I$(src)/libs/pjproject/pjlib/include \ -I$(src)/libs/pjproject/pjlib/include \
......
...@@ -51,7 +51,8 @@ noinst_HEADERS = \ ...@@ -51,7 +51,8 @@ noinst_HEADERS = \
noncopyable.h \ noncopyable.h \
cc_thread.h \ cc_thread.h \
cc_config.h \ cc_config.h \
sfl_types.h sfl_types.h \
array_size.h
libsflphone_la_LIBADD = \ libsflphone_la_LIBADD = \
$(top_builddir)/libs/iax2/libiax2.la \ $(top_builddir)/libs/iax2/libiax2.la \
......
/*
* Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
* Author: Tristan Matthews <tristan.matthews@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.
*/
#ifndef ARRAY_SIZE_H_
#define ARRAY_SIZE_H_
// Returns the number of elements in a, calculated at compile-time
#define ARRAYSIZE(a) \
((sizeof(a) / sizeof(*(a))) / \
static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
#endif // ARRAY_SIZE_H_
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "manager.h" #include "manager.h"
#include "noncopyable.h" #include "noncopyable.h"
#include "dbus/configurationmanager.h" #include "dbus/configurationmanager.h"
#include <ctime>
class AlsaThread : public ost::Thread { class AlsaThread : public ost::Thread {
public: public:
...@@ -107,7 +108,8 @@ bool AlsaLayer::openDevice(snd_pcm_t **pcm, const std::string &dev, snd_pcm_stre ...@@ -107,7 +108,8 @@ bool AlsaLayer::openDevice(snd_pcm_t **pcm, const std::string &dev, snd_pcm_stre
// Retry if busy, since dmix plugin may not have released the device yet // Retry if busy, since dmix plugin may not have released the device yet
for (int tries = 0; tries < MAX_RETRIES and err == -EBUSY; ++tries) { for (int tries = 0; tries < MAX_RETRIES and err == -EBUSY; ++tries) {
usleep(10000); const struct timespec req = {0, 10000000};
nanosleep(&req, 0);
err = snd_pcm_open(pcm, dev.c_str(), stream, 0); err = snd_pcm_open(pcm, dev.c_str(), stream, 0);
} }
......
...@@ -132,7 +132,7 @@ class AudioRtpRecordHandler { ...@@ -132,7 +132,7 @@ class AudioRtpRecordHandler {
} }
int DtmfPending() const { int DtmfPending() const {
return audioRtpRecord_.dtmfQueue_.size() > 0; return not audioRtpRecord_.dtmfQueue_.empty();
} }
const unsigned char *getMicDataEncoded() const { const unsigned char *getMicDataEncoded() const {
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
*/ */
#include "audio_srtp_session.h" #include "audio_srtp_session.h"
#include "logger.h" #include "logger.h"
#include "array_size.h"
#include <openssl/sha.h> #include <openssl/sha.h>
#include <openssl/hmac.h> #include <openssl/hmac.h>
...@@ -103,12 +104,9 @@ namespace { ...@@ -103,12 +104,9 @@ namespace {
std::vector<unsigned char> random_key(length); std::vector<unsigned char> random_key(length);
// Generate ryptographically strong pseudo-random bytes // Generate ryptographically strong pseudo-random bytes
int err; if (RAND_bytes(&(*random_key.begin()), length) != 1)
if ((err = RAND_bytes(&(*random_key.begin()), length)) != 1)
DEBUG("Error occured while generating cryptographically strong pseudo-random key"); DEBUG("Error occured while generating cryptographically strong pseudo-random key");
assert((sizeof dest / sizeof dest[0]) <= length);
memcpy(dest, &(*random_key.begin()), length); memcpy(dest, &(*random_key.begin()), length);
} }
} }
...@@ -211,6 +209,7 @@ void AudioSrtpSession::initializeLocalMasterKey() ...@@ -211,6 +209,7 @@ void AudioSrtpSession::initializeLocalMasterKey()
DEBUG("AudioSrtp: Init local master key"); DEBUG("AudioSrtp: Init local master key");
// @TODO key may have different length depending on cipher suite // @TODO key may have different length depending on cipher suite
localMasterKeyLength_ = sfl::CryptoSuites[localCryptoSuite_].masterKeyLength / 8; localMasterKeyLength_ = sfl::CryptoSuites[localCryptoSuite_].masterKeyLength / 8;
assert(ARRAYSIZE(localMasterKey_) >= localMasterKeyLength_);
DEBUG("AudioSrtp: Local master key length %d", localMasterKeyLength_); DEBUG("AudioSrtp: Local master key length %d", localMasterKeyLength_);
buffer_fill(localMasterKey_, localMasterKeyLength_); buffer_fill(localMasterKey_, localMasterKeyLength_);
} }
...@@ -219,6 +218,7 @@ void AudioSrtpSession::initializeLocalMasterSalt() ...@@ -219,6 +218,7 @@ void AudioSrtpSession::initializeLocalMasterSalt()
{ {
// @TODO key may have different length depending on cipher suite // @TODO key may have different length depending on cipher suite
localMasterSaltLength_ = sfl::CryptoSuites[localCryptoSuite_].masterSaltLength / 8; localMasterSaltLength_ = sfl::CryptoSuites[localCryptoSuite_].masterSaltLength / 8;
assert(ARRAYSIZE(localMasterSalt_) >= localMasterSaltLength_);
DEBUG("AudioSrtp: Local master salt length %d", localMasterSaltLength_); DEBUG("AudioSrtp: Local master salt length %d", localMasterSaltLength_);
buffer_fill(localMasterSalt_, localMasterSaltLength_); buffer_fill(localMasterSalt_, localMasterSaltLength_);
} }
......
...@@ -153,22 +153,22 @@ class AudioSrtpSession : public AudioSymmetricRtpSession { ...@@ -153,22 +153,22 @@ class AudioSrtpSession : public AudioSymmetricRtpSession {
uint8 localMasterKey_[16]; uint8 localMasterKey_[16];
/** local master key length in byte */ /** local master key length in byte */
int localMasterKeyLength_; size_t localMasterKeyLength_;
uint8 localMasterSalt_[14]; uint8 localMasterSalt_[14];
/** local master salt length in byte */ /** local master salt length in byte */
int localMasterSaltLength_; size_t localMasterSaltLength_;
uint8 remoteMasterKey_[16]; uint8 remoteMasterKey_[16];
/** remote master key length in byte */ /** remote master key length in byte */
int remoteMasterKeyLength_; size_t remoteMasterKeyLength_;
uint8 remoteMasterSalt_[14]; uint8 remoteMasterSalt_[14];
/** remote master salt length in byte */ /** remote master salt length in byte */
int remoteMasterSaltLength_; size_t remoteMasterSaltLength_;
/** Used to make sure remote crypto context not initialized wice. */ /** Used to make sure remote crypto context not initialized wice. */
bool remoteOfferIsSet_; bool remoteOfferIsSet_;
......
...@@ -30,6 +30,9 @@ ...@@ -30,6 +30,9 @@
#include "dcblocker.h" #include "dcblocker.h"
DcBlocker::DcBlocker() : y_(0), x_(0), xm1_(0), ym1_(0)
{}
void DcBlocker::reset() void DcBlocker::reset()
{ {
y_ = 0; y_ = 0;
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
class DcBlocker { class DcBlocker {
public: public:
DcBlocker();
void reset(); void reset();
void process(SFLDataFormat *out, SFLDataFormat *in, int samples); void process(SFLDataFormat *out, SFLDataFormat *in, int samples);
......
...@@ -82,7 +82,7 @@ double GainControl::DetectionAverage::getAverage(double in) ...@@ -82,7 +82,7 @@ double GainControl::DetectionAverage::getAverage(double in)
GainControl::Limiter::Limiter(double r, double thresh) : ratio_(r), threshold_(thresh) GainControl::Limiter::Limiter(double r, double thresh) : ratio_(r), threshold_(thresh)
{} {}
double GainControl::Limiter::limit(double in) double GainControl::Limiter::limit(double in) const
{ {
double out = (in > threshold_ ? (ratio_ * (in - threshold_)) + threshold_ : double out = (in > threshold_ ? (ratio_ * (in - threshold_)) + threshold_ :
in < -threshold_ ? (ratio_ * (in + threshold_)) - threshold_ : in); in < -threshold_ ? (ratio_ * (in + threshold_)) - threshold_ : in);
......
...@@ -80,7 +80,7 @@ class GainControl { ...@@ -80,7 +80,7 @@ class GainControl {
/** /**
* Perform compression on input signal * Perform compression on input signal
*/ */
double limit(double); double limit(double) const;
private: private:
double ratio_; double ratio_;
......
...@@ -133,19 +133,16 @@ void MainBuffer::bindCallID(const std::string & call_id1, const std::string & ca ...@@ -133,19 +133,16 @@ void MainBuffer::bindCallID(const std::string & call_id1, const std::string & ca
{ {
ost::MutexLock guard(mutex_); ost::MutexLock guard(mutex_);
RingBuffer* ring_buffer; if (getRingBuffer(call_id1) == NULL)
CallIDSet* callid_set;
if ((ring_buffer = getRingBuffer(call_id1)) == NULL)
createRingBuffer(call_id1); createRingBuffer(call_id1);
if ((callid_set = getCallIDSet(call_id1)) == NULL) if (getCallIDSet(call_id1) == NULL)
createCallIDSet(call_id1); createCallIDSet(call_id1);
if ((ring_buffer = getRingBuffer(call_id2)) == NULL) if (getRingBuffer(call_id2) == NULL)
createRingBuffer(call_id2); createRingBuffer(call_id2);
if ((callid_set = getCallIDSet(call_id2)) == NULL) if (getCallIDSet(call_id2) == NULL)
createCallIDSet(call_id2); createCallIDSet(call_id2);
getRingBuffer(call_id1)->createReadPointer(call_id2); getRingBuffer(call_id1)->createReadPointer(call_id2);
......
...@@ -140,7 +140,7 @@ Tone::fillWavetable() ...@@ -140,7 +140,7 @@ Tone::fillWavetable()
} }
double double
Tone::interpolate(double x) Tone::interpolate(double x) const
{ {
int xi_0 = x; int xi_0 = x;
int xi_1 = xi_0 + 1; int xi_1 = xi_0 + 1;
......
...@@ -73,8 +73,7 @@ class Tone : public AudioLoop { ...@@ -73,8 +73,7 @@ class Tone : public AudioLoop {
*/ */
void fillWavetable(); void fillWavetable();
double interpolate(double x); double interpolate(double x) const;
private: private:
......
...@@ -43,10 +43,14 @@ SpeexEchoCancel::SpeexEchoCancel() : ...@@ -43,10 +43,14 @@ SpeexEchoCancel::SpeexEchoCancel() :
preState_(speex_preprocess_state_init(EC_FRAME_SIZE, SPEEX_SAMPLE_RATE)), preState_(speex_preprocess_state_init(EC_FRAME_SIZE, SPEEX_SAMPLE_RATE)),
micData_(RINGBUFFER_SIZE), micData_(RINGBUFFER_SIZE),
spkrData_(RINGBUFFER_SIZE), spkrData_(RINGBUFFER_SIZE),
spkrStopped_(true) spkrStopped_(true),
tmpSpkr_(),
tmpMic_(),
tmpOut_()
{ {
DEBUG("EchoCancel: Initializing echo canceller with delay: %d, filter length: %d, frame size: %d and samplerate %d", DEBUG("EchoCancel: Initializing echo canceller with delay: %d, filter "
echoDelay_, echoTailLength_, EC_FRAME_SIZE, SPEEX_SAMPLE_RATE); "length: %d, frame size: %d and samplerate %d", echoDelay_,
echoTailLength_, EC_FRAME_SIZE, SPEEX_SAMPLE_RATE);
int rate = SPEEX_SAMPLE_RATE; int rate = SPEEX_SAMPLE_RATE;
speex_echo_ctl(echoState_, SPEEX_ECHO_SET_SAMPLING_RATE, &rate); speex_echo_ctl(echoState_, SPEEX_ECHO_SET_SAMPLING_RATE, &rate);
......
...@@ -118,8 +118,8 @@ void YamlEmitter::serializeAccount(MappingNode *map) ...@@ -118,8 +118,8 @@ void YamlEmitter::serializeAccount(MappingNode *map)
throw YamlEmitterException("Could not append account mapping to sequence"); throw YamlEmitterException("Could not append account mapping to sequence");
Mapping *internalmap = map->getMapping(); Mapping *internalmap = map->getMapping();
for (Mapping::iterator iter = internalmap->begin(); iter != internalmap->end(); ++iter) for (Mapping::const_iterator i = internalmap->begin(); i != internalmap->end(); ++i)
addMappingItem(accountmapping, iter->first, iter->second); addMappingItem(accountmapping, i->first, i->second);
} }
void YamlEmitter::serializePreference(MappingNode *map) void YamlEmitter::serializePreference(MappingNode *map)
...@@ -141,8 +141,8 @@ void YamlEmitter::serializePreference(MappingNode *map) ...@@ -141,8 +141,8 @@ void YamlEmitter::serializePreference(MappingNode *map)
throw YamlEmitterException("Could not add mapping pair to top leve mapping"); throw YamlEmitterException("Could not add mapping pair to top leve mapping");
Mapping *internalmap = map->getMapping(); Mapping *internalmap = map->getMapping();
for (Mapping::iterator iter = internalmap->begin(); iter != internalmap->end(); ++iter) for (Mapping::const_iterator i = internalmap->begin(); i != internalmap->end(); ++i)
addMappingItem(preferencemapping, iter->first, iter->second); addMappingItem(preferencemapping, i->first, i->second);
} }
void YamlEmitter::serializeVoipPreference(MappingNode *map) void YamlEmitter::serializeVoipPreference(MappingNode *map)
...@@ -164,12 +164,8 @@ void YamlEmitter::serializeVoipPreference(MappingNode *map) ...@@ -164,12 +164,8 @@ void YamlEmitter::serializeVoipPreference(MappingNode *map)
throw YamlEmitterException("Could not add mapping pair to top leve mapping"); throw YamlEmitterException("Could not add mapping pair to top leve mapping");
Mapping *internalmap = map->getMapping(); Mapping *internalmap = map->getMapping();
Mapping::iterator iter = internalmap->begin(); for (Mapping::const_iterator i = internalmap->begin(); i != internalmap->end(); ++i)
addMappingItem(preferencemapping, i->first, i->second);
while (iter != internalmap->end()) {
addMappingItem(preferencemapping, iter->first, iter->second);
iter++;
}
} }
void YamlEmitter::serializeAddressbookPreference(MappingNode *map) void YamlEmitter::serializeAddressbookPreference(MappingNode *map)
...@@ -189,8 +185,8 @@ void YamlEmitter::serializeAddressbookPreference(MappingNode *map) ...@@ -189,8 +185,8 @@ void YamlEmitter::serializeAddressbookPreference(MappingNode *map)
throw YamlEmitterException("Could not add mapping pair to top leve mapping"); throw YamlEmitterException("Could not add mapping pair to top leve mapping");
Mapping *internalmap = map->getMapping(); Mapping *internalmap = map->getMapping();
for (Mapping::iterator iter = internalmap->begin(); iter != internalmap->end(); ++iter) for (Mapping::const_iterator i = internalmap->begin(); i != internalmap->end(); ++i)
addMappingItem(preferencemapping, iter->first, iter->second); addMappingItem(preferencemapping, i->first, i->second);
} }
void YamlEmitter::serializeHooksPreference(MappingNode *map) void YamlEmitter::serializeHooksPreference(MappingNode *map)
...@@ -211,8 +207,8 @@ void YamlEmitter::serializeHooksPreference(MappingNode *map) ...@@ -211,8 +207,8 @@ void YamlEmitter::serializeHooksPreference(MappingNode *map)
throw YamlEmitterException("Could not add mapping pair to top leve mapping"); throw YamlEmitterException("Could not add mapping pair to top leve mapping");
Mapping *internalmap = map->getMapping(); Mapping *internalmap = map->getMapping();
for (Mapping::iterator iter = internalmap->begin(); iter != internalmap->end(); ++iter) for (Mapping::const_iterator i = internalmap->begin(); i != internalmap->end(); ++i)
addMappingItem(preferencemapping, iter->first, iter->second); addMappingItem(preferencemapping, i->first, i->second);
} }
...@@ -235,8 +231,8 @@ void YamlEmitter::serializeAudioPreference(MappingNode *map) ...@@ -235,8 +231,8 @@ void YamlEmitter::serializeAudioPreference(MappingNode *map)
throw YamlEmitterException("Could not add mapping pair to top leve mapping"); throw YamlEmitterException("Could not add mapping pair to top leve mapping");
Mapping *internalmap = map->getMapping(); Mapping *internalmap = map->getMapping();
for (Mapping::iterator iter = internalmap->begin(); iter != internalmap->end(); ++iter) for (Mapping::const_iterator i = internalmap->begin(); i != internalmap->end(); ++i)
addMappingItem(preferencemapping, iter->first, iter->second); addMappingItem(preferencemapping, i->first, i->second);
} }
...@@ -257,13 +253,13 @@ void YamlEmitter::serializeShortcutPreference(MappingNode *map) ...@@ -257,13 +253,13 @@ void YamlEmitter::serializeShortcutPreference(MappingNode *map)
if (yaml_document_append_mapping_pair(&document_, topLevelMapping_, preferenceid, preferencemapping) == 0) if (yaml_document_append_mapping_pair(&document_, topLevelMapping_, preferenceid, preferencemapping) == 0)
throw YamlEmitterException("Could not add mapping pair to top leve mapping"); throw YamlEmitterException("Could not add mapping pair to top leve mapping");
Mapping *internalmap = map->getMapping(); Mapping *mapping = map->getMapping();
for (Mapping::iterator iter = internalmap->begin(); iter != internalmap->end(); ++iter) for (Mapping::const_iterator i = mapping->begin(); i != mapping->end(); ++i)
addMappingItem(preferencemapping, iter->first, iter->second); addMappingItem(preferencemapping, i->first, i->second);
} }
void YamlEmitter::addMappingItem(int mappingid, std::string key, YamlNode *node) void YamlEmitter::addMappingItem(int mappingid, const std::string &key, YamlNode *node)
{ {
if (node->getType() == SCALAR) { if (node->getType() == SCALAR) {
ScalarNode *sclr = static_cast<ScalarNode *>(node); ScalarNode *sclr = static_cast<ScalarNode *>(node);
...@@ -294,8 +290,8 @@ void YamlEmitter::addMappingItem(int mappingid, std::string key, YamlNode *node) ...@@ -294,8 +290,8 @@ void YamlEmitter::addMappingItem(int mappingid, std::string key, YamlNode *node)
throw YamlEmitterException("Could not add mapping pair to mapping"); throw YamlEmitterException("Could not add mapping pair to mapping");
Mapping *internalmap = map->getMapping(); Mapping *internalmap = map->getMapping();
for (Mapping::iterator iter = internalmap->begin(); iter != internalmap->end(); ++iter) for (Mapping::const_iterator i = internalmap->begin(); i != internalmap->end(); ++i)
addMappingItem(temp2, iter->first, iter->second); addMappingItem(temp2, i->first, i->second);
} else if (node->getType() == SEQUENCE) { } else if (node->getType() == SEQUENCE) {
SequenceNode *seqnode = static_cast<SequenceNode *>(node); SequenceNode *seqnode = static_cast<SequenceNode *>(node);
...@@ -323,10 +319,8 @@ void YamlEmitter::addMappingItem(int mappingid, std::string key, YamlNode *node) ...@@ -323,10 +319,8 @@ void YamlEmitter::addMappingItem(int mappingid, std::string key, YamlNode *node)
MappingNode *mapnode = static_cast<MappingNode*>(yamlNode); MappingNode *mapnode = static_cast<MappingNode*>(yamlNode);
Mapping *map = mapnode->getMapping(); Mapping *map = mapnode->getMapping();
Mapping::iterator mapit; for (Mapping::const_iterator i = map->begin(); i != map->end(); ++i)
addMappingItem(id, i->first, i->second);
for (mapit = map->begin(); mapit != map->end() ; ++mapit)
addMappingItem(id, mapit->first, mapit->second);
} }
} else } else
throw YamlEmitterException("Unknown node type while adding mapping node"); throw YamlEmitterException("Unknown node type while adding mapping node");
......
...@@ -84,7 +84,7 @@ class YamlEmitter { ...@@ -84,7 +84,7 @@ class YamlEmitter {
private: private:
NON_COPYABLE(YamlEmitter); NON_COPYABLE(YamlEmitter);
void addMappingItem(int mappingid, std::string key, YamlNode *node); void addMappingItem(int mappingid, const std::string &key, YamlNode *node);
std::string filename_; std::string filename_;
......
...@@ -34,28 +34,25 @@ ...@@ -34,28 +34,25 @@
namespace Conf { namespace Conf {
void YamlDocument::addNode(YamlNode *node) void YamlDocument::addNode(YamlNode *node)
{ {
Sequence::iterator it = doc.end(); Sequence::iterator it = doc_.end();
doc.insert(it, node); doc_.insert(it, node);
} }
YamlNode *YamlDocument::popNode() YamlNode *YamlDocument::popNode()
{ {
YamlNode *node = doc.front(); YamlNode *node = doc_.front();
//removed element's destructor is called //removed element's destructor is called
doc.pop_front(); doc_.pop_front();
return node; return node;
} }
void YamlDocument::deleteChildNodes() void YamlDocument::deleteChildNodes()
{ {
Sequence::iterator it = doc.begin(); for (Sequence::iterator it = doc_.begin(); it != doc_.end(); ++it) {
while (it != doc.end()) {
YamlNode *yamlNode = static_cast<YamlNode *>(*it); YamlNode *yamlNode = static_cast<YamlNode *>(*it);
switch (yamlNode->getType()) { switch (yamlNode->getType()) {
...@@ -84,36 +81,31 @@ void YamlDocument::deleteChildNodes() ...@@ -84,36 +81,31 @@ void YamlDocument::deleteChildNodes()
default: default:
break; break;
} }
it++;
} }
} }
void MappingNode::addNode(YamlNode *node) void MappingNode::addNode(YamlNode *node)
{ {
Mapping::iterator it = map.end(); setKeyValue(tmpKey_, node);
map.insert(it, std::pair<std::string, YamlNode *> (tmpKey, node));
} }
void MappingNode::setKeyValue(const std::string &key, YamlNode *value) void MappingNode::setKeyValue(const std::string &key, YamlNode *value)
{ {
Mapping::iterator it = map.end(); Mapping::iterator it = map_.end();
map.insert(it, std::pair<std::string, YamlNode *> (key, value)); map_.insert(it, std::pair<std::string, YamlNode *>(key, value));
} }
void MappingNode::removeKeyValue(const std::string &key) void MappingNode::removeKeyValue(const std::string &key)
{ {
Mapping::iterator it = map_.find(key);
Mapping::iterator it = map.find(key); map_.erase(it);
map.erase(it);
} }
YamlNode *MappingNode::getValue(const std::string &key) const YamlNode *MappingNode::getValue(const std::string &key) const
{ {
Mapping::const_iterator it = map.find(key); Mapping::const_iterator it = map_.find(key);
if (it != map.end()) { if (it != map_.end()) {
return it->second; return it->second;
} else { } else {
DEBUG("MappingNode: Could not find %s", key.c_str()); DEBUG("MappingNode: Could not find %s", key.c_str());
...@@ -124,7 +116,6 @@ YamlNode *MappingNode::getValue(const std::string &key) const ...@@ -124,7 +116,6 @@ YamlNode *MappingNode::getValue(const std::string &key) const
void MappingNode::getValue(const std::string &key, bool *b) const void MappingNode::getValue(const std::string &key, bool *b) const
{ {
ScalarNode *node = static_cast<ScalarNode*>(getValue(key)); ScalarNode *node = static_cast<ScalarNode*>(getValue(key));
if (!node) if (!node)
return; return;
...@@ -154,9 +145,7 @@ void MappingNode::getValue(const std::string &key, std::string *v) const ...@@ -154,9 +145,7 @@ void MappingNode::getValue(const std::string &key, std::string *v) const
void MappingNode::deleteChildNodes() void MappingNode::deleteChildNodes()
{ {
Mapping::iterator it; for (Mapping::iterator it = map_.begin(); it != map_.end(); ++it) {
for (it = map.begin(); it != map.end(); ++it) {
YamlNode *yamlNode = static_cast<YamlNode *>(it->second); YamlNode *yamlNode = static_cast<YamlNode *>(it->second);
if (!yamlNode) if (!yamlNode)
...@@ -193,16 +182,13 @@ void MappingNode::deleteChildNodes() ...@@ -193,16 +182,13 @@ void MappingNode::deleteChildNodes()
void SequenceNode::addNode(YamlNode *node) void SequenceNode::addNode(YamlNode *node)
{ {
Sequence::iterator it = seq.end(); Sequence::iterator it = seq_.end();
seq.insert(it, node); seq_.insert(it, node);
} }
void SequenceNode::deleteChildNodes() void SequenceNode::deleteChildNodes()
{ {
Sequence::iterator it; for (Sequence::iterator it = seq_.begin(); it != seq_.end(); ++it) {
for (it = seq.begin(); it != seq.end(); ++it) {
YamlNode *yamlNode = static_cast<YamlNode *>(*it); YamlNode *yamlNode = static_cast<YamlNode *>(*it);
switch (yamlNode->getType()) { switch (yamlNode->getType()) {
......
...@@ -48,51 +48,51 @@ enum NodeType { DOCUMENT, SCALAR, MAPPING, SEQUENCE }; ...@@ -48,51 +48,51 @@ enum NodeType { DOCUMENT, SCALAR, MAPPING, SEQUENCE };
class YamlNode { class YamlNode {
public: public:
YamlNode(NodeType t, YamlNode *top = NULL) : type(t), topNode(top) {} YamlNode(NodeType t, YamlNode *top = NULL) : type_(t), topNode_(top) {}
virtual ~YamlNode() {} virtual ~YamlNode() {}
NodeType getType() { NodeType getType() const {
return type; return type_;
} }
YamlNode *getTopNode() { YamlNode *getTopNode() {
return topNode; return topNode_;
} }
virtual void deleteChildNodes() = 0; virtual void deleteChildNodes() = 0;
private: private:
NON_COPYABLE(YamlNode); NON_COPYABLE(YamlNode);
NodeType type; NodeType type_;
YamlNode *topNode; YamlNode *topNode_;
}; };
class YamlDocument : public YamlNode { class YamlDocument : public YamlNode {
public: public:
YamlDocument(YamlNode* top=NULL) : YamlNode(DOCUMENT, top), doc() {} YamlDocument(YamlNode* top = NULL) : YamlNode(DOCUMENT, top), doc_() {}
void addNode(YamlNode *node); void addNode(YamlNode *node);
YamlNode *popNode(); YamlNode *popNode();
Sequence *getSequence() { Sequence *getSequence() {
return &doc; return &doc_;
} }
virtual void deleteChildNodes(); virtual void deleteChildNodes();
private: private:
Sequence doc; Sequence doc_;
}; };
class SequenceNode : public YamlNode { class SequenceNode : public YamlNode {
public: public:
SequenceNode(YamlNode *top) : YamlNode(SEQUENCE, top), seq() {} SequenceNode(YamlNode *top) : YamlNode(SEQUENCE, top), seq_() {}
Sequence *getSequence() { Sequence *getSequence() {
return &seq; return &seq_;
} }
void addNode(YamlNode *node); void addNode(YamlNode *node);
...@@ -100,22 +100,23 @@ class SequenceNode : public YamlNode { ...@@ -100,22 +100,23 @@ class SequenceNode : public YamlNode {
virtual void deleteChildNodes(); virtual void deleteChildNodes();
private: private:
Sequence seq; Sequence seq_;
}; };
class MappingNode : public YamlNode { class MappingNode : public YamlNode {
public: public:
MappingNode(YamlNode *top) : YamlNode(MAPPING, top), map(), tmpKey() {} MappingNode(YamlNode *top) :
YamlNode(MAPPING, top), map_(), tmpKey_() {}
Mapping *getMapping() { Mapping *getMapping() {
return &map; return &map_;
} }
void addNode(YamlNode *node); void addNode(YamlNode *node);
void setTmpKey(std::string key) { void setTmpKey(std::string key) {
tmpKey = key; tmpKey_ = key;
} }
void setKeyValue(const std::string &key, YamlNode *value); void setKeyValue(const std::string &key, YamlNode *value);
...@@ -130,27 +131,27 @@ class MappingNode : public YamlNode { ...@@ -130,27 +131,27 @@ class MappingNode : public YamlNode {
virtual void deleteChildNodes(); virtual void deleteChildNodes();
private: private:
Mapping map; Mapping map_;
std::string tmpKey; std::string tmpKey_;
}; };
class ScalarNode : public YamlNode { class ScalarNode : public YamlNode {
public: public:
ScalarNode(std::string s="", YamlNode *top=NULL) : YamlNode(SCALAR, top), str(s) {} ScalarNode(std::string s="", YamlNode *top=NULL) : YamlNode(SCALAR, top), str_(s) {}
ScalarNode(bool b, YamlNode *top=NULL) : YamlNode(SCALAR, top), str(b ? "true" : "false") {} ScalarNode(bool b, YamlNode *top=NULL) : YamlNode(SCALAR, top), str_(b ? "true" : "false") {}
const std::string &getValue() { const std::string &getValue() const {
return str; return str_;
} }
void setValue(const std::string &s) { void setValue(const std::string &s) {
str = s; str_ = s;
} }
virtual void deleteChildNodes() {} virtual void deleteChildNodes() {}
private: private:
std::string str; std::string str_;
}; };
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment