PUD: allow output pointers to be NULL in determineStateWithHysteresis
authorFerry Huberts <ferry.huberts@pelagic.nl>
Thu, 15 Mar 2012 10:18:29 +0000 (11:18 +0100)
committerFerry Huberts <ferry.huberts@pelagic.nl>
Thu, 15 Mar 2012 10:31:16 +0000 (11:31 +0100)
Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
lib/pud/src/receiver.c
lib/pud/src/state.c

index dfd7c61..f94e3ee 100644 (file)
@@ -350,7 +350,6 @@ static void doImmediateTransmit(MovementState externalState) {
  */
 static void pud_gateway_timer_callback(void *context __attribute__ ((unused))) {
        union olsr_ip_addr bestGateway;
-       bool subStateExternalStateChange;
        bool externalStateChange;
        MovementState externalState;
        TristateBoolean movingNow = TRISTATE_BOOLEAN_UNSET;
@@ -371,8 +370,7 @@ static void pud_gateway_timer_callback(void *context __attribute__ ((unused))) {
         * State Determination
         */
 
-       determineStateWithHysteresis(SUBSTATE_GATEWAY, movingNow, &externalState, &externalStateChange,
-                       &subStateExternalStateChange);
+       determineStateWithHysteresis(SUBSTATE_GATEWAY, movingNow, &externalState, &externalStateChange, NULL);
 
        /*
         * Update transmitGpsInformation
index 06cab4c..c64c245 100644 (file)
@@ -97,6 +97,7 @@ void determineStateWithHysteresis(SubStateIndex subStateIndex, TristateBoolean m
                bool * externalStateChange, bool * subStateExternalStateChange) {
        MovementState newState;
        bool internalStateChange;
+       bool subStateExternalStateChanged;
        SubStateType * subState = &state.substate[subStateIndex];
 
        (void) pthread_mutex_lock(&state.mutex);
@@ -162,15 +163,20 @@ void determineStateWithHysteresis(SubStateIndex subStateIndex, TristateBoolean m
                }
        }
 
-       *subStateExternalStateChange = (subState->externalState != newState);
+       subStateExternalStateChanged = (subState->externalState != newState);
+       if (subStateExternalStateChange) {
+               *subStateExternalStateChange = subStateExternalStateChanged;
+       }
        subState->externalState = newState;
 
        /*
         * external state may transition into MOVING when either one of the sub-states say so (OR), and
         * may transition into STATIONARY when all of the sub-states say so (AND)
         */
-       *externalStateChange = false;
-       if (*subStateExternalStateChange) {
+       if (externalStateChange) {
+               *externalStateChange = false;
+       }
+       if (subStateExternalStateChanged) {
                bool transition;
 
                if (newState == MOVEMENT_STATE_STATIONARY) {
@@ -187,12 +193,16 @@ void determineStateWithHysteresis(SubStateIndex subStateIndex, TristateBoolean m
                }
 
                if (transition) {
-                       *externalStateChange = (state.externalState != newState);
+                       if (externalStateChange) {
+                               *externalStateChange = (state.externalState != newState);
+                       }
                        state.externalState = newState;
                }
        }
 
-       *externalState = state.externalState;
+       if (externalState) {
+               *externalState = state.externalState;
+       }
 
        (void) pthread_mutex_unlock(&state.mutex);
 }