Commit 0ee7fe44 authored by Patrick Bellot's avatar Patrick Bellot
Browse files

EDP

parent 7d04ddac
......@@ -46,121 +46,66 @@ protected:
ReadResponse ** pRResponse
)
{
return STATUS_OK ;
// uint32_t loopCpt = 0 ;
//
// CallbackData_Invoke callbackData_Invoke ;
// callbackData_Invoke.baseClient = (void *)this ;
// callbackData_Invoke.pData = (void *)pRResponse ;
// callbackData_Invoke.event = 0 ;
//
// debug(MAIN_LIFE_DBG,"BaseQuery","Invoke_Read begin") ;
//
// StubClient_CallbackData callbackData ;
// callbackData.stub = &callbackData_Invoke ;
//
// SOPC_StatusCode status = STATUS_OK ;
//
// OpcUa_ReadRequest request ;
//
// rrequest->fromCpptoC(&status,request) ;
//
// if(status != STATUS_OK) {
// debug_i(COM_ERR,"BaseQuery","Invoke_Read failed (case 1): status=0x%08x",status) ;
// goto out ;
// }
//
// status = OpcUa_ClientApi_BeginRead(
// hChannel,
// &(request.RequestHeader),
// request.MaxAge,
// request.TimestampsToReturn,
// request.NoOfNodesToRead,
// request.NodesToRead,
// (SOPC_Channel_PfnRequestComplete*) &BaseQuery::_Invoke_Read_Callback,
// &callbackData);
//
// if(status != STATUS_OK) {
// debug_i(COM_ERR,"BaseQuery","Invoke_Read failed (case 2): status=0x%08x",status) ;
// goto out ;
// }
//
// while (status == STATUS_OK && callbackData_Invoke.event == 0 && loopCpt*sleepTimeout <= loopTimeout) {
// debug(COM_ERR,"BaseQuery","Invoke_Read loop") ;
// status = SOPC_TreatReceivedMessages(sleepTimeout) ;
// loopCpt++ ;
// }
//
// if (status != STATUS_OK) {
// debug_i(COM_ERR,"BaseQuery","Invoke_Read failed (case 3): status=0x%08x",status) ;
// if (*pRResponse != NULL) {
// (*pRResponse)->checkRefCount() ;
// *pRResponse = NULL ;
// }
// goto out ;
// }
//
// if (*pRResponse == NULL) {
// debug(COM_ERR,"BaseQuery","Invoke_Read failed (case 4)") ;
// status = _Bad_InternalError ;
// }
//
// out:
// OpcUa_ReadRequest_Clear(&request) ;
// return status ;
}
debug(MAIN_LIFE_DBG,"BaseSession","Connexion_Read begin") ;
SOPC_StatusCode status = STATUS_OK ;
OpcUa_RequestHeader requestHeader ;
OpcUa_RequestHeader_Initialize(&requestHeader);
OpcUa_ReadRequest request ;
OpcUa_ReadRequest_Initialize(&request);
rrequest->fromCpptoC(&status,requestHeader,request) ;
int loopCpt = 0;
BaseDataType * obj = NULL ;
if(status != STATUS_OK) {
debug_i(COM_ERR,"BaseSession","Connexion_Read failed (case 1): status=0x%08x",status) ;
goto out ;
}
debug_ii(IPCS_DBG,"BaseSession","Connexion_Read: sending request with scId=%d ad requestId=%d...",channel_config_idx,num) ;
//protected:
//
// static SOPC_StatusCode _Invoke_Read_Callback(
// SOPC_Channel channel,
// void * response,
// SOPC_EncodeableType * responseType,
// void * callbackData,
// SOPC_StatusCode status)
// {
// return STATUS_OK ;
//
// NOT_USED(channel) ;
// NOT_USED(status) ;
//
// StubClient_CallbackData * ptrToStub = (StubClient_CallbackData *)callbackData ;
// CallbackData_Invoke * pCallbackData = (CallbackData_Invoke *)(ptrToStub->stub) ;
// BaseQuery * baseClient = (BaseQuery *)(pCallbackData->baseClient) ;
// ReadResponse ** pResponse = (ReadResponse **)(pCallbackData->pData) ;
//
// pCallbackData->event = 1 ;
//
// return baseClient->Invoke_Read_Callback(response,responseType,pResponse) ;
// }
//
//private:
//
// SOPC_StatusCode Invoke_Read_Callback(void * response, SOPC_EncodeableType * responseType, ReadResponse ** pResponse)
// {
// SOPC_StatusCode status = STATUS_OK ;
//
// if (OpcUa_ReadResponse_EncodeableType.TypeId == responseType->TypeId) { /* check response type */
//
// *pResponse = ReadResponse::fromCtoCpp(&status, *((const OpcUa_ReadResponse *)response)) ;
//
// if(status != STATUS_OK) {
// debug_i(COM_ERR,"BaseQuery","Invoke_Read_Callback failed in from CtoCpp: status=0x%08x",status) ;
// if (*pResponse != NULL) {
// (*pResponse)->checkRefCount() ;
// *pResponse = NULL ;
// }
// }
//
// OpcUa_ReadResponse_Clear(response);
// } else {
// status = Invoke_Error("Invoke_Read_Callback",response,responseType) ;
// }
//
// free(response) ;
// return status ;
// }
Service_SendRequest(
channel_config_idx,
num,
&OpcUa_ReadRequest_EncodeableType,
&requestHeader,
&request) ;
debug(IPCS_DBG,"BaseSession","Connexion_Read: waiting for answer...") ;
while ((obj = responsesQueue->tryPop()) == NULL && loopCpt * sleepTimeout <= loopTimeout) {
loopCpt++;
SOPC_Sleep(sleepTimeout);
}
debug(IPCS_DBG,"BaseSession","After waiting for answer...") ;
if (obj==NULL || loopCpt * sleepTimeout > loopTimeout) {
debug_i(COM_ERR,"BaseSession","Connexion_Read: service failed with timeout, client=%d",num) ;
status = SOPC_STATUS_TIMEOUT;
goto out ;
}
if (obj->getTypeId() == OpcUaId_ServiceFault) {
ServiceFault * serviceFault = (ServiceFault *)obj ;
status = serviceFault->getResponseHeader()->getServiceResult()->get() ;
delete obj ;
debug_ii(COM_ERR,"BaseSession","Connexion_Read: service failed with rc=0x%08x for client=%d",status,num) ;
goto out ;
}
debug(IPCS_DBG,"BaseSession","Connexion_Read: answer is Read") ;
*pRResponse = (ReadResponse *)obj ;
out:
OpcUa_RequestHeader_Clear(&requestHeader) ;
OpcUa_ReadRequest_Clear(&request) ;
return status ;
}
#endif // WITH_READ== 1
......@@ -173,119 +118,66 @@ protected:
WriteResponse ** pRResponse
)
{
return STATUS_OK ;
// uint32_t loopCpt = 0 ;
//
// CallbackData_Invoke callbackData_Invoke ;
// callbackData_Invoke.baseClient = (void *)this ;
// callbackData_Invoke.pData = (void *)pRResponse ;
// callbackData_Invoke.event = 0 ;
//
// debug(MAIN_LIFE_DBG,"BaseQuery","Invoke_Write begin") ;
//
// StubClient_CallbackData callbackData ;
// callbackData.stub = &callbackData_Invoke ;
//
// SOPC_StatusCode status = STATUS_OK ;
//
// OpcUa_WriteRequest request ;
// OpcUa_WriteRequest_Initialize(&request);
// rrequest->fromCpptoC(&status,request) ;
//
// if(status != STATUS_OK) {
// debug_i(COM_ERR,"BaseQuery","Invoke_Write failed (case 1): status=0x%08x",status) ;
// goto out ;
// }
//
// status = OpcUa_ClientApi_BeginWrite(
// hChannel,
// &(request.RequestHeader),
// request.NoOfNodesToWrite,
// request.NodesToWrite,
// (SOPC_Channel_PfnRequestComplete*) &BaseQuery::_Invoke_Write_Callback,
// &callbackData);
//
// if(status != STATUS_OK) {
// debug_i(COM_ERR,"BaseQuery","Invoke_Write failed (case 2): status=0x%08x",status) ;
// goto out ;
// }
//
// while (status == STATUS_OK && callbackData_Invoke.event == 0 && loopCpt*sleepTimeout <= loopTimeout) {
// debug(COM_ERR,"BaseQuery","Invoke_Write loop") ;
// status = SOPC_TreatReceivedMessages(sleepTimeout) ;
// loopCpt++ ;
// }
//
// if (status != STATUS_OK) {
// debug_i(COM_ERR,"BaseQuery","Invoke_Write failed (case 4): status=0x%08x",status) ;
// if (*pRResponse != NULL) {
// (*pRResponse)->checkRefCount() ;
// *pRResponse = NULL ;
// }
// goto out ;
// }
//
// if (*pRResponse == NULL) {
// debug(COM_ERR,"BaseQuery","Invoke_Write failed (case 3)") ;
// status = _Bad_InternalError ;
// }
//
// out:
// OpcUa_WriteRequest_Clear(&request) ;
// return status ;
}
debug(MAIN_LIFE_DBG,"BaseSession","Connexion_Write begin") ;
SOPC_StatusCode status = STATUS_OK ;
OpcUa_RequestHeader requestHeader ;
OpcUa_RequestHeader_Initialize(&requestHeader);
OpcUa_WriteRequest request ;
OpcUa_WriteRequest_Initialize(&request);
rrequest->fromCpptoC(&status,requestHeader,request) ;
int loopCpt = 0;
BaseDataType * obj = NULL ;
if(status != STATUS_OK) {
debug_i(COM_ERR,"BaseSession","Connexion_Write failed (case 1): status=0x%08x",status) ;
goto out ;
}
debug_ii(IPCS_DBG,"BaseSession","Connexion_Write: sending request with scId=%d ad requestId=%d...",channel_config_idx,num) ;
//protected:
//
// static SOPC_StatusCode _Invoke_Write_Callback(
// SOPC_Channel channel,
// void * response,
// SOPC_EncodeableType * responseType,
// void * callbackData,
// SOPC_StatusCode status)
// {
// return STATUS_OK ;
//
// NOT_USED(channel) ;
// NOT_USED(status) ;
//
// StubClient_CallbackData * ptrToStub = (StubClient_CallbackData *)callbackData ;
// CallbackData_Invoke * pCallbackData = (CallbackData_Invoke *)(ptrToStub->stub) ;
// BaseQuery * baseClient = (BaseQuery *)(pCallbackData->baseClient) ;
// WriteResponse ** pResponse = (WriteResponse **)(pCallbackData->pData) ;
//
// pCallbackData->event = 1 ;
//
// return baseClient->Invoke_Write_Callback(response,responseType,pResponse) ;
// }
//
//private:
//
// SOPC_StatusCode Invoke_Write_Callback(void * response, SOPC_EncodeableType * responseType, WriteResponse ** pResponse)
// {
// SOPC_StatusCode status = STATUS_OK ;
//
// if (OpcUa_WriteResponse_EncodeableType.TypeId == responseType->TypeId) { /* check response type */
//
// *pResponse = WriteResponse::fromCtoCpp(&status, *((const OpcUa_WriteResponse *)response)) ;
//
// if(status != STATUS_OK) {
// debug_i(COM_ERR,"BaseQuery","Invoke_Write_Callback failed in from CtoCpp: status=0x%08x",status) ;
// if (*pResponse != NULL) {
// (*pResponse)->checkRefCount() ;
// *pResponse = NULL ;
// }
// }
//
// OpcUa_WriteResponse_Clear(response);
// } else {
// status = Invoke_Error("Invoke_Write_Callback",response,responseType) ;
// }
//
// free(response) ;
// return status ;
// }
Service_SendRequest(
channel_config_idx,
num,
&OpcUa_WriteRequest_EncodeableType,
&requestHeader,
&request) ;
debug(IPCS_DBG,"BaseSession","Connexion_Write: waiting for answer...") ;
while ((obj = responsesQueue->tryPop()) == NULL && loopCpt * sleepTimeout <= loopTimeout) {
loopCpt++;
SOPC_Sleep(sleepTimeout);
}
debug(IPCS_DBG,"BaseSession","After waiting for answer...") ;
if (obj==NULL || loopCpt * sleepTimeout > loopTimeout) {
debug_i(COM_ERR,"BaseSession","Connexion_Write: service failed with timeout, client=%d",num) ;
status = SOPC_STATUS_TIMEOUT;
goto out ;
}
if (obj->getTypeId() == OpcUaId_ServiceFault) {
ServiceFault * serviceFault = (ServiceFault *)obj ;
status = serviceFault->getResponseHeader()->getServiceResult()->get() ;
delete obj ;
debug_ii(COM_ERR,"BaseSession","Connexion_Write: service failed with rc=0x%08x for client=%d",status,num) ;
goto out ;
}
debug(IPCS_DBG,"BaseSession","Connexion_Write: answer is Write") ;
*pRResponse = (WriteResponse *)obj ;
out:
OpcUa_RequestHeader_Clear(&requestHeader) ;
OpcUa_WriteRequest_Clear(&request) ;
return status ;
}
#endif // WITH_WRITE== 1
......
......@@ -63,7 +63,7 @@ protected: // INTERNAL CREATE SESSION
goto out ;
}
debug(IPCS_DBG,"BaseSession","Connexion_CreateSession: sending request...") ;
debug_ii(IPCS_DBG,"BaseSession","Connexion_CreateSession: sending request with scId=%d ad requestId=%d...",channel_config_idx,num) ;
Service_SendRequest(
channel_config_idx,
......@@ -104,55 +104,147 @@ protected: // INTERNAL CREATE SESSION
return status ;
}
//protected: // INTERNAL ACTIVATE SESSION
//
// SOPC_StatusCode Connexion_ActivateSession()
// {
// SOPC_ToolkitClient_AsyncActivateSession(channel_config_idx,num);
//
// int loopCpt = 0 ;
// while(!sessionActivated && loopCpt*sleepTimeout<=loopTimeout) {
// loopCpt++ ;
// SOPC_Sleep(sleepTimeout) ;
// }
//
// if (loopCpt*sleepTimeout>loopTimeout) {
// debug(COM_ERR,"BaseSession","Connexion_ActivateSession failed (case1: timeout)") ;
// return SOPC_STATUS_TIMEOUT ;
// }
//
// if (!sessionActivated) {
// debug(COM_ERR,"BaseSession","Connexion_ActivateSession failed (case 2)") ;
// return SOPC_STATUS_NOK ;
// }
//
// return STATUS_OK ;
// }
//
//protected: // INTERNAL CLOSE SESSION
//
// SOPC_StatusCode Connexion_CloseSession()
// {
// SOPC_ToolkitClient_AsyncCloseSession(num);
//
// int loopCpt = 0 ;
// while(sessionActivated && loopCpt*sleepTimeout<=loopTimeout) {
// loopCpt++ ;
// SOPC_Sleep(sleepTimeout) ;
// }
//
// if (loopCpt*sleepTimeout>loopTimeout) {
// debug(COM_ERR,"BaseSession","Connexion_CloseSession failed (case1: timeout)") ;
// return SOPC_STATUS_TIMEOUT ;
// }
//
// if (sessionActivated) {
// debug(COM_ERR,"BaseSession","Connexion_CloseSession failed (case 2)") ;
// return SOPC_STATUS_NOK ;
// }
//
// return STATUS_OK ;
// }
protected: // INTERNAL ACTIVATE SESSION
SOPC_StatusCode Connexion_ActivateSession(
ActivateSessionRequest * rrequest,
ActivateSessionResponse ** pRResponse
)
{
debug(MAIN_LIFE_DBG,"BaseSession","Connexion_ActivateSession begin") ;
SOPC_StatusCode status = STATUS_OK ;
OpcUa_RequestHeader requestHeader ;
OpcUa_RequestHeader_Initialize(&requestHeader);
OpcUa_ActivateSessionRequest request ;
OpcUa_ActivateSessionRequest_Initialize(&request);
rrequest->fromCpptoC(&status,requestHeader,request) ;
int loopCpt = 0;
BaseDataType * obj = NULL ;
if(status != STATUS_OK) {
debug_i(COM_ERR,"BaseSession","Connexion_ActivateSession failed (case 1): status=0x%08x",status) ;
goto out ;
}
debug_ii(IPCS_DBG,"BaseSession","Connexion_ActivateSession: sending request with scId=%d ad requestId=%d...",channel_config_idx,num) ;
Service_SendRequest(
channel_config_idx,
num,
&OpcUa_ActivateSessionRequest_EncodeableType,
&requestHeader,
&request) ;
debug(IPCS_DBG,"BaseSession","Connexion_ActivateSession: waiting for answer...") ;
while ((obj = responsesQueue->tryPop()) == NULL && loopCpt * sleepTimeout <= loopTimeout) {
loopCpt++;
SOPC_Sleep(sleepTimeout);
}
debug(IPCS_DBG,"BaseSession","After waiting for answer...") ;
if (obj==NULL || loopCpt * sleepTimeout > loopTimeout) {
debug_i(COM_ERR,"BaseSession","Connexion_ActivateSession: service failed with timeout, client=%d",num) ;
status = SOPC_STATUS_TIMEOUT;
goto out ;
}
if (obj->getTypeId() == OpcUaId_ServiceFault) {
ServiceFault * serviceFault = (ServiceFault *)obj ;
status = serviceFault->getResponseHeader()->getServiceResult()->get() ;
delete obj ;
debug_ii(COM_ERR,"BaseSession","Connexion_ActivateSession: service failed with rc=0x%08x for client=%d",status,num) ;
goto out ;
}
debug(IPCS_DBG,"BaseSession","Connexion_ActivateSession: answer is ActivateSession") ;
*pRResponse = (ActivateSessionResponse *)obj ;
out:
OpcUa_RequestHeader_Clear(&requestHeader) ;
OpcUa_ActivateSessionRequest_Clear(&request) ;
return status ;
}
//protected: // INTERNAL CLOSE SESSION
SOPC_StatusCode Connexion_CloseSession(
CloseSessionRequest * rrequest,
CloseSessionResponse ** pRResponse
)
{
debug(MAIN_LIFE_DBG,"BaseSession","Connexion_CloseSession begin") ;
SOPC_StatusCode status = STATUS_OK ;
OpcUa_RequestHeader requestHeader ;
OpcUa_RequestHeader_Initialize(&requestHeader);
OpcUa_CloseSessionRequest request ;
OpcUa_CloseSessionRequest_Initialize(&request);
rrequest->fromCpptoC(&status,requestHeader,request) ;
int loopCpt = 0;
BaseDataType * obj = NULL ;
if(status != STATUS_OK) {
debug_i(COM_ERR,"BaseSession","Connexion_CloseSession failed (case 1): status=0x%08x",status) ;
goto out ;
}
debug_ii(IPCS_DBG,"BaseSession","Connexion_CloseSession: sending request with scId=%d ad requestId=%d...",channel_config_idx,num) ;
Service_SendRequest(
channel_config_idx,
num,
&OpcUa_CloseSessionRequest_EncodeableType,
&requestHeader,
&request) ;
debug(IPCS_DBG,"BaseSession","Connexion_CloseSession: waiting for answer...") ;
while ((obj = responsesQueue->tryPop()) == NULL && loopCpt * sleepTimeout <= loopTimeout) {
loopCpt++;
SOPC_Sleep(sleepTimeout);
}
debug(IPCS_DBG,"BaseSession","After waiting for answer...") ;
if (obj==NULL || loopCpt * sleepTimeout > loopTimeout) {
debug_i(COM_ERR,"BaseSession","Connexion_CloseSession: service failed with timeout, client=%d",num) ;
status = SOPC_STATUS_TIMEOUT;
goto out ;
}
if (obj->getTypeId() == OpcUaId_ServiceFault) {
ServiceFault * serviceFault = (ServiceFault *)obj ;
status = serviceFault->getResponseHeader()->getServiceResult()->get() ;
delete obj ;
debug_ii(COM_ERR,"BaseSession","Connexion_CloseSession: service failed with rc=0x%08x for client=%d",status,num) ;
goto out ;
}
debug(IPCS_DBG,"BaseSession","Connexion_CloseSession: answer is CloseSession") ;
*pRResponse = (CloseSessionResponse *)obj ;
out:
OpcUa_RequestHeader_Clear(&requestHeader) ;
OpcUa_CloseSessionRequest_Clear(&request) ;
return status ;
}
} ; /* class BaseClient */
} /* namespace opcua */
......
......@@ -239,6 +239,15 @@ namespace opcua {
// }
// Namespace table
SOPC_NamespaceTable nsTable ;
SOPC_Namespace_Initialize(&nsTable) ;
SOPC_ToolkitConfig_SetNamespaceUris(&nsTable) ;
debug(MAIN_LIFE_DBG,"Sample Client","Create parameters") ;
#if (SECURITY == UANONE)
const char * pRequestedSecurityPolicyUri = SOPC_SecurityPolicy_None_URI;
......
......@@ -17,6 +17,8 @@
*/
#include "S2OPC_Services.h"
#include "sopc_types.h"
#include "../OpcUa_BaseClient.h"
extern "C" {
......@@ -74,6 +76,7 @@ MYDLL void Service_SendRequest(
}
// SEND EVENT TO SC LAYER: ASK TO SEND MSG ON SC
odebug_ii(S2OPC_DBG,"Service_SendRequest","EnqueueEvent with scId=%d and requestId=%d",scConnectionId,requestId) ;
SOPC_SecureChannels_EnqueueEvent(SC_SERVICE_SND_MSG,scConnectionId,(void*) buffer,requestId);
if (status != SOPC_STATUS_OK) {
......@@ -95,6 +98,7 @@ MYDLL void Service_SendResponse(
NOT_USED(encodeable) ;
NOT_USED(responseHeader) ;
NOT_USED(response) ;
OCHECK_INT(0) ;
}
......@@ -136,11 +140,162 @@ MYDLL void Service_CreateSession(
return ;
}
debug_ii(IPCS_DBG,"Service_CreateSession","Receiving CreateSessionRespone with scId=%d and requestId=%d",scConnectionId,requestId) ;
the_clients[requestId]->pushResponse(r) ;
OpcUa_ResponseHeader_Clear(responseHeader) ;
OpcUa_CreateSessionResponse_Clear(response) ;