S5-P05 / ConfigurationFile

Dependencies:   ConfigFile

Dependents:   Ethernet

Committer:
13075593
Date:
Mon Apr 04 22:04:09 2016 +0000
Revision:
1:5b6c5c2a33d0
Parent:
0:1405a58a7e8d
Child:
2:5af11ca8e085
Ajout pour la lecture de fichier Server et node

Who changed what in which revision?

UserRevisionLine numberNew contents of line
13075593 0:1405a58a7e8d 1 #include "ConfigurationFile.h"
13075593 0:1405a58a7e8d 2
13075593 0:1405a58a7e8d 3 ConfigurationFile::ConfigurationFile()
13075593 0:1405a58a7e8d 4 {
13075593 0:1405a58a7e8d 5 }
13075593 0:1405a58a7e8d 6
13075593 0:1405a58a7e8d 7 ConfigurationFile::~ConfigurationFile()
13075593 0:1405a58a7e8d 8 {
13075593 0:1405a58a7e8d 9 }
13075593 0:1405a58a7e8d 10
13075593 0:1405a58a7e8d 11 void ConfigurationFile::setIP()
13075593 0:1405a58a7e8d 12 {
13075593 0:1405a58a7e8d 13 char value[BUFSIZ];
13075593 0:1405a58a7e8d 14 if (cfg.getValue( "IP", &value[0], sizeof(value)))
13075593 0:1405a58a7e8d 15 {
13075593 0:1405a58a7e8d 16 printf("'%s'='%s'\n", "IP", value);
13075593 0:1405a58a7e8d 17 string s = value;
13075593 0:1405a58a7e8d 18 ip = s;
13075593 0:1405a58a7e8d 19 }
13075593 0:1405a58a7e8d 20 else
13075593 0:1405a58a7e8d 21 {
13075593 0:1405a58a7e8d 22 error("Failure to read IP key");
13075593 0:1405a58a7e8d 23 }
13075593 0:1405a58a7e8d 24 }
13075593 0:1405a58a7e8d 25
13075593 0:1405a58a7e8d 26 string ConfigurationFile::getIP()
13075593 0:1405a58a7e8d 27 {
13075593 0:1405a58a7e8d 28 return ip;
13075593 0:1405a58a7e8d 29 }
13075593 0:1405a58a7e8d 30
13075593 0:1405a58a7e8d 31 void ConfigurationFile::setMask()
13075593 0:1405a58a7e8d 32 {
13075593 0:1405a58a7e8d 33 char value[BUFSIZ];
13075593 0:1405a58a7e8d 34 if (cfg.getValue( "MASK", &value[0], sizeof(value)))
13075593 0:1405a58a7e8d 35 {
13075593 0:1405a58a7e8d 36 printf("'%s'='%s'\n", "MASK", value);
13075593 0:1405a58a7e8d 37 string s = value;
13075593 0:1405a58a7e8d 38 mask = s;
13075593 0:1405a58a7e8d 39 }
13075593 0:1405a58a7e8d 40 else
13075593 0:1405a58a7e8d 41 {
13075593 0:1405a58a7e8d 42 error("Failure to read MASK key");
13075593 0:1405a58a7e8d 43 }
13075593 0:1405a58a7e8d 44 }
13075593 0:1405a58a7e8d 45
13075593 0:1405a58a7e8d 46 string ConfigurationFile::getMask()
13075593 0:1405a58a7e8d 47 {
13075593 0:1405a58a7e8d 48 return mask;
13075593 0:1405a58a7e8d 49 }
13075593 0:1405a58a7e8d 50
13075593 0:1405a58a7e8d 51 void ConfigurationFile::setGateway()
13075593 0:1405a58a7e8d 52 {
13075593 0:1405a58a7e8d 53 char value[BUFSIZ];
13075593 0:1405a58a7e8d 54 if (cfg.getValue( "GATEWAY", &value[0], sizeof(value)))
13075593 0:1405a58a7e8d 55 {
13075593 0:1405a58a7e8d 56 printf("'%s'='%s'\n", "GATEWAY", value);
13075593 0:1405a58a7e8d 57 string s = value;
13075593 0:1405a58a7e8d 58 gateway = s;
13075593 0:1405a58a7e8d 59 }
13075593 0:1405a58a7e8d 60 else
13075593 0:1405a58a7e8d 61 {
13075593 0:1405a58a7e8d 62 error("Failure to read GATEWAY key");
13075593 0:1405a58a7e8d 63 }
13075593 0:1405a58a7e8d 64 }
13075593 0:1405a58a7e8d 65
13075593 0:1405a58a7e8d 66 string ConfigurationFile::getGateway()
13075593 0:1405a58a7e8d 67 {
13075593 0:1405a58a7e8d 68 return gateway;
13075593 0:1405a58a7e8d 69 }
13075593 0:1405a58a7e8d 70
13075593 0:1405a58a7e8d 71 void ConfigurationFile::setURL()
13075593 0:1405a58a7e8d 72 {
13075593 0:1405a58a7e8d 73 char value[BUFSIZ];
13075593 0:1405a58a7e8d 74 if (cfg.getValue( "URL", &value[0], sizeof(value)))
13075593 0:1405a58a7e8d 75 {
13075593 0:1405a58a7e8d 76 printf("'%s'='%s'\n", "URL", value);
13075593 0:1405a58a7e8d 77 string s = value;
13075593 0:1405a58a7e8d 78 url = s;
13075593 0:1405a58a7e8d 79 }
13075593 0:1405a58a7e8d 80 else
13075593 0:1405a58a7e8d 81 {
13075593 0:1405a58a7e8d 82 error("Failure to read URL key");
13075593 0:1405a58a7e8d 83 }
13075593 0:1405a58a7e8d 84 }
13075593 0:1405a58a7e8d 85
13075593 0:1405a58a7e8d 86 string ConfigurationFile::getURL()
13075593 0:1405a58a7e8d 87 {
13075593 0:1405a58a7e8d 88 return url;
13075593 0:1405a58a7e8d 89 }
13075593 0:1405a58a7e8d 90
13075593 1:5b6c5c2a33d0 91 void ConfigurationFile::setServerAddress()
13075593 1:5b6c5c2a33d0 92 {
13075593 1:5b6c5c2a33d0 93 char value[BUFSIZ];
13075593 1:5b6c5c2a33d0 94 if (cfg.getValue( "SERVER", &value[0], sizeof(value)))
13075593 1:5b6c5c2a33d0 95 {
13075593 1:5b6c5c2a33d0 96 printf("'%s'='%s'\n", "Server Address", value);
13075593 1:5b6c5c2a33d0 97 string s = value;
13075593 1:5b6c5c2a33d0 98 serverAddress = s;
13075593 1:5b6c5c2a33d0 99 }
13075593 1:5b6c5c2a33d0 100 else
13075593 1:5b6c5c2a33d0 101 {
13075593 1:5b6c5c2a33d0 102 error("Failure to read Server Address key");
13075593 1:5b6c5c2a33d0 103 }
13075593 1:5b6c5c2a33d0 104 }
13075593 1:5b6c5c2a33d0 105
13075593 1:5b6c5c2a33d0 106 string ConfigurationFile::getServerAddress()
13075593 1:5b6c5c2a33d0 107 {
13075593 1:5b6c5c2a33d0 108 return serverAddress;
13075593 1:5b6c5c2a33d0 109 }
13075593 1:5b6c5c2a33d0 110
13075593 0:1405a58a7e8d 111
13075593 0:1405a58a7e8d 112 void ConfigurationFile::readServerEthernetConfiguration()
13075593 0:1405a58a7e8d 113 {
13075593 0:1405a58a7e8d 114 setIP();
13075593 0:1405a58a7e8d 115 setMask();
13075593 0:1405a58a7e8d 116 setGateway();
13075593 0:1405a58a7e8d 117 setURL();
13075593 0:1405a58a7e8d 118 }
13075593 0:1405a58a7e8d 119
13075593 0:1405a58a7e8d 120 void ConfigurationFile::readNodeEthernetConfiguration()
13075593 0:1405a58a7e8d 121 {
13075593 0:1405a58a7e8d 122 setIP();
13075593 0:1405a58a7e8d 123 setMask();
13075593 0:1405a58a7e8d 124 setGateway();
13075593 1:5b6c5c2a33d0 125 setServerAddress();
13075593 1:5b6c5c2a33d0 126 }
13075593 1:5b6c5c2a33d0 127
13075593 1:5b6c5c2a33d0 128 void ConfigurationFile::getServerConfiguration()
13075593 1:5b6c5c2a33d0 129 {
13075593 1:5b6c5c2a33d0 130 getIP();
13075593 1:5b6c5c2a33d0 131 getMask();
13075593 1:5b6c5c2a33d0 132 getGateway();
13075593 1:5b6c5c2a33d0 133 getURL();
13075593 1:5b6c5c2a33d0 134 }
13075593 1:5b6c5c2a33d0 135
13075593 1:5b6c5c2a33d0 136 void ConfigurationFile::getNodeConfiguration()
13075593 1:5b6c5c2a33d0 137 {
13075593 1:5b6c5c2a33d0 138 getIP();
13075593 1:5b6c5c2a33d0 139 getMask();
13075593 1:5b6c5c2a33d0 140 getGateway();
13075593 1:5b6c5c2a33d0 141 getServerAddress();
13075593 0:1405a58a7e8d 142 }
13075593 0:1405a58a7e8d 143
13075593 0:1405a58a7e8d 144 void ConfigurationFile::readConfigurationFile(char *pathName)
13075593 0:1405a58a7e8d 145 {
13075593 0:1405a58a7e8d 146 if (!cfg.read(pathName))
13075593 0:1405a58a7e8d 147 {
13075593 0:1405a58a7e8d 148 error("Failure to read a configuration file.\n");
13075593 0:1405a58a7e8d 149 }
13075593 0:1405a58a7e8d 150 }