2019-10-31 15:20:38 +00:00
# pragma once
namespace MWR : : C3 : : Linter
{
2019-11-18 12:57:56 +00:00
/// Device bridge used to mock its functionality
2019-10-31 15:20:38 +00:00
class MockDeviceBridge : public MWR : : C3 : : AbstractDeviceBridge , public std : : enable_shared_from_this < MockDeviceBridge >
{
public :
2019-11-18 12:57:56 +00:00
/// Create Mock device bridge to device
/// @param device to bridge to
2019-10-31 15:20:38 +00:00
MockDeviceBridge ( std : : shared_ptr < Device > device ) ;
2019-11-18 12:57:56 +00:00
/// Called by Relay just after the Device creation.
2019-10-31 15:20:38 +00:00
void OnAttach ( ) override ;
2019-11-18 12:57:56 +00:00
/// Detaches the Device.
2019-10-31 15:20:38 +00:00
void Detach ( ) override ;
2019-11-18 12:57:56 +00:00
/// Notify the relay that this bridge should be closed
2019-10-31 15:20:38 +00:00
void Close ( ) override ;
2019-11-18 12:57:56 +00:00
/// Callback periodically fired by Relay for Device to update it's state. Might be called from a separate thread. Device should perform all necessary actions and leave as soon as possible.
2019-10-31 15:20:38 +00:00
void OnReceive ( ) override ;
2019-11-18 12:57:56 +00:00
/// Fired by Channel when a C3 packet arrives.
/// @param packet full C3 packet.
2019-10-31 15:20:38 +00:00
void PassNetworkPacket ( ByteView packet ) override ;
2019-11-18 12:57:56 +00:00
/// Fired by Relay to pass provided C3 packet through the Channel Device.
/// @param packet full C3 packet.
2019-10-31 15:20:38 +00:00
void OnPassNetworkPacket ( ByteView packet ) override ;
2019-11-18 12:57:56 +00:00
/// Called whenever Peripheral wants to send a Command to its Connector Binder.
/// @param command full Command with arguments.
2019-10-31 15:20:38 +00:00
void PostCommandToConnector ( ByteView command ) override ;
2019-11-18 12:57:56 +00:00
/// Fired by Relay to pass by provided Command from Connector.
/// @param command full Command with arguments.
2019-10-31 15:20:38 +00:00
void OnCommandFromConnector ( ByteView command ) override ;
2019-11-18 12:57:56 +00:00
/// Runs Device's Command.
/// @param command Device's Command to run.
/// @return Command result.
2019-10-31 15:20:38 +00:00
ByteVector RunCommand ( ByteView command ) override ;
2019-11-18 12:57:56 +00:00
/// Tells Device's type name.
/// @return A buffer with Device's description.
2019-10-31 15:20:38 +00:00
ByteVector WhoAreYou ( ) override ;
2019-11-18 12:57:56 +00:00
/// Logs a message. Used by internal mechanisms to report errors, warnings, informations and debug messages.
/// @param message information to log.
2019-10-31 15:20:38 +00:00
void Log ( LogMessage const & message ) override ;
2019-11-18 12:57:56 +00:00
/// Modifies the duration and jitter of OnReceive() calls. If minUpdateDelayInMs != maxUpdateDelayInMs then update frequency is randomized in range between those values.
/// @param minUpdateDelayInMs minimum update frequency.
/// @param maxUpdateDelayInMs maximum update frequency.
void SetUpdateDelay ( std : : chrono : : milliseconds minUpdateDelayInMs , std : : chrono : : milliseconds maxUpdateDelayInMs ) override ;
2019-10-31 15:20:38 +00:00
2019-11-18 12:57:56 +00:00
/// Sets time span between OnReceive() calls to a fixed value.
/// @param frequencyInMs frequency of OnReceive() calls.
void SetUpdateDelay ( std : : chrono : : milliseconds frequencyInMs ) override ;
2019-10-31 15:20:38 +00:00
void SetErrorStatus ( std : : string_view errorMessage ) override ;
std : : string GetErrorStatus ( ) override ;
2019-11-18 12:57:56 +00:00
/// @returns Bridged device
2019-10-31 15:20:38 +00:00
std : : shared_ptr < MWR : : C3 : : Device > GetDevice ( ) const ;
private :
2019-11-18 12:57:56 +00:00
/// Bridged device
2019-10-31 15:20:38 +00:00
std : : shared_ptr < Device > m_Device ;
} ;
}