Commit 0387a0cd authored by Patrick Bellot's avatar Patrick Bellot
Browse files

EDP

parent 1fe61658
......@@ -18,7 +18,7 @@
#include "lib/OpcUa.h"
#define SAMPLE 3
#define SAMPLE 4
#if (SAMPLE==1)
# include "Client_01_Subscription/StartClients_01.h"
......
......@@ -104,19 +104,20 @@ MYDLL void Service_SendResponse(
namespace opcua {
MYDLL void Service_SendServiceFault(
MYDLL void Service_SendError( /* Because of a link probleme. */
uint32_t scConnectionId,
uint32_t requestId,
SOPC_StatusCode s)
uint32_t requestHandle,
SOPC_StatusCode status)
{
NOT_USED(scConnectionId) ;
NOT_USED(requestId) ;
NOT_USED(s) ;
NOT_USED(requestHandle) ;
NOT_USED(status) ;
CHECK_INT(0) ;
}
#include "lib/Services/Session/OpcUa_IPCS_CreateSessionResponse.h"
MYDLL void Service_ServiceFault(
......
......@@ -39,19 +39,20 @@ MYDLL void Service_SendResponse(
namespace opcua {
MYDLL void Service_SendError(
uint32_t scConnectionId,
uint32_t requestId,
OpcUa_ResponseHeader * responseHeader,
SOPC_StatusCode status) ;
MYDLL void Service_SendError( /* Because of a link probleme. */
uint32_t scConnectionId,
uint32_t requestId,
uint32_t requestHandle,
SOPC_StatusCode status) ;
MYDLL void Service_ServiceFault(
uint32_t scConnectionId,
uint32_t requestId,
OpcUa_ResponseHeader * responsetHeader,
OpcUa_ResponseHeader * responseHeader,
OpcUa_ServiceFault * response) ;
MYDLL void Service_CreateSession(
uint32_t scConnectionId,
uint32_t requestId,
......
......@@ -270,9 +270,8 @@ void SOPC_Services_EnqueueEvent(SOPC_Services_Event scEvent, uint32_t id, void*
}
} else {
odebug_is(S2OPC_ERR,"Services_EnqueueEvent","Cannot decode msg body in response %d (%s)",encType->TypeId,encType->TypeName) ;
fprintf(stderr,"..... status=0x%08x and sequence=0x%08x\n", responseHeader->ServiceResult ,responseHeader->RequestHandle) ;
if (encType->TypeId == OpcUaId_ServiceFault) {
opcua::Service_ServiceFault(id,requestId,responseHeader,(OpcUa_ServiceFault *)msgBody) ;
opcua::Service_ServiceFault(id,requestId,responseHeader,(OpcUa_ServiceFault *)NULL) ;
} else {
odebug(S2OPC_ERR,"","Aborting...")
}
......
......@@ -79,84 +79,38 @@ namespace opcua {
MYDLL void Service_SendError(
uint32_t scConnectionId,
uint32_t requestId,
OpcUa_ResponseHeader * responseHeader,
uint32_t requestHandle,
SOPC_StatusCode status)
{
OpcUa_ResponseHeader faultHeader ;
OpcUa_ResponseHeader_Initialize(&faultHeader) ;
faultHeader.RequestHandle = responseHeader->RequestHandle ;
SOPC_DiagnosticInfo diagnosticInfo ;
SOPC_DiagnosticInfo_Initialize(&diagnosticInfo) ;
faultHeader.RequestHandle = requestHandle ;
faultHeader.Timestamp = (uint64_t)(Clock::get_microsecondssince1601() * 10) ;
faultHeader.ServiceResult = status ;
faultHeader.ServiceDiagnostics = responseHeader->ServiceDiagnostics ;
faultHeader.NoOfStringTable = responseHeader->NoOfStringTable ;
faultHeader.StringTable = responseHeader->StringTable ;
faultHeader.ServiceDiagnostics = diagnosticInfo ;
faultHeader.NoOfStringTable = 0 ;
faultHeader.StringTable = NULL ;
Service_SendResponse(scConnectionId,requestId,&OpcUa_ServiceFault_EncodeableType,&faultHeader,NULL) ;
OpcUa_ResponseHeader_Clear(&faultHeader) ;
}
MYDLL void Service_SendServiceFault(
MYDLL void Service_SendError(
uint32_t scConnectionId,
uint32_t requestId,
SOPC_StatusCode s)
OpcUa_RequestHeader * requestHeader,
SOPC_StatusCode status)
{
OpcUa_ResponseHeader rHeader ;
OpcUa_ResponseHeader_Initialize(&rHeader) ;
rHeader.Timestamp = (uint64_t)(Clock::get_microsecondssince1601() * 10) ;
rHeader.ServiceResult = s ;
SOPC_Buffer* buffer = SOPC_Buffer_Create(SOPC_MAX_MESSAGE_LENGTH);
if (buffer == NULL) {
odebug_i(S2OPC_ERR,"Service_SendServiceFault","Cannot SOPC_Buffer_Create a buffer of length %d",SOPC_MAX_MESSAGE_LENGTH) ;
return ;
}
SOPC_StatusCode status = SOPC_Buffer_SetDataLength(
buffer,
SOPC_UA_SECURE_MESSAGE_HEADER_LENGTH +
SOPC_UA_SYMMETRIC_SECURITY_HEADER_LENGTH +
SOPC_UA_SECURE_MESSAGE_SEQUENCE_LENGTH);
if (status != SOPC_STATUS_OK) {
odebug(S2OPC_ERR,"Service_SendServiceFault","Cannot SOPC_Buffer_SetDataLength on a buffer") ;
return ;
}
status = SOPC_Buffer_SetPosition(
buffer,
SOPC_UA_SECURE_MESSAGE_HEADER_LENGTH +
SOPC_UA_SYMMETRIC_SECURITY_HEADER_LENGTH +
SOPC_UA_SECURE_MESSAGE_SEQUENCE_LENGTH);
if (status != SOPC_STATUS_OK) {
odebug(S2OPC_ERR,"Service_SendServiceFault","Cannot SOPC_Buffer_SetPosition on a buffer") ;
goto error ;
}
status = SOPC_EncodeMsg_Type_Header_Body(buffer, &OpcUa_ServiceFault_EncodeableType,&OpcUa_ResponseHeader_EncodeableType, (void*) &rHeader, NULL);
if (status != SOPC_STATUS_OK) {
odebug(S2OPC_ERR,"Service_SendServiceFault","Cannot SOPC_EncodeMsg_Type_Header_Body in the buffer") ;
goto error ;
}
// SEND EVENT TO SC LAYER: ASK TO SEND MSG ON SC
SOPC_SecureChannels_EnqueueEvent(SC_SERVICE_SND_MSG, scConnectionId, (void*) buffer,requestId) ;
if (status != SOPC_STATUS_OK) {
odebug(S2OPC_ERR,"Service_SendServiceFault","Cannot SOPC_SecureChannels_EnqueueEvent the buffer") ;
}
error:
OpcUa_ResponseHeader_Clear(&rHeader) ;
Service_SendError(scConnectionId,requestId,requestHeader->RequestHandle,status) ;
}
#if (WITH_DISCOVERY == 1)
MYDLL void Service_FindServers(
uint32_t scConnectionId,
......@@ -177,7 +131,7 @@ MYDLL void Service_FindServers(
Service_SendResponse(scConnectionId,requestId,&OpcUa_FindServersResponse_EncodeableType,&responseHeader,(void*)&response) ;
} else {
debug_i(S2OPC_ERR,"Service_FindServers","Failed with status=0x%08x",status) ;
Service_SendError(scConnectionId,requestId,&responseHeader,status) ;
Service_SendError(scConnectionId,requestId,requestHeader,status) ;
}
SOPC_Encodeable_Delete(&OpcUa_RequestHeader_EncodeableType,(void **)&requestHeader);
......@@ -208,7 +162,7 @@ MYDLL void Service_GetEndpoints(
Service_SendResponse(scConnectionId,requestId,&OpcUa_GetEndpointsResponse_EncodeableType,&responseHeader,(void*)&response) ;
} else {
debug_i(S2OPC_ERR,"Service_GetEndpoints","Failed with status=0x%08x",status) ;
Service_SendError(scConnectionId,requestId,&responseHeader,status) ;
Service_SendError(scConnectionId,requestId,requestHeader,status) ;
}
SOPC_Encodeable_Delete(&OpcUa_RequestHeader_EncodeableType,(void **)&requestHeader);
......@@ -237,7 +191,7 @@ MYDLL void Service_Call(
if (status == STATUS_OK) {
Service_SendResponse(scConnectionId,requestId,&OpcUa_CallResponse_EncodeableType,&responseHeader,(void*)&response) ;
} else {
Service_SendError(scConnectionId,requestId,&responseHeader,status) ;
Service_SendError(scConnectionId,requestId,requestHeader,status) ;
}
SOPC_Encodeable_Delete(&OpcUa_RequestHeader_EncodeableType,(void **)&requestHeader);
......@@ -266,7 +220,7 @@ MYDLL void Service_AddNodes(
if (status == STATUS_OK) {
Service_SendResponse(scConnectionId,requestId,&OpcUa_AddNodesResponse_EncodeableType,&responseHeader,(void*)&response) ;
} else {
Service_SendError(scConnectionId,requestId,&responseHeader,status) ;
Service_SendError(scConnectionId,requestId,requestHeader,status) ;
}
SOPC_Encodeable_Delete(&OpcUa_RequestHeader_EncodeableType,(void **)&requestHeader);
......@@ -295,7 +249,7 @@ MYDLL void Service_AddReferences(
if (status == STATUS_OK) {
Service_SendResponse(scConnectionId,requestId,&OpcUa_AddReferencesResponse_EncodeableType,&responseHeader,(void*)&response) ;
} else {
Service_SendError(scConnectionId,requestId,&responseHeader,status) ;
Service_SendError(scConnectionId,requestId,requestHeader,status) ;
}
SOPC_Encodeable_Delete(&OpcUa_RequestHeader_EncodeableType,(void **)&requestHeader);
......@@ -324,7 +278,7 @@ MYDLL void Service_Read(
if (status == STATUS_OK) {
Service_SendResponse(scConnectionId,requestId,&OpcUa_ReadResponse_EncodeableType,&responseHeader,(void*)&response) ;
} else {
Service_SendError(scConnectionId,requestId,&responseHeader,status) ;
Service_SendError(scConnectionId,requestId,requestHeader,status) ;
}
SOPC_Encodeable_Delete(&OpcUa_RequestHeader_EncodeableType,(void **)&requestHeader);
......@@ -353,7 +307,7 @@ MYDLL void Service_Write(
if (status == STATUS_OK) {
Service_SendResponse(scConnectionId,requestId,&OpcUa_WriteResponse_EncodeableType,&responseHeader,(void*)&response) ;
} else {
Service_SendError(scConnectionId,requestId,&responseHeader,status) ;
Service_SendError(scConnectionId,requestId,requestHeader,status) ;
}
SOPC_Encodeable_Delete(&OpcUa_RequestHeader_EncodeableType,(void **)&requestHeader);
......@@ -381,7 +335,7 @@ MYDLL void Service_CreateSession(
if (status == STATUS_OK) {
Service_SendResponse(scConnectionId,requestId,&OpcUa_CreateSessionResponse_EncodeableType,&responseHeader,(void*)&response) ;
} else {
Service_SendError(scConnectionId,requestId,&responseHeader,status) ;
Service_SendError(scConnectionId,requestId,requestHeader,status) ;
}
SOPC_Encodeable_Delete(&OpcUa_RequestHeader_EncodeableType,(void **)&requestHeader);
......@@ -408,7 +362,7 @@ MYDLL void Service_ActivateSession(
if (status == STATUS_OK) {
Service_SendResponse(scConnectionId,requestId,&OpcUa_ActivateSessionResponse_EncodeableType,&responseHeader,(void*)&response) ;
} else {
Service_SendError(scConnectionId,requestId,&responseHeader,status) ;
Service_SendError(scConnectionId,requestId,requestHeader,status) ;
}
SOPC_Encodeable_Delete(&OpcUa_RequestHeader_EncodeableType,(void **)&requestHeader);
......@@ -435,7 +389,7 @@ MYDLL void Service_CloseSession(
if (status == STATUS_OK) {
Service_SendResponse(scConnectionId,requestId,&OpcUa_CloseSessionResponse_EncodeableType,&responseHeader,(void*)&response) ;
} else {
Service_SendError(scConnectionId,requestId,&responseHeader,status) ;
Service_SendError(scConnectionId,requestId,requestHeader,status) ;
}
SOPC_Encodeable_Delete(&OpcUa_RequestHeader_EncodeableType,(void **)&requestHeader);
......@@ -463,7 +417,7 @@ MYDLL void Service_Browse(
if (status == STATUS_OK) {
Service_SendResponse(scConnectionId,requestId,&OpcUa_BrowseResponse_EncodeableType,&responseHeader,(void*)&response) ;
} else {
Service_SendError(scConnectionId,requestId,&responseHeader,status) ;
Service_SendError(scConnectionId,requestId,requestHeader,status) ;
}
SOPC_Encodeable_Delete(&OpcUa_RequestHeader_EncodeableType,(void **)&requestHeader);
......@@ -492,7 +446,7 @@ MYDLL void Service_RegisterNodes(
if (status == STATUS_OK) {
Service_SendResponse(scConnectionId,requestId,&OpcUa_RegisterNodesResponse_EncodeableType,&responseHeader,(void*)&response) ;
} else {
Service_SendError(scConnectionId,requestId,&responseHeader,status) ;
Service_SendError(scConnectionId,requestId,requestHeader,status) ;
}
SOPC_Encodeable_Delete(&OpcUa_RequestHeader_EncodeableType,(void **)&requestHeader);
......@@ -521,7 +475,7 @@ MYDLL void Service_TranslateBrowsePathsToNodeIds(
if (status == STATUS_OK) {
Service_SendResponse(scConnectionId,requestId,&OpcUa_TranslateBrowsePathsToNodeIdsResponse_EncodeableType,&responseHeader,(void*)&response) ;
} else {
Service_SendError(scConnectionId,requestId,&responseHeader,status) ;
Service_SendError(scConnectionId,requestId,requestHeader,status) ;
}
SOPC_Encodeable_Delete(&OpcUa_RequestHeader_EncodeableType,(void **)&requestHeader);
......@@ -550,7 +504,7 @@ MYDLL void Service_UnregisterNodes(
if (status == STATUS_OK) {
Service_SendResponse(scConnectionId,requestId,&OpcUa_UnregisterNodesResponse_EncodeableType,&responseHeader,(void*)&response) ;
} else {
Service_SendError(scConnectionId,requestId,&responseHeader,status) ;
Service_SendError(scConnectionId,requestId,requestHeader,status) ;
}
SOPC_Encodeable_Delete(&OpcUa_RequestHeader_EncodeableType,(void **)&requestHeader);
......@@ -579,7 +533,7 @@ MYDLL void Service_CreateMonitoredItems(
if (status == STATUS_OK) {
Service_SendResponse(scConnectionId,requestId,&OpcUa_CreateMonitoredItemsResponse_EncodeableType,&responseHeader,(void*)&response) ;
} else {
Service_SendError(scConnectionId,requestId,&responseHeader,status) ;
Service_SendError(scConnectionId,requestId,requestHeader,status) ;
}
SOPC_Encodeable_Delete(&OpcUa_RequestHeader_EncodeableType,(void **)&requestHeader);
......@@ -608,7 +562,7 @@ MYDLL void Service_DeleteMonitoredItems(
if (status == STATUS_OK) {
Service_SendResponse(scConnectionId,requestId,&OpcUa_DeleteMonitoredItemsResponse_EncodeableType,&responseHeader,(void*)&response) ;
} else {
Service_SendError(scConnectionId,requestId,&responseHeader,status) ;
Service_SendError(scConnectionId,requestId,requestHeader,status) ;
}
SOPC_Encodeable_Delete(&OpcUa_RequestHeader_EncodeableType,(void **)&requestHeader);
......@@ -637,7 +591,7 @@ MYDLL void Service_ModifyMonitoredItems(
if (status == STATUS_OK) {
Service_SendResponse(scConnectionId,requestId,&OpcUa_ModifyMonitoredItemsResponse_EncodeableType,&responseHeader,(void*)&response) ;
} else {
Service_SendError(scConnectionId,requestId,&responseHeader,status) ;
Service_SendError(scConnectionId,requestId,requestHeader,status) ;
}
SOPC_Encodeable_Delete(&OpcUa_RequestHeader_EncodeableType,(void **)&requestHeader);
......@@ -666,7 +620,7 @@ MYDLL void Service_SetMonitoringMode(
if (status == STATUS_OK) {
Service_SendResponse(scConnectionId,requestId,&OpcUa_SetMonitoringModeResponse_EncodeableType,&responseHeader,(void*)&response) ;
} else {
Service_SendError(scConnectionId,requestId,&responseHeader,status) ;
Service_SendError(scConnectionId,requestId,requestHeader,status) ;
}
SOPC_Encodeable_Delete(&OpcUa_RequestHeader_EncodeableType,(void **)&requestHeader);
......@@ -695,7 +649,7 @@ MYDLL void Service_CreateSubscription(
if (status == STATUS_OK) {
Service_SendResponse(scConnectionId,requestId,&OpcUa_CreateSubscriptionResponse_EncodeableType,&responseHeader,(void*)&response) ;
} else {
Service_SendError(scConnectionId,requestId,&responseHeader,status) ;
Service_SendError(scConnectionId,requestId,requestHeader,status) ;
}
SOPC_Encodeable_Delete(&OpcUa_RequestHeader_EncodeableType,(void **)&requestHeader);
......@@ -724,7 +678,7 @@ MYDLL void Service_DeleteSubscriptions(
if (status == STATUS_OK) {
Service_SendResponse(scConnectionId,requestId,&OpcUa_DeleteSubscriptionsResponse_EncodeableType,&responseHeader,(void*)&response) ;
} else {
Service_SendError(scConnectionId,requestId,&responseHeader,status) ;
Service_SendError(scConnectionId,requestId,requestHeader,status) ;
}
SOPC_Encodeable_Delete(&OpcUa_RequestHeader_EncodeableType,(void **)&requestHeader);
......@@ -753,7 +707,7 @@ MYDLL void Service_ModifySubscription(
if (status == STATUS_OK) {
Service_SendResponse(scConnectionId,requestId,&OpcUa_ModifySubscriptionResponse_EncodeableType,&responseHeader,(void*)&response) ;
} else {
Service_SendError(scConnectionId,requestId,&responseHeader,status) ;
Service_SendError(scConnectionId,requestId,requestHeader,status) ;
}
SOPC_Encodeable_Delete(&OpcUa_RequestHeader_EncodeableType,(void **)&requestHeader);
......@@ -782,7 +736,7 @@ MYDLL void Service_Republish(
if (status == STATUS_OK) {
Service_SendResponse(scConnectionId,requestId,&OpcUa_RepublishResponse_EncodeableType,&responseHeader,(void*)&response) ;
} else {
Service_SendError(scConnectionId,requestId,&responseHeader,status) ;
Service_SendError(scConnectionId,requestId,requestHeader,status) ;
}
SOPC_Encodeable_Delete(&OpcUa_RequestHeader_EncodeableType,(void **)&requestHeader);
......@@ -811,7 +765,7 @@ MYDLL void Service_SetPublishingMode(
if (status == STATUS_OK) {
Service_SendResponse(scConnectionId,requestId,&OpcUa_SetPublishingModeResponse_EncodeableType,&responseHeader,(void*)&response) ;
} else {
Service_SendError(scConnectionId,requestId,&responseHeader,status) ;
Service_SendError(scConnectionId,requestId,requestHeader,status) ;
}
SOPC_Encodeable_Delete(&OpcUa_RequestHeader_EncodeableType,(void **)&requestHeader);
......@@ -840,7 +794,7 @@ MYDLL void Service_TransferSubscriptions(
if (status == STATUS_OK) {
Service_SendResponse(scConnectionId,requestId,&OpcUa_TransferSubscriptionsResponse_EncodeableType,&responseHeader,(void*)&response) ;
} else {
Service_SendError(scConnectionId,requestId,&responseHeader,status) ;
Service_SendError(scConnectionId,requestId,requestHeader,status) ;
}
SOPC_Encodeable_Delete(&OpcUa_RequestHeader_EncodeableType,(void **)&requestHeader);
......@@ -872,11 +826,11 @@ MYDLL void Service_Publish(
if (status == STATUS_OK) {
Service_SendResponse(scConnectionId,requestId,&OpcUa_PublishResponse_EncodeableType,&responseHeader,(void*)&response) ;
} else {
Service_SendError(scConnectionId,requestId,&responseHeader,status) ;
Service_SendError(scConnectionId,requestId,requestHeader,status) ;
}
} else {
if (status != STATUS_OK) {
Service_SendError(scConnectionId,requestId,&responseHeader,status) ;
Service_SendError(scConnectionId,requestId,requestHeader,status) ;
}
}
......
......@@ -34,13 +34,15 @@ namespace opcua {
MYDLL void Service_SendError(
uint32_t scConnectionId,
uint32_t requestId,
OpcUa_ResponseHeader * responseHeader,
uint32_t requestHandle,
SOPC_StatusCode status) ;
MYDLL void Service_SendError(
uint32_t scConnectionId,
uint32_t requestId,
OpcUa_RequestHeader * requestHeader,
SOPC_StatusCode status) ;
MYDLL void Service_SendServiceFault(
uint32_t scConnectionId,
uint32_t requestId,
SOPC_StatusCode status) ;
#if (WITH_DISCOVERY == 1)
MYDLL void Service_FindServers(
......
......@@ -317,7 +317,7 @@ void SOPC_Services_EnqueueEvent(SOPC_Services_Event scEvent, uint32_t id, void*
#endif
default:
odebug_i(S2OPC_ERR,"Services_EnqueueEvent","Service not implemented: %d",encType->TypeId) ;
opcua::Service_SendServiceFault(id,requestId,_Bad_ServiceUnsupported) ;
opcua::Service_SendError(id,requestId,requestHeader,_Bad_ServiceUnsupported) ;
break ;
}
} else {
......
......@@ -65,13 +65,9 @@ namespace opcua {
MYDLL void Service_SendError(
uint32_t scConnectionId,
uint32_t requestId,
OpcUa_ResponseHeader * responseHeader,
uint32_t requestHandle,
SOPC_StatusCode status) ;
MYDLL void Service_SendServiceFault(
uint32_t scConnectionId,
uint32_t requestId,
SOPC_StatusCode status) ;
}
namespace opcua {
......@@ -828,8 +824,9 @@ private:
PublishingReq * publishingReq = publishingReqQueue->pop() ;
/* send the response */
uint32_t requestId = publishingReq->getRequestId() ;
uint32_t requestHandle = publishingReq->getRequestHeader()->getRequestHandle()->get() ;
Service_SendServiceFault(secureChannelIdNum,requestId,_Bad_NoSubscription) ;
Service_SendError(secureChannelIdNum,requestId,requestHandle,_Bad_NoSubscription) ;
delete publishingReq ;
}
......
......@@ -30,9 +30,9 @@ namespace opcua {
MYDLL SOPC_StatusCode OpcUa_ServerApi_FindServers(
OpcUa_RequestHeader * pRequestHeader,
OpcUa_FindServersRequest * pRequest,
OpcUa_FindServersRequest * pRequest,
OpcUa_ResponseHeader * pResponseHeader,
OpcUa_FindServersResponse * pResponse)
OpcUa_FindServersResponse * pResponse)
{
SOPC_StatusCode status = STATUS_OK ;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment