Commit 630b671a authored by jehan's avatar jehan

move FlexisipException implementation to bctoolbox.

parent c76b7f0f
......@@ -76,7 +76,7 @@ endfunction()
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# Required packages
find_package(SofiaSipUa 1.13.11bc REQUIRED)
find_package(SofiaSipUa 1.13.11 REQUIRED) #find_package only allow numbers
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
include("${EP_ortp_CONFIG_DIR}/ORTPConfig.cmake")
else()
......
......@@ -110,6 +110,8 @@ function(ADD_XSD_WRAPPERS file _comment)
set(FLEXISIP_SOURCES ${FLEXISIP_SOURCES} ${destinations} PARENT_SCOPE)
endfunction()
list(APPEND FLEXISIP_INCLUDES ${BCTOOLBOX_INCLUDE_DIRS})
if(ENABLE_XSD)
list(APPEND FLEXISIP_LIBS ${XERCES_LIBS})
list(APPEND FLEXISIP_INCLUDES ${XERCES_INCLUDE_DIRS} ${XSDCXX_ROOT_PATH}/libxsd ${CMAKE_CURRENT_BINARY_DIR}/xml)
......
......@@ -81,14 +81,6 @@ inline std::basic_istream<CharT, TraitsT> &operator>>(std::basic_istream<CharT,
typedef std::ostream flexisip_record_type;
#if (__GNUC__ == 4 && __GNUC_MINOR__ < 5)
template <typename _Tp> inline pumpstream &operator<<(pumpstream &&__os, const _Tp &__x) {
(static_cast<std::ostringstream &>(__os)) << __x;
return __os;
}
#endif
#define SLOGA_FL(file, line) throw FlexisipException() << " " << file << ":" << line << " "
#define SLOG(thelevel) BCTBX_SLOG(FLEXISIP_LOG_DOMAIN,thelevel)
......
......@@ -19,6 +19,7 @@
#include "list-subscription.hh"
#include "belle-sip/belle-sip.h"
#include "bellesip-signaling-exception.hh"
#include "log/logmanager.hh"
#include "resource-lists.hxx"
#include <chrono>
#include "rlmi+xml.hxx"
......
......@@ -24,6 +24,7 @@
#include "pidf+xml.hxx"
#include <memory>
#include "presentity-manager.hh"
#include "log/logmanager.hh"
#define ETAG_SIZE 8
using namespace pidf;
......
......@@ -19,6 +19,7 @@
#include "subscription.hh"
#include "belle-sip/belle-sip.h"
#include <time.h>
#include "log/logmanager.hh"
using namespace std;
namespace flexisip {
......
/*
Flexisip, a flexible SIP proxy server with media capabilities.
Copyright (C) 2010-2015 Belledonne Communications SARL, All rights reserved.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "flexisip-exception.hh"
#include <execinfo.h>
#include <unistd.h>
static void uncaught_handler() {
std::exception_ptr p = current_exception();
try {
rethrow_exception(p);
} catch (FlexisipException &e) {
SLOGE << e;
} catch (std::exception &ee) {
SLOGE << "Unexpected exception [" << ee.what() << " ] use FlexisipException for better debug";
}
abort();
}
FlexisipException e;
FlexisipException::FlexisipException(const char *message) : mOffset(1), mSize(0) {
mSize = backtrace(mArray, sizeof(mArray) / sizeof(void *));
if (message)
mOs << message;
#if __clang
if (get_terminate() != uncaught_handler)
#endif
set_terminate(uncaught_handler); // invoke in case of uncautch exception for this thread
}
FlexisipException::FlexisipException(const FlexisipException &other) : mOffset(other.mOffset), mSize(other.mSize) {
memcpy(mArray, other.mArray, sizeof(mArray));
mOs << other.str();
}
#if __cplusplus > 199711L
FlexisipException::FlexisipException(const string &msg) : FlexisipException(msg.c_str()) {
mOffset++;
}
#else
FlexisipException::FlexisipException(const string &message) : mOffset(1) {
mSize = backtrace(mArray, sizeof(mArray) / sizeof(void *));
*this << message;
set_terminate(uncaught_handler); // invoke in case of uncautch exception for this thread
}
#endif
FlexisipException::~FlexisipException() throw() {
// nop
}
#if __cplusplus > 199711L
FlexisipException::FlexisipException() : FlexisipException("") {
mOffset++;
}
#else
FlexisipException::FlexisipException() : mOffset(1) {
mSize = backtrace(mArray, sizeof(mArray) / sizeof(void *));
*this << "";
set_terminate(uncaught_handler); // invoke in case of uncautch exception for this thread
}
#endif
void FlexisipException::printStackTrace() const {
backtrace_symbols_fd(mArray + mOffset, mSize - mOffset, STDERR_FILENO);
}
void FlexisipException::printStackTrace(std::ostream &os) const {
char **bt = backtrace_symbols(mArray, mSize);
for (unsigned int i = mOffset; i < mSize; ++i) {
os << bt[i] << endl;
}
delete (bt);
}
const std::string &FlexisipException::str() const {
mMessage = mOs.str(); // avoid returning a reference to temporary
return mMessage;
}
const char *FlexisipException::what() const throw() {
return str().c_str();
}
// Class Flexisip
std::ostream &operator<<(std::ostream &__os, const FlexisipException &e) {
__os << e.str() << std::endl;
e.printStackTrace(__os);
return __os;
}
/*
Flexisip, a flexible SIP proxy server with media capabilities.
Copyright (C) 2014 Belledonne Communications SARL.
Copyright (C) 2016 Belledonne Communications SARL.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero 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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FLEXISIPEXCEPTION_H_
#define FLEXISIPEXCEPTION_H_
#include <exception>
#include <string>
#include <iostream>
#include <sstream>
#include <ostream>
#include "log/logmanager.hh"
using namespace std;
#ifndef FLEXISIP_EXCEPTION_HH_
#define FLEXISIP_EXCEPTION_HH_
class FlexisipException : public exception {
public:
FlexisipException();
FlexisipException(const string &message);
FlexisipException(const char *message);
virtual ~FlexisipException() throw();
FlexisipException(const FlexisipException &other);
/**
* print stack strace to stderr
* */
void printStackTrace() const;
#include "bctoolbox/exception.hh"
#include <string.h>
void printStackTrace(std::ostream &os) const;
const char *what() const throw();
const std::string &str() const;
/* same as osstringstream, but as osstream does not have cp contructor, FlexisipException can't inherit from
* osstream*/
/**
* @brief This exception inherits \ref BctoolboxException.
*
*
*/
class FlexisipException : public BctbxException {
public:
FlexisipException() {mOffset++;};
FlexisipException(const string &message):BctbxException(message){mOffset++;};
FlexisipException(const char *message):BctbxException(message){mOffset++;};
virtual ~FlexisipException() throw(){};
FlexisipException(const FlexisipException &other):BctbxException(other){};
template <typename T2> FlexisipException &operator<<(const T2 &val) {
mOs << val;
BctbxException::operator<<(val);
return *this;
}
protected:
int mOffset; /*to hide last stack traces*/
private:
void *mArray[20];
size_t mSize;
ostringstream mOs;
mutable string mMessage;
};
std::ostream &operator<<(std::ostream &__os, const FlexisipException &e);
#define FLEXISIP_EXCEPTION FlexisipException() << " " << __FILE__ << ":" << __LINE__ << " "
#endif /* FLEXISIPEXCEPTION_H_ */
#endif /* FLEXISIP_EXCEPTION_HH_ */
bctoolbox @ 7f951f6d
Subproject commit d0c166650a4a39aaae1d5bc17b5ae64639982930
Subproject commit 7f951f6d3d25b328de9fb006fbdc43a1463ad8ea
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment