-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[core] refactor registration receiver.
- Loading branch information
1 parent
4d67a9f
commit 10d21f3
Showing
5 changed files
with
153 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
ecal/core/src/registration/ecal_registration_receiver_udp.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* ========================= eCAL LICENSE ================================= | ||
* | ||
* Copyright (C) 2016 - 2024 Continental Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* ========================= eCAL LICENSE ================================= | ||
*/ | ||
|
||
#include "registration/ecal_registration_receiver_udp.h" | ||
|
||
#include "io/udp/ecal_udp_receiver_attr.h" | ||
#include "io/udp/ecal_udp_sample_receiver.h" | ||
#include "io/udp/ecal_udp_configurations.h" | ||
#include "serialization/ecal_serialize_sample_registration.h" | ||
#include <ecal/ecal_config.h> | ||
|
||
namespace | ||
{ | ||
using namespace eCAL; | ||
UDP::SReceiverAttr CreateAttributes() | ||
{ | ||
// set network attributes | ||
eCAL::UDP::SReceiverAttr attr; | ||
attr.address = UDP::GetRegistrationAddress(); | ||
attr.port = UDP::GetRegistrationPort(); | ||
attr.broadcast = UDP::IsBroadcast(); | ||
attr.loopback = true; | ||
attr.rcvbuf = Config::GetUdpMulticastRcvBufSizeBytes(); | ||
return attr; | ||
} | ||
|
||
} | ||
|
||
using namespace eCAL; | ||
|
||
eCAL::CRegistrationReceiverUDP::CRegistrationReceiverUDP(RegistrationApplySampleCallbackT apply_sample_callback) | ||
: m_registration_receiver(std::make_unique<UDP::CSampleReceiver>( | ||
CreateAttributes(), | ||
[](const std::string& sample_name_) {return true; }, | ||
[apply_sample_callback](const char* serialized_sample_data_, size_t serialized_sample_size_) { | ||
Registration::Sample sample; | ||
if (!DeserializeFromBuffer(serialized_sample_data_, serialized_sample_size_, sample)) return false; | ||
return apply_sample_callback(sample); | ||
} | ||
)) | ||
{} | ||
|
||
eCAL::CRegistrationReceiverUDP::~CRegistrationReceiverUDP() = default; |
52 changes: 52 additions & 0 deletions
52
ecal/core/src/registration/ecal_registration_receiver_udp.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* ========================= eCAL LICENSE ================================= | ||
* | ||
* Copyright (C) 2016 - 2024 Continental Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* ========================= eCAL LICENSE ================================= | ||
*/ | ||
|
||
/** | ||
* @brief eCAL UDP registration receiver | ||
* | ||
* Handles UDP samples coming from other processes | ||
* | ||
**/ | ||
|
||
#include <memory> | ||
#include <registration/ecal_registration_types.h> | ||
|
||
namespace eCAL | ||
{ | ||
namespace UDP | ||
{ | ||
class CSampleReceiver; | ||
} | ||
|
||
class CRegistrationReceiverUDP | ||
{ | ||
public: | ||
CRegistrationReceiverUDP(RegistrationApplySampleCallbackT apply_sample_callback); | ||
~CRegistrationReceiverUDP(); | ||
|
||
// Special member functionss | ||
CRegistrationReceiverUDP(const CRegistrationReceiverUDP& other) = delete; | ||
CRegistrationReceiverUDP& operator=(const CRegistrationReceiverUDP& other) = delete; | ||
CRegistrationReceiverUDP(CRegistrationReceiverUDP&& other) noexcept = delete; | ||
CRegistrationReceiverUDP& operator=(CRegistrationReceiverUDP&& other) noexcept = delete; | ||
|
||
private: | ||
std::unique_ptr<UDP::CSampleReceiver> m_registration_receiver; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* ========================= eCAL LICENSE ================================= | ||
* | ||
* Copyright (C) 2016 - 2024 Continental Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* ========================= eCAL LICENSE ================================= | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <functional> | ||
#include <serialization/ecal_struct_sample_registration.h> | ||
|
||
namespace eCAL { | ||
/** | ||
* @brief Apply sample callback type. | ||
* | ||
* @param sample_ The sample protocol buffer registration payload buffer. | ||
* @param sample_size_ The payload buffer size. | ||
**/ | ||
using RegistrationApplySampleCallbackT = std::function<bool(const Registration::Sample&)>; | ||
} |