Commit 044efcae authored by Ghislain MARY's avatar Ghislain MARY

Add CMakeLists.txt for C++/CX liblinphone wrapper + use correct namespaces.

parent ac498067
......@@ -17,53 +17,55 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "ApiLock.h"
#include "Address.h"
Platform::String^ Linphone::Native::Address::DisplayName::get()
using namespace BelledonneCommunications::Linphone::Native;
Platform::String^ Address::DisplayName::get()
{
API_LOCK;
return Linphone::Native::Utils::cctops(linphone_address_get_display_name(this->address));
return Utils::cctops(linphone_address_get_display_name(this->address));
}
void Linphone::Native::Address::DisplayName::set(Platform::String^ name)
void Address::DisplayName::set(Platform::String^ name)
{
API_LOCK;
const char *cc = Linphone::Native::Utils::pstoccs(name);
const char *cc = Utils::pstoccs(name);
linphone_address_set_display_name(this->address, cc);
delete(cc);
}
Platform::String^ Linphone::Native::Address::Domain::get()
Platform::String^ Address::Domain::get()
{
API_LOCK;
return Linphone::Native::Utils::cctops(linphone_address_get_domain(this->address));
return Utils::cctops(linphone_address_get_domain(this->address));
}
void Linphone::Native::Address::Domain::set(Platform::String^ domain)
void Address::Domain::set(Platform::String^ domain)
{
API_LOCK;
const char *cc = Linphone::Native::Utils::pstoccs(domain);
const char *cc = Utils::pstoccs(domain);
linphone_address_set_domain(this->address, cc);
delete(cc);
}
int Linphone::Native::Address::Port::get()
int Address::Port::get()
{
API_LOCK;
return linphone_address_get_port(this->address);
}
void Linphone::Native::Address::Port::set(int port)
void Address::Port::set(int port)
{
API_LOCK;
linphone_address_set_port(this->address, port);
}
Platform::String^ Linphone::Native::Address::Scheme::get()
Platform::String^ Address::Scheme::get()
{
API_LOCK;
return Linphone::Native::Utils::cctops(linphone_address_get_scheme(this->address));
return Utils::cctops(linphone_address_get_scheme(this->address));
}
Linphone::Native::Transport Linphone::Native::Address::Transport::get()
Transport Address::Transport::get()
{
API_LOCK;
::LinphoneTransportType transport = linphone_address_get_transport(this->address);
......@@ -71,29 +73,29 @@ Linphone::Native::Transport Linphone::Native::Address::Transport::get()
{
default:
case LinphoneTransportUdp:
return Linphone::Native::Transport::UDP;
return BelledonneCommunications::Linphone::Native::Transport::UDP;
case LinphoneTransportTcp:
return Linphone::Native::Transport::TCP;
return BelledonneCommunications::Linphone::Native::Transport::TCP;
case LinphoneTransportTls:
return Linphone::Native::Transport::TLS;
return BelledonneCommunications::Linphone::Native::Transport::TLS;
case LinphoneTransportDtls:
return Linphone::Native::Transport::DTLS;
return BelledonneCommunications::Linphone::Native::Transport::DTLS;
}
}
void Linphone::Native::Address::Transport::set(Linphone::Native::Transport transport)
void Address::Transport::set(BelledonneCommunications::Linphone::Native::Transport transport)
{
API_LOCK;
::LinphoneTransportType transportType = LinphoneTransportUdp;
if (transport == Linphone::Native::Transport::TCP)
if (transport == BelledonneCommunications::Linphone::Native::Transport::TCP)
{
transportType = LinphoneTransportTcp;
}
else if (transport == Linphone::Native::Transport::TLS)
else if (transport == BelledonneCommunications::Linphone::Native::Transport::TLS)
{
transportType = LinphoneTransportTls;
}
else if (transport == Linphone::Native::Transport::DTLS)
else if (transport == BelledonneCommunications::Linphone::Native::Transport::DTLS)
{
transportType = LinphoneTransportDtls;
}
......@@ -101,50 +103,50 @@ void Linphone::Native::Address::Transport::set(Linphone::Native::Transport trans
linphone_address_set_transport(this->address, transportType);
}
Platform::String^ Linphone::Native::Address::UserName::get()
Platform::String^ Address::UserName::get()
{
API_LOCK;
return Linphone::Native::Utils::cctops(linphone_address_get_username(this->address));
return Utils::cctops(linphone_address_get_username(this->address));
}
void Linphone::Native::Address::UserName::set(Platform::String^ username)
void Address::UserName::set(Platform::String^ username)
{
API_LOCK;
const char *cc = Linphone::Native::Utils::pstoccs(username);
const char *cc = Utils::pstoccs(username);
linphone_address_set_username(this->address, cc);
delete(cc);
}
Platform::String^ Linphone::Native::Address::AsString()
Platform::String^ Address::AsString()
{
API_LOCK;
return Linphone::Native::Utils::cctops(linphone_address_as_string(this->address));
return Utils::cctops(linphone_address_as_string(this->address));
}
Platform::String^ Linphone::Native::Address::AsStringUriOnly()
Platform::String^ Address::AsStringUriOnly()
{
API_LOCK;
return Linphone::Native::Utils::cctops(linphone_address_as_string_uri_only(this->address));
return Utils::cctops(linphone_address_as_string_uri_only(this->address));
}
void Linphone::Native::Address::Clean()
void Address::Clean()
{
API_LOCK;
linphone_address_clean(this->address);
}
Platform::String^ Linphone::Native::Address::ToString()
Platform::String^ Address::ToString()
{
return this->AsString();
}
Linphone::Native::Address::Address(::LinphoneAddress *addr) :
Address::Address(::LinphoneAddress *addr) :
address(addr)
{
linphone_address_ref(this->address);
}
Linphone::Native::Address::Address(const char *uri)
Address::Address(const char *uri)
{
this->address = linphone_address_new(uri);
if (this->address != nullptr) {
......@@ -152,7 +154,7 @@ Linphone::Native::Address::Address(const char *uri)
}
}
Linphone::Native::Address::~Address()
Address::~Address()
{
if (this->address != nullptr) {
linphone_address_unref(this->address);
......
......@@ -18,118 +18,121 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "Core.h"
namespace Linphone
namespace BelledonneCommunications
{
namespace Native
namespace Linphone
{
/// <summary>
/// Object that represents a SIP address.
/// It's an opaque object that represents a SIP address, i.e. the content of SIP's "from" and "to" headers.
/// A SIP address is made of a display name, username, domain, port and various URI headers(such as tags).
/// It looks like "Alice &lt;sip:alice@example.net&gt;". The LinphoneAddress has methods to extract and manipulate all parts of the address.
/// When some part of the address (for example the username) is empty, the accessor method return null.
/// </summary>
/// <example>
/// Can be instancied using:
/// <code>
/// Address addr = Core.CreateAddress("sip:alice@example.net");
/// </code>
/// or
/// <code>
/// Address addr = Core.CreateAddress("alice", "example.net", "Alice B.");
/// </code>
/// </example>
public ref class Address sealed
namespace Native
{
public:
/// <summary>
/// The human display name of the address.
/// For example for the "Alice &lt;sip:alice@example.net&gt;" URI, it will return "Alice".
/// Object that represents a SIP address.
/// It's an opaque object that represents a SIP address, i.e. the content of SIP's "from" and "to" headers.
/// A SIP address is made of a display name, username, domain, port and various URI headers(such as tags).
/// It looks like "Alice &lt;sip:alice@example.net&gt;". The LinphoneAddress has methods to extract and manipulate all parts of the address.
/// When some part of the address (for example the username) is empty, the accessor method return null.
/// </summary>
property Platform::String^ DisplayName
/// <example>
/// Can be instancied using:
/// <code>
/// Address addr = Core.CreateAddress("sip:alice@example.net");
/// </code>
/// or
/// <code>
/// Address addr = Core.CreateAddress("alice", "example.net", "Alice B.");
/// </code>
/// </example>
public ref class Address sealed
{
Platform::String^ get();
void set(Platform::String^ value);
}
public:
/// <summary>
/// The human display name of the address.
/// For example for the "Alice &lt;sip:alice@example.net&gt;" URI, it will return "Alice".
/// </summary>
property Platform::String^ DisplayName
{
Platform::String^ get();
void set(Platform::String^ value);
}
/// <summary>
/// The domain part of the address.
/// For example for the "Alice &lt;sip:alice@example.net&gt;" URI, it will return "example.net".
/// </summary>
property Platform::String^ Domain
{
Platform::String^ get();
void set(Platform::String^ value);
}
/// <summary>
/// The domain part of the address.
/// For example for the "Alice &lt;sip:alice@example.net&gt;" URI, it will return "example.net".
/// </summary>
property Platform::String^ Domain
{
Platform::String^ get();
void set(Platform::String^ value);
}
/// <summary>
/// The port part of the address.
/// </summary>
property int Port
{
int get();
void set(int value);
}
/// <summary>
/// The port part of the address.
/// </summary>
property int Port
{
int get();
void set(int value);
}
/// <summary>
/// The address scheme, normally "sip".
/// </summary>
property Platform::String^ Scheme
{
Platform::String^ get();
}
/// <summary>
/// The address scheme, normally "sip".
/// </summary>
property Platform::String^ Scheme
{
Platform::String^ get();
}
/// <summary>
/// The transport of the address.
/// </summary>
property Linphone::Native::Transport Transport
{
Linphone::Native::Transport get();
void set(Linphone::Native::Transport value);
}
/// <summary>
/// The transport of the address.
/// </summary>
property Transport Transport
{
BelledonneCommunications::Linphone::Native::Transport get();
void set(BelledonneCommunications::Linphone::Native::Transport value);
}
/// <summary>
/// The username part of the address.
/// For example for the "Alice &lt;sip:alice@example.net&gt;" URI, it will return "alice".
/// </summary>
property Platform::String^ UserName
{
Platform::String^ get();
void set(Platform::String^ value);
}
/// <summary>
/// The username part of the address.
/// For example for the "Alice &lt;sip:alice@example.net&gt;" URI, it will return "alice".
/// </summary>
property Platform::String^ UserName
{
Platform::String^ get();
void set(Platform::String^ value);
}
/// <summary>
/// Gets the string representation of the address.
/// </summary>
/// <returns>The address as a string</returns>
Platform::String^ AsString();
/// <summary>
/// Gets the string representation of the address.
/// </summary>
/// <returns>The address as a string</returns>
Platform::String^ AsString();
/// <summary>
/// Gets the string representation of the URI part of the address (without the display name).
/// </summary>
/// <returns>The address without display name as a string</returns>
Platform::String^ AsStringUriOnly();
/// <summary>
/// Gets the string representation of the URI part of the address (without the display name).
/// </summary>
/// <returns>The address without display name as a string</returns>
Platform::String^ AsStringUriOnly();
/// <summary>
/// Removes address's tags and uri headers so that it is displayable to the user.
/// </summary>
void Clean();
/// <summary>
/// Removes address's tags and uri headers so that it is displayable to the user.
/// </summary>
void Clean();
/// <summary>
/// Same as AsString.
/// </summary>
/// <seealso cref="AsString()" />
virtual Platform::String^ ToString() override;
/// <summary>
/// Same as AsString.
/// </summary>
/// <seealso cref="AsString()" />
virtual Platform::String^ ToString() override;
private:
friend class Utils;
friend ref class Core;
private:
friend class Linphone::Native::Utils;
friend ref class Linphone::Native::Core;
Address(::LinphoneAddress *addr);
Address(const char *uri);
~Address();
Address(::LinphoneAddress *addr);
Address(const char *uri);
~Address();
::LinphoneAddress *address;
};
::LinphoneAddress *address;
};
}
}
}
\ No newline at end of file
......@@ -17,106 +17,102 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "ApiLock.h"
#include "mediastreamer2/mscommon.h"
namespace Linphone
{
namespace Native
{
GlobalApiLock *GlobalApiLock::instance = nullptr;
std::mutex GlobalApiLock::instance_mutex;
using namespace BelledonneCommunications::Linphone::Native;
GlobalApiLock *GlobalApiLock::instance = nullptr;
std::mutex GlobalApiLock::instance_mutex;
#ifdef API_LOCK_DEBUG
std::list<LockInfo> GlobalApiLock::lock_info_list;
std::list<LockInfo> GlobalApiLock::lock_info_list;
#endif
GlobalApiLock::GlobalApiLock() : count(0), pool(nullptr)
{}
GlobalApiLock::GlobalApiLock() : count(0), pool(nullptr)
{}
GlobalApiLock::~GlobalApiLock()
{}
GlobalApiLock::~GlobalApiLock()
{}
GlobalApiLock * GlobalApiLock::Instance()
{
if (instance == nullptr) {
instance_mutex.lock();
if (instance == nullptr) {
instance = new GlobalApiLock();
}
instance_mutex.unlock();
}
return instance;
GlobalApiLock * GlobalApiLock::Instance()
{
if (instance == nullptr) {
instance_mutex.lock();
if (instance == nullptr) {
instance = new GlobalApiLock();
}
instance_mutex.unlock();
}
return instance;
}
void GlobalApiLock::Lock(std::string func)
{
void GlobalApiLock::Lock(std::string func)
{
#ifdef API_LOCK_DEBUG
RegisterLocking(func);
RegisterLocking(func);
#endif
mutex.lock();
mutex.lock();
#ifdef API_LOCK_DEBUG
RegisterLocked(func);
RegisterLocked(func);
#endif
if (count == 0) {
pool = belle_sip_object_pool_push();
}
count++;
}
if (count == 0) {
pool = belle_sip_object_pool_push();
}
count++;
}
void GlobalApiLock::Unlock(std::string func)
{
count--;
if ((count == 0) && (pool != nullptr)) {
belle_sip_object_unref(pool);
pool = nullptr;
}
void GlobalApiLock::Unlock(std::string func)
{
count--;
if ((count == 0) && (pool != nullptr)) {
belle_sip_object_unref(pool);
pool = nullptr;
}
#ifdef API_LOCK_DEBUG
UnregisterLocked(func);
UnregisterLocked(func);
#endif
mutex.unlock();
}
mutex.unlock();
}
#ifdef API_LOCK_DEBUG
void GlobalApiLock::RegisterLocking(std::string func)
{
instance_mutex.lock();
LockInfo li = { WIN_thread_self(), func, false };
lock_info_list.push_back(li);
instance_mutex.unlock();
}
void GlobalApiLock::RegisterLocking(std::string func)
{
instance_mutex.lock();
LockInfo li = { WIN_thread_self(), func, false };
lock_info_list.push_back(li);
instance_mutex.unlock();
}
void GlobalApiLock::RegisterLocked(std::string func)
{
instance_mutex.lock();
unsigned long current_thread = WIN_thread_self();
for (std::list<LockInfo>::reverse_iterator it = lock_info_list.rbegin(); it != lock_info_list.rend(); it++) {
if ((it->func == func) && (it->thread = current_thread) && !it->locked) {
it->locked = true;
break;
}
}
instance_mutex.unlock();
void GlobalApiLock::RegisterLocked(std::string func)
{
instance_mutex.lock();
unsigned long current_thread = WIN_thread_self();
for (std::list<LockInfo>::reverse_iterator it = lock_info_list.rbegin(); it != lock_info_list.rend(); it++) {
if ((it->func == func) && (it->thread = current_thread) && !it->locked) {
it->locked = true;
break;
}
}
instance_mutex.unlock();
}
void GlobalApiLock::UnregisterLocked(std::string func)
{
instance_mutex.lock();
unsigned long current_thread = WIN_thread_self();
for (std::list<LockInfo>::reverse_iterator it = lock_info_list.rbegin(); it != lock_info_list.rend(); it++) {
if ((it->func == func) && (it->thread = current_thread) && it->locked) {
lock_info_list.erase(--(it.base()));
break;
}
}
instance_mutex.unlock();
void GlobalApiLock::UnregisterLocked(std::string func)
{
instance_mutex.lock();
unsigned long current_thread = WIN_thread_self();
for (std::list<LockInfo>::reverse_iterator it = lock_info_list.rbegin(); it != lock_info_list.rend(); it++) {
if ((it->func == func) && (it->thread = current_thread) && it->locked) {
lock_info_list.erase(--(it.base()));
break;
}
}
instance_mutex.unlock();
}
#endif
ApiLock::ApiLock(std::string func) : func(func)
{
GlobalApiLock::Instance()->Lock(func);
}
ApiLock::ApiLock(std::string func) : func(func)
{
GlobalApiLock::Instance()->Lock(func);
}
ApiLock::~ApiLock()
{
GlobalApiLock::Instance()->Unlock(func);
}
}
ApiLock::~ApiLock()
{
GlobalApiLock::Instance()->Unlock(func);
}
......@@ -31,59 +31,62 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//#define API_LOCK_DEBUG
#define API_LOCK Linphone::Native::ApiLock apiLock(__FUNCTION__)
#define API_LOCK ApiLock apiLock(__FUNCTION__)
namespace Linphone
namespace BelledonneCommunications
{
namespace Native
{
#ifdef API_LOCK_DEBUG
struct LockInfo
namespace Linphone
{
namespace Native
{
unsigned long thread;
std::string func;
bool locked;
};
#ifdef API_LOCK_DEBUG
struct LockInfo
{
unsigned long thread;
std::string func;
bool locked;
};
#endif
class GlobalApiLock
{
public:
static GlobalApiLock * Instance();
class GlobalApiLock
{
public:
static GlobalApiLock * Instance();
#ifdef API_LOCK_DEBUG
static std::list<LockInfo> lock_info_list;
static std::list<LockInfo> lock_info_list;
#endif
void Lock(std::string func);
void Unlock(std::string func);
void Lock(std::string func);
void Unlock(std::string func);
private:
GlobalApiLock();
~GlobalApiLock();
private:
GlobalApiLock();
~GlobalApiLock();
#ifdef API_LOCK_DEBUG
void RegisterLocking(std::string func);
void RegisterLocked(std::string func);
void UnregisterLocked(std::string func);
void RegisterLocking(std::string func);
void RegisterLocked(std::string func);
void UnregisterLocked(std::string func);
#endif
static GlobalApiLock *instance;
static std::mutex instance_mutex;
std::recursive_mutex mutex;
int count;
belle_sip_object_pool_t *pool;
};
static GlobalApiLock *instance;
static std::mutex instance_mutex;
std::recursive_mutex mutex;
int count;
belle_sip_object_pool_t *pool;
};
/// <summary>
/// A class that implements a mutex mechanism to protect objects accessible from the API surface exposed by this DLL
/// </summary>
class ApiLock
{
public:
ApiLock(std::string func);
~ApiLock();
/// <summary>
/// A class that implements a mutex mechanism to protect objects accessible from the API surface exposed by this DLL
/// </summary>
class ApiLock
{
public:
ApiLock(std::string func);
~ApiLock();
private:
std::string func;
};
}
private:
std::string func;
};
}
}
}
......@@ -17,78 +17,79 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "AuthInfo.h"
#include "Utils.h"
using namespace BelledonneCommunications::Linphone::Native;
Platform::String^ Linphone::Native::AuthInfo::Ha1::get()
Platform::String^ AuthInfo::Ha1::get()
{
API_LOCK;
return Utils::cctops(linphone_auth_info_get_ha1(this->auth_info));
}
void Linphone::Native::AuthInfo::Ha1::set(Platform::String^ ha1)
void AuthInfo::Ha1::set(Platform::String^ ha1)
{
API_LOCK;
const char *cc = Linphone::Native::Utils::pstoccs(ha1);
const char *cc = Utils::pstoccs(ha1);
linphone_auth_info_set_ha1(this->auth_info, cc);
delete(cc);
}
Platform::String^ Linphone::Native::AuthInfo::Passwd::get()
Platform::String^ AuthInfo::Passwd::get()
{
API_LOCK;
return Utils::cctops(linphone_auth_info_get_passwd(this->auth_info));
}
void Linphone::Native::AuthInfo::Passwd::set(Platform::String^ password)
void AuthInfo::Passwd::set(Platform::String^ password)
{
API_LOCK;
const char *cc = Linphone::Native::Utils::pstoccs(password);
const char *cc = Utils::pstoccs(password);
linphone_auth_info_set_passwd(this->auth_info, cc);
delete(cc);
}
Platform::String^ Linphone::Native::AuthInfo::Realm::get()
Platform::String^ AuthInfo::Realm::get()
{
API_LOCK;