diff --git a/.gitignore b/.gitignore index 567609b1..7b22ecfe 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ build/ +/Debug/ diff --git a/src/iec61850/client/ied_connection.c b/src/iec61850/client/ied_connection.c index d3c6f922..8846fc01 100644 --- a/src/iec61850/client/ied_connection.c +++ b/src/iec61850/client/ied_connection.c @@ -587,7 +587,12 @@ static void IedConnection_setState(IedConnection self, IedConnectionState newState) { Semaphore_wait(self->stateMutex); + + if (self->state != newState) + self->connectionStateChangedHandler(self->connectionStateChangedHandlerParameter, self, newState); + self->state = newState; + Semaphore_post(self->stateMutex); } @@ -599,7 +604,7 @@ IedConnection_installConnectionClosedHandler(IedConnection self, IedConnectionCl self->connectionClosedParameter = parameter; } -//TODO remove - not required - replace by mmsConnectionStateChangedHandler +/* TODO remove - not required - replace by mmsConnectionStateChangedHandler */ static void connectionLostHandler(MmsConnection connection, void* parameter) { @@ -640,6 +645,13 @@ IedConnection_connect(IedConnection self, IedClientError* error, const char* hos *error = IED_ERROR_ALREADY_CONNECTED; } +void +IedConnection_installStateChangedHandler(IedConnection self, IedConnectionStateChangedHandler handler, void* parameter) +{ + self->connectionStateChangedHandler = handler; + self->connectionStateChangedHandlerParameter = parameter; +} + static void mmsConnectionStateChangedHandler(MmsConnection connection, void* parameter, MmsConnectionState newState) { diff --git a/src/iec61850/inc_private/ied_connection_private.h b/src/iec61850/inc_private/ied_connection_private.h index d81783b8..be74e3e9 100644 --- a/src/iec61850/inc_private/ied_connection_private.h +++ b/src/iec61850/inc_private/ied_connection_private.h @@ -58,6 +58,10 @@ struct sIedConnection IedConnectionClosedHandler connectionCloseHandler; void* connectionClosedParameter; + + IedConnectionStateChangedHandler connectionStateChangedHandler; + void* connectionStateChangedHandlerParameter; + uint32_t connectionTimeout; };