Changes related to PR : smartdevicelink/sdl_core#2164
This proposal is about refactoring NetworkInterfaceListener for better cross platform support.
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.
It is proposed to implement this feature by following 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/>
...
)
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).