Using Parser and Results

After you initialize environment you can create MLP Parser object that can process MLP messages. MlpParser does not use any multi threading techniques so DO NOT USE one instance of one parser in more threads without your own synchronization. There can coexist more MlpParser in one program and they can work simultaneously. There can be for example one parser per each thread. After the MlpParser is created you can use it to process MLP message as many times as you want, without any reinitialization.

Create Parser

After the initialization of the environment you can create a MlpParser. Use dynamically allocated MlpParser so it can be deleted before MLP_LIB_CPP_TERMINATE macro is called. Ore use any other technique that can guarantee that MlpParser is deleted before terminating macro.

#include <libmlp-cpp/MlpLib.hpp>

... some code 

    MlpParser * myMlpParser = new MlpParser();

Configuration and Initialization

MlpParser uses local DTD files to validate MLP messages. DTD files are not read from Internet for case where program that is using MLP Library does not have an access to the Internet. Now it is default and only behavior. To pass a file-path to DTD files to parser use MlpConfig object.

// Need MlpConfig.hpp
#include <libmlp-cpp/MlpConfig.hpp>

... some code 

    MlpConfig config;
    config.setDTDpath( "../../dtd/" );

Now you can pass the config object to the parser. Than you have to initialize parser. This initializes some Xerces-c options.

// Need MlpException.hpp
#include <libmlp-cpp/MlpException.hpp>

 ... some code

    try {
        // Configure and initialize the parser
        myMlpParser->configure( &config );
        myMlpParser->init();
    }
    catch ( MlpException &e ) {
        // Print error message in case of parser initialisation error
        std::cout << e.getMessage() << std::endl;
  
        // Delete in case of exception
        delete myMlpParser;
        myMlpParser = NULL;
    }

Parsing the MLP Message

MlpParser takes two arguments. First one is object MlpMessage. It has to be empty. MlpParser puts information from MLP messages into it. The second one argument is a string containing some MLP message that is ready to be parsed. MlpParser reads std::string as source data. For future releases reading from streams is planned.

// Need MlpMessage.hpp
#include <libmlp-cpp/MlpMessage.hpp>

 ... some code

    // Create new clean MlpMessage
    MlpMessage parsedMsg;

    // Create sample MLP Message
    std::string myMsg =  "... Put here your MLP message ..."

    try {
        // Process myMsg
        myMlpParser->parse( &parsedMsg, myMsg );
    }
    catch ( MlpException &e ) {
        // Print error message in case of parsing error
        std::cout << e.getMessage() << std::endl;
    }


Using the Results

If everything goes well you have all information from MLP message std::string myMsg in parsedMsg object. Useful information can be accessed by simple calling of member functions of this object. Most important member functions are:

getMsgType()

Returns type of message. That meas either service initiation, service response or general error message.

getServiceType()

Returns type of service message. This determines exact type of service message: Standard Location Immediate Request (SLIR), Standard Location Immediate Answer (SLIA), etc...

getMlpHdr()

Returns pointer to the MLP message header. More detailed information about header can be retrieved using received pointer. For example You can retrieve a client list. Client list is std::list of MlpClients which are entities that requested the localization. In response messages header is not mandatory so this function can return null pointer.

getSubscriberList()

Returns pointer to the std::list of MlpSubscribers. MlpSubscriber contains subscribers that should be localized.

getPositionList()

Returns pointer to the std::list of MlpPositions. MlpPosition contains subscribers locations.

Information returned by the member functions of MlpMessage are either strings, pointers or constants. All constants important to user of MLP Library are in MlpConstants.h file.

Detailed information about member functions of different object can be found in API reference on MLP Library web-pages or documentation directory.

Reusing the Parser and Cleaning the Environment

You can reuse MlpParser object after parsing a message. Previous results do not affect future results. MlpParser is completely cleaned after the parsing is done.

    ... some code

    delete myMlpParser;

    MLP_LIB_CPP_TERMINATE;

    return 0;
}