From 1796203783c6e00b58fbfe2fe6b94bec0927a59b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grisez?= Date: Wed, 17 Sep 2014 11:35:43 +0200 Subject: [PATCH] Simplification of TunnelManager class * TunnelManager does not implement the TunnelClientController anymore * Methods which are not uses by functions of linphone_tunnel.h have been turn to private * Private methods which are not used by any other methods have been deleted * Unused attributes have been deleted --- coreapi/TunnelManager.cc | 57 ++++++++++++++------------------- coreapi/TunnelManager.hh | 65 +++++++++++++++++--------------------- coreapi/linphone_tunnel.cc | 2 +- coreapi/linphone_tunnel.h | 6 ++++ 4 files changed, 59 insertions(+), 71 deletions(-) diff --git a/coreapi/TunnelManager.cc b/coreapi/TunnelManager.cc index 6c50abf13..1c9bd1e38 100644 --- a/coreapi/TunnelManager.cc +++ b/coreapi/TunnelManager.cc @@ -19,7 +19,6 @@ #ifndef USE_BELLESIP #include "eXosip2/eXosip_transport_hook.h" #endif -#include "tunnel/udp_mirror.hh" #include "private.h" #ifdef ANDROID @@ -67,11 +66,6 @@ void TunnelManager::reconnect(){ mTunnelClient->reconnect(); } -void TunnelManager::setCallback(StateCallback cb, void *userdata) { - mCallback=cb; - mCallbackData=userdata; -} - static void sCloseRtpTransport(RtpTransport *t, void *userData){ TunnelSocket *s=(TunnelSocket*)userData; TunnelManager *manager=(TunnelManager*)s->getUserPointer(); @@ -102,10 +96,10 @@ RtpTransport *TunnelManager::createRtpTransport(int port){ return t; } -void TunnelManager::start() { +void TunnelManager::connect() { if (!mTunnelClient) { mTunnelClient = new TunnelClient(); - mTunnelClient->setCallback((StateCallback)tunnelCallback,this); + mTunnelClient->setCallback((TunnelClientController::StateCallback)tunnelCallback,this); list::iterator it; for(it=mServerAddrs.begin();it!=mServerAddrs.end();++it){ const ServerAddr &addr=*it; @@ -116,12 +110,8 @@ void TunnelManager::start() { mTunnelClient->start(); } -bool TunnelManager::isStarted() const { - return mTunnelClient != 0 && mTunnelClient->isStarted(); -} - -bool TunnelManager::isReady() const { - return mTunnelClient && mTunnelClient->isReady() && mReady; +bool TunnelManager::isConnected() const { + return mTunnelClient && mTunnelClient->isReady() && mIsConnected; } int TunnelManager::customSendto(struct _RtpTransport *t, mblk_t *msg , int flags, const struct sockaddr *to, socklen_t tolen){ @@ -139,17 +129,16 @@ int TunnelManager::customRecvfrom(struct _RtpTransport *t, mblk_t *msg, int flag } -TunnelManager::TunnelManager(LinphoneCore* lc) :TunnelClientController() - ,mCore(lc) - ,mCallback(NULL) - ,mEnabled(false) - ,mTunnelClient(NULL) - ,mAutoDetectStarted(false) - ,mReady(false) - ,mHttpProxyPort(0) - ,mPreviousRegistrationEnabled(false) - ,mTunnelizeSipPackets(true){ - +TunnelManager::TunnelManager(LinphoneCore* lc) : + mCore(lc), + mEnabled(false), + mTunnelClient(NULL), + mAutoDetectStarted(false), + mIsConnected(false), + mHttpProxyPort(0), + mPreviousRegistrationEnabled(false), + mTunnelizeSipPackets(true) +{ linphone_core_add_iterate_hook(mCore,(LinphoneCoreIterateHook)sOnIterate,this); mTransportFactories.audio_rtcp_func=sCreateRtpTransport; mTransportFactories.audio_rtcp_func_data=this; @@ -162,10 +151,10 @@ TunnelManager::TunnelManager(LinphoneCore* lc) :TunnelClientController() } TunnelManager::~TunnelManager(){ - stopClient(); + disconnect(); } -void TunnelManager::stopClient(){ +void TunnelManager::disconnect(){ sal_disable_tunnel(mCore->sal); if (mTunnelClient){ delete mTunnelClient; @@ -177,7 +166,7 @@ void TunnelManager::registration(){ LinphoneProxyConfig* lProxy; // tunnel was enabled - if (isReady()){ + if (isConnected()){ linphone_core_set_rtp_transport_factories(mCore,&mTransportFactories); if(mTunnelizeSipPackets) { sal_enable_tunnel(mCore->sal, mTunnelClient); @@ -196,12 +185,12 @@ void TunnelManager::registration(){ void TunnelManager::processTunnelEvent(const Event &ev){ if (mEnabled && mTunnelClient->isReady()){ - mReady=true; + mIsConnected=true; ms_message("Tunnel is up, registering now"); registration(); }else if (mEnabled && !mTunnelClient->isReady()){ /* we got disconnected from the tunnel */ - mReady=false; + mIsConnected=false; } } @@ -243,15 +232,15 @@ void TunnelManager::enable(bool isEnable) { //1 unregister waitUnRegistration(); //2 insert tunnel - start(); + connect(); }else if (!isEnable && mEnabled){ //1 unregister waitUnRegistration(); // 2 stop tunnel mEnabled=false; - stopClient(); - mReady=false; + disconnect(); + mIsConnected=false; linphone_core_set_rtp_transport_factories(mCore,NULL); sal_disable_tunnel(mCore->sal); @@ -393,7 +382,7 @@ void TunnelManager::setHttpProxyAuthInfo(const char* username,const char* passwd void TunnelManager::tunnelizeSipPackets(bool enable){ if(enable != mTunnelizeSipPackets) { mTunnelizeSipPackets = enable; - if(mEnabled && isReady()) { + if(mEnabled && isConnected()) { waitUnRegistration(); registration(); } diff --git a/coreapi/TunnelManager.hh b/coreapi/TunnelManager.hh index c7d8eeb9f..0f656b7d4 100644 --- a/coreapi/TunnelManager.hh +++ b/coreapi/TunnelManager.hh @@ -12,18 +12,17 @@ #define __TUNNEL_CLIENT_MANAGER_H__ #include #include -#include "tunnel/client.hh" +#include +#include #include "linphonecore.h" #ifndef USE_BELLESIP extern "C" { - #include "eXosip2/eXosip_transport_hook.h" + #include } #endif namespace belledonnecomm { -class TunnelClient; -class UdpMirrorClient; /** * @addtogroup tunnel_client * @{ @@ -39,7 +38,7 @@ class UdpMirrorClient; * It takes in charge automatically the SIP registration procedure when connecting or disconnecting to a tunnel server. * No other action on LinphoneCore is required to enable full operation in tunnel mode. **/ - class TunnelManager : public TunnelClientController{ + class TunnelManager { public: /** @@ -63,18 +62,6 @@ class UdpMirrorClient; * Removes all tunnel server address previously entered with addServer() **/ void cleanServers(); - /** - * Register a state callback to be notified whenever the tunnel client is connected or disconnected to the tunnel server. - * @param cb application callback function to use for notifying of connection/disconnection events. - * @param userdata An opaque pointer passed to the callback, used optionally by the application to retrieve a context. - **/ - void setCallback(StateCallback cb, void *userdata); - /** - * Start connecting to a tunnel server. - * At this step, nothing is tunneled yet. The enable() method must be used to state whether SIP and RTP traffic - * need to be tunneled or not. - **/ - void start(); /** * Forces reconnection to the tunnel server. * This method is useful when the device switches from wifi to Edge/3G or vice versa. In most cases the tunnel client socket @@ -115,6 +102,7 @@ class UdpMirrorClient; * @param passwd The password. **/ void setHttpProxyAuthInfo(const char* username,const char* passwd); + void setHttpProxy(const char *host,int port, const char *username, const char *passwd); /** * Indicate to the tunnel manager whether SIP packets must pass * through the tunnel. That featurte is automatically enabled at @@ -128,31 +116,37 @@ class UdpMirrorClient; * @return True, SIP packets pass through the tunnel */ bool tunnelizeSipPacketsEnabled() const; - /** - * @brief Destructor - */ - ~TunnelManager(); /** * @brief Constructor * @param lc The LinphoneCore instance of which the TunnelManager will be associated to. */ TunnelManager(LinphoneCore* lc); /** - * Destroy the given RtpTransport. + * @brief Destructor */ - void closeRtpTransport(RtpTransport *t, TunnelSocket *s); - + ~TunnelManager(); /** - * Create an RtpTransport. + * @brief Create an RtpTransport + * @param port + * @return */ RtpTransport *createRtpTransport(int port); - /** - * Get associated Linphone Core. + * @brief Destroy the given RtpTransport + * @param t + * @param s + */ + void closeRtpTransport(RtpTransport *t, TunnelSocket *s); + /** + * @brief Get associated Linphone Core + * @return pointer on the associated LinphoneCore */ LinphoneCore *getLinphoneCore() const; - virtual void setHttpProxy(const char *host,int port, const char *username, const char *passwd); - virtual bool isReady() const; + /** + * @brief Check wehter the tunnel is connected + * @return True whether the tunnel is connected + */ + bool isConnected() const; private: enum EventType{ UdpMirrorClientEvent, @@ -166,8 +160,6 @@ class UdpMirrorClient; }mData; }; typedef std::list UdpMirrorClientList; - virtual bool isStarted() const; - void onIterate(); static int customSendto(struct _RtpTransport *t, mblk_t *msg , int flags, const struct sockaddr *to, socklen_t tolen); static int customRecvfrom(struct _RtpTransport *t, mblk_t *msg, int flags, struct sockaddr *from, socklen_t *fromlen); static int eXosipSendto(int fd,const void *buf, size_t len, int flags, const struct sockaddr *to, socklen_t tolen,void* userdata); @@ -176,12 +168,16 @@ class UdpMirrorClient; static void tunnelCallback(bool connected, TunnelManager *zis); static void sOnIterate(TunnelManager *zis); static void sUdpMirrorClientCallback(bool result, void* data); + + private: + void onIterate(); void registration(); void waitUnRegistration(); void processTunnelEvent(const Event &ev); void processUdpMirrorEvent(const Event &ev); void postEvent(const Event &ev); - void stopClient(); + void connect(); + void disconnect(); private: LinphoneCore* mCore; @@ -189,8 +185,6 @@ class UdpMirrorClient; TunnelSocket *mSipSocket; eXosip_transport_hooks_t mExosipTransport; #endif - StateCallback mCallback; - void * mCallbackData; bool mEnabled; std::queue mEvq; std::list mServerAddrs; @@ -198,9 +192,8 @@ class UdpMirrorClient; UdpMirrorClientList::iterator mCurrentUdpMirrorClient; TunnelClient* mTunnelClient; Mutex mMutex; - static Mutex sMutex; bool mAutoDetectStarted; - bool mReady; + bool mIsConnected; LinphoneRtpTransportFactories mTransportFactories; std::string mHttpUserName; std::string mHttpPasswd; diff --git a/coreapi/linphone_tunnel.cc b/coreapi/linphone_tunnel.cc index 60d490063..ec41d89c1 100644 --- a/coreapi/linphone_tunnel.cc +++ b/coreapi/linphone_tunnel.cc @@ -243,7 +243,7 @@ bool_t linphone_tunnel_enabled(const LinphoneTunnel *tunnel){ } bool_t linphone_tunnel_connected(const LinphoneTunnel *tunnel){ - return bcTunnel(tunnel)->isReady(); + return bcTunnel(tunnel)->isConnected(); } static OrtpLogFunc tunnelOrtpLogHandler=NULL; diff --git a/coreapi/linphone_tunnel.h b/coreapi/linphone_tunnel.h index 38d577eb6..72fb38134 100644 --- a/coreapi/linphone_tunnel.h +++ b/coreapi/linphone_tunnel.h @@ -50,6 +50,12 @@ extern "C" typedef struct _LinphoneTunnelConfig LinphoneTunnelConfig; +typedef enum _LinphoneTunnelMode { + LinphoneTunnelModeDisabled, + LinphoneTunnelModeEnabled, + LinphoneTunnelModeAuto +} LinphoneTunnelMode; + /** * Create a new tunnel configuration */