mirror of
https://github.com/eclipse-openvehicle-api/openvehicle-api.git
synced 2026-08-30 04:15:10 +00:00
connection between 2 systems and bug fixes (#14)
This commit is contained in:
@@ -56,15 +56,15 @@ sdv::IInterfaceAccess* CSharedMemChannelMgnt::Access(const sdv::u8string& ssConn
|
||||
sdv::toml::CTOMLParser parser(ssConnectString);
|
||||
if (!parser.IsValid()) return nullptr;
|
||||
|
||||
// Is this a configuration provided by the endpoint (uses a "Provider" key), then this is a connection string. Use this
|
||||
// Is this a configuration provided by the endpoint (uses a "ConnectParam" key), then this is a connection string. Use this
|
||||
// to connect to the shared memory.
|
||||
std::shared_ptr<CConnection> ptrConnection;
|
||||
if (parser.GetDirect("Provider").IsValid())
|
||||
if (parser.GetDirect("ConnectParam").IsValid())
|
||||
ptrConnection = std::make_shared<CConnection>(m_watchdog, ssConnectString.c_str());
|
||||
else
|
||||
{
|
||||
std::string ssName = static_cast<std::string>(parser.GetDirect("IpcChannel.Name").GetValue());
|
||||
ptrConnection = std::make_shared<CConnection>(m_watchdog, 0,ssName, false);
|
||||
ptrConnection = std::make_shared<CConnection>(m_watchdog, 0, ssName, false);
|
||||
}
|
||||
if (!ptrConnection) return {};
|
||||
m_watchdog.AddConnection(ptrConnection);
|
||||
|
||||
@@ -43,9 +43,7 @@ public:
|
||||
|
||||
// Object declarations
|
||||
DECLARE_OBJECT_CLASS_TYPE(sdv::EObjectType::system_object)
|
||||
DECLARE_OBJECT_CLASS_NAME("DefaultSharedMemoryChannelControl")
|
||||
DECLARE_OBJECT_CLASS_ALIAS("LocalChannelControl")
|
||||
DECLARE_DEFAULT_OBJECT_NAME("LocalChannelControl")
|
||||
DECLARE_OBJECT_CLASS_NAME("DefaultSharedMemory")
|
||||
DECLARE_OBJECT_SINGLETON()
|
||||
|
||||
/**
|
||||
|
||||
@@ -117,7 +117,7 @@ std::string CConnection::GetConnectionString()
|
||||
{
|
||||
// The connection string is of the form:
|
||||
// [Provider]
|
||||
// Name = "DefaultSharedMemoryChannelControl"
|
||||
// Name = "DefaultSharedMemory"
|
||||
//
|
||||
// [[ConnectParam]]
|
||||
// Type = "shared_mem"
|
||||
@@ -132,9 +132,9 @@ std::string CConnection::GetConnectionString()
|
||||
// SyncTx = "SDV_TX_SYNC_REQUEST_1234"
|
||||
// SyncRx = "SDV_RX_SYNC_REQUEST_1234"
|
||||
// Direction = "request"
|
||||
std::string ssConnectionString = R"code([Provider]
|
||||
Name = "LocalChannelControl"
|
||||
)code" + std::string("\n") + m_sender.GetConnectionString() + "\n" + m_receiver.GetConnectionString();
|
||||
std::string ssConnectionString = R"toml([Provider]
|
||||
Name = "DefaultSharedMemory"
|
||||
)toml" + std::string("\n") + m_sender.GetConnectionString() + "\n" + m_receiver.GetConnectionString();
|
||||
return ssConnectionString;
|
||||
}
|
||||
|
||||
@@ -352,7 +352,7 @@ bool CConnection::AsyncConnect(sdv::IInterfaceAccess* pReceiver)
|
||||
std::unique_lock<std::mutex> lock(m_mtxConnect);
|
||||
|
||||
// Allowed to connect?
|
||||
if (m_eConnectState != sdv::ipc::EConnectState::uninitialized)
|
||||
if (m_eConnectState != sdv::ipc::EConnectState::uninitialized && m_eConnectState != sdv::ipc::EConnectState::disconnected)
|
||||
{
|
||||
for (auto& rprEventCallback : m_lstEventCallbacks)
|
||||
if (rprEventCallback.pCallback && rprEventCallback.uiCookie)
|
||||
@@ -377,9 +377,9 @@ bool CConnection::AsyncConnect(sdv::IInterfaceAccess* pReceiver)
|
||||
SetConnectState(sdv::ipc::EConnectState::initialized);
|
||||
|
||||
// Start the receiving thread (wait until started).
|
||||
m_threadReceive = std::thread(&CConnection::ReceiveMessages, this);
|
||||
m_threadReceive = sdv::core::secure_thread(&CConnection::ReceiveMessages, this);
|
||||
#if ENABLE_DECOUPLING > 0
|
||||
m_threadDecoupleReceive = std::thread(&CConnection::DecoupleReceive, this);
|
||||
m_threadDecoupleReceive = sdv::core::secure_thread(&CConnection::DecoupleReceive, this);
|
||||
#endif
|
||||
if (!m_bStarted)
|
||||
m_cvStartConnect.wait_for(lock, std::chrono::milliseconds(1000));
|
||||
@@ -602,9 +602,10 @@ void CConnection::ReceiveMessages()
|
||||
auto optPacket = m_receiver.TryRead();
|
||||
if (!optPacket)
|
||||
{
|
||||
// TODO EVE: Also allow synchronization take place when disconnected.
|
||||
// Start communication, but only if connection is client based. Server based should not start the communication. If
|
||||
// there is no client, the server would otherwise fill its send-buffer. Repeat sending every 500ms.
|
||||
if (!m_bServer && (/*m_eConnectState == sdv::ipc::EConnectState::disconnected ||*/ m_eConnectState == sdv::ipc::EConnectState::initialized))
|
||||
if (!m_bServer && (m_eConnectState == sdv::ipc::EConnectState::disconnected || m_eConnectState == sdv::ipc::EConnectState::initialized))
|
||||
{
|
||||
// Send request
|
||||
auto tpNow = std::chrono::high_resolution_clock::now();
|
||||
@@ -1001,9 +1002,10 @@ void CConnection::ReceiveConnectTerm(CMessage& /*rMessage*/)
|
||||
m_sender.CancelSend();
|
||||
m_sender.ResetRx();
|
||||
|
||||
// Send sync request (do not wait until next round in case a very short connection <100ms took place).
|
||||
if (m_bServer)
|
||||
Send(SMsgHdr{ SDVFrameworkInterfaceVersion, EMsgType::sync_request });
|
||||
// TODO EVE: Disabled, since state of client straight goes into "connecting" after being disconnected.
|
||||
//// Send sync request (do not wait until next round in case a very short connection <100ms took place).
|
||||
//if (m_bServer)
|
||||
// Send(SMsgHdr{ SDVFrameworkInterfaceVersion, EMsgType::sync_request });
|
||||
}
|
||||
|
||||
void CConnection::ReceiveDataMessage(CMessage& rMessage, SDataContext& rsDataCtxt)
|
||||
|
||||
@@ -257,7 +257,7 @@ private:
|
||||
sdv::CLifetimeCookie m_cookie = sdv::CreateLifetimeCookie(); ///< Lifetime cookie to manage module lifetime.
|
||||
CSharedMemBufferTx m_sender; ///< Shared buffer for sending.
|
||||
CSharedMemBufferRx m_receiver; ///< Shared buffer for receiving.
|
||||
std::thread m_threadReceive; ///< Thread which receives data from the socket.
|
||||
sdv::core::secure_thread m_threadReceive; ///< Thread which receives data from the socket.
|
||||
std::atomic<sdv::ipc::EConnectState> m_eConnectState = sdv::ipc::EConnectState::uninitialized; ///< the state of the connection
|
||||
sdv::ipc::IDataReceiveCallback* m_pReceiver = nullptr; ///< Receiver to pass the messages to if available
|
||||
std::shared_mutex m_mtxEventCallbacks; ///< Protect access to callback list. Only locking when
|
||||
@@ -275,7 +275,7 @@ private:
|
||||
#if ENABLE_DECOUPLING > 0
|
||||
std::mutex m_mtxReceive; ///< Protect receive queue.
|
||||
std::queue<sdv::sequence<sdv::pointer<uint8_t>>> m_queueReceive; ///< Receive queue to decouple receiving and processing.
|
||||
std::thread m_threadDecoupleReceive; ///< Decoupled receive thread.
|
||||
sdv::core::secure_thread m_threadDecoupleReceive; ///< Decoupled receive thread.
|
||||
std::condition_variable m_cvReceiveAvailable; ///< Condition variable synchronizing the processing.
|
||||
std::condition_variable m_cvReceiveProcessed; ///< Condition variable synchronizing the processing.
|
||||
#endif
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
CWatchDog::CWatchDog()
|
||||
{
|
||||
m_threadScheduledConnectionDestructions = std::thread(&CWatchDog::HandleScheduledConnectionDestructions, this);
|
||||
m_threadScheduledConnectionDestructions = sdv::core::secure_thread(&CWatchDog::HandleScheduledConnectionDestructions, this);
|
||||
}
|
||||
|
||||
CWatchDog::~CWatchDog()
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
|
||||
#include <interfaces/process.h>
|
||||
#include <support/interface_ptr.h>
|
||||
#include <support/local_service_access.h>
|
||||
#include <mutex>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
@@ -127,7 +128,7 @@ private:
|
||||
std::condition_variable m_cvTriggerConnectionDestruction; ///< Condition variable used to trigger when a
|
||||
///< connection is scheduled for destruction.
|
||||
std::queue<std::shared_ptr<CConnection>> m_queueScheduledConnectionDestructions; ///< Scheduled connection for destruction.
|
||||
std::thread m_threadScheduledConnectionDestructions; ///< Thread processing the scheduled destructions.
|
||||
sdv::core::secure_thread m_threadScheduledConnectionDestructions; ///< Thread processing the scheduled destructions.
|
||||
std::atomic_bool m_bShutdown = false; ///< Set when shutting down the watchdog
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user