Skip to content

Commit

Permalink
Merge pull request #19 from F2I-Consulting/gcc4.8
Browse files Browse the repository at this point in the history
  • Loading branch information
philippeVerney authored Oct 13, 2023
2 parents 4c5ec7d + 317f920 commit f67e350
Show file tree
Hide file tree
Showing 21 changed files with 18,543 additions and 2,191 deletions.
14 changes: 11 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,14 @@ if (WITH_FESAPI)
${FETPAPI_FESAPI_SOURCES}
${FETPAPI_FESAPI_HEADERS}
)
target_include_directories(${PROJECT_NAME} PRIVATE ${HDF5_C_INCLUDE_DIR} ${FESAPI_INCLUDE_DIR})
target_include_directories(${PROJECT_NAME} PRIVATE ${FESAPI_INCLUDE_DIR})
endif (WITH_FESAPI)

target_sources(${PROJECT_NAME} PRIVATE ${ALL_SOURCES_AND_HEADERS})

target_include_directories(${PROJECT_NAME} PRIVATE ${AVRO_INCLUDE_DIR} ${Boost_INCLUDE_DIR})
target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE ${AVRO_INCLUDE_DIR} ${Boost_INCLUDE_DIR})
if (WITH_ETP_SSL)
target_include_directories(${PROJECT_NAME} PRIVATE ${OPENSSL_INCLUDE_DIR})
target_include_directories(${PROJECT_NAME} SYSTEM PRIVATE ${OPENSSL_INCLUDE_DIR})
endif ()

