Commit 6cae0630 authored by Patrick Bellot's avatar Patrick Bellot
Browse files

EDP

parent 8c6b01b2
......@@ -21,6 +21,8 @@
#include "lib/OpcUa.h"
#include "lib/Utils/OpcUa_SyncQueue.h"
#include "lib/s2opc/S2OPC_ClientServices.h"
#include "OpcUa_BaseMethod.h"
namespace opcua {
......
......@@ -125,15 +125,13 @@ public:
responsesQueue->push(response) ;
}
protected: // ERROR CASE
SOPC_StatusCode Invoke_Error(
const char * type,
void * response,
SOPC_EncodeableType * responseType)
{
return STATUS_OK ;
//protected: // ERROR CASE
//
// SOPC_StatusCode Invoke_Error(
// const char * type,
// void * response,
// SOPC_EncodeableType * responseType)
// {
// if (responseType->TypeId == OpcUaId_ServiceFault) { /* check for fault */
// SOPC_StatusCode status = ((OpcUa_ServiceFault *)response)->ResponseHeader.ServiceResult ;
// debug_si((uint32_t)IPCS_ERR,
......@@ -151,7 +149,7 @@ protected: // ERROR CASE
// "%s: Bad response type = %d",
// responseType->TypeId) ;
// return _Bad_InternalError ;
}
// }
} ; /* class BaseError */
} /* namespace opcua */
......
......@@ -66,7 +66,7 @@ protected:
debug_ii(IPCS_DBG,"BaseMethod","Connexion_Call: sending request with scId=%d ad requestId=%d...",channel_config_idx,num) ;
Service_SendRequest(
ClientService_SendRequest(
channel_config_idx,
num,
&OpcUa_CallRequest_EncodeableType,
......
......@@ -68,7 +68,7 @@ protected:
debug_ii(IPCS_DBG,"BaseMonitoredItem","Connexion_CreateMonitoredItems: sending request with scId=%d ad requestId=%d...",channel_config_idx,num) ;
Service_SendRequest(
ClientService_SendRequest(
channel_config_idx,
num,
&OpcUa_CreateMonitoredItemsRequest_EncodeableType,
......@@ -144,7 +144,7 @@ protected:
debug_ii(IPCS_DBG,"BaseMonitoredItem","Connexion_DeleteMonitoredItems: sending request with scId=%d ad requestId=%d...",channel_config_idx,num) ;
Service_SendRequest(
ClientService_SendRequest(
channel_config_idx,
num,
&OpcUa_DeleteMonitoredItemsRequest_EncodeableType,
......@@ -220,7 +220,7 @@ protected:
debug_ii(IPCS_DBG,"BaseMonitoredItem","Connexion_ModifyMonitoredItems: sending request with scId=%d ad requestId=%d...",channel_config_idx,num) ;
Service_SendRequest(
ClientService_SendRequest(
channel_config_idx,
num,
&OpcUa_ModifyMonitoredItemsRequest_EncodeableType,
......@@ -296,7 +296,7 @@ protected:
debug_ii(IPCS_DBG,"BaseMonitoredItem","Connexion_SetMonitoringMode: sending request with scId=%d ad requestId=%d...",channel_config_idx,num) ;
Service_SendRequest(
ClientService_SendRequest(
channel_config_idx,
num,
&OpcUa_SetMonitoringModeRequest_EncodeableType,
......
......@@ -68,7 +68,7 @@ protected:
debug_ii(IPCS_DBG,"BaseNodeManagement","Connexion_AddNodes: sending request with scId=%d ad requestId=%d...",channel_config_idx,num) ;
Service_SendRequest(
ClientService_SendRequest(
channel_config_idx,
num,
&OpcUa_AddNodesRequest_EncodeableType,
......@@ -144,7 +144,7 @@ protected:
debug_ii(IPCS_DBG,"BaseNodeManagement","Connexion_AddReferences: sending request with scId=%d ad requestId=%d...",channel_config_idx,num) ;
Service_SendRequest(
ClientService_SendRequest(
channel_config_idx,
num,
&OpcUa_AddReferencesRequest_EncodeableType,
......
......@@ -68,7 +68,7 @@ protected:
debug_ii(IPCS_DBG,"BaseSession","Connexion_Read: sending request with scId=%d ad requestId=%d...",channel_config_idx,num) ;
Service_SendRequest(
ClientService_SendRequest(
channel_config_idx,
num,
&OpcUa_ReadRequest_EncodeableType,
......@@ -148,7 +148,7 @@ protected:
debug_ii(IPCS_DBG,"BaseSession","Connexion_Write: sending request with scId=%d ad requestId=%d...",channel_config_idx,num) ;
Service_SendRequest(
ClientService_SendRequest(
channel_config_idx,
num,
&OpcUa_WriteRequest_EncodeableType,
......
......@@ -21,7 +21,6 @@
#include "lib/OpcUa.h"
#include "OpcUa_BaseSubscription.h"
#include "s2opc_server/S2OPC_Services.h"
namespace opcua {
......@@ -65,7 +64,7 @@ protected: // INTERNAL CREATE SESSION
debug_ii(IPCS_DBG,"BaseSession","Connexion_CreateSession: sending request with scId=%d ad requestId=%d...",channel_config_idx,num) ;
Service_SendRequest(
ClientService_SendRequest(
channel_config_idx,
num,
&OpcUa_CreateSessionRequest_EncodeableType,
......@@ -141,7 +140,7 @@ protected: // INTERNAL ACTIVATE SESSION
debug_ii(IPCS_DBG,"BaseSession","Connexion_ActivateSession: sending request with scId=%d ad requestId=%d...",channel_config_idx,num) ;
Service_SendRequest(
ClientService_SendRequest(
channel_config_idx,
num,
&OpcUa_ActivateSessionRequest_EncodeableType,
......@@ -219,7 +218,7 @@ protected: // INTERNAL ACTIVATE SESSION
debug_ii(IPCS_DBG,"BaseSession","Connexion_CloseSession: sending request with scId=%d ad requestId=%d...",channel_config_idx,num) ;
Service_SendRequest(
ClientService_SendRequest(
channel_config_idx,
num,
&OpcUa_CloseSessionRequest_EncodeableType,
......
......@@ -21,7 +21,6 @@
#include "lib/OpcUa.h"
#include "OpcUa_BaseView.h"
#include "s2opc_server/S2OPC_Services.h"
namespace opcua {
......@@ -69,7 +68,7 @@ protected:
debug_ii(IPCS_DBG,"BaseSubscription","Connexion_CreateSubscription: sending request with scId=%d ad requestId=%d...",channel_config_idx,num) ;
Service_SendRequest(
ClientService_SendRequest(
channel_config_idx,
num,
&OpcUa_CreateSubscriptionRequest_EncodeableType,
......@@ -145,7 +144,7 @@ protected:
debug_ii(IPCS_DBG,"BaseSubscription","Connexion_DeleteSubscriptions: sending request with scId=%d ad requestId=%d...",channel_config_idx,num) ;
Service_SendRequest(
ClientService_SendRequest(
channel_config_idx,
num,
&OpcUa_DeleteSubscriptionsRequest_EncodeableType,
......@@ -221,7 +220,7 @@ protected:
debug_ii(IPCS_DBG,"BaseSubscription","Connexion_ModifySubscription: sending request with scId=%d ad requestId=%d...",channel_config_idx,num) ;
Service_SendRequest(
ClientService_SendRequest(
channel_config_idx,
num,
&OpcUa_ModifySubscriptionRequest_EncodeableType,
......@@ -297,7 +296,7 @@ protected:
debug_ii(IPCS_DBG,"BaseSubscription","Connexion_Publish: sending request with scId=%d ad requestId=%d...",channel_config_idx,num) ;
Service_SendRequest(
ClientService_SendRequest(
channel_config_idx,
num,
&OpcUa_PublishRequest_EncodeableType,
......@@ -373,7 +372,7 @@ protected:
debug_ii(IPCS_DBG,"BaseSubscription","Connexion_Republish: sending request with scId=%d ad requestId=%d...",channel_config_idx,num) ;
Service_SendRequest(
ClientService_SendRequest(
channel_config_idx,
num,
&OpcUa_RepublishRequest_EncodeableType,
......@@ -449,7 +448,7 @@ protected:
debug_ii(IPCS_DBG,"BaseSubscription","Connexion_SetPublishingMode: sending request with scId=%d ad requestId=%d...",channel_config_idx,num) ;
Service_SendRequest(
ClientService_SendRequest(
channel_config_idx,
num,
&OpcUa_SetPublishingModeRequest_EncodeableType,
......@@ -525,7 +524,7 @@ protected:
debug_ii(IPCS_DBG,"BaseSubscription","Connexion_TransferSubscriptions: sending request with scId=%d ad requestId=%d...",channel_config_idx,num) ;
Service_SendRequest(
ClientService_SendRequest(
channel_config_idx,
num,
&OpcUa_TransferSubscriptionsRequest_EncodeableType,
......
......@@ -21,7 +21,7 @@
#include "lib/OpcUa.h"
#include "OpcUa_BaseError.h"
#include "s2opc_server/S2OPC_Services.h"
#include "lib/s2opc/S2OPC_ClientServices.h"
namespace opcua {
......@@ -67,7 +67,7 @@ protected: // INTERNAL BROWSE
debug_ii(IPCS_DBG,"BaseView","Connexion_Browse: sending request with scId=%d ad requestId=%d...",channel_config_idx,num) ;
Service_SendRequest(
ClientService_SendRequest(
channel_config_idx,
num,
&OpcUa_BrowseRequest_EncodeableType,
......@@ -150,7 +150,7 @@ protected: // INTERNAL REGISTERNODES
debug_ii(IPCS_DBG,"BaseView","Connexion_RegisterNodes: sending request with scId=%d ad requestId=%d...",channel_config_idx,num) ;
Service_SendRequest(
ClientService_SendRequest(
channel_config_idx,
num,
&OpcUa_RegisterNodesRequest_EncodeableType,
......@@ -226,7 +226,7 @@ protected:
debug_ii(IPCS_DBG,"BaseView","Connexion_UnregisterNodes: sending request with scId=%d ad requestId=%d...",channel_config_idx,num) ;
Service_SendRequest(
ClientService_SendRequest(
channel_config_idx,
num,
&OpcUa_UnregisterNodesRequest_EncodeableType,
......@@ -307,7 +307,7 @@ protected:
debug_ii(IPCS_DBG,"BaseView","Connexion_TranslateBrowsePathsToNodeIds: sending request with scId=%d ad requestId=%d...",channel_config_idx,num) ;
Service_SendRequest(
ClientService_SendRequest(
channel_config_idx,
num,
&OpcUa_TranslateBrowsePathsToNodeIdsRequest_EncodeableType,
......
......@@ -40,10 +40,8 @@ extern "C" {
void ComEvent_FctClient(SOPC_App_Com_Event event, uint32_t idOrStatus, void* param, uintptr_t appContext) ;
opcua::BaseClient ** the_clients = NULL ;
int the_nbClients = 0 ;
int endpointOpened = 0 ; // 0=false, Managed in s2opc_server/S2OPC_StubServices.cpp
extern int endpointOpened ; ; // 0=false, Managed in s2opc_server/S2OPC_StubServices.cpp
extern bool isServer ;
} // extern "C"
......@@ -81,6 +79,8 @@ namespace opcua {
int main(int argc, char *argv[], char *envp[])
{
isServer = false ;
NOT_USED(envp) ;
SOPC_StatusCode status = STATUS_OK ;
......
/*
* Copyright (C) 2018 Systerel and others.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "S2OPC_Services.h"
#include "S2OPC_StubServices.h"
#include "lib/OpcUa.h"
#include "lib/Services/All.h"
#include "lib/Stacks/OpcUa_ChannelsTable.h"
#include "../OpcUa_BaseClient.h"
extern "C" {
extern opcua::BaseClient ** the_clients ;
extern int the_nbClients ;
extern int endpointOpened ; // Managed in s2opc_server/S2OPC_StubServices.cpp
}
extern "C" {
void SOPC_Services_EnqueueEvent(SOPC_Services_Event scEvent, uint32_t id, void* params, uintptr_t auxParam)
{
switch (scEvent)
{
case SC_TO_SE_SC_CONNECTED: // Secure channel open on client side
{
// id = secure channel connection index,
// params = NULL
// (uint32_t)auxParams = secure channel connection configuration index
// CLIENT: A new secure channel is connected:
// - retrieve secure channel index
// - retrieve secure channel configuration
uint32_t secureChannelIdx = (uint32_t) auxParam;
odebug_i(MAIN_LIFE_DBG,"Services_EnqueueEvent","SC_TO_SE_SC_CONNECTED with secureChannelIdx=%d",id) ;
SOPC_SecureChannel_Config *scConfig = SOPC_ToolkitClient_GetSecureChannelConfig((uint32_t)auxParam);
if (scConfig != NULL) {
// Keep association scIdx => scConfig to could retrieve config later (on message reception)
opcua::ChannelsTable::self->createNewChannel(secureChannelIdx,scConfig,id) ;
endpointOpened = 1 ;
} else {
odebug_i(S2OPC_ERR,"Services_EnqueueEvent","SC_TO_SE_SC_CONNECTED with scConfig=null (error) with secureChannelIdx=%d",id) ;
}
} break;
case SC_TO_SE_SC_CONNECTION_TIMEOUT: // Client cannot connect to Server
{
// id = secure channel connection CONFIG index
odebug_i(MAIN_LIFE_DBG,"Services_EnqueueEvent","SC_TO_SE_SC_CONNECTION_TIMEOUT with secureChannelConfigurationIdx=%d",id) ;
endpointOpened = 0 ;
} break;
case SC_TO_SE_SC_DISCONNECTED:
{
// id = secure channel connection index
// auxParam == secure channel configuration index
// CLIENT / SERVER: secure channel disconnection
odebug_i(MAIN_LIFE_DBG,"Services_EnqueueEvent","SC_TO_SE_SC_DISCONNECTED with secureChannelIdx=%d",id) ;
if (! opcua::ChannelsTable::self->remove(id,true))
odebug_i(S2OPC_ERR,"Services_EnqueueEvent","SC_TO_SE_SC_DISCONNECTED cannot remove channel (error) with secureChannelIdx=%d",id) ;
endpointOpened = 0 ;
} break;
case SC_TO_SE_SC_SERVICE_RCV_MSG:
{
// id = secure channel connection index,
// params = (SOPC_Buffer*) OPC UA message payload buffer,
// auxParam = request Id context (server side only)
// CLIENT / SERVER: message received on secure channel
uint32_t requestId = (uint32_t) auxParam;
if (params != NULL) {
SOPC_Buffer * buffer = (SOPC_Buffer*) params;
SOPC_EncodeableType * encType = NULL;
SOPC_ReturnStatus status = SOPC_MsgBodyType_Read(buffer, &encType);
if (SOPC_STATUS_OK == status) {
OpcUa_ResponseHeader * responseHeader = NULL ;
status = SOPC_DecodeMsg_HeaderOrBody(buffer, &OpcUa_ResponseHeader_EncodeableType, (void **)(&responseHeader));
if (SOPC_STATUS_OK == status) {
void * msgBody = NULL ;
status = SOPC_DecodeMsg_HeaderOrBody(buffer, encType, &msgBody);
if (SOPC_STATUS_OK == status) {
odebug_ii(S2OPC_DBG,"Services_EnqueueEvent","SC_TO_SE_SC_SERVICE_RCV_MSG with secureChannelIdx=%d, encType=%d",id,encType->TypeId) ;
switch (encType->TypeId) {
//#if (WITH_DISCOVERY == 1)
// case OpcUaId_FindServersResponse:
// opcua::Service_FindServers(id,requestId,responseHeader, (OpcUa_FindServersResponse *)msgBody) ;
// break ;
//#endif
#if 0
case OpcUaId_FindServersOnNetworkResponse:
break ;
#endif
//#if (WITH_DISCOVERY == 1)
// case OpcUaId_GetEndpointsResponse:
// opcua::Service_GetEndpoints(id,requestId,responseHeader, (OpcUa_GetEndpointsResponse *)msgBody) ;
// break ;
//#endif
#if 0
case OpcUaId_RegisterServerResponse:
break ;
#endif
#if 0
case OpcUaId_RegisterServer2Response:
break ;
#endif
case OpcUaId_CreateSessionResponse:
opcua::Service_CreateSession(id,requestId,responseHeader,(OpcUa_CreateSessionResponse *)msgBody) ;
break ;
case OpcUaId_ActivateSessionResponse:
opcua::Service_ActivateSession(id,requestId,responseHeader,(OpcUa_ActivateSessionResponse *)msgBody) ;
break ;
case OpcUaId_CloseSessionResponse:
opcua::Service_CloseSession(id,requestId,responseHeader,(OpcUa_CloseSessionResponse *)msgBody) ;
break ;
#if 0
case OpcUaId_CancelResponse:
break ;
#endif
#if (WITH_NODEMNGT == 1)
case OpcUaId_AddNodesResponse:
opcua::Service_AddNodes(id,requestId,responseHeader, (OpcUa_AddNodesResponse *)msgBody) ;
break ;
#endif
#if (WITH_NODEMNGT == 1)
case OpcUaId_AddReferencesResponse:
opcua::Service_AddReferences(id,requestId,responseHeader, (OpcUa_AddReferencesResponse *)msgBody) ;
break ;
#endif
#if 0
case OpcUaId_DeleteNodesResponse:
break ;
#endif
#if 0
case OpcUaId_DeleteReferencesResponse:
break ;
#endif
#if (WITH_BROWSE == 1)
case OpcUaId_BrowseResponse:
opcua::Service_Browse(id,requestId,responseHeader, (OpcUa_BrowseResponse *)msgBody) ;
break ;
#endif
#if 0
case OpcUaId_BrowseNextResponse:
break ;
#endif
#if (WITH_TRANSLATE_BROWSEPATHS_TO_NODEIDS == 1)
case OpcUaId_TranslateBrowsePathsToNodeIdsResponse:
opcua::Service_TranslateBrowsePathsToNodeIds(id,requestId,responseHeader, (OpcUa_TranslateBrowsePathsToNodeIdsResponse *)msgBody) ;
break ;
#endif
#if (WITH_REGISTER_UNREGISTER_NODES == 1)
case OpcUaId_RegisterNodesResponse:
opcua::Service_RegisterNodes(id,requestId,responseHeader, (OpcUa_RegisterNodesResponse *)msgBody) ;
break ;
#endif
#if (WITH_REGISTER_UNREGISTER_NODES == 1)
case OpcUaId_UnregisterNodesResponse:
opcua::Service_UnregisterNodes(id,requestId,responseHeader, (OpcUa_UnregisterNodesResponse *)msgBody) ;
break ;
#endif
#if 0
case OpcUaId_QueryFirstResponse:
break ;
#endif
#if 0
case OpcUaId_QueryNextResponse:
break ;
#endif
#if (WITH_READ == 1)
case OpcUaId_ReadResponse:
opcua::Service_Read(id,requestId,responseHeader, (OpcUa_ReadResponse *)msgBody) ;
break ;
#endif
#if 0
case OpcUaId_HistoryReadResponse:
break ;
#endif
#if (WITH_WRITE == 1)
case OpcUaId_WriteResponse:
opcua::Service_Write(id,requestId,responseHeader, (OpcUa_WriteResponse *)msgBody) ;
break ;
#endif
#if 0
case OpcUaId_HistoryUpdateResponse:
break ;
#endif
#if (WITH_CALL == 1)
case OpcUaId_CallResponse:
opcua::Service_Call(id,requestId,responseHeader, (OpcUa_CallResponse *)msgBody) ;
break ;
#endif
#if (WITH_SUBSCRIPTION == 1)
case OpcUaId_CreateMonitoredItemsResponse:
opcua::Service_CreateMonitoredItems(id,requestId,responseHeader, (OpcUa_CreateMonitoredItemsResponse *)msgBody) ;
break ;
#endif
#if (WITH_SUBSCRIPTION == 1)
case OpcUaId_ModifyMonitoredItemsResponse:
opcua::Service_ModifyMonitoredItems(id,requestId,responseHeader, (OpcUa_ModifyMonitoredItemsResponse *)msgBody) ;
break ;
#endif
#if (WITH_SUBSCRIPTION == 1)
case OpcUaId_SetMonitoringModeResponse:
opcua::Service_SetMonitoringMode(id,requestId,responseHeader, (OpcUa_SetMonitoringModeResponse *)msgBody) ;
break ;
#endif
#if 0
case OpcUaId_SetTriggeringResponse:
break ;
#endif
#if (WITH_SUBSCRIPTION == 1)
case OpcUaId_DeleteMonitoredItemsResponse:
opcua::Service_DeleteMonitoredItems(id,requestId,responseHeader, (OpcUa_DeleteMonitoredItemsResponse *)msgBody) ;
break ;
#endif
#if (WITH_SUBSCRIPTION == 1)
case OpcUaId_CreateSubscriptionResponse:
opcua::Service_CreateSubscription(id,requestId,responseHeader, (OpcUa_CreateSubscriptionResponse *)msgBody) ;
break ;
#endif
#if (WITH_SUBSCRIPTION == 1)
case OpcUaId_ModifySubscriptionResponse:
opcua::Service_ModifySubscription(id,requestId,responseHeader, (OpcUa_ModifySubscriptionResponse *)msgBody) ;
break ;
#endif
#if (WITH_SUBSCRIPTION == 1)
case OpcUaId_SetPublishingModeResponse:
opcua::Service_SetPublishingMode(id,requestId,responseHeader, (OpcUa_SetPublishingModeResponse *)msgBody) ;
break ;
#endif
#if (WITH_SUBSCRIPTION == 1)
case OpcUaId_PublishResponse:
opcua::Service_Publish(id,requestId,responseHeader, (OpcUa_PublishResponse *)msgBody) ;
break ;
#endif
#if (WITH_SUBSCRIPTION == 1)
case OpcUaId_RepublishResponse:
opcua::Service_Republish(id,requestId,responseHeader, (OpcUa_RepublishResponse *)msgBody) ;
break ;
#endif
#if (WITH_SUBSCRIPTION == 1)
case OpcUaId_TransferSubscriptionsResponse:
opcua::Service_TransferSubscriptions(id,requestId,responseHeader, (OpcUa_TransferSubscriptionsResponse *)msgBody) ;
break ;
#endif
#if (WITH_SUBSCRIPTION == 1)
case OpcUaId_DeleteSubscriptionsResponse:
opcua::Service_DeleteSubscriptions(id,requestId,responseHeader, (OpcUa_DeleteSubscriptionsResponse *)msgBody) ;
break ;
#endif
default:
odebug_i(S2OPC_ERR,"Services_EnqueueEvent","Not an answer message: %d",encType->TypeId) ;
break ;
}
} else {
odebug_is(S2OPC_ERR,"Services_EnqueueEvent","Cannot decode msg body in response %d (%s)",encType->TypeId,encType->TypeName) ;
if (encType->TypeId == OpcUaId_ServiceFault) {
opcua::Service_ServiceFault(id,requestId,responseHeader,(OpcUa_ServiceFault *)NULL) ;
} else {
odebug(S2OPC_ERR,"","Aborting...")
}
}
} else {
odebug_is(S2OPC_ERR,"Services_EnqueueEvent","Cannot decode header in response %d (%s)",encType->TypeId,encType->TypeName) ;
}
} else {
odebug_ii(S2OPC_ERR,"Services_EnqueueEvent","Cannot read encType in message on channel %d with requestId %d",id,requestId) ;
}
SOPC_Buffer_Delete(buffer);
}
} break;
case SC_TO_SE_SND_FAILURE:
{
odebug_iii(S2OPC_DBG,"Services_EnqueueEvent","SC_TO_SE_SND_FAILURE scid=%d, requestid=%d with statusCode=0x%08x",id,*(int *)params,(uint32_t)auxParam) ;
} break ;
default:
odebug_ii(S2OPC_DBG,"Services_EnqueueEvent","Receiving unknown message with scEvent=%d and id=%d",scEvent,id) ;
}
}
} // extern "C"
extern "C" {
void SOPC_Services_Initialize() {}
void SOPC_Services_ToolkitConfigured() {}
void SOPC_Services_PreClear() {}
void SOPC_Services_Clear() {}
} // extern "C"
/*
* Copyright (C) 2018 Systerel and others.
*