Commit a79465df authored by Ronan's avatar Ronan

unstable

parent 5cfa0913
......@@ -354,20 +354,6 @@ void linphone_call_params_set_avpf_rr_interval(LinphoneCallParams *params, uint1
* Reference and user data handling functions *
******************************************************************************/
/**
* Get the user data associated with the call params.
* @param[in] cp LinphoneCallParams object
* @return The user data associated with the call params.
**/
LINPHONE_PUBLIC void *linphone_call_params_get_user_data(const LinphoneCallParams *cp);
/**
* Assign a user data to the call params.
* @param[in] cp LinphoneCallParams object
* @param[in] ud The user data to associate with the call params.
**/
LINPHONE_PUBLIC void linphone_call_params_set_user_data(LinphoneCallParams *cp, void *ud);
/**
* Acquire a reference to the call params.
* @param[in] cp LinphoneCallParams object
......
......@@ -31,27 +31,27 @@
LINPHONE_BEGIN_NAMESPACE
template<typename T, typename Value>
typename T::const_iterator find (const T &container, const Value &value) {
inline typename T::const_iterator find (const T &container, const Value &value) {
return std::find(container.cbegin(), container.cend(), value);
}
template<typename T, typename Value>
typename T::iterator find (T &container, const Value &value) {
inline typename T::iterator find (T &container, const Value &value) {
return std::find(container.begin(), container.end(), value);
}
template<typename T, typename Predicate>
typename T::const_iterator findIf (const T &container, Predicate predicate) {
inline typename T::const_iterator findIf (const T &container, Predicate predicate) {
return std::find_if(container.cbegin(), container.cend(), predicate);
}
template<typename T, typename Predicate>
typename T::iterator findIf (T &container, Predicate predicate) {
inline typename T::iterator findIf (T &container, Predicate predicate) {
return std::find_if(container.begin(), container.end(), predicate);
}
template<typename T, typename Value>
bool removeFirst (T &container, const Value &value) {
inline bool removeFirst (T &container, const Value &value) {
auto it = find(container, value);
if (it != container.end()) {
container.erase(it);
......@@ -61,7 +61,7 @@ bool removeFirst (T &container, const Value &value) {
}
template<typename T, typename Predicate>
void removeIf (T &container, Predicate predicate) {
inline void removeIf (T &container, Predicate predicate) {
std::remove_if(container.begin(), container.end(), predicate);
}
......
......@@ -118,6 +118,9 @@ std::unique_ptr<T> makeUnique(Args && ...args) {
// Class tools.
// -----------------------------------------------------------------------------
#define L_DISABLE_ASSIGNMENT(CLASS) \
CLASS &operator= (const CLASS &) = delete;
#define L_DISABLE_COPY(CLASS) \
CLASS (const CLASS &) = delete; \
CLASS &operator= (const CLASS &) = delete;
......@@ -133,6 +136,9 @@ class ClonableObjectPrivate;
class Object;
class ObjectPrivate;
template<typename T>
class ClonableSharedPointer;
namespace Private {
template<typename T>
using BetterPrivateAncestor = typename std::conditional<
......@@ -145,26 +151,19 @@ namespace Private {
>::type
>::type;
// Generic public helper.
template<
typename R,
typename P,
typename C
>
constexpr R *getPublicHelper (P *object, const C *) {
return static_cast<R *>(object);
template<typename T>
constexpr T *getPrivateHelper (T *p) {
return p;
}
template<typename T>
T *getPrivateHelper (ClonableSharedPointer<T> &p) {
return p.get();
}
// Generic public helper. Deal with shared data.
template<
typename R,
typename P,
typename C
>
inline R *getPublicHelper (const P &objectSet, const C *) {
auto it = objectSet.cbegin();
L_ASSERT(it != objectSet.cend());
return static_cast<R *>(*it);
template<typename T>
const T *getPrivateHelper (const ClonableSharedPointer<T> &p) {
return p.get();
}
template<typename T, typename U>
......@@ -188,13 +187,13 @@ namespace Private {
inline CLASS ## Private *getPrivate () { \
L_INTERNAL_CHECK_OBJECT_INHERITANCE(CLASS); \
return reinterpret_cast<CLASS ## Private *>( \
LinphonePrivate::Private::BetterPrivateAncestor<CLASS>::mPrivate \
Private::getPrivateHelper(LinphonePrivate::Private::BetterPrivateAncestor<CLASS>::mPrivate) \
); \
} \
inline const CLASS ## Private *getPrivate () const { \
L_INTERNAL_CHECK_OBJECT_INHERITANCE(CLASS); \
return reinterpret_cast<const CLASS ## Private *>( \
LinphonePrivate::Private::BetterPrivateAncestor<CLASS>::mPrivate \
Private::getPrivateHelper(LinphonePrivate::Private::BetterPrivateAncestor<CLASS>::mPrivate) \
); \
} \
friend class CLASS ## Private; \
......@@ -212,10 +211,10 @@ namespace Private {
#define L_DECLARE_PUBLIC(CLASS) \
CLASS *getPublic () { \
return LinphonePrivate::Private::getPublicHelper<CLASS>(mPublic, this); \
return static_cast<CLASS *>(mPublic); \
} \
const CLASS *getPublic () const { \
return LinphonePrivate::Private::getPublicHelper<const CLASS>(mPublic, this); \
return static_cast<const CLASS *>(mPublic); \
} \
friend class CLASS;
......
......@@ -32,14 +32,20 @@ struct SalAddress;
LINPHONE_BEGIN_NAMESPACE
class AddressPrivate : public ClonableObjectPrivate {
friend class Address;
public:
inline const SalAddress *getInternalAddress () const {
~AddressPrivate ();
const SalAddress *getInternalAddress () const {
return internalAddress;
}
void setInternalAddress (const SalAddress *value);
private:
struct AddressCache {
SharedObject *clone () override;
mutable struct {
std::string scheme;
std::string displayName;
std::string username;
......@@ -50,12 +56,9 @@ private:
std::unordered_map<std::string, std::string> headers;
std::unordered_map<std::string, std::string> params;
std::unordered_map<std::string, std::string> uriParams;
};
} cache;
SalAddress *internalAddress = nullptr;
mutable AddressCache cache;
L_DECLARE_PUBLIC(Address);
};
LINPHONE_END_NAMESPACE
......
......@@ -33,16 +33,29 @@ LINPHONE_BEGIN_NAMESPACE
// -----------------------------------------------------------------------------
AddressPrivate::~AddressPrivate () {
if (internalAddress)
sal_address_destroy(internalAddress);
}
void AddressPrivate::setInternalAddress (const SalAddress *addr) {
if (internalAddress)
sal_address_unref(internalAddress);
internalAddress = sal_address_clone(addr);
}
SharedObject *AddressPrivate::clone () {
AddressPrivate *dAddress = new AddressPrivate();
if (internalAddress)
dAddress->internalAddress = sal_address_clone(internalAddress);
return dAddress;
}
// -----------------------------------------------------------------------------
Address::Address (const string &address) : ClonableObject(*new AddressPrivate) {
L_D();
// TODO: Optimize, use a cache.
if (!(d->internalAddress = sal_address_new(L_STRING_TO_C(address)))) {
lWarning() << "Cannot create Address, bad uri [" << address << "]";
}
......@@ -65,34 +78,10 @@ Address::Address (const IdentityAddress &identityAddress) : ClonableObject(*new
if (identityAddress.hasGruu())
uri += ";gr=" + identityAddress.getGruu();
// TODO: Optimize, use a cache.
d->internalAddress = sal_address_new(L_STRING_TO_C(uri));
}
Address::Address (const Address &other) : ClonableObject(*new AddressPrivate) {
L_D();
SalAddress *salAddress = other.getPrivate()->internalAddress;
if (salAddress)
d->internalAddress = sal_address_clone(salAddress);
}
Address::~Address () {
L_D();
if (d->internalAddress)
sal_address_destroy(d->internalAddress);
}
Address &Address::operator= (const Address &other) {
L_D();
if (this != &other) {
if (d->internalAddress)
sal_address_destroy(d->internalAddress);
SalAddress *salAddress = other.getPrivate()->internalAddress;
d->internalAddress = salAddress ? sal_address_clone(salAddress) : nullptr;
}
return *this;
}
bool Address::operator== (const Address &other) const {
return asString() == other.asString();
}
......
......@@ -42,10 +42,6 @@ class LINPHONE_PUBLIC Address : public ClonableObject {
public:
explicit Address (const std::string &address = "");
Address (const IdentityAddress &identityAddress);
Address (const Address &other);
~Address ();
Address &operator= (const Address &other);
bool operator== (const Address &other) const;
bool operator!= (const Address &other) const;
......
......@@ -39,6 +39,12 @@ public:
std::string username;
std::string domain;
std::string gruu;
private:
SharedObject *clone () override {
// Default copy constructor is nice here. :)
return new IdentityAddressPrivate(*this);
}
};
// -----------------------------------------------------------------------------
......@@ -63,25 +69,6 @@ IdentityAddress::IdentityAddress (const Address &address) : ClonableObject(*new
d->gruu = address.getUriParamValue("gr");
}
IdentityAddress::IdentityAddress (const IdentityAddress &other) : ClonableObject(*new IdentityAddressPrivate) {
L_D();
d->scheme = other.getScheme();
d->username = other.getUsername();
d->domain = other.getDomain();
d->gruu = other.getGruu();
}
IdentityAddress &IdentityAddress::operator= (const IdentityAddress &other) {
L_D();
if (this != &other) {
d->scheme = other.getScheme();
d->username = other.getUsername();
d->domain = other.getDomain();
d->gruu = other.getGruu();
}
return *this;
}
bool IdentityAddress::operator== (const IdentityAddress &other) const {
return asString() == other.asString();
}
......
......@@ -29,14 +29,11 @@ LINPHONE_BEGIN_NAMESPACE
class Address;
class IdentityAddressPrivate;
// TODO: Inherit from address and disable copy. Provide a virtual clone method on Address instead.
class LINPHONE_PUBLIC IdentityAddress : public ClonableObject {
public:
explicit IdentityAddress (const std::string &address = "");
IdentityAddress (const Address &address);
IdentityAddress (const IdentityAddress &other);
~IdentityAddress () = default;
IdentityAddress &operator= (const IdentityAddress &other);
bool operator== (const IdentityAddress &other) const;
bool operator!= (const IdentityAddress &other) const;
......
......@@ -489,14 +489,6 @@ void linphone_call_params_set_no_user_consent (LinphoneCallParams *params, bool_
// Reference and user data handling functions.
// =============================================================================
void *linphone_call_params_get_user_data (const LinphoneCallParams *cp) {
return L_GET_USER_DATA_FROM_C_OBJECT(cp);
}
void linphone_call_params_set_user_data (LinphoneCallParams *cp, void *ud) {
L_SET_USER_DATA_FROM_C_OBJECT(cp, ud);
}
LinphoneCallParams *linphone_call_params_ref (LinphoneCallParams *cp) {
belle_sip_object_ref(cp);
return cp;
......
......@@ -31,6 +31,11 @@ class ChatRoomIdPrivate : public ClonableObjectPrivate {
public:
IdentityAddress peerAddress;
IdentityAddress localAddress;
private:
SharedObject *clone () override {
return new ChatRoomIdPrivate(*this);
}
};
// -----------------------------------------------------------------------------
......@@ -46,8 +51,6 @@ ChatRoomId::ChatRoomId (
d->localAddress = localAddress;
}
L_USE_DEFAULT_CLONABLE_OBJECT_SHARED_IMPL(ChatRoomId);
bool ChatRoomId::operator== (const ChatRoomId &other) const {
L_D();
const ChatRoomIdPrivate *dChatRoomId = other.getPrivate();
......
......@@ -32,9 +32,6 @@ class LINPHONE_PUBLIC ChatRoomId : public ClonableObject {
public:
ChatRoomId ();
ChatRoomId (const IdentityAddress &peerAddress, const IdentityAddress &localAddress);
ChatRoomId (const ChatRoomId &other);
ChatRoomId &operator= (const ChatRoomId &other);
bool operator== (const ChatRoomId &other) const;
bool operator!= (const ChatRoomId &other) const;
......
......@@ -22,9 +22,8 @@
#include <unordered_map>
#include "object/clonable-object-p.h"
#include "call-session-params.h"
#include "object/clonable-object-p.h"
// =============================================================================
......@@ -33,6 +32,8 @@ LINPHONE_BEGIN_NAMESPACE
class CallSession;
class CallSessionParamsPrivate : public ClonableObjectPrivate {
friend class CallSessionParams;
public:
CallSessionParamsPrivate () = default;
......@@ -45,7 +46,7 @@ public:
bool getNoUserConsent () const { return noUserConsent; }
void setNoUserConsent (bool value) { noUserConsent = value; }
SalCustomHeader * getCustomHeaders () const;
SalCustomHeader *getCustomHeaders () const;
void setCustomHeaders (const SalCustomHeader *ch);
const std::unordered_map<std::string, std::string> &getCustomContactParameters () const { return customContactParameters; }
......@@ -59,14 +60,18 @@ public:
LinphonePrivacyMask privacy = LinphonePrivacyNone;
private:
SharedObject *clone () override {
// TODO: Return SharedObject.
L_ASSERT(false);
return nullptr;
}
bool inConference = false;
bool internalCallUpdate = false;
bool noUserConsent = false; /* When set to true an UPDATE request will be used instead of reINVITE */
SalCustomHeader *customHeaders = nullptr;
std::unordered_map<std::string, std::string> customContactParameters;
std::shared_ptr<CallSession> referer; /* In case call creation is consecutive to an incoming transfer, this points to the original call */
L_DECLARE_PUBLIC(CallSessionParams);
};
LINPHONE_END_NAMESPACE
......
......@@ -65,25 +65,12 @@ CallSessionParams::CallSessionParams () : ClonableObject(*new CallSessionParamsP
CallSessionParams::CallSessionParams (CallSessionParamsPrivate &p) : ClonableObject(p) {}
CallSessionParams::CallSessionParams (const CallSessionParams &other)
: ClonableObject(*new CallSessionParamsPrivate) {
L_D();
d->clone(other.getPrivate());
}
CallSessionParams::~CallSessionParams () {
L_D();
if (d->customHeaders)
sal_custom_header_free(d->customHeaders);
}
CallSessionParams &CallSessionParams::operator= (const CallSessionParams &other) {
L_D();
if (this != &other)
d->clone(other.getPrivate());
return *this;
}
// -----------------------------------------------------------------------------
void CallSessionParams::initDefault (const std::shared_ptr<Core> &core) {
......
......@@ -33,6 +33,8 @@ extern LinphoneCallParams * linphone_call_params_new_for_wrapper(void);
LINPHONE_BEGIN_NAMESPACE
class MediaSessionParamsPrivate : public CallSessionParamsPrivate {
friend class MediaSessionParams;
public:
void clone (const MediaSessionParamsPrivate *src);
void clean ();
......@@ -66,6 +68,12 @@ public:
void setUsedVideoCodec (OrtpPayloadType *pt) { usedVideoCodec = pt; }
void setUsedRealtimeTextCodec (OrtpPayloadType *pt) { usedRealtimeTextCodec = pt; }
void enableVideo (bool value) {
videoEnabled = value;
if (videoEnabled && videoDirection == LinphoneMediaDirectionInactive)
videoDirection = LinphoneMediaDirectionSendRecv;
}
SalCustomSdpAttribute * getCustomSdpAttributes () const;
void setCustomSdpAttributes (const SalCustomSdpAttribute *csa);
SalCustomSdpAttribute * getCustomSdpMediaAttributes (LinphoneStreamType lst) const;
......@@ -103,6 +111,12 @@ public:
bool mandatoryMediaEncryptionEnabled = false;
private:
SharedObject *clone () override {
// TODO: Return SharedObject.
L_ASSERT(false);
return nullptr;
}
bool _implicitRtcpFbEnabled = false;
int downBandwidth = 0;
int upBandwidth = 0;
......@@ -111,8 +125,6 @@ private:
bool updateCallWhenIceCompleted = true;
SalCustomSdpAttribute *customSdpAttributes = nullptr;
SalCustomSdpAttribute *customSdpMediaAttributes[LinphoneStreamTypeUnknown];
L_DECLARE_PUBLIC(MediaSessionParams);
};
LINPHONE_END_NAMESPACE
......
......@@ -122,34 +122,31 @@ LinphoneMediaDirection MediaSessionParamsPrivate::salStreamDirToMediaDirection (
// -----------------------------------------------------------------------------
void MediaSessionParamsPrivate::adaptToNetwork (LinphoneCore *core, int pingTimeMs) {
L_Q();
if ((pingTimeMs > 0) && lp_config_get_int(linphone_core_get_config(core), "net", "activate_edge_workarounds", 0)) {
lInfo() << "STUN server ping time is " << pingTimeMs << " ms";
int threshold = lp_config_get_int(linphone_core_get_config(core), "net", "edge_ping_time", 500);
if (pingTimeMs > threshold) {
/* We might be in a 2G network */
q->enableLowBandwidth(true);
lowBandwidthEnabled = true;
} /* else use default settings */
}
if (q->lowBandwidthEnabled()) {
if (lowBandwidthEnabled) {
setUpBandwidth(linphone_core_get_edge_bw(core));
setDownBandwidth(linphone_core_get_edge_bw(core));
setUpPtime(linphone_core_get_edge_ptime(core));
setDownPtime(linphone_core_get_edge_ptime(core));
q->enableVideo(false);
enableVideo(false);
}
}
// -----------------------------------------------------------------------------
SalStreamDir MediaSessionParamsPrivate::getSalAudioDirection () const {
L_Q();
return mediaDirectionToSalStreamDir(q->getAudioDirection());
return mediaDirectionToSalStreamDir(audioDirection);
}
SalStreamDir MediaSessionParamsPrivate::getSalVideoDirection () const {
L_Q();
return mediaDirectionToSalStreamDir(q->getVideoDirection());
return mediaDirectionToSalStreamDir(videoDirection);
}
// -----------------------------------------------------------------------------
......@@ -306,9 +303,7 @@ void MediaSessionParams::setAudioDirection (LinphoneMediaDirection direction) {
void MediaSessionParams::enableVideo (bool value) {
L_D();
d->videoEnabled = value;
if (d->videoEnabled && (getVideoDirection() == LinphoneMediaDirectionInactive))
setVideoDirection(LinphoneMediaDirectionSendRecv);
d->enableVideo(value);
}
void MediaSessionParams::enableVideoMulticast (bool value) {
......
......@@ -35,6 +35,11 @@ public:
string type;
string subType;
string parameter;
private:
SharedObject *clone () override {
return new ContentTypePrivate(*this);
}
};
// -----------------------------------------------------------------------------
......@@ -91,18 +96,6 @@ ContentType::ContentType (
setParameter(parameter);
}
ContentType::ContentType (const ContentType &other) : ContentType(other.getType(), other.getSubType(), other.getParameter()) {}
ContentType &ContentType::operator= (const ContentType &other) {
if (this != &other) {
setType(other.getType());
setSubType(other.getSubType());
setParameter(other.getParameter());
}
return *this;
}
bool ContentType::operator== (const ContentType &other) const {
return getType() == other.getType() &&
getSubType() == other.getSubType() &&
......
......@@ -33,9 +33,6 @@ public:
explicit ContentType (const std::string &contentType = "");
ContentType (const std::string &type, const std::string &subType);
ContentType (const std::string &type, const std::string &subType, const std::string &parameter);
ContentType (const ContentType &other);
ContentType &operator= (const ContentType &other);
bool operator== (const ContentType &other) const;
bool operator!= (const ContentType &other) const;
......
......@@ -20,32 +20,17 @@
#ifndef _L_CLONABLE_OBJECT_P_H_
#define _L_CLONABLE_OBJECT_P_H_
#include <set>
#include "linphone/utils/general.h"
#include "clonable-shared-pointer.h"
#include "object-head-p.h"
// =============================================================================
LINPHONE_BEGIN_NAMESPACE
class ClonableObjectPrivate {
class ClonableObjectPrivate : public SharedObject {
L_OBJECT_PRIVATE;
public:
ClonableObjectPrivate () = default;
virtual ~ClonableObjectPrivate () = default;
protected:
std::set<ClonableObject *> mPublic;
private:
L_DECLARE_PUBLIC(ClonableObject);
// It's forbidden to copy directly one Clonable object private.
// To allow copy, you must define copy constructor in inherited object.
L_DISABLE_COPY(ClonableObjectPrivate);
friend class ClonableObject;
};
LINPHONE_END_NAMESPACE
......
......@@ -22,45 +22,12 @@
// =============================================================================
using namespace std;
LINPHONE_BEGIN_NAMESPACE
// -----------------------------------------------------------------------------
L_OBJECT_IMPL(ClonableObject);
ClonableObject::ClonableObject (ClonableObjectPrivate &p) {
setRef(p);
}
#define UNREF() \
do { \
auto &h = mPrivate->mPublic; \
h.erase(this); \
if (h.empty()) \
delete mPrivate; \
} while (false);
ClonableObject::~ClonableObject () {
UNREF();
}
void ClonableObject::setRef (const ClonableObjectPrivate &p) {
// Q-pointer must exist if private data is defined.
L_ASSERT(!mPrivate || !mPrivate->mPublic.empty());
// Nothing, same reference.
if (&p == mPrivate)
return;
// Unref previous private data.
if (mPrivate)
UNREF();
// Add and reference new private data.
mPrivate = const_cast<ClonableObjectPrivate *>(&p);
mPrivate->mPublic.insert(this);
}
ClonableObject::ClonableObject (ClonableObjectPrivate &p) : mPrivate(&p) {}
LINPHONE_END_NAMESPACE
......@@ -20,28 +20,18 @@
#ifndef _L_CLONABLE_OBJECT_H_
#define _L_CLONABLE_OBJECT_H_
#include "clonable-shared-pointer.h"
#include "object-head.h"
#include "property-container.h"
// =============================================================================
#define L_USE_DEFAULT_CLONABLE_OBJECT_SHARED_IMPL(CLASS) \
CLASS::CLASS (const CLASS &other) : ClonableObject( \
const_cast<std::decay<decltype(*other.getPrivate())>::type &>(*other.getPrivate()) \
) {} \
CLASS &CLASS::operator= (const CLASS &other) { \
if (this != &other) \
setRef(*other.getPrivate()); \
return *this; \
}
LINPHONE_BEGIN_NAMESPACE
/*
* Clonable Object of Linphone. Generally it's just a data object with no
* intelligence.
*/
class LINPHONE_PUBLIC ClonableObject : public PropertyContainer {
class LINPHONE_PUBLIC ClonableObject {
L_OBJECT;
public:
......@@ -50,17 +40,10 @@ public:
protected:
explicit ClonableObject (ClonableObjectPrivate &p);
// Change the ClonableObjectPrivate. Unref previous.
void setRef (const ClonableObjectPrivate &p);
ClonableObjectPrivate *mPrivate = nullptr;
ClonableSharedPointer<SharedObject> mPrivate;
private:
L_DECLARE_PRIVATE(ClonableObject);
// Yeah, it's a `ClonableObject` that cannot be copied.
// Only inherited classes must implement copy.
L_DISABLE_COPY(ClonableObject);
};
LINPHONE_END_NAMESPACE
......
......@@ -31,28 +31,26 @@ template<typename T>
friend class ClonableSharedPointer;
public:
SharedObject () : mRefCounter(1) {};
SharedObject (const SharedObject &) : SharedObject() {}
virtual ~SharedObject () = default;
virtual SharedObject *clone () = 0;
int getRefCount () {
return mRefCounter;
}
protected:
SharedObject () : mRefCounter(1) {}