1 package cz.cuni.amis.pogamut.usar2004.agent.module.configuration; 2 3 import cz.cuni.amis.pogamut.usar2004.agent.module.datatypes.ConfigType; 4 import cz.cuni.amis.pogamut.usar2004.communication.messages.usarinfomessages.ConfigurationMessage; 5 import java.util.Map; 6 import java.util.Set; 7 8 /** 9 * Parent class for all possible configuration subjects. It covers the basic and 10 * common properties for all the configuration subjects. 11 * 12 * @author vejmanm 13 */ 14 public abstract class SuperConfiguration 15 { 16 protected ConfigType confType; 17 protected ConfigurationMessage lastMessage; 18 19 /** 20 * Ctor. 21 * 22 * @param type Configuration type describes particular subject about which 23 * we want to know about. It is used to distinguish incoming message from 24 * the server. 25 */ 26 public SuperConfiguration(ConfigType type) 27 { 28 this.confType = type; 29 } 30 31 /** 32 * Used to make sure the object is filled. 33 * 34 * @return Returns true if the object is filled with Conf. message. 35 */ 36 public Boolean isReady() 37 { 38 return (lastMessage != null); 39 } 40 41 /** 42 * Type describes the vehicle type. It will be one of the following values: 43 * "GroundVehicle”, “LeggedRobot”, “NauticVehicle”, or “AerialVehicle” of 44 * "Camera" or some kind of sensor or effecter or "MisPkg". 45 * 46 * @return Returns type of the geometry message. 47 */ 48 public String getType() 49 { 50 return lastMessage.getType(); 51 } 52 53 /** 54 * Name of the subject that this geometry message concerns. 55 * 56 * @return Returns the name of the Geometry item. 57 */ 58 public String getName() 59 { 60 return lastMessage.getName(); 61 } 62 63 /** 64 * ConfigType is a descriptor used for creating particular instance and for 65 * getting type information about particular configuration subject. 66 * 67 * @return Returns ConfigType. 68 */ 69 public ConfigType getConfigType() 70 { 71 return this.confType; 72 } 73 74 /** 75 * For a camera, sensor or effecter, a configuration message conatins a pair 76 * ‘{Name Value}’ that describes the feature of this sensor type. Different 77 * sensor types have different name value pairs. For detailed information, 78 * please refer to section 10 of USARSim manual v3.1.3 about how to 79 * configure the sensor. 80 * 81 * Example: CONF {Type Camera} {CameraDefFov 0.8727} {CameraMinFov 0.3491} 82 * {CameraMaxFov 2.0943} {CameraFov 0.8726} 83 * 84 * @return Returns keySet of features. 85 */ 86 public Set<String> getFeatureNames() 87 { 88 return lastMessage.getFeatures().keySet(); 89 } 90 91 /** 92 * For a camera, sensor or effecter, a configuration message conatins a pair 93 * ‘{Name Value}’ that describes the feature of this sensor type. Different 94 * sensor types have different name value pairs. For detailed information, 95 * please refer to section 10 of USARSim manual v3.1.3 about how to 96 * configure the sensor. 97 * 98 * Example: CONF {Type Camera} {CameraDefFov 0.8727} {CameraMinFov 0.3491} 99 * {CameraMaxFov 2.0943} {CameraFov 0.8726} 100 * 101 * @return Returns feature value by feature name from the feature map. 102 */ 103 public String getFeatureValueBy(String Name) 104 { 105 return lastMessage.getFeatures().get(Name); 106 } 107 108 /** 109 * For a camera, sensor or effecter, a configuration message conatins a pair 110 * ‘{Name Value}’ that describes the feature of this sensor type. Different 111 * sensor types have different name value pairs. For detailed information, 112 * please refer to section 10 of USARSim manual v3.1.3 about how to 113 * configure the sensor. 114 * 115 * Example: CONF {Type Camera} {CameraDefFov 0.8727} {CameraMinFov 0.3491} 116 * {CameraMaxFov 2.0943} {CameraFov 0.8726} 117 * 118 * @return Returns the size of the feature map. 119 */ 120 public int getFeatureSize() 121 { 122 return lastMessage.getFeatures().size(); 123 } 124 125 /** 126 * For a camera, sensor or effecter, a configuration message conatins a pair 127 * ‘{Name Value}’ that describes the feature of this sensor type. Different 128 * sensor types have different name value pairs. For detailed information, 129 * please refer to section 10 of USARSim manual v3.1.3 about how to 130 * configure the sensor. 131 * 132 * Example: CONF {Type Camera} {CameraDefFov 0.8727} {CameraMinFov 0.3491} 133 * {CameraMaxFov 2.0943} {CameraFov 0.8726} 134 * 135 * @return Returns Map of features. 136 */ 137 public Map<String, String> getFeatures() 138 { 139 return lastMessage.getFeatures(); 140 } 141 142 /** 143 * Method used for updating the message object that provides particular 144 * properties for given type. Note that this object is created by yylex 145 * parser and contains properties for all configuration subject types. But 146 * only relevat to individual Config Subject are filled. 147 * 148 * @param message Configuration message from server. 149 */ 150 public void updateMessage(ConfigurationMessage message) 151 { 152 lastMessage = message; 153 } 154 }