target_include_directories(${PROJECT_NAME} INTERFACE
Expand All @@ -284,6 +284,14 @@ endif (WIN32)

add_subdirectory(doc)

if (WITH_FESAPI)
set (WITH_TEST OFF CACHE BOOL "Also build the unit tests.")
if (WITH_TEST)
enable_testing()
add_subdirectory(test)
endif (WITH_TEST)
endif (WITH_FESAPI)

# ============================================================================
# Install Fetpapi library
# ============================================================================
Expand Down
60 changes: 0 additions & 60 deletions cmake/swigEtp1_2Include.i.in
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ typedef long long time_t;
%{
#include "../src/etp/ClientSessionLaunchers.h"
#include "../src/etp/EtpHelpers.h"
#include "../src/etp/PlainServerSession.h"
#include "../src/etp/Server.h"
%}

#ifdef WITH_FESAPI
Expand All @@ -165,8 +163,6 @@ typedef long long time_t;
%nspace ETP_NS::AbstractSession;
%nspace ETP_NS::PlainClientSession;
%nspace ETP_NS::InitializationParameters;
%nspace ETP_NS::ServerInitializationParameters;
%nspace ETP_NS::Server;
#ifdef WITH_FESAPI
%nspace ETP_NS::FesapiHdfProxyFactory;
#endif
Expand Down Expand Up @@ -1074,26 +1070,10 @@ namespace Energistics {
%feature("director") ETP_NS::TransactionHandlers;
%feature("director") ETP_NS::DataspaceHandlers;
%feature("director") ETP_NS::InitializationParameters;
%feature("director") ETP_NS::ServerInitializationParameters;

/* Following extensions aims at preventing the Python garbage collector from
garbage collecting a protocol handler that may be still used by a session. */
#ifdef SWIGPYTHON
%fragment("server_initialization_parameters_reference_init", "init") {
server_initialization_parameters_reference();
}
%fragment("server_initialization_parameters_reference_function", "header", fragment="server_initialization_parameters_reference_init") {
static PyObject *server_initialization_parameters_reference() {
static PyObject *server_initialization_parameters_reference_string = SWIG_Python_str_FromChar("__server_initialization_parameters_reference");
return server_initialization_parameters_reference_string;
}
}
%extend ETP_NS::Server {
%typemap(ret, fragment="server_initialization_parameters_reference_function") void listen(ServerInitializationParameters* serverInitializationParams, int threadCount) %{
PyObject_SetAttr($self, server_initialization_parameters_reference(), args);
%}
}

%fragment("core_handler_reference_init", "init") {
core_handler_reference();
}
Expand Down Expand Up @@ -1213,15 +1193,6 @@ namespace Energistics {
#endif

#ifdef SWIGCSHARP
%typemap(cscode) ETP_NS::Server %{
private ServerInitializationParameters serverInitializationParametersReference;
%}

%typemap(csin,
post=" serverInitializationParametersReference = $csinput;"
) ETP_NS::ServerInitializationParameters* serverInitializationParams "ServerInitializationParameters.getCPtr($csinput)"


%typemap(cscode) ETP_NS::AbstractSession %{
private CoreHandlers coreHandlersReference = null;
private DiscoveryHandlers discoveryHandlersReference = null;
Expand Down Expand Up @@ -1262,14 +1233,6 @@ namespace Energistics {
#endif

#ifdef SWIGJAVA
%typemap(javacode) ETP_NS::Server %{
private ServerInitializationParameters serverInitializationParametersReference;
%}

%typemap(javain,
post=" serverInitializationParametersReference = $javainput;"
) ETP_NS::ServerInitializationParameters* serverInitializationParams "ServerInitializationParameters.getCPtr($javainput)"

%typemap(javacode) ETP_NS::AbstractSession %{
private CoreHandlers coreHandlersReference;
private DiscoveryHandlers discoveryHandlersReference;
Expand Down Expand Up @@ -1967,29 +1930,6 @@ namespace ETP_NS
#endif
}

/******************* SERVER ***************************/

class ServerInitializationParameters : public InitializationParameters
{
public:
ServerInitializationParameters(const std::string & serverUuid, const std::string & host, unsigned short port);
virtual ~ServerInitializationParameters();

virtual std::string getContactEmail() const;
virtual std::string getContactName() const;
virtual std::string getContactPhone() const;
virtual std::string getOrganizationName() const;

virtual std::vector<std::string> makeSupportedEncodings() const;
};

class Server
{
public:
Server();
void listen(ServerInitializationParameters* serverInitializationParams, int threadCount);
};

#ifdef WITH_FESAPI
%typemap(javaimports) FesapiHdfProxyFactory %{
import com.f2i_consulting.fesapi.common.HdfProxyFactory;
Expand Down
2 changes: 1 addition & 1 deletion src/etp/AbstractClientSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ namespace ETP_NS
{
if (ec) {
std::cerr << "on_handshake : " << ec.message() << std::endl;
std::cerr << "Sometimes some ETP server require a trailing slash at the end of their URL" << std::endl;
std::cerr << "Sometimes some ETP server require a trailing slash at the end of their URL. Did you also check your optional \"data-partition-id\" additional Header Field?" << std::endl;
return;
}

Expand Down
11 changes: 6 additions & 5 deletions src/etp/AbstractSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ void AbstractSession::on_read(boost::system::error_code ec, std::size_t bytes_tr
}
} // Scope for specificProtocolHandlersLock

size_t receivedMhProtocol = static_cast<size_t>(receivedMh.protocol);
if (specificProtocolHandler) {
// Receive a message which has been asked to be processed with a specific protocol handler
specificProtocolHandler->decodeMessageBody(receivedMh, d);
Expand All @@ -121,13 +122,13 @@ void AbstractSession::on_read(boost::system::error_code ec, std::size_t bytes_tr
specificProtocolHandlers.erase(specificProtocolHandlerIt);
}
}
else if (receivedMh.protocol < protocolHandlers.size() && protocolHandlers[receivedMh.protocol] != nullptr) {
else if (receivedMhProtocol < protocolHandlers.size() && protocolHandlers[receivedMhProtocol] != nullptr) {
// Receive a message to be processed with a common protocol handler in case for example an unsollicited notification
protocolHandlers[receivedMh.protocol]->decodeMessageBody(receivedMh, d);
protocolHandlers[receivedMhProtocol]->decodeMessageBody(receivedMh, d);
}
else {
std::cerr << "Received a message with id " << receivedMh.messageId << " for which non protocol handlers is associated. Protocol " << receivedMh.protocol << std::endl;
send(ETP_NS::EtpHelpers::buildSingleMessageProtocolException(4, "The agent does not support the protocol " + std::to_string(receivedMh.protocol) + " identified in a message header."), receivedMh.messageId, 0x02);
std::cerr << "Received a message with id " << receivedMh.messageId << " for which non protocol handlers is associated. Protocol " << receivedMhProtocol << std::endl;
send(ETP_NS::EtpHelpers::buildSingleMessageProtocolException(4, "The agent does not support the protocol " + std::to_string(receivedMhProtocol) + " identified in a message header."), receivedMh.messageId, 0x02);
}
}
flushReceivingBuffer();
Expand Down Expand Up @@ -311,7 +312,7 @@ std::string AbstractSession::startTransaction(std::vector<std::string> dataspace
throw std::logic_error("You did not register any transaction protocol handlers.");
}
if (handlers->isInAnActiveTransaction()) {
throw std::logic_error("You cannot start a transaction before the current transaction is rolled back or committed. ETP1.2 intentionally supports a single open transaction on a session.");
throw std::logic_error("You cannot start a transaction before the current transaction is rolled back or committed. ETP1.2 intentionally supports a single opened transaction on a session.");
}

Energistics::Etp::v12::Protocol::Transaction::StartTransaction startTransactionMsg;
Expand Down
2 changes: 1 addition & 1 deletion src/etp/EtpMessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -1946,7 +1946,7 @@ namespace Energistics {
namespace v12 {
namespace Datatypes {
struct Uuid{
std::array<uint8_t, 16> array;
std::array<uint8_t, 16> array{};
};
}
}
Expand Down
29 changes: 0 additions & 29 deletions src/etp/PlainServerSession.cpp

This file was deleted.

43 changes: 0 additions & 43 deletions src/etp/PlainServerSession.h

This file was deleted.

104 changes: 3 additions & 101 deletions src/etp/ProtocolHandlers/CoreHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@ under the License.
-----------------------------------------------------------------------*/
#include "CoreHandlers.h"

#include "../PlainServerSession.h"
#ifdef WITH_ETP_SSL
#include "../ssl/SslServerSession.h"
#endif
#include "../AbstractSession.h"
#include "../EtpHelpers.h"
#include "../ServerInitializationParameters.h"

using namespace ETP_NS;

Expand Down Expand Up @@ -101,103 +97,9 @@ void CoreHandlers::decodeMessageBody(const Energistics::Etp::v12::Datatypes::Mes
}
}

void CoreHandlers::on_RequestSession(const Energistics::Etp::v12::Protocol::Core::RequestSession & rs, int64_t correlationId)
void CoreHandlers::on_RequestSession(const Energistics::Etp::v12::Protocol::Core::RequestSession&, int64_t correlationId)
{
ServerInitializationParameters const* serverInitializationParams = nullptr;

PlainServerSession* pss = dynamic_cast<PlainServerSession*>(session);
if (pss != nullptr) {
serverInitializationParams = pss->getServerInitializationParameters();
}
#ifdef WITH_ETP_SSL
else {
SslServerSession* sss = dynamic_cast<SslServerSession*>(session);
if (sss != nullptr) {
serverInitializationParams = sss->getServerInitializationParameters();
}
}
#endif

if (serverInitializationParams == nullptr) {
std::cerr << "Request Session message must be received on a server session." << std::endl;
}

// Check format
if (std::find(rs.supportedFormats.begin(), rs.supportedFormats.end(), "xml") == rs.supportedFormats.end()) {
session->send(ETP_NS::EtpHelpers::buildSingleMessageProtocolException(21, "Per the ETP1.2 official specification, \"xml\" format MUST BE supported."), correlationId, 0x02);
session->close();
return;
}

// Check requested protocols
auto supportedProtocols = serverInitializationParams->makeSupportedProtocols();
std::vector<Energistics::Etp::v12::Datatypes::SupportedProtocol> requestedAndSupportedProtocols;
for (auto& rp : rs.requestedProtocols) {
const auto validatedProtocol = std::find_if(supportedProtocols.begin(), supportedProtocols.end(),
[rp](const Energistics::Etp::v12::Datatypes::SupportedProtocol & sp) -> bool {
return sp.protocol == rp.protocol &&
sp.role == rp.role &&
sp.protocolVersion.major == rp.protocolVersion.major &&
sp.protocolVersion.minor == rp.protocolVersion.minor &&
sp.protocolVersion.patch == rp.protocolVersion.patch &&
sp.protocolVersion.revision == rp.protocolVersion.revision;
}
);
if (validatedProtocol != std::end(supportedProtocols)) {
requestedAndSupportedProtocols.push_back(*validatedProtocol);
}
}

if (requestedAndSupportedProtocols.empty()) {
session->send(ETP_NS::EtpHelpers::buildSingleMessageProtocolException(2, "The server does not support any of the requested protocols."), correlationId, 0x02);
session->close();
return;
}

// Check requested dataobjects
auto supportedDataobjects = serverInitializationParams->makeSupportedDataObjects();
std::vector<Energistics::Etp::v12::Datatypes::SupportedDataObject> requestedAndSupportedDataObjects;
for (auto& rd : rs.supportedDataObjects) {
const auto validatedDataObject = std::find_if(supportedDataobjects.begin(), supportedDataobjects.end(),
[rd](const Energistics::Etp::v12::Datatypes::SupportedDataObject & sd) -> bool {
return sd.qualifiedType == rd.qualifiedType;
}
);
if (validatedDataObject != std::end(supportedDataobjects)) {
requestedAndSupportedDataObjects.push_back(*validatedDataObject);
}
}

// Check MaxWebSocketMessagePayloadSize endpoint capability
auto supportedEndPointCaps = serverInitializationParams->makeEndpointCapabilities();
const auto requestedMaxWebSocketMessagePayloadSizeIt = rs.endpointCapabilities.find("MaxWebSocketMessagePayloadSize");
if (requestedMaxWebSocketMessagePayloadSizeIt != rs.endpointCapabilities.end() && requestedMaxWebSocketMessagePayloadSizeIt->second.item.idx() == 3) {
const int64_t requestedMaxWebSocketMessagePayloadSize = requestedMaxWebSocketMessagePayloadSizeIt->second.item.get_long();
if (requestedMaxWebSocketMessagePayloadSize > 0 && requestedMaxWebSocketMessagePayloadSize != session->getMaxWebSocketMessagePayloadSize()) {
session->setMaxWebSocketMessagePayloadSize(requestedMaxWebSocketMessagePayloadSize);

Energistics::Etp::v12::Datatypes::DataValue value;
value.item.set_long(requestedMaxWebSocketMessagePayloadSize);
supportedEndPointCaps["MaxWebSocketFramePayloadSize"] = value;
supportedEndPointCaps["MaxWebSocketMessagePayloadSize"] = value;
}
}

// Build Open Session message
Energistics::Etp::v12::Protocol::Core::OpenSession openSession;
openSession.applicationName = serverInitializationParams->getApplicationName();
openSession.applicationVersion = serverInitializationParams->getApplicationVersion();
std::copy(std::begin(session->getIdentifier().data), std::end(session->getIdentifier().data), openSession.sessionId.array.begin());
std::copy(std::begin(serverInitializationParams->getInstanceId().data), std::end(serverInitializationParams->getInstanceId().data), openSession.serverInstanceId.array.begin());
openSession.supportedFormats.push_back("xml");
openSession.supportedProtocols = requestedAndSupportedProtocols;
openSession.endpointCapabilities = supportedEndPointCaps;
openSession.supportedDataObjects = requestedAndSupportedDataObjects;
openSession.currentDateTime = std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count();

session->send(openSession, correlationId, 0x02);

session->fesapi_log("A new websocket session", session->getIdentifier(), "has been opened by a client");
session->send(ETP_NS::EtpHelpers::buildSingleMessageProtocolException(1, "You cannot request a session to a client."), correlationId, 0x02);
}

void CoreHandlers::on_OpenSession(const Energistics::Etp::v12::Protocol::Core::OpenSession &, int64_t)
Expand Down
Loading

0 comments on commit f67e350

Please sign in to comment.