The Robot Application Programming Interface Delegate Project
RAPID Logo

RapidStatusExampleModel.java

/*
 * Copyright (c) 2009 United States Government as represented by the
 * Administrator of the National Aeronautics and Space Administration.
 * All Rights Reserved.
 */

package gov.nasa.rapid.examples.models;

import gov.nasa.rapid.dds.Agent;
import gov.nasa.rapid.event.IRapidEventListener;
import gov.nasa.rapid.examples.DDSExampleSettings;
import gov.nasa.rapid.message.IRapidMessage;
import gov.nasa.rapid.message.MessageType;
import gov.nasa.rapid.message.RapidAssetState;

public class RapidStatusExampleModel extends RapidExampleModel {

    public static final String ID = "gov.nasa.rapid.examples.models.RapidStatusExampleModel";

    public RapidStatusExampleModel() {
        this(DDSExampleSettings.CLIENT_AGENT);
    }

    public RapidStatusExampleModel(Agent agent) {
        super(agent);

        setModelName("RapidStatusModel");

        try {
            registerForMessage(Agent.GenericSim, MessageType.ASSET_STATE_TYPE, new IRapidEventListener() {

                public void rapidEventReceived(Agent agent, MessageType type, IRapidMessage msg) {
                    RapidAssetState status = null;

                    if (msg instanceof RapidAssetState)
                        status = (RapidAssetState)msg;

                    if (status == null) return;

                    System.err.println("\n\n\n---- RapidStatusModel: " + status + "\n\n\n\n");
                    setModelName("RapidStatusModel");
                    setMessage(status.toString());
                    setTimeStamp(status.getHeader().timeStamp);

                    updateModelChangedListeners();
                }
            });
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines