AllJoyn/Samples/BACnetAdapter/bacnet-stack-0.8.2/demo/epics/main.c
EPICS_STATES ProcessRPMData(
    BACNET_READ_ACCESS_DATA * rpm_data,
    EPICS_STATES myState)
{
    BACNET_READ_ACCESS_DATA *old_rpm_data;
    BACNET_PROPERTY_REFERENCE *rpm_property;
    BACNET_PROPERTY_REFERENCE *old_rpm_property;
    BACNET_APPLICATION_DATA_VALUE *value;
    BACNET_APPLICATION_DATA_VALUE *old_value;
    bool bSuccess = true;
    EPICS_STATES nextState = myState;   /* assume no change */
    /* Some flags to keep the output "pretty" -
     * wait and put these object lists at the end */
    bool bHasObjectList = false;
    bool bHasStructuredViewList = false;
    int i = 0;

    while (rpm_data) {
        rpm_property = rpm_data->listOfProperties;
        while (rpm_property) {
            /* For the GET_LIST_OF_ALL_RESPONSE case,
             * just keep what property this was */
            if (myState == GET_LIST_OF_ALL_RESPONSE) {
                switch (rpm_property->propertyIdentifier) {
                    case PROP_OBJECT_LIST:
                        bHasObjectList = true;  /* Will append below */
                        break;
                    case PROP_STRUCTURED_OBJECT_LIST:
                        bHasStructuredViewList = true;
                        break;
                    default:
                        Property_List[Property_List_Index] =
                            rpm_property->propertyIdentifier;
                        Property_List_Index++;
                        Property_List_Length++;
                        break;
                }
                /* Free up the value(s) */
                value = rpm_property->value;
                while (value) {
                    old_value = value;
                    value = value->next;
                    free(old_value);
                }
            } else if (myState == GET_HEADING_RESPONSE) {
                Property_Value_List[i++].value = rpm_property->value;
                /* copy this pointer.
                 * On error, the pointer will be null
                 * We won't free these values; they will free at exit */
            } else {
                fprintf(stdout, "    ");
                Print_Property_Identifier(rpm_property->propertyIdentifier);
                fprintf(stdout, ": ");
                PrintReadPropertyData(rpm_data->object_type,
                    rpm_data->object_instance, rpm_property);
            }
            old_rpm_property = rpm_property;
            rpm_property = rpm_property->next;
            free(old_rpm_property);
        }
        old_rpm_data = rpm_data;
        rpm_data = rpm_data->next;
        free(old_rpm_data);
    }

    /* Now determine the next state */
    if (myState == GET_HEADING_RESPONSE)
        nextState = PRINT_HEADING;
    /* press ahead with or without the data */
    else if (bSuccess && (myState == GET_ALL_RESPONSE))
        nextState = NEXT_OBJECT;
    else if (bSuccess) {        /* and GET_LIST_OF_ALL_RESPONSE */
        /* Now append the properties we waited on. */
        if (bHasStructuredViewList) {
            Property_List[Property_List_Index] = PROP_STRUCTURED_OBJECT_LIST;
            Property_List_Index++;
            Property_List_Length++;
        }
        if (bHasObjectList) {
            Property_List[Property_List_Index] = PROP_OBJECT_LIST;
            Property_List_Index++;
            Property_List_Length++;
        }
        /* Now insert the -1 list terminator, but don't count it. */
        Property_List[Property_List_Index] = -1;
        assert(Property_List_Length < MAX_PROPS);
        Property_List_Index = 0;        /* Will start at top of the list */
        nextState = GET_PROPERTY_REQUEST;
    }
    return nextState;
}
/** Process the RPM list, either printing out on success or building a
 *  properties list for later use.
 *  Also need to free the data in the list.
 *  If the present state is GET_HEADING_RESPONSE, store the results
 *  in globals for later use.
 * @param rpm_data [in] The list of RPM data received.
 * @param myState [in] The current state.
 * @return The next state of the EPICS state machine, normally NEXT_OBJECT
 *         if the RPM got good data, or GET_PROPERTY_REQUEST if we have to
 *         singly process the list of Properties.
 */
Process the RPM list, either printing out on success or building a
properties list for later use.
Also need to free the data in the list.
If the present state is GET_HEADING_RESPONSE, store the results
in globals for later use.
@param rpm_data [in] The list of RPM data received.
@param myState [in] The current state.
@return The next state of the EPICS state machine, normally NEXT_OBJECT
if the RPM got good data, or GET_PROPERTY_REQUEST if we have to
singly process the list of Properties.
Process the RPM list either printing out on success or building a properties list for later use . Also need to free the data in the list . If the present state is GET_HEADING_RESPONSE store the results in globals for later use . @param rpm_data [ in ] The list of RPM data received . @param myState [ in ] The current state . @return The next state of the EPICS state machine normally NEXT_OBJECT if the RPM got good data or GET_PROPERTY_REQUEST if we have to singly process the list of Properties .
EPICS_STATES ProcessRPMData(
    BACNET_READ_ACCESS_DATA * rpm_data,
    EPICS_STATES myState)
{
    BACNET_READ_ACCESS_DATA *old_rpm_data;
    BACNET_PROPERTY_REFERENCE *rpm_property;
    BACNET_PROPERTY_REFERENCE *old_rpm_property;
    BACNET_APPLICATION_DATA_VALUE *value;
    BACNET_APPLICATION_DATA_VALUE *old_value;
    bool bSuccess = true;
    EPICS_STATES nextState = myState;   
    bool bHasObjectList = false;
    bool bHasStructuredViewList = false;
    int i = 0;
    while (rpm_data) {
        rpm_property = rpm_data->listOfProperties;
        while (rpm_property) {
            if (myState == GET_LIST_OF_ALL_RESPONSE) {
                switch (rpm_property->propertyIdentifier) {
                    case PROP_OBJECT_LIST:
                        bHasObjectList = true;  
                        break;
                    case PROP_STRUCTURED_OBJECT_LIST:
                        bHasStructuredViewList = true;
                        break;
                    default:
                        Property_List[Property_List_Index] =
                            rpm_property->propertyIdentifier;
                        Property_List_Index++;
                        Property_List_Length++;
                        break;
                }
                value = rpm_property->value;
                while (value) {
                    old_value = value;
                    value = value->next;
                    free(old_value);
                }
            } else if (myState == GET_HEADING_RESPONSE) {
                Property_Value_List[i++].value = rpm_property->value;
            } else {
                fprintf(stdout, "    ");
                Print_Property_Identifier(rpm_property->propertyIdentifier);
                fprintf(stdout, ": ");
                PrintReadPropertyData(rpm_data->object_type,
                    rpm_data->object_instance, rpm_property);
            }
            old_rpm_property = rpm_property;
            rpm_property = rpm_property->next;
            free(old_rpm_property);
        }
        old_rpm_data = rpm_data;
        rpm_data = rpm_data->next;
        free(old_rpm_data);
    }
    if (myState == GET_HEADING_RESPONSE)
        nextState = PRINT_HEADING;
    else if (bSuccess && (myState == GET_ALL_RESPONSE))
        nextState = NEXT_OBJECT;
    else if (bSuccess) {        
        if (bHasStructuredViewList) {
            Property_List[Property_List_Index] = PROP_STRUCTURED_OBJECT_LIST;
            Property_List_Index++;
            Property_List_Length++;
        }
        if (bHasObjectList) {
            Property_List[Property_List_Index] = PROP_OBJECT_LIST;
            Property_List_Index++;
            Property_List_Length++;
        }
        Property_List[Property_List_Index] = -1;
        assert(Property_List_Length < MAX_PROPS);
        Property_List_Index = 0;        
        nextState = GET_PROPERTY_REQUEST;
    }
    return nextState;
}
EPICS_STATES ProcessRPMData ( BACNET_READ_ACCESS_DATA * rpm_data , EPICS_STATES myState ) { BACNET_READ_ACCESS_DATA * old_rpm_data ; BACNET_PROPERTY_REFERENCE * rpm_property ; BACNET_PROPERTY_REFERENCE * old_rpm_property ; BACNET_APPLICATION_DATA_VALUE * value ; BACNET_APPLICATION_DATA_VALUE * old_value ; bool bSuccess = true ; EPICS_STATES nextState = myState ; bool bHasObjectList = false ; bool bHasStructuredViewList = false ; int i = 0 ; while ( rpm_data ) { rpm_property = rpm_data -> listOfProperties ; while ( rpm_property ) { if ( myState == GET_LIST_OF_ALL_RESPONSE ) { switch ( rpm_property -> propertyIdentifier ) { case PROP_OBJECT_LIST : bHasObjectList = true ; break ; case PROP_STRUCTURED_OBJECT_LIST : bHasStructuredViewList = true ; break ; default : Property_List [ Property_List_Index ] = rpm_property -> propertyIdentifier ; Property_List_Index ++ ; Property_List_Length ++ ; break ; } value = rpm_property -> value ; while ( value ) { old_value = value ; value = value -> next ; free ( old_value ) ; } } else if ( myState == GET_HEADING_RESPONSE ) { Property_Value_List [ i ++ ] . value = rpm_property -> value ; } else { fprintf ( stdout , " " ) ; Print_Property_Identifier ( rpm_property -> propertyIdentifier ) ; fprintf ( stdout , " " ) ; PrintReadPropertyData ( rpm_data -> object_type , rpm_data -> object_instance , rpm_property ) ; } old_rpm_property = rpm_property ; rpm_property = rpm_property -> next ; free ( old_rpm_property ) ; } old_rpm_data = rpm_data ; rpm_data = rpm_data -> next ; free ( old_rpm_data ) ; } if ( myState == GET_HEADING_RESPONSE ) nextState = PRINT_HEADING ; else if ( bSuccess && ( myState == GET_ALL_RESPONSE ) ) nextState = NEXT_OBJECT ; else if ( bSuccess ) { if ( bHasStructuredViewList ) { Property_List [ Property_List_Index ] = PROP_STRUCTURED_OBJECT_LIST ; Property_List_Index ++ ; Property_List_Length ++ ; } if ( bHasObjectList ) { Property_List [ Property_List_Index ] = PROP_OBJECT_LIST ; Property_List_Index ++ ; Property_List_Length ++ ; } Property_List [ Property_List_Index ] = -1 ; assert ( Property_List_Length < MAX_PROPS ) ; Property_List_Index = 0 ; nextState = GET_PROPERTY_REQUEST ; } return nextState ; }
Process the RPM list, either printing out on success or building a
  properties list for later use.
Process the RPM list either printing out on success or building a properties list for later use .
/* assume no change */ /* Some flags to keep the output "pretty" -
     * wait and put these object lists at the end */ /* For the GET_LIST_OF_ALL_RESPONSE case,
             * just keep what property this was */ /* Will append below */ /* Free up the value(s) */ /* copy this pointer.
                 * On error, the pointer will be null
                 * We won't free these values; they will free at exit */ /* Now determine the next state */ /* press ahead with or without the data */ /* and GET_LIST_OF_ALL_RESPONSE */ /* Now append the properties we waited on. */ /* Now insert the -1 list terminator, but don't count it. */ /* Will start at top of the list */