forked from eclipse-4diac/4diac-forte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
67 changed files
with
1,177 additions
and
440 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
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,41 @@ | ||
## This file conforms to ISO/IEC 5962:2021 a.k.a. SPDX-2.2.1 (lite variant) | ||
SPDXVersion: SPDX-2.2 | ||
DataLicense: CC0-1.0 | ||
SPDXID: SPDXRef-DOCUMENT | ||
DocumentName: Eclipse-4diac-FORTE-SBOM | ||
DocumentNamespace: https://eclipse.dev/4diac/ | ||
Creator: Organization: Eclipse-4diac | ||
Created: 2024-11-21T14:43:43Z | ||
CreatorComment: <text>This file documents optional external dependencies of 4diac FORTE in a standardised machine-readable format</text> | ||
|
||
## This package | ||
##################################### | ||
PackageName: 4diac-FORTE | ||
SPDXID: SPDXRef-4diac-FORTE | ||
PackageComment: <text>4diac FORTE source code</text> | ||
ExternalRef: PACKAGE-MANAGER purl pkg:github/eclipse-4diac/4diac-forte@develop | ||
PackageVersion: develop | ||
PackageSupplier: Organization: Eclipse-4diac | ||
Relationship: SPDXRef-DOCUMENT DESCRIBES SPDXRef-4diac-FORTE | ||
PackageDownloadLocation: https://github.com/eclipse-4diac/4diac-forte/archive/develop.zip | ||
FilesAnalyzed: false | ||
PackageLicenseConcluded: NOASSERTION | ||
PackageLicenseDeclared: NOASSERTION | ||
PackageCopyrightText: NOASSERTION | ||
|
||
## Optional dependencies | ||
##################################### | ||
PackageName: open62541 | ||
SPDXID: SPDXRef-open62541 | ||
PackageComment: <text>OPC-UA support library</text> | ||
ExternalRef: PACKAGE-MANAGER purl pkg:github/open62541/[email protected] | ||
PackageVersion: 1.4.7 | ||
PackageSupplier: Organization: open62541 | ||
Relationship: SPDXRef-open62541 OPTIONAL_DEPENDENCY_OF SPDXRef-4diac-FORTE | ||
PackageDownloadLocation: https://github.com/open62541/open62541/archive/refs/tags/v1.4.7.zip | ||
PackageChecksum: SHA256: 598889ae4bdc468d39c5c961ba76c648747b64337a9d0c0ef07b032c4819dea8 | ||
FilesAnalyzed: false | ||
PackageLicenseConcluded: NOASSERTION | ||
PackageLicenseDeclared: NOASSERTION | ||
PackageCopyrightText: NOASSERTION | ||
|
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
if(FORTE_COM_OPC_UA_MULTICAST) | ||
forte_add_sourcefile_hcpp(lds_me_handler) | ||
endif(FORTE_COM_OPC_UA_MULTICAST) |
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,100 @@ | ||
|
||
#include "lds_me_handler.h" | ||
|
||
#include "devlog.h" | ||
|
||
using namespace forte::com::opc_ua::detail; | ||
|
||
LdsMeHandler::LdsMeHandler(UA_Server& paUaServer) : mUaServer{paUaServer} { | ||
UA_Server_setServerOnNetworkCallback(&mUaServer, serverOnNetworkCallback, this); | ||
} | ||
|
||
LdsMeHandler::~LdsMeHandler() { | ||
for(const auto& registeredServer : mRegisteredServers){ | ||
deregisterDiscoveryServer(registeredServer.mString); | ||
} | ||
UA_Server_setServerOnNetworkCallback(&mUaServer, nullptr, nullptr); | ||
} | ||
|
||
void LdsMeHandler::configureServer(UA_ServerConfig& paUaServerConfig, const std::string& paServerName) { | ||
UA_String_clear(&paUaServerConfig.mdnsConfig.mdnsServerName); | ||
paUaServerConfig.mdnsConfig.mdnsServerName = UA_String_fromChars(paServerName.c_str()); | ||
// Enable the mDNS announce and response functionality | ||
paUaServerConfig.mdnsEnabled = true; | ||
} | ||
|
||
void LdsMeHandler::serverOnNetworkCallback(const UA_ServerOnNetwork* paServerOnNetwork, UA_Boolean paIsServerAnnounce, UA_Boolean paIsTxtReceived, void* paData) { | ||
|
||
if(!paIsTxtReceived) { | ||
return; // we wait until the corresponding TXT record is announced. | ||
} | ||
|
||
DEVLOG_DEBUG("[OPC UA LDS ME]: mDNS %s '%.*s' with url '%.*s'\n", paIsServerAnnounce ? "announce" : "remove", paServerOnNetwork->serverName.length, | ||
paServerOnNetwork->serverName.data, paServerOnNetwork->discoveryUrl.length, paServerOnNetwork->discoveryUrl.data); | ||
|
||
// check if server is LDS | ||
bool isServerLDS = false; | ||
|
||
UA_StringRAII ldsStr("LDS"); | ||
for(unsigned int i = 0; i < paServerOnNetwork->serverCapabilitiesSize; i++) { | ||
if(UA_String_equal(&paServerOnNetwork->serverCapabilities[i], &ldsStr.mString)) { | ||
isServerLDS = true; | ||
break; | ||
} | ||
} | ||
|
||
// skip non-LDS servers | ||
if(!isServerLDS) { | ||
return; | ||
} | ||
|
||
auto handler = static_cast<LdsMeHandler*>(paData); | ||
|
||
auto foundDiscoveryUrl = handler->mRegisteredServers.end(); | ||
for(auto iter = handler->mRegisteredServers.begin(); iter != handler->mRegisteredServers.end(); iter++) { | ||
if(UA_String_equal(&paServerOnNetwork->discoveryUrl, &iter->mString)) { | ||
foundDiscoveryUrl = iter; | ||
break; | ||
} | ||
} | ||
|
||
// if a new server is being announced | ||
if(paIsServerAnnounce && foundDiscoveryUrl == handler->mRegisteredServers.end()) { | ||
if(handler->registerDiscoveryServer(paServerOnNetwork->discoveryUrl)){ | ||
handler->mRegisteredServers.emplace_back(paServerOnNetwork->discoveryUrl); | ||
} | ||
// if a known server is being un-announced | ||
} else if(!paIsServerAnnounce && foundDiscoveryUrl != handler->mRegisteredServers.end()) { | ||
handler->deregisterDiscoveryServer(foundDiscoveryUrl->mString); | ||
handler->mRegisteredServers.erase(foundDiscoveryUrl); | ||
} | ||
} | ||
|
||
bool LdsMeHandler::registerDiscoveryServer(const UA_String& paDiscoveryUrl) { | ||
|
||
UA_ClientConfig clientConfig; | ||
memset(&clientConfig, 0, sizeof(UA_ClientConfig)); | ||
UA_ClientConfig_setDefault(&clientConfig); | ||
auto retVal = UA_Server_registerDiscovery(&mUaServer, &clientConfig, paDiscoveryUrl, UA_STRING_NULL); | ||
if( UA_STATUSCODE_GOOD != retVal) { | ||
DEVLOG_ERROR("[OPC UA LDSME]: Could not register with LDS. Error: %s\n", UA_StatusCode_name(retVal)); | ||
return false; | ||
} | ||
DEVLOG_INFO("[OPC UA LDSME]: Registered to LDS '%.*s'\n", paDiscoveryUrl.length, paDiscoveryUrl.data); | ||
return true; | ||
} | ||
|
||
void LdsMeHandler::deregisterDiscoveryServer(const UA_String& paDiscoveryUrl) { | ||
UA_ClientConfig clientConfig; | ||
memset(&clientConfig, 0, sizeof(UA_ClientConfig)); | ||
UA_ClientConfig_setDefault(&clientConfig); | ||
|
||
auto retVal = UA_Server_deregisterDiscovery(&mUaServer, &clientConfig, paDiscoveryUrl); | ||
// if unregister fails, we don't do anything else | ||
if( UA_STATUSCODE_GOOD != retVal) { | ||
DEVLOG_ERROR("[OPC UA LDSME]: Could not deregister with LDS. Error: %s\n", UA_StatusCode_name(retVal)); | ||
return; | ||
} | ||
|
||
DEVLOG_INFO("[OPC UA LDSME]: Unregistered from LDS '%.*s'\n", paDiscoveryUrl.length, paDiscoveryUrl.data); | ||
} |
Oops, something went wrong.