| 1 | /* |
|---|
| 2 | Author: Kalpesh Solanki |
|---|
| 3 | */ |
|---|
| 4 | |
|---|
| 5 | #include "McastToEEWProperties.h" |
|---|
| 6 | #include "Configuration.h" |
|---|
| 7 | #include <stdio.h> |
|---|
| 8 | #include <errno.h> |
|---|
| 9 | #include "GenLimits.h" |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | McastToEEWProperties::McastToEEWProperties(){}; |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | McastToEEWProperties::McastToEEWProperties(string config_filename) throw(Error){ |
|---|
| 17 | //Check if file exists// |
|---|
| 18 | fstream file; |
|---|
| 19 | file.open(config_filename.c_str(),fstream::in); |
|---|
| 20 | if(file.fail()){ |
|---|
| 21 | throw Error("McastToEEWProperties::McastToEEWProperties: Unable to open "+config_filename); |
|---|
| 22 | } |
|---|
| 23 | file.close(); |
|---|
| 24 | |
|---|
| 25 | //Populate KeyValue Map// |
|---|
| 26 | char key[MAXSTR]; |
|---|
| 27 | char value[MAXSTR]; |
|---|
| 28 | int ret=TN_EOF; |
|---|
| 29 | Configuration cfg(config_filename.c_str()); |
|---|
| 30 | |
|---|
| 31 | while((ret=cfg.next(key,value))==TN_SUCCESS){ |
|---|
| 32 | if(kvm[key] != ""){ |
|---|
| 33 | throw Error("McastToEEWProperties::McastToEEWProperties: Duplicate key found :"+string(key)); |
|---|
| 34 | } |
|---|
| 35 | kvm[key] = value; |
|---|
| 36 | } |
|---|
| 37 | //Check for non-defaults// |
|---|
| 38 | |
|---|
| 39 | if(kvm["LogFile"] == ""){ |
|---|
| 40 | |
|---|
| 41 | throw Error("McastToEEWProperties::McastToEEWProperties: Parameter LogFile not found."); |
|---|
| 42 | |
|---|
| 43 | } |
|---|
| 44 | else{ |
|---|
| 45 | try{ |
|---|
| 46 | |
|---|
| 47 | _logfile = kvm["LogFile"]; |
|---|
| 48 | |
|---|
| 49 | } |
|---|
| 50 | catch(Error& e){ |
|---|
| 51 | throw Error("Configuration file is not in a valid format. LogFile is invalid"); |
|---|
| 52 | } |
|---|
| 53 | } |
|---|
| 54 | |
|---|
| 55 | if(kvm["ChannelSet"] == ""){ |
|---|
| 56 | |
|---|
| 57 | throw Error("McastToEEWProperties::McastToEEWProperties: Parameter ChannelSet not found."); |
|---|
| 58 | |
|---|
| 59 | } |
|---|
| 60 | else{ |
|---|
| 61 | try{ |
|---|
| 62 | |
|---|
| 63 | _channelset = kvm["ChannelSet"]; |
|---|
| 64 | |
|---|
| 65 | } |
|---|
| 66 | catch(Error& e){ |
|---|
| 67 | throw Error("Configuration file is not in a valid format. ChannelSet is invalid"); |
|---|
| 68 | } |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | if(kvm["GCDAFile"] == ""){ |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | _gcdafile = "gcda.cfg"; |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | } |
|---|
| 78 | else{ |
|---|
| 79 | try{ |
|---|
| 80 | |
|---|
| 81 | _gcdafile = kvm["GCDAFile"]; |
|---|
| 82 | |
|---|
| 83 | } |
|---|
| 84 | catch(Error& e){ |
|---|
| 85 | throw Error("Configuration file is not in a valid format. GCDAFile is invalid"); |
|---|
| 86 | } |
|---|
| 87 | } |
|---|
| 88 | |
|---|
| 89 | if(kvm["DBService"] == ""){ |
|---|
| 90 | |
|---|
| 91 | throw Error("McastToEEWProperties::McastToEEWProperties: Parameter DBService not found."); |
|---|
| 92 | |
|---|
| 93 | } |
|---|
| 94 | else{ |
|---|
| 95 | try{ |
|---|
| 96 | |
|---|
| 97 | _dbservice = kvm["DBService"]; |
|---|
| 98 | |
|---|
| 99 | } |
|---|
| 100 | catch(Error& e){ |
|---|
| 101 | throw Error("Configuration file is not in a valid format. DBService is invalid"); |
|---|
| 102 | } |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | if(kvm["DBUser"] == ""){ |
|---|
| 106 | |
|---|
| 107 | throw Error("McastToEEWProperties::McastToEEWProperties: Parameter DBUser not found."); |
|---|
| 108 | |
|---|
| 109 | } |
|---|
| 110 | else{ |
|---|
| 111 | try{ |
|---|
| 112 | |
|---|
| 113 | _dbuser = kvm["DBUser"]; |
|---|
| 114 | |
|---|
| 115 | } |
|---|
| 116 | catch(Error& e){ |
|---|
| 117 | throw Error("Configuration file is not in a valid format. DBUser is invalid"); |
|---|
| 118 | } |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | if(kvm["DBPassword"] == ""){ |
|---|
| 122 | |
|---|
| 123 | throw Error("McastToEEWProperties::McastToEEWProperties: Parameter DBPassword not found."); |
|---|
| 124 | |
|---|
| 125 | } |
|---|
| 126 | else{ |
|---|
| 127 | try{ |
|---|
| 128 | |
|---|
| 129 | _dbpassword = kvm["DBPassword"]; |
|---|
| 130 | |
|---|
| 131 | } |
|---|
| 132 | catch(Error& e){ |
|---|
| 133 | throw Error("Configuration file is not in a valid format. DBPassword is invalid"); |
|---|
| 134 | } |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | if(kvm["MulticastAddress"] == ""){ |
|---|
| 138 | |
|---|
| 139 | throw Error("McastToEEWProperties::McastToEEWProperties: Parameter MulticastAddress not found."); |
|---|
| 140 | |
|---|
| 141 | } |
|---|
| 142 | else{ |
|---|
| 143 | try{ |
|---|
| 144 | |
|---|
| 145 | _multicastaddress = kvm["MulticastAddress"]; |
|---|
| 146 | |
|---|
| 147 | } |
|---|
| 148 | catch(Error& e){ |
|---|
| 149 | throw Error("Configuration file is not in a valid format. MulticastAddress is invalid"); |
|---|
| 150 | } |
|---|
| 151 | } |
|---|
| 152 | |
|---|
| 153 | if(kvm["QMAMulticastAddress"] == ""){ |
|---|
| 154 | |
|---|
| 155 | throw Error("McastToEEWProperties::McastToEEWProperties: Parameter QMAMulticastAddress not found."); |
|---|
| 156 | |
|---|
| 157 | } |
|---|
| 158 | else{ |
|---|
| 159 | try{ |
|---|
| 160 | |
|---|
| 161 | _qmamulticastaddress = kvm["QMAMulticastAddress"]; |
|---|
| 162 | |
|---|
| 163 | } |
|---|
| 164 | catch(Error& e){ |
|---|
| 165 | throw Error("Configuration file is not in a valid format. QMAMulticastAddress is invalid"); |
|---|
| 166 | } |
|---|
| 167 | } |
|---|
| 168 | |
|---|
| 169 | if(kvm["IFID"] == ""){ |
|---|
| 170 | |
|---|
| 171 | throw Error("McastToEEWProperties::McastToEEWProperties: Parameter IFID not found."); |
|---|
| 172 | |
|---|
| 173 | } |
|---|
| 174 | else{ |
|---|
| 175 | try{ |
|---|
| 176 | |
|---|
| 177 | _ifid = kvm["IFID"]; |
|---|
| 178 | |
|---|
| 179 | } |
|---|
| 180 | catch(Error& e){ |
|---|
| 181 | throw Error("Configuration file is not in a valid format. IFID is invalid"); |
|---|
| 182 | } |
|---|
| 183 | } |
|---|
| 184 | |
|---|
| 185 | } |
|---|
| 186 | |
|---|
| 187 | McastToEEWProperties::McastToEEWProperties(const McastToEEWProperties& prop){ |
|---|
| 188 | |
|---|
| 189 | _logfile = prop.getLogFile(); |
|---|
| 190 | |
|---|
| 191 | _channelset = prop.getChannelSet(); |
|---|
| 192 | |
|---|
| 193 | _gcdafile = prop.getGCDAFile(); |
|---|
| 194 | |
|---|
| 195 | _dbservice = prop.getDBService(); |
|---|
| 196 | |
|---|
| 197 | _dbuser = prop.getDBUser(); |
|---|
| 198 | |
|---|
| 199 | _dbpassword = prop.getDBPassword(); |
|---|
| 200 | |
|---|
| 201 | _multicastaddress = prop.getMulticastAddress(); |
|---|
| 202 | |
|---|
| 203 | _qmamulticastaddress = prop.getQMAMulticastAddress(); |
|---|
| 204 | |
|---|
| 205 | _ifid = prop.getIFID(); |
|---|
| 206 | |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | McastToEEWProperties& McastToEEWProperties::operator=(const McastToEEWProperties& prop){ |
|---|
| 210 | |
|---|
| 211 | _logfile = prop.getLogFile(); |
|---|
| 212 | |
|---|
| 213 | _channelset = prop.getChannelSet(); |
|---|
| 214 | |
|---|
| 215 | _gcdafile = prop.getGCDAFile(); |
|---|
| 216 | |
|---|
| 217 | _dbservice = prop.getDBService(); |
|---|
| 218 | |
|---|
| 219 | _dbuser = prop.getDBUser(); |
|---|
| 220 | |
|---|
| 221 | _dbpassword = prop.getDBPassword(); |
|---|
| 222 | |
|---|
| 223 | _multicastaddress = prop.getMulticastAddress(); |
|---|
| 224 | |
|---|
| 225 | _qmamulticastaddress = prop.getQMAMulticastAddress(); |
|---|
| 226 | |
|---|
| 227 | _ifid = prop.getIFID(); |
|---|
| 228 | |
|---|
| 229 | return (*this); |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | |
|---|
| 233 | int McastToEEWProperties::toInt(string int_val) throw(Error){ |
|---|
| 234 | char val[32]; |
|---|
| 235 | strcpy(val,int_val.c_str()); |
|---|
| 236 | |
|---|
| 237 | int v = atoi(val); |
|---|
| 238 | // if(errno == ERANGE || errno == EINVAL){ |
|---|
| 239 | // throw Error("Invalid Integer"); |
|---|
| 240 | // } |
|---|
| 241 | |
|---|
| 242 | return v; |
|---|
| 243 | } |
|---|
| 244 | |
|---|
| 245 | float McastToEEWProperties::toFloat(string float_val) throw(Error){ |
|---|
| 246 | char val[32]; |
|---|
| 247 | strcpy(val,float_val.c_str()); |
|---|
| 248 | |
|---|
| 249 | float v = atof(val); |
|---|
| 250 | // if(errno == ERANGE || errno == EINVAL){ |
|---|
| 251 | // throw Error("Invalid Float"); |
|---|
| 252 | // } |
|---|
| 253 | return v; |
|---|
| 254 | } |
|---|
| 255 | |
|---|
| 256 | double McastToEEWProperties::toDouble(string double_val) throw(Error){ |
|---|
| 257 | char val[32]; |
|---|
| 258 | strcpy(val,double_val.c_str()); |
|---|
| 259 | |
|---|
| 260 | double v = (double)atof(val); |
|---|
| 261 | // if(errno == ERANGE || errno == EINVAL){ |
|---|
| 262 | // throw Error("Invalid Double"); |
|---|
| 263 | // } |
|---|
| 264 | return v; |
|---|
| 265 | } |
|---|
| 266 | |
|---|
| 267 | |
|---|
| 268 | bool McastToEEWProperties::toBool(string bool_val) throw(Error){ |
|---|
| 269 | if(bool_val == "true"){ |
|---|
| 270 | return true; |
|---|
| 271 | } |
|---|
| 272 | else if(bool_val == "false"){ |
|---|
| 273 | return false; |
|---|
| 274 | } |
|---|
| 275 | else{ |
|---|
| 276 | throw Error("Invalid Bool"); |
|---|
| 277 | } |
|---|
| 278 | } |
|---|
| 279 | |
|---|
| 280 | |
|---|
| 281 | |
|---|
| 282 | string McastToEEWProperties::getLogFile() const{ |
|---|
| 283 | return _logfile; |
|---|
| 284 | } |
|---|
| 285 | |
|---|
| 286 | string McastToEEWProperties::getChannelSet() const{ |
|---|
| 287 | return _channelset; |
|---|
| 288 | } |
|---|
| 289 | |
|---|
| 290 | string McastToEEWProperties::getGCDAFile() const{ |
|---|
| 291 | return _gcdafile; |
|---|
| 292 | } |
|---|
| 293 | |
|---|
| 294 | string McastToEEWProperties::getDBService() const{ |
|---|
| 295 | return _dbservice; |
|---|
| 296 | } |
|---|
| 297 | |
|---|
| 298 | string McastToEEWProperties::getDBUser() const{ |
|---|
| 299 | return _dbuser; |
|---|
| 300 | } |
|---|
| 301 | |
|---|
| 302 | string McastToEEWProperties::getDBPassword() const{ |
|---|
| 303 | return _dbpassword; |
|---|
| 304 | } |
|---|
| 305 | |
|---|
| 306 | string McastToEEWProperties::getMulticastAddress() const{ |
|---|
| 307 | return _multicastaddress; |
|---|
| 308 | } |
|---|
| 309 | |
|---|
| 310 | string McastToEEWProperties::getQMAMulticastAddress() const{ |
|---|
| 311 | return _qmamulticastaddress; |
|---|
| 312 | } |
|---|
| 313 | |
|---|
| 314 | string McastToEEWProperties::getIFID() const{ |
|---|
| 315 | return _ifid; |
|---|
| 316 | } |
|---|
| 317 | |
|---|
| 318 | |
|---|
| 319 | |
|---|