- removed old smart pointer implementation. Switch to C++ 11 std::shared_ptr instead
This commit is contained in:
parent
5afaa1299e
commit
58483a0395
|
|
@ -6,5 +6,29 @@ set (CMAKE_CXX_STANDARD_REQUIRED ON)
|
|||
|
||||
file(GLOB MEDIA_LIB_SOURCES "*.cpp" "*.h")
|
||||
|
||||
# SRTP requires this
|
||||
add_definitions(-DHAVE_STDINT_H -DHAVE_UINT64_T -DHAVE_NETINET_IN_H)
|
||||
|
||||
if(CMAKE_SYSTEM MATCHES "Linux*")
|
||||
add_definitions(-DHAVE_NETINET_IN_H)
|
||||
endif(CMAKE_SYSTEM MATCHES "Linux*")
|
||||
|
||||
if(CMAKE_SYSTEM MATCHES "Darwin*")
|
||||
# OS X Specific flags
|
||||
add_definitions(-DHAVE_NETINET_IN_H)
|
||||
endif(CMAKE_SYSTEM MATCHES "Darwin*")
|
||||
|
||||
if (CMAKE_SYSTEM MATCHES "Win*")
|
||||
# Windows Specific flags - MSVC expected
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS -DHAVE_WINSOCK2_H
|
||||
-D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS -DUNICODE -D_UNICODE )
|
||||
endif(CMAKE_SYSTEM MATCHES "Win*")
|
||||
|
||||
add_library(media_lib ${MEDIA_LIB_SOURCES})
|
||||
target_include_directories(media_lib PRIVATE ../../libs/ ../ ../../libs/srtp/include ../../libs/srtp/crypto/include)
|
||||
|
||||
target_include_directories(media_lib PRIVATE ../../libs/
|
||||
../ ../../libs/srtp/include
|
||||
../../libs/srtp/crypto/include
|
||||
../../libs/webrtc)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
/* Copyright(C) 2007-2014 VoIP objects (voipobjects.com)
|
||||
/* Copyright(C) 2007-2018 VoIP objects (voipobjects.com)
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "MT_SingleAudioStream.h"
|
||||
#include "MT_CodecList.h"
|
||||
#include "resip/stack/SdpContents.hxx"
|
||||
//#include "resip/stack/SdpContents.hxx"
|
||||
#include "../engine/helper/HL_Log.h"
|
||||
|
||||
#define LOG_SUBSYSTEM "SingleAudioStream"
|
||||
|
|
@ -24,7 +24,7 @@ SingleAudioStream::~SingleAudioStream()
|
|||
void SingleAudioStream::process(std::shared_ptr<jrtplib::RTPPacket> packet)
|
||||
{
|
||||
ICELogMedia(<< "Processing incoming RTP/RTCP packet");
|
||||
if (packet->GetPayloadType() == resip::Codec::TelephoneEvent.payloadType())
|
||||
if (packet->GetPayloadType() == 101/*resip::Codec::TelephoneEvent.payloadType()*/)
|
||||
mDtmfReceiver.add(packet);
|
||||
else
|
||||
mReceiver.add(packet);
|
||||
|
|
|
|||
|
|
@ -32,4 +32,6 @@ set (ICE_STACK_SOURCES ICEAddress.cpp
|
|||
ICETime.cpp
|
||||
ICETransactionList.cpp)
|
||||
|
||||
add_definitions(-DUSE_NATIVE_SMARTPTR)
|
||||
|
||||
add_library(ice_stack ${ICE_STACK_SOURCES})
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
#ifndef __ICE_ACTION__H
|
||||
#define __ICE_ACTION__H
|
||||
|
||||
#include "ICESmartPtr.h"
|
||||
#include <memory>
|
||||
#include "ICECandidatePair.h"
|
||||
|
||||
namespace ice
|
||||
|
|
@ -35,8 +35,8 @@ namespace ice
|
|||
virtual void finished(Transaction& transaction) = 0;
|
||||
};
|
||||
|
||||
typedef SmartPtr<Action> PAction;
|
||||
typedef std::shared_ptr<Action> PAction;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ void AuthTransaction::init()
|
|||
buildAuthenticatedMsg();
|
||||
else
|
||||
{
|
||||
SmartPtr<StunMessage> msg(new StunMessage());
|
||||
std::shared_ptr<StunMessage> msg(new StunMessage());
|
||||
msg->setTransactionId(mTransactionID);
|
||||
setInitialRequest(*msg);
|
||||
mComposed = false;
|
||||
|
|
@ -44,7 +44,7 @@ void AuthTransaction::buildAuthenticatedMsg()
|
|||
md5Bin(key.c_str(), key.size(), mKey);
|
||||
|
||||
// Create new authenticated message
|
||||
SmartPtr<StunMessage> newMsg( new StunMessage() );
|
||||
std::shared_ptr<StunMessage> newMsg( new StunMessage() );
|
||||
|
||||
// Optional - generate new transaction ID
|
||||
// mTransactionID = StunMessage::TransactionID::GenerateNew();
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#ifndef __AUTH_TRANSACTION_H
|
||||
#define __AUTH_TRANSACTION_H
|
||||
|
||||
#include <memory>
|
||||
#include "ICEPlatform.h"
|
||||
#include "ICEStunTransaction.h"
|
||||
|
||||
|
|
@ -23,7 +24,7 @@ public:
|
|||
virtual void setInitialRequest(StunMessage& msg) = 0;
|
||||
virtual void setAuthenticatedRequest(StunMessage& msg) = 0;
|
||||
virtual void processSuccessMessage(StunMessage& msg, NetworkAddress& sourceAddress) = 0;
|
||||
virtual void processError() {};
|
||||
virtual void processError() {}
|
||||
|
||||
virtual bool processData(StunMessage& msg, NetworkAddress& address);
|
||||
virtual ByteBuffer* generateData(bool force = false);
|
||||
|
|
@ -44,7 +45,7 @@ protected:
|
|||
bool mComposed;
|
||||
int mErrorCode;
|
||||
std::string mErrorResponse;
|
||||
std::deque<SmartPtr<StunMessage> > mOutgoingMsgQueue;
|
||||
std::deque<std::shared_ptr<StunMessage> > mOutgoingMsgQueue;
|
||||
unsigned char mKey[16];
|
||||
bool mConformsToKeepaliveSchedule;
|
||||
std::string mRealm;
|
||||
|
|
@ -56,4 +57,4 @@ protected:
|
|||
|
||||
} // end of namespace
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
/* Copyright(C) 2007-2017 VoIP objects (voipobjects.com)
|
||||
/* Copyright(C) 2007-2018 VoIP objects (voipobjects.com)
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "ICEBoxImpl.h"
|
||||
#include "ICELog.h"
|
||||
//#include "TargetConditionals.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#define LOG_SUBSYSTEM "ICE"
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
#define __ICE_CANDIDATE_H
|
||||
|
||||
#include "ICEPlatform.h"
|
||||
#include "ICESmartPtr.h"
|
||||
#include "ICEAddress.h"
|
||||
|
||||
#include <string>
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
#include "ICEPlatform.h"
|
||||
#include "ICECandidate.h"
|
||||
#include "ICEByteBuffer.h"
|
||||
#include "ICESmartPtr.h"
|
||||
|
||||
namespace ice
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
#include "ICEPlatform.h"
|
||||
#include "ICECandidatePair.h"
|
||||
#include "ICESmartPtr.h"
|
||||
#include <vector>
|
||||
|
||||
namespace ice
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright(C) 2007-2014 VoIP objects (voipobjects.com)
|
||||
/* Copyright(C) 2007-2018 VoIP objects (voipobjects.com)
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
|
@ -10,6 +10,8 @@
|
|||
#include "ICELog.h"
|
||||
#include "ICEStream.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
using namespace ice;
|
||||
|
||||
#define LOG_SUBSYSTEM "ICE"
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
#include "ICESession.h"
|
||||
#include "ICENetworkHelper.h"
|
||||
#include "ICEAction.h"
|
||||
#include "ICESmartPtr.h"
|
||||
#include "ICEBinding.h"
|
||||
#include "ICERelaying.h"
|
||||
#include "ICEAddress.h"
|
||||
|
|
|
|||
|
|
@ -18,11 +18,10 @@
|
|||
#include "ICESync.h"
|
||||
#include "ICECheckList.h"
|
||||
#include "ICETime.h"
|
||||
#include "ICESmartPtr.h"
|
||||
#include "ICEStream.h"
|
||||
|
||||
namespace ice {
|
||||
|
||||
namespace ice
|
||||
{
|
||||
// ICE session context
|
||||
struct Session
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,396 +0,0 @@
|
|||
// Based on resiprocate's implementation of smart pointer, which is based on boost implementation
|
||||
// Its license is smth close to BSD
|
||||
|
||||
#ifndef __ICE_SMART_COUNT_H
|
||||
#define __ICE_SMART_COUNT_H
|
||||
|
||||
// Note: This implementation is a modified version of shared_count from
|
||||
// Boost.org
|
||||
//
|
||||
|
||||
#include <memory> // std::auto_ptr, std::allocator
|
||||
#include <functional> // std::less
|
||||
#include <exception> // std::exception
|
||||
#include <new> // std::bad_alloc
|
||||
#include <typeinfo> // std::type_info in get_deleter
|
||||
#include <cstddef> // std::size_t
|
||||
#include "ICESync.h"
|
||||
|
||||
namespace ice
|
||||
{
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
# pragma warn -8026 // Functions with excep. spec. are not expanded inline
|
||||
# pragma warn -8027 // Functions containing try are not expanded inline
|
||||
#endif
|
||||
|
||||
// verify that types are complete for increased safety
|
||||
template<class T> inline void checked_delete(T * x)
|
||||
{
|
||||
// intentionally complex - simplification causes regressions
|
||||
typedef char type_must_be_complete[ sizeof(T)? 1: -1 ];
|
||||
(void) sizeof(type_must_be_complete);
|
||||
delete x;
|
||||
};
|
||||
|
||||
template<class T> struct checked_deleter
|
||||
{
|
||||
typedef void result_type;
|
||||
typedef T * argument_type;
|
||||
|
||||
void operator()(T * x) const
|
||||
{
|
||||
// resip:: disables ADL
|
||||
checked_delete(x);
|
||||
}
|
||||
};
|
||||
|
||||
// The standard library that comes with Borland C++ 5.5.1
|
||||
// defines std::exception and its members as having C calling
|
||||
// convention (-pc). When the definition of bad_weak_ptr
|
||||
// is compiled with -ps, the compiler issues an error.
|
||||
// Hence, the temporary #pragma option -pc below. The version
|
||||
// check is deliberately conservative.
|
||||
#if defined(__BORLANDC__) && __BORLANDC__ == 0x551
|
||||
# pragma option push -pc
|
||||
#endif
|
||||
|
||||
class bad_weak_ptr: public std::exception
|
||||
{
|
||||
public:
|
||||
|
||||
virtual char const * what() const throw()
|
||||
{
|
||||
return "resip::bad_weak_ptr";
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(__BORLANDC__) && __BORLANDC__ == 0x551
|
||||
# pragma option pop
|
||||
#endif
|
||||
|
||||
class sp_counted_base
|
||||
{
|
||||
private:
|
||||
|
||||
public:
|
||||
|
||||
sp_counted_base(): use_count_(1), weak_count_(1)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~sp_counted_base() // nothrow
|
||||
{
|
||||
}
|
||||
|
||||
// dispose() is called when use_count_ drops to zero, to release
|
||||
// the resources managed by *this.
|
||||
virtual void dispose() = 0; // nothrow
|
||||
|
||||
// destruct() is called when weak_count_ drops to zero.
|
||||
virtual void destruct() // nothrow
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
virtual void * get_deleter(std::type_info const & ti) = 0;
|
||||
|
||||
void add_ref_copy()
|
||||
{
|
||||
Lock lock(mMutex); (void)lock;
|
||||
++use_count_;
|
||||
//GenericLog(Subsystem::SIP, resip::Log::Info, << "********* SharedCount::add_ref_copy: " << use_count_);
|
||||
}
|
||||
|
||||
void add_ref_lock()
|
||||
{
|
||||
Lock lock(mMutex); (void)lock;
|
||||
// if(use_count_ == 0) throw(resip::bad_weak_ptr());
|
||||
if (use_count_ == 0) throw bad_weak_ptr();
|
||||
++use_count_;
|
||||
//GenericLog(Subsystem::SIP, resip::Log::Info, << "********* SharedCount::add_ref_lock: " << use_count_);
|
||||
}
|
||||
|
||||
void release() // nothrow
|
||||
{
|
||||
{
|
||||
Lock lock(mMutex); (void)lock;
|
||||
long new_use_count = --use_count_;
|
||||
//GenericLog(Subsystem::SIP, resip::Log::Info, << "********* SharedCount::release: " << use_count_);
|
||||
|
||||
if(new_use_count != 0) return;
|
||||
}
|
||||
|
||||
dispose();
|
||||
weak_release();
|
||||
}
|
||||
|
||||
void weak_add_ref() // nothrow
|
||||
{
|
||||
Lock lock(mMutex); (void)lock;
|
||||
++weak_count_;
|
||||
}
|
||||
|
||||
void weak_release() // nothrow
|
||||
{
|
||||
long new_weak_count;
|
||||
|
||||
{
|
||||
Lock lock(mMutex); (void)lock;
|
||||
new_weak_count = --weak_count_;
|
||||
}
|
||||
|
||||
if(new_weak_count == 0)
|
||||
{
|
||||
destruct();
|
||||
}
|
||||
}
|
||||
|
||||
long use_count() const // nothrow
|
||||
{
|
||||
Lock lock(mMutex); (void)lock;
|
||||
return use_count_;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
sp_counted_base(sp_counted_base const &);
|
||||
sp_counted_base & operator= (sp_counted_base const &);
|
||||
|
||||
long use_count_; // #shared
|
||||
long weak_count_; // #weak + (#shared != 0)
|
||||
|
||||
mutable Mutex mMutex;
|
||||
};
|
||||
|
||||
//
|
||||
// Borland's Codeguard trips up over the -Vx- option here:
|
||||
//
|
||||
#ifdef __CODEGUARD__
|
||||
# pragma option push -Vx-
|
||||
#endif
|
||||
|
||||
template<class P, class D> class sp_counted_base_impl: public sp_counted_base
|
||||
{
|
||||
private:
|
||||
|
||||
P ptr; // copy constructor must not throw
|
||||
D del; // copy constructor must not throw
|
||||
|
||||
sp_counted_base_impl(sp_counted_base_impl const &);
|
||||
sp_counted_base_impl & operator= (sp_counted_base_impl const &);
|
||||
|
||||
typedef sp_counted_base_impl<P, D> this_type;
|
||||
|
||||
public:
|
||||
|
||||
// pre: initial_use_count <= initial_weak_count, d(p) must not throw
|
||||
sp_counted_base_impl(P p, D d): ptr(p), del(d)
|
||||
{
|
||||
}
|
||||
|
||||
virtual void dispose() // nothrow
|
||||
{
|
||||
del(ptr);
|
||||
}
|
||||
|
||||
virtual void * get_deleter(std::type_info const & ti)
|
||||
{
|
||||
return ti == typeid(D)? &del: 0;
|
||||
}
|
||||
|
||||
void * operator new(size_t)
|
||||
{
|
||||
return std::allocator<this_type>().allocate(1, static_cast<this_type *>(0));
|
||||
}
|
||||
|
||||
void operator delete(void * p)
|
||||
{
|
||||
std::allocator<this_type>().deallocate(static_cast<this_type *>(p), 1);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class shared_count
|
||||
{
|
||||
private:
|
||||
|
||||
sp_counted_base * pi_;
|
||||
|
||||
public:
|
||||
|
||||
shared_count(): pi_(0) // nothrow
|
||||
{
|
||||
}
|
||||
|
||||
template<class P, class D> shared_count(P p, D d): pi_(0)
|
||||
{
|
||||
try
|
||||
{
|
||||
pi_ = new sp_counted_base_impl<P, D>(p, d);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
d(p); // delete p
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
// auto_ptr<Y> is special cased to provide the strong guarantee
|
||||
template<class Y>
|
||||
explicit shared_count(std::auto_ptr<Y> & r): pi_(new sp_counted_base_impl< Y *, checked_deleter<Y> >(r.get(), checked_deleter<Y>()))
|
||||
{
|
||||
r.release();
|
||||
}
|
||||
|
||||
~shared_count() // nothrow
|
||||
{
|
||||
if(pi_ != 0) pi_->release();
|
||||
}
|
||||
|
||||
shared_count(shared_count const & r): pi_(r.pi_) // nothrow
|
||||
{
|
||||
if(pi_ != 0) pi_->add_ref_copy();
|
||||
}
|
||||
|
||||
shared_count & operator= (shared_count const & r) // nothrow
|
||||
{
|
||||
sp_counted_base * tmp = r.pi_;
|
||||
if(tmp != 0) tmp->add_ref_copy();
|
||||
if(pi_ != 0) pi_->release();
|
||||
pi_ = tmp;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void swap(shared_count & r) // nothrow
|
||||
{
|
||||
sp_counted_base * tmp = r.pi_;
|
||||
r.pi_ = pi_;
|
||||
pi_ = tmp;
|
||||
}
|
||||
|
||||
long use_count() const // nothrow
|
||||
{
|
||||
return pi_ != 0? pi_->use_count(): 0;
|
||||
}
|
||||
|
||||
bool unique() const // nothrow
|
||||
{
|
||||
return use_count() == 1;
|
||||
}
|
||||
|
||||
friend inline bool operator==(shared_count const & a, shared_count const & b)
|
||||
{
|
||||
return a.pi_ == b.pi_;
|
||||
}
|
||||
|
||||
friend inline bool operator<(shared_count const & a, shared_count const & b)
|
||||
{
|
||||
return std::less<sp_counted_base *>()(a.pi_, b.pi_);
|
||||
}
|
||||
|
||||
void * get_deleter(std::type_info const & ti) const
|
||||
{
|
||||
return pi_? pi_->get_deleter(ti): 0;
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef __CODEGUARD__
|
||||
# pragma option pop
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
# pragma warn .8027 // Functions containing try are not expanded inline
|
||||
# pragma warn .8026 // Functions with excep. spec. are not expanded inline
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// Note: This implementation is a modified version of shared_count from
|
||||
// Boost.org
|
||||
//
|
||||
|
||||
/* ====================================================================
|
||||
*
|
||||
* Boost Software License - Version 1.0 - August 17th, 2003
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person or organization
|
||||
* obtaining a copy of the software and accompanying documentation covered by
|
||||
* this license (the "Software") to use, reproduce, display, distribute,
|
||||
* execute, and transmit the Software, and to prepare derivative works of the
|
||||
* Software, and to permit third-parties to whom the Software is furnished to
|
||||
* do so, all subject to the following:
|
||||
*
|
||||
* The copyright notices in the Software and this entire statement, including
|
||||
* the above license grant, this restriction and the following disclaimer,
|
||||
* must be included in all copies of the Software, in whole or in part, and
|
||||
* all derivative works of the Software, unless such copies or derivative
|
||||
* works are solely in the form of machine-executable object code generated by
|
||||
* a source language processor.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
* SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
* FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
* ====================================================================
|
||||
*/
|
||||
|
||||
|
||||
/* ====================================================================
|
||||
* The Vovida Software License, Version 1.0
|
||||
*
|
||||
* Copyright (c) 2000 Vovida Networks, Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* 3. The names "VOCAL", "Vovida Open Communication Application Library",
|
||||
* and "Vovida Open Communication Application Library (VOCAL)" must
|
||||
* not be used to endorse or promote products derived from this
|
||||
* software without prior written permission. For written
|
||||
* permission, please contact vocal@vovida.org.
|
||||
*
|
||||
* 4. Products derived from this software may not be called "VOCAL", nor
|
||||
* may "VOCAL" appear in their name, without prior written
|
||||
* permission of Vovida Networks, Inc.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
|
||||
* NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA
|
||||
* NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
|
||||
* IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
||||
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
||||
* DAMAGE.
|
||||
*
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by Vovida
|
||||
* Networks, Inc. and many individuals on behalf of Vovida Networks,
|
||||
* Inc. For more information on Vovida Networks, Inc., please see
|
||||
* <http://www.vovida.org/>.
|
||||
*
|
||||
*/
|
||||
|
|
@ -1,382 +0,0 @@
|
|||
// Based on resiprocate's implementation of smart pointer, which is based on boost implementation
|
||||
// Its license is smth close to BSD
|
||||
|
||||
#ifndef __ICE_SMART_PTR_H
|
||||
#define __ICE_SMART_PTR_H
|
||||
|
||||
#ifndef USE_NATIVE_SMARTPTR
|
||||
|
||||
#include "ICESmartCount.h"
|
||||
#include <memory> // for std::auto_ptr
|
||||
#include <algorithm> // for std::swap
|
||||
#include <functional> // for std::less
|
||||
#include <typeinfo> // for std::bad_cast
|
||||
#include <iosfwd> // for std::basic_ostream
|
||||
#include <cassert>
|
||||
|
||||
namespace ice
|
||||
{
|
||||
|
||||
|
||||
template<class T> class enable_shared_from_this;
|
||||
|
||||
struct static_cast_tag {};
|
||||
struct const_cast_tag {};
|
||||
struct dynamic_cast_tag {};
|
||||
struct polymorphic_cast_tag {};
|
||||
|
||||
template<class T> struct SmartPtr_traits
|
||||
{
|
||||
typedef T & reference;
|
||||
};
|
||||
|
||||
template<> struct SmartPtr_traits<void>
|
||||
{
|
||||
typedef void reference;
|
||||
};
|
||||
|
||||
template<> struct SmartPtr_traits<void const>
|
||||
{
|
||||
typedef void reference;
|
||||
};
|
||||
|
||||
template<> struct SmartPtr_traits<void volatile>
|
||||
{
|
||||
typedef void reference;
|
||||
};
|
||||
|
||||
template<> struct SmartPtr_traits<void const volatile>
|
||||
{
|
||||
typedef void reference;
|
||||
};
|
||||
|
||||
// enable_shared_from_this support
|
||||
|
||||
template<class T, class Y> void sp_enable_shared_from_this( shared_count const & pn, enable_shared_from_this<T> const * pe, Y const * px )
|
||||
{
|
||||
if(pe != 0) pe->_internal_weak_this._internal_assign(const_cast<Y*>(px), pn);
|
||||
}
|
||||
|
||||
inline void sp_enable_shared_from_this( shared_count const & /*pn*/, ... )
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// SmartPtr
|
||||
//
|
||||
// Reference counted copy semantics.
|
||||
// The object pointed to is deleted when the last SmartPtr pointing to it
|
||||
// is destroyed or reset.
|
||||
//
|
||||
|
||||
template<class T> class SmartPtr
|
||||
{
|
||||
private:
|
||||
|
||||
// Borland 5.5.1 specific workaround
|
||||
typedef SmartPtr<T> this_type;
|
||||
|
||||
public:
|
||||
|
||||
typedef T element_type;
|
||||
typedef T value_type;
|
||||
typedef T * pointer;
|
||||
typedef typename SmartPtr_traits<T>::reference reference;
|
||||
|
||||
SmartPtr(): px(0), pn() // never throws in 1.30+
|
||||
{
|
||||
}
|
||||
|
||||
template<class Y>
|
||||
explicit SmartPtr(Y * p): px(p), pn(p, checked_deleter<Y>()) // Y must be complete
|
||||
{
|
||||
sp_enable_shared_from_this( pn, p, p );
|
||||
}
|
||||
|
||||
//
|
||||
// Requirements: D's copy constructor must not throw
|
||||
//
|
||||
// SmartPtr will release p by calling d(p)
|
||||
//
|
||||
|
||||
template<class Y, class D> SmartPtr(Y * p, D d): px(p), pn(p, d)
|
||||
{
|
||||
sp_enable_shared_from_this( pn, p, p );
|
||||
}
|
||||
|
||||
// generated copy constructor, assignment, destructor are fine...
|
||||
|
||||
// except that Borland C++ has a bug, and g++ with -Wsynth warns
|
||||
#if defined(__BORLANDC__) || defined(__GNUC__)
|
||||
SmartPtr & operator=(SmartPtr const & r) // never throws
|
||||
{
|
||||
px = r.px;
|
||||
pn = r.pn; // shared_count::op= doesn't throw
|
||||
return *this;
|
||||
}
|
||||
#endif
|
||||
|
||||
template<class Y>
|
||||
SmartPtr(SmartPtr<Y> const & r): px(r.px), pn(r.pn) // never throws
|
||||
{
|
||||
}
|
||||
|
||||
template<class Y>
|
||||
SmartPtr(SmartPtr<Y> const & r, static_cast_tag): px(static_cast<element_type *>(r.px)), pn(r.pn)
|
||||
{
|
||||
}
|
||||
|
||||
template<class Y>
|
||||
SmartPtr(SmartPtr<Y> const & r, const_cast_tag): px(const_cast<element_type *>(r.px)), pn(r.pn)
|
||||
{
|
||||
}
|
||||
|
||||
template<class Y>
|
||||
SmartPtr(SmartPtr<Y> const & r, dynamic_cast_tag): px(dynamic_cast<element_type *>(r.px)), pn(r.pn)
|
||||
{
|
||||
if(px == 0) // need to allocate new counter -- the cast failed
|
||||
{
|
||||
pn = /*resip::*/shared_count();
|
||||
}
|
||||
}
|
||||
|
||||
template<class Y>
|
||||
SmartPtr(SmartPtr<Y> const & r, polymorphic_cast_tag): px(dynamic_cast<element_type *>(r.px)), pn(r.pn)
|
||||
{
|
||||
if(px == 0)
|
||||
{
|
||||
throw std::bad_cast();
|
||||
}
|
||||
}
|
||||
|
||||
template<class Y>
|
||||
explicit SmartPtr(std::auto_ptr<Y> & r): px(r.get()), pn()
|
||||
{
|
||||
Y * tmp = r.get();
|
||||
pn = shared_count(r);
|
||||
sp_enable_shared_from_this( pn, tmp, tmp );
|
||||
}
|
||||
|
||||
template<class Y>
|
||||
SmartPtr & operator=(SmartPtr<Y> const & r) // never throws
|
||||
{
|
||||
px = r.px;
|
||||
pn = r.pn; // shared_count::op= doesn't throw
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class Y>
|
||||
SmartPtr & operator=(std::auto_ptr<Y> & r)
|
||||
{
|
||||
this_type(r).swap(*this);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void reset() // never throws in 1.30+
|
||||
{
|
||||
this_type().swap(*this);
|
||||
}
|
||||
|
||||
template<class Y> void reset(Y * p) // Y must be complete
|
||||
{
|
||||
assert(p == 0 || p != px); // catch self-reset errors
|
||||
this_type(p).swap(*this);
|
||||
}
|
||||
|
||||
template<class Y, class D> void reset(Y * p, D d)
|
||||
{
|
||||
this_type(p, d).swap(*this);
|
||||
}
|
||||
|
||||
reference operator* () const // never throws
|
||||
{
|
||||
assert(px != 0);
|
||||
return *px;
|
||||
}
|
||||
|
||||
T * operator-> () const // never throws
|
||||
{
|
||||
//assert(px != 0);
|
||||
return px;
|
||||
}
|
||||
|
||||
T * get() const // never throws
|
||||
{
|
||||
return px;
|
||||
}
|
||||
|
||||
// implicit conversion to "bool"
|
||||
#if defined(__SUNPRO_CC) // BOOST_WORKAROUND(__SUNPRO_CC, <= 0x530)
|
||||
operator bool () const
|
||||
{
|
||||
return px != 0;
|
||||
}
|
||||
#elif defined(__MWERKS__) // BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003))
|
||||
typedef T * (this_type::*unspecified_bool_type)() const;
|
||||
operator unspecified_bool_type() const // never throws
|
||||
{
|
||||
return px == 0? 0: &this_type::get;
|
||||
}
|
||||
#else
|
||||
typedef T * this_type::*unspecified_bool_type;
|
||||
operator unspecified_bool_type() const // never throws
|
||||
{
|
||||
return px == 0? 0: &this_type::px;
|
||||
}
|
||||
#endif
|
||||
|
||||
// operator! is redundant, but some compilers need it
|
||||
bool operator! () const // never throws
|
||||
{
|
||||
return px == 0;
|
||||
}
|
||||
|
||||
bool unique() const // never throws
|
||||
{
|
||||
return pn.unique();
|
||||
}
|
||||
|
||||
long use_count() const // never throws
|
||||
{
|
||||
return pn.use_count();
|
||||
}
|
||||
|
||||
void swap(SmartPtr<T> & other) // never throws
|
||||
{
|
||||
std::swap(px, other.px);
|
||||
pn.swap(other.pn);
|
||||
}
|
||||
|
||||
template<class Y> bool _internal_less(SmartPtr<Y> const & rhs) const
|
||||
{
|
||||
return pn < rhs.pn;
|
||||
}
|
||||
|
||||
void * _internal_get_deleter(std::type_info const & ti) const
|
||||
{
|
||||
return pn.get_deleter(ti);
|
||||
}
|
||||
|
||||
// Tasteless as this may seem, making all members public allows member templates
|
||||
// to work in the absence of member template friends. (Matthew Langston)
|
||||
|
||||
private:
|
||||
|
||||
template<class Y> friend class SmartPtr;
|
||||
|
||||
T * px; // contained pointer
|
||||
shared_count pn; // reference counter
|
||||
|
||||
}; // SmartPtr
|
||||
|
||||
template<class T, class U> inline bool operator==(SmartPtr<T> const & a, SmartPtr<U> const & b)
|
||||
{
|
||||
return a.get() == b.get();
|
||||
}
|
||||
|
||||
template<class T, class U> inline bool operator!=(SmartPtr<T> const & a, SmartPtr<U> const & b)
|
||||
{
|
||||
return a.get() != b.get();
|
||||
}
|
||||
|
||||
#if __GNUC__ == 2 && __GNUC_MINOR__ <= 96
|
||||
|
||||
// Resolve the ambiguity between our op!= and the one in rel_ops
|
||||
|
||||
template<class T> inline bool operator!=(SmartPtr<T> const & a, SmartPtr<T> const & b)
|
||||
{
|
||||
return a.get() != b.get();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
template<class T, class U> inline bool operator<(SmartPtr<T> const & a, SmartPtr<U> const & b)
|
||||
{
|
||||
return a._internal_less(b);
|
||||
}
|
||||
|
||||
template<class T> inline void swap(SmartPtr<T> & a, SmartPtr<T> & b)
|
||||
{
|
||||
a.swap(b);
|
||||
}
|
||||
|
||||
template<class T, class U> SmartPtr<T> static_pointer_cast(SmartPtr<U> const & r)
|
||||
{
|
||||
return SmartPtr<T>(r, static_cast_tag());
|
||||
}
|
||||
|
||||
template<class T, class U> SmartPtr<T> const_pointer_cast(SmartPtr<U> const & r)
|
||||
{
|
||||
return SmartPtr<T>(r, const_cast_tag());
|
||||
}
|
||||
|
||||
template<class T, class U> SmartPtr<T> dynamic_pointer_cast(SmartPtr<U> const & r)
|
||||
{
|
||||
return SmartPtr<T>(r, dynamic_cast_tag());
|
||||
}
|
||||
|
||||
// shared_*_cast names are deprecated. Use *_pointer_cast instead.
|
||||
|
||||
template<class T, class U> SmartPtr<T> shared_static_cast(SmartPtr<U> const & r)
|
||||
{
|
||||
return SmartPtr<T>(r, static_cast_tag());
|
||||
}
|
||||
|
||||
template<class T, class U> SmartPtr<T> shared_dynamic_cast(SmartPtr<U> const & r)
|
||||
{
|
||||
return SmartPtr<T>(r, dynamic_cast_tag());
|
||||
}
|
||||
|
||||
template<class T, class U> SmartPtr<T> shared_polymorphic_cast(SmartPtr<U> const & r)
|
||||
{
|
||||
return SmartPtr<T>(r, polymorphic_cast_tag());
|
||||
}
|
||||
|
||||
template<class T, class U> SmartPtr<T> shared_polymorphic_downcast(SmartPtr<U> const & r)
|
||||
{
|
||||
assert(dynamic_cast<T *>(r.get()) == r.get());
|
||||
return shared_static_cast<T>(r);
|
||||
}
|
||||
|
||||
template<class T> inline T * get_pointer(SmartPtr<T> const & p)
|
||||
{
|
||||
return p.get();
|
||||
}
|
||||
|
||||
// operator<<
|
||||
#if defined(__GNUC__) && (__GNUC__ < 3)
|
||||
template<class Y> std::ostream & operator<< (std::ostream & os, SmartPtr<Y> const & p)
|
||||
{
|
||||
os << p.get();
|
||||
return os;
|
||||
}
|
||||
#else
|
||||
template<class E, class T, class Y> std::basic_ostream<E, T> & operator<< (std::basic_ostream<E, T> & os, SmartPtr<Y> const & p)
|
||||
{
|
||||
os << p.get();
|
||||
return os;
|
||||
}
|
||||
#endif
|
||||
|
||||
// get_deleter (experimental)
|
||||
#if (defined(__GNUC__) && (__GNUC__ < 3)) || (defined(__EDG_VERSION__) && (__EDG_VERSION__ <= 238))
|
||||
// g++ 2.9x doesn't allow static_cast<X const *>(void *)
|
||||
// apparently EDG 2.38 also doesn't accept it
|
||||
template<class D, class T> D * get_deleter(SmartPtr<T> const & p)
|
||||
{
|
||||
void const * q = p._internal_get_deleter(typeid(D));
|
||||
return const_cast<D *>(static_cast<D const *>(q));
|
||||
}
|
||||
#else
|
||||
template<class D, class T> D * get_deleter(SmartPtr<T> const & p)
|
||||
{
|
||||
return static_cast<D *>(p._internal_get_deleter(typeid(D)));
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -14,6 +14,7 @@
|
|||
#include <stdexcept>
|
||||
#include <strstream>
|
||||
#include <algorithm>
|
||||
#include <assert.h>
|
||||
|
||||
using namespace ice;
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ namespace ice
|
|||
extern const char* RunningStateToString(RunningState state);
|
||||
|
||||
// Smart pointer to ICE stream type
|
||||
typedef SmartPtr<Stream> ICEStreamPtr;
|
||||
typedef std::shared_ptr<Stream> ICEStreamPtr;
|
||||
|
||||
|
||||
// Map of used channel TURN prefixes as key and corresponding address as value
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@
|
|||
#include "ICEStunAttributes.h"
|
||||
#include "ICENetworkHelper.h"
|
||||
#include <stdexcept>
|
||||
#include <assert.h>
|
||||
|
||||
using namespace ice;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
#ifndef _WIN32
|
||||
# include <stdexcept>
|
||||
#endif
|
||||
#include <assert.h>
|
||||
|
||||
using namespace ice;
|
||||
#define LOG_SUBSYSTEM "ICE"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright(C) 2007-2014 VoIP objects (voipobjects.com)
|
||||
/* Copyright(C) 2007-2018 VoIP objects (voipobjects.com)
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
|
@ -11,7 +11,6 @@
|
|||
|
||||
#include "ICEStunMessage.h"
|
||||
#include "ICEPacketTimer.h"
|
||||
#include "ICESmartPtr.h"
|
||||
#include "ICECandidatePair.h"
|
||||
#include "ICEAction.h"
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue