Home · All Commands · First Steps · Tutorials · Demos · FAQ
 

Remote Interface Documentation

Reading a stationlist from the navigator

Introduction

In this example we will show how to handle a request with multiple packages returned. The sending of the request is similar to the tutorials we saw before, so we do not explain it here anymore.
In the windowproc, we check for our message as in the tutorials before:

LRESULT CDlgMFC_ReadStationList::WindowProc ( UINT  message , WPARAM  wParam , LPARAM  lParam )
{
    if ( message == RI_MESSAGE_GETSTOPOFFPOINTLIST )
    {
        if ( (LRESULT)wParam == RI_NOERROR )
        {
            RI_CGetStopOffPointList data;
            LRESULT read_suc = RI_GetStopOffPointList_ReadData( lParam, data );

In this case, the received a data struct that has a field m_listcount. This field holds the number of stations available. If you want to read all stations, you have to increase the m_index field in this received struct, write it with the writer function back to the shared memory and resend the message.
So the next time, we receive the message, the second package will be transfered, and so on until there are no more packages available.

    if (data.m_index < data.m_listcount )
    {
        data.m_index = data.m_index + 1;
        LRESULT sharing_ret = RI_GetStopOffPointList_WriteData( data.m_ID, data );
        RI_MESSAGE( RI_MESSAGE_GETSTOPOFFPOINTLIST, GetSafeHwnd(), data.m_ID );
    }

The complete sequence:

#define USE_LOADLIBRARY
#include "TNSRemoteInterfaceDll.h"

LPARAM GetUniqueID()
{
    //generate unique ID
    static LPARAM id = 0;
    if (++id == 0) ++id; // do not use 0 !!!!!
    return id;
}

inline LRESULT RI_MESSAGE( const UINT request, HWND h_client, LPARAM id )
{
    //check if RI handle is valid
    if ( !IsWindow( RI_GetTNS() ) ) 
        return RI_NAVIGATIONNOTACTIVE;
    //send the request
    PostMessage( RI_GetTNS(), request, WPARAM(h_client), id );
    return RI_NOERROR;
}

LRESULT CDlgMFC_ReadStationList::WindowProc ( UINT  message , WPARAM  wParam , LPARAM  lParam )
{
    //check messages for answer from RI
    if ( message == RI_MESSAGE_GETSTOPOFFPOINTLIST )
    {
        if ( (LRESULT)wParam == RI_NOERROR )
        {
            RI_CGetStopOffPointList data;
            LRESULT read_suc = RI_GetStopOffPointList_ReadData( lParam, data );
            if ( read_suc != RI_NOERROR )
                //...data was overwritten. errorcode (-2)
            else
            {   
                //examine whether the current station-index is smaller than the stationcount
                if (data.m_index < data.m_listcount )
                {
                    //show data:
                    TRACE(TEXT("Caption: %s\n"),data.m_Caption);
                    TRACE(TEXT("Description: %s\n"), data.m_Description);
                    TRACE(TEXT("X-Koorinate: %i\n"), data.m_mercator_x);
                    TRACE(TEXT("Y-Koordinate: %i\n"), data.m_mercator_y);
                    TRACE(TEXT("ID: %i"),data.m_StationID);
                    //advance station counter 1
                    data.m_index = data.m_index + 1;
                    //write data
                    LRESULT sharing_ret = RI_GetStopOffPointList_WriteData( data.m_ID, data );
                    //get next station from the list
                    RI_MESSAGE( RI_MESSAGE_GETSTOPOFFPOINTLIST, GetSafeHwnd(), data.m_ID );
                }
            }

        }
        else 
            //Get Stop of Point List not succeeded. errorcode (-1)
    }
    return CDialog::WindowProc( message, wParam, lParam );
}

void CDlgMFC_ReadStationList::foo()
{
    //*** copy data ***
    RI_CGetStopOffPointList data;
    //write flag and index
    data.m_index = 0;

    //*** write data in shared memory ***
    LPARAM id = GetUniqueID();
    LRESULT sharing_ret = RI_GetStopOffPointList_WriteData( id, data );
    if ( sharing_ret != RI_NOERROR )
            return;
    if ( RI_MESSAGE( RI_MESSAGE_GETSTOPOFFPOINTLIST, GetSafeHwnd(), id ) == RI_NOERROR )
        //message sending succeeded
    else
        //navigation software not running
}

© PTV AG 2011 Generated on Fri Oct 14 2011 10:17:32 for RI by doxygen 1.7.1