Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save LuxoftAKutsan/206680b502b8e2b1412923673609b60b to your computer and use it in GitHub Desktop.
Save LuxoftAKutsan/206680b502b8e2b1412923673609b60b to your computer and use it in GitHub Desktop.
NetworkInterface refactoring proposal.

Preconditions

For adding custom implementation of Network Interface Listener should be changes CMakelists.txt and added additional implementation of platform_specific_network_interface_listener.cc

Example adding implementation for custom_os

  1. Crete folder src/components/transport_manager/include/transport_manager/tcp/platform_specific/custom_os
  2. Crete file src/components/transport_manager/include/transport_manager/tcp/platform_specific/custom_os/platform_specific_network_interface_listener_impl.h with class PlatformSpecificNetworkInterfaceListener:
    • PlatformSpecificNetworkInterfaceListener should be inherited from NetworkInterfaceListener.
    • PlatformSpecificNetworkInterfaceListener may contain os specific data types and privte functions, it won't affect other SDL classes
  3. Create folder src/components/transport_manager/src/tcp/platform_specific/custom_os :
  4. Create file platform_specific_network_interface_listener.cc with custom_os implementation of PlatformSpecificNetworkInterfaceListener
  5. Modify src/components/transport_manager/CMakeLists.txt :
    • Add to include path src/components/transport_manager/include/transport_manager/tcp/platform_specific/custom_os in case if compile target is custom_os
    • Add to source list src/components/transport_manager/src/tcp/platform_specific/custom_os/platform_specific_network_interface_listener.cc in case if compile target is custom_os

Check

After compilation of SDL for custom_os it will use custom created implementation of Network Interface Listener

Changes related to PR : smartdevicelink/sdl_core#2164

Description

This proposal is about refactoring NetworkInterfaceListener for better cross platform support.

Motivation

NetworkInterfaceListener main purpose is to listeno to following system events:

  • The interface of Ip address changed
  • Interfaces added
  • Interface removed

and to notify TcpClientListener about them.

There is no way to do cross platform implementation of NetworkInterfaceListener.
Proposed solution is to use Pimple design pattern for easy implementation replacing
and reducing platform specific dependencies for other components.

Detailed design

It is proposed to implement this feature by following design: Proposaed design

Followign files will be created:

include/network_interface_listener.h :

Interface of NetworkInterfaceListener without any implementation, should be used by other cmponents that will handle with class

class NetworkInterfaceListener {
 public:
  virtual bool Init() = 0;
  ...

include/network_interface_listener_impl.h :

Pimple implementation of NetworkInterfaceListener, actually this class should only transmit method calls to platform specific implementation

class NetworkInterfaceListenerImpl : NetworkInterfaceListener {
 public:
  bool Init() OVERRIDE;
  
  std::unique_ptr<NetworkInterfaceListener> impl_; // platform specific implementation of NetworkInterfaceListener
  ...

scr/network_interface_listener_impl.cc :

Implementation of Pimple class that transmit method calls to platform specific implementation Platform specific implementation should be configured by build system, and any platform specific types may be accessible only in source files, but not public headers

#include "network_interface_listener_impl.h"
#include "platfrom_specific_network_interface_listener.h"

  bool NetworkInterfaceListenerImpl::NetworkInterfaceListenerImpl() :
    impl_(new PlatformSpecificNetworkInterfaceListener) {}
    
  bool NetworkInterfaceListenerImpl::Init() {
    return impl_->Init();
  }
  ...

include/pimple/linux/platfrom_specific_network_interface_listener.h :

Linux implementation of NetworkInterfaceListener

// Linux specific uncludes
class PlatformSpecificNetworkInterfaceListener : NetworkInterfaceListener {
 public:
  bool Init() OVERRIDE;
  
  // Linux specific class members
  ...

src/pimple/linux/platfrom_specific_network_interface_listener.cc :

Linux implementation of NetworkInterfaceListener

  bool PlatformSpecificNetworkInterfaceListener::Init() {
    // Linux specific code
  }

include/pimple/qnx/platfrom_specific_network_interface_listener.h :

QNX implementation of NetworkInterfaceListener

// Linux specific uncludes
class PlatformSpecificNetworkInterfaceListener : NetworkInterfaceListener {
 public:
  bool Init() OVERRIDE;
  
  // QNX specific class members
  ...

src/pimple/qnx/platfrom_specific_network_interface_listener.cc :

QNX implementation of NetworkInterfaceListener QNX implementation for open source may be just a stub

  bool PlatformSpecificNetworkInterfaceListener::Init() {
    // QNX specific code
  }

CMakeLists.txt

Configuration file includes in compilation certain implementation depending on target system

set (SOURCES
       network_interface_listener_impl.cc
       $<$<BOOL:${QNX}>:pimple/qnx/platfrom_specific_network_interface_listener.cc>
       $<$<BOOL:${LINUX}>:pimple/linux/platfrom_specific_network_interface_listener.cc>
       ...
)

include_dirs ()
       $<$<BOOL:${QNX}>:include/pimple/qnx/>
       $<$<BOOL:${LINUX}>:include/pimple/linux/>
       ...
)

Alternative solution:

We may use ifefs inside scr/network_interface_listener_impl.cc creating platform specific class, but it would introduce not desired entropy (ifdefs also should be added for includes).

PreConditions

  1. Make sure the following parameters are defined in SDL .INI file:
    • MultipleTransportsEnabled = true
    • SecondaryTransportForBluetooth = WiFi
  2. Make sure Bluetooth and WiFi connections available
  3. Make sure Mobile device is connected to the same WiFi network as SDL
  4. Make sure specific version of SPT is installed on Mobile device (4001-20170510)
  5. Run SDL, Web-HMI and SPT

Steps

  1. Register NAVI mobile applicaion using BT transport. Observe the following messages in SPT log:
    - onEnableSecondaryTransport(): 
secondaryTransport list: TCP_WIFI
audio list: 1, 2
video list: 1, 2
secondaryConnectionEnabled: true
    - onTransportEventUpdate(): 
ipAddr is: <real_ip_address>; port is: <real_port>
secondaryConnectionEnabled: true
secondaryTransportTypes: TCP
Start TCP Transport.
    - startStreamingServices(): 
Start Pending Services on Secondary Transport.
secondaryServices is Empty.
    - onRegisterSecondaryTransportACK(): 
Start Streaming Services now.
  1. Start Video streaming and allow it on Web-HMI.
    - startService(): 
secondarySdlConnection != null: true; allowed: true
isEncrypted: false
secondarySdlConnection startService
    - onProtocolSessionStarted: 
SessionID: 1 ServiceType: NAV Encrypted: false
    - startVideoStream(): 
AcceptedProtocol is: RAW
ServiceAllowed for Secondary: true
  1. Stop Video streaming.
using secondarySdlConnection
    - OnServiceEnded for ServiceType: NAV
    - onProtocolSessionEnded: 
SessionID: 1 End ServiceType: NAV
  1. Start Audio streaming and allow it on Web-HMI.
    - startService(): 
secondarySdlConnection != null: true; allowed: true
isEncrypted: false
secondarySdlConnection startService
    - onProtocolSessionStarted: 
SessionID: 1 ServiceType: PCM Encrypted: false
    - startAudioStream(): 
ServiceAllowed for Secondary: true
  1. Stop Audio streaming
using secondarySdlConnection
    - OnServiceEnded for ServiceType: PCM
    - onProtocolSessionEnded: 
SessionID: 1 End ServiceType: PCM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment