S5-P05 / ConfigurationFile

Dependencies:   ConfigFile

Dependents:   Ethernet

ConfigurationFile.cpp

Committer:
13075593
Date:
2016-04-06
Revision:
2:5af11ca8e085
Parent:
1:5b6c5c2a33d0
Child:
3:7177e463ac52

File content as of revision 2:5af11ca8e085:

#include "ConfigurationFile.h"

ConfigurationFile::ConfigurationFile()
{
}

ConfigurationFile::~ConfigurationFile()
{
}

void ConfigurationFile::setIP()
{
    char value[BUFSIZ];
    if (cfg.getValue( "IP", &value[0], sizeof(value))) 
    {
        printf("'%s'='%s'\n", "IP", value);
        string s = value;
        ip = s;
    }
    else
    {
        error("Failure to read IP key");
    }
}

string ConfigurationFile::getIP()
{
    return ip;
}

void ConfigurationFile::setMask()
{
    char value[BUFSIZ];
    if (cfg.getValue( "MASK", &value[0], sizeof(value))) 
    {
        printf("'%s'='%s'\n", "MASK", value);
        string s = value;
        mask = s;
    }
    else
    {
        error("Failure to read MASK key");
    }
}

string ConfigurationFile::getMask()
{
    return mask;
}

void ConfigurationFile::setGateway()
{
    char value[BUFSIZ];
    if (cfg.getValue( "GATEWAY", &value[0], sizeof(value))) 
    {
        printf("'%s'='%s'\n", "GATEWAY", value);
        string s = value;
        gateway = s;
    }
    else
    {
        error("Failure to read GATEWAY key");
    }
}

string ConfigurationFile::getGateway()
{
    return gateway;
}

void ConfigurationFile::setURL()
{
    char value[BUFSIZ];
    if (cfg.getValue( "URL", &value[0], sizeof(value))) 
    {
        printf("'%s'='%s'\n", "URL", value);
        string s = value;
        url = s;
    }
    else
    {
        error("Failure to read URL key");
    }
}

string ConfigurationFile::getURL()
{
    return url;
}

void ConfigurationFile::setBroadcastAddress()
{
    char value[BUFSIZ];
    if (cfg.getValue( "BROADCAST", &value[0], sizeof(value))) 
    {
        printf("'%s'='%s'\n", "Broadcast Address", value);
        string s = value;
        broadcastAddress = s;
    }
    else
    {
        error("Failure to read Broadcast Address key");
    }
}

string ConfigurationFile::getBroadcastAddress()
{
    return broadcastAddress;
}


void ConfigurationFile::readServerEthernetConfiguration()
{
    setIP();
    setMask();
    setGateway();
    setURL();
    setBroadcastAddress();
}

void ConfigurationFile::readNodeEthernetConfiguration()
{
    setIP();
    setMask();
    setGateway();
    setBroadcastAddress();
}

void ConfigurationFile::getServerConfiguration()
{
    getIP();
    getMask();
    getGateway();
    getURL();
    getBroadcastAddress();
}

void ConfigurationFile::getNodeConfiguration()
{
    getIP();
    getMask();
    getGateway();
    getBroadcastAddress();
}

void ConfigurationFile::readConfigurationFile(char *pathName)
{
    if (!cfg.read(pathName)) 
    {
        error("Failure to read a configuration file.\n");
    }
}