simplified cfg class

pull/12/head
Tom Early 7 years ago
parent 5910117048
commit beb8851578

@ -49,26 +49,26 @@ dvap : $(DVP_PROGRAMS)
dvrptr : $(DVR_PROGRAMS)
itap : $(TAP_PROGRAMS)
qngateway : $(IRCOBJS) QnetGateway.o aprs.o UnixDgramSocket.o
g++ $(CPPFLAGS) -o qngateway QnetGateway.o aprs.o UnixDgramSocket.o $(IRCOBJS) $(LDFLAGS) -pthread
qngateway : $(IRCOBJS) QnetGateway.o aprs.o UnixDgramSocket.o QnetConfigure.o
g++ $(CPPFLAGS) -o qngateway QnetGateway.o aprs.o UnixDgramSocket.o QnetConfigure.o $(IRCOBJS) $(LDFLAGS) -pthread
qnlink : QnetLink.o DPlusAuthenticator.o TCPReaderWriterClient.o Random.o UnixDgramSocket.o
g++ $(CPPFLAGS) -o qnlink QnetLink.o DPlusAuthenticator.o TCPReaderWriterClient.o Random.o UnixDgramSocket.o $(LDFLAGS) -pthread
qnlink : QnetLink.o DPlusAuthenticator.o TCPReaderWriterClient.o Random.o UnixDgramSocket.o QnetConfigure.o
g++ $(CPPFLAGS) -o qnlink QnetLink.o DPlusAuthenticator.o TCPReaderWriterClient.o Random.o UnixDgramSocket.o QnetConfigure.o $(LDFLAGS) -pthread
qnrelay : QnetRelay.o UnixDgramSocket.o
g++ $(CPPFLAGS) -o qnrelay QnetRelay.o UnixDgramSocket.o $(LDFLAGS)
qnrelay : QnetRelay.o UnixDgramSocket.o QnetConfigure.o
g++ $(CPPFLAGS) -o qnrelay QnetRelay.o UnixDgramSocket.o QnetConfigure.o $(LDFLAGS)
qnitap : QnetITAP.o Random.o UnixDgramSocket.o
g++ $(CPPFLAGS) -o qnitap QnetITAP.o Random.o UnixDgramSocket.o $(LDFLAGS)
qnitap : QnetITAP.o Random.o UnixDgramSocket.o QnetConfigure.o
g++ $(CPPFLAGS) -o qnitap QnetITAP.o Random.o UnixDgramSocket.o QnetConfigure.o $(LDFLAGS)
qndvap : QnetDVAP.o DVAPDongle.o Random.o $(DSTROBJS) UnixDgramSocket.o
g++ $(CPPFLAGS) -o qndvap QnetDVAP.o DVAPDongle.o Random.o UnixDgramSocket.o $(DSTROBJS) $(LDFLAGS) -pthread
qndvap : QnetDVAP.o DVAPDongle.o Random.o $(DSTROBJS) UnixDgramSocket.o QnetConfigure.o
g++ $(CPPFLAGS) -o qndvap QnetDVAP.o DVAPDongle.o Random.o UnixDgramSocket.o QnetConfigure.o $(DSTROBJS) $(LDFLAGS) -pthread
qndvrptr : QnetDVRPTR.o $(DSTROBJS) Random.o UnixDgramSocket.o
g++ $(CPPFLAGS) -o qndvrptr QnetDVRPTR.o Random.o UnixDgramSocket.o $(DSTROBJS) $(LDFLAGS)
qndvrptr : QnetDVRPTR.o $(DSTROBJS) Random.o UnixDgramSocket.o QnetConfigure.o
g++ $(CPPFLAGS) -o qndvrptr QnetDVRPTR.o Random.o UnixDgramSocket.o QnetConfigure.o $(DSTROBJS) $(LDFLAGS)
qnremote : QnetRemote.o Random.o UnixDgramSocket.o ConfigureBase.o
g++ $(CPPFLAGS) -o qnremote QnetRemote.o Random.o UnixDgramSocket.o ConfigureBase.o $(LDFLAGS)
qnremote : QnetRemote.o Random.o UnixDgramSocket.o QnetConfigure.o
g++ $(CPPFLAGS) -o qnremote QnetRemote.o Random.o UnixDgramSocket.o QnetConfigure.o $(LDFLAGS)
qnvoice : QnetVoice.o Random.o
g++ $(CPPFLAGS) -o qnvoice QnetVoice.o Random.o $(LDFLAGS)

@ -18,18 +18,19 @@
#include <cstdio>
#include <cstring>
#include "ConfigureBase.h"
#include "QnetConfigure.h"
CConfigureBase::CConfigureBase()
CQnetConfigure::CQnetConfigure()
{
}
CConfigureBase::~CConfigureBase()
CQnetConfigure::~CQnetConfigure()
{
defaults.empty();
cfg.empty();
}
char *CConfigureBase::Trim(char *s)
char *CQnetConfigure::Trim(char *s)
{
size_t len = strlen(s);
while (len && isspace(s[len-1]))
@ -39,7 +40,7 @@ char *CConfigureBase::Trim(char *s)
return s;
}
bool CConfigureBase::ReadConfigFile(const char *configfile, std::map<std::string, std::string> &amap)
bool CQnetConfigure::ReadConfigFile(const char *configfile, std::map<std::string, std::string> &amap)
{
FILE *fp = fopen(configfile, "r");
if (fp) {
@ -64,7 +65,7 @@ bool CConfigureBase::ReadConfigFile(const char *configfile, std::map<std::string
return true;
}
bool CConfigureBase::Initialize(const char *file)
bool CQnetConfigure::Initialize(const char *file)
{
std::string filename(CFG_DIR);
filename.append("/qndefaults");
@ -73,7 +74,7 @@ bool CConfigureBase::Initialize(const char *file)
return ReadConfigFile(file, cfg);
}
bool CConfigureBase::GetDefaultBool(const std::string &path, const std::string &mod, bool &dvalue)
bool CQnetConfigure::GetDefaultBool(const std::string &path, const std::string &mod, bool &dvalue)
{
std::string value;
if (GetDefaultString(path, mod, value))
@ -89,7 +90,7 @@ bool CConfigureBase::GetDefaultBool(const std::string &path, const std::string &
return false;
}
bool CConfigureBase::GetDefaultDouble(const std::string &path, const std::string &mod, double &dvalue)
bool CQnetConfigure::GetDefaultDouble(const std::string &path, const std::string &mod, double &dvalue)
{
std::string value;
if (GetDefaultString(path, mod, value))
@ -98,7 +99,7 @@ bool CConfigureBase::GetDefaultDouble(const std::string &path, const std::string
return false;
}
bool CConfigureBase::GetDefaultInt(const std::string &path, const std::string &mod, int &dvalue)
bool CQnetConfigure::GetDefaultInt(const std::string &path, const std::string &mod, int &dvalue)
{
std::string value;
if (GetDefaultString(path, mod, value))
@ -107,7 +108,7 @@ bool CConfigureBase::GetDefaultInt(const std::string &path, const std::string &m
return false;
}
bool CConfigureBase::GetDefaultString(const std::string &path, const std::string &mod, std::string &dvalue)
bool CQnetConfigure::GetDefaultString(const std::string &path, const std::string &mod, std::string &dvalue)
{
std::string search, search_again;
if (mod.empty()) {
@ -142,7 +143,7 @@ bool CConfigureBase::GetDefaultString(const std::string &path, const std::string
return false;
}
bool CConfigureBase::GetValue(const std::string &path, const std::string &mod, bool &value)
bool CQnetConfigure::GetValue(const std::string &path, const std::string &mod, bool &value)
{
auto it = cfg.find(path);
if (cfg.end() == it) {
@ -167,7 +168,7 @@ bool CConfigureBase::GetValue(const std::string &path, const std::string &mod, b
return false;
}
bool CConfigureBase::GetValue(const std::string &path, const std::string &mod, double &value, const double min, const double max)
bool CQnetConfigure::GetValue(const std::string &path, const std::string &mod, double &value, const double min, const double max)
{
auto it = cfg.find(path);
if (cfg.end() == it) {
@ -192,7 +193,7 @@ bool CConfigureBase::GetValue(const std::string &path, const std::string &mod, d
return false;
}
bool CConfigureBase::GetValue(const std::string &path, const std::string &mod, int &value, const int min, const int max)
bool CQnetConfigure::GetValue(const std::string &path, const std::string &mod, int &value, const int min, const int max)
{
auto it = cfg.find(path);
if (cfg.end() == it) {
@ -217,7 +218,7 @@ bool CConfigureBase::GetValue(const std::string &path, const std::string &mod, i
return false;
}
bool CConfigureBase::GetValue(const std::string &path, const std::string &mod, std::string &value, int min, int max)
bool CQnetConfigure::GetValue(const std::string &path, const std::string &mod, std::string &value, int min, int max)
{
auto it = cfg.find(path);
if (cfg.end() != it) {

@ -21,25 +21,23 @@
#include <string>
#include <map>
class CConfigureBase {
class CQnetConfigure {
public:
CConfigureBase();
virtual ~CConfigureBase();
virtual bool ReadCfgFile() = 0;
CQnetConfigure();
virtual ~CQnetConfigure();
//virtual bool ReadCfgFile() = 0;
bool Initialize(const char *configfile);
protected:
std::map<std::string, std::string> cfg;
char *Trim(char *s);
bool ReadConfigFile(const char *file, std::map<std::string, std::string> &amap);
bool GetValue(const std::string &path, const std::string &mod, bool &value);
bool GetValue(const std::string &path, const std::string &mod, double &value, const double min, const double max);
bool GetValue(const std::string &path, const std::string &mod, int &value, const int min, const int max);
bool GetValue(const std::string &path, const std::string &mod, std::string &value, const int min, const int max);
private:
std::map<std::string, std::string> defaults;
std::map<std::string, std::string> cfg;
char *Trim(char *s);
bool ReadConfigFile(const char *file, std::map<std::string, std::string> &amap);
bool GetDefaultBool (const std::string &key, const std::string &mod, bool &dval);
bool GetDefaultDouble(const std::string &key, const std::string &mod, double &dval);
bool GetDefaultInt (const std::string &key, const std::string &mod, int &dval);

@ -36,7 +36,7 @@
#include "QnetTypeDefs.h"
#include "Random.h"
#include "ConfigureBase.h"
#include "QnetConfigure.h"
#include "UnixDgramSocket.h"
#define VERSION "v2.0"
@ -69,34 +69,32 @@ unsigned short crc_tabccitt[256] = {
0xf78f,0xe606,0xd49d,0xc514,0xb1ab,0xa022,0x92b9,0x8330,0x7bc7,0x6a4e,0x58d5,0x495c,0x3de3,0x2c6a,0x1ef1,0x0f78
};
class CConfigure : public CConfigureBase
CQnetConfigure cfg;
bool ReadCfgFile()
{
public:
bool ReadCfgFile()
{
const std::string estr;
std::string type;
std::string path = "module_";
path.append(1, module);
if (GetValue(path, estr, type, 1, 16)) {
fprintf(stderr, "%s not found!\n", path.c_str());
return true;
}
if (type.compare("dvap") && type.compare("dvrptr") && type.compare("mmdvm") && type.compare("itap")) {
fprintf(stderr, "module type '%s is invalid!\n", type.c_str());
const std::string estr;
std::string type;
std::string path = "module_";
path.append(1, module);
if (cfg.GetValue(path, estr, type, 1, 16)) {
fprintf(stderr, "%s not found!\n", path.c_str());
return true;
}
if (type.compare("dvap") && type.compare("dvrptr") && type.compare("mmdvm") && type.compare("itap")) {
fprintf(stderr, "module type '%s is invalid!\n", type.c_str());
return true;
}
if (cfg.GetValue(path+"_callsign", type, REPEATER, 3, 6)) {
if (cfg.GetValue("ircddb.login", estr, REPEATER, 3, 6)) {
fprintf(stderr, "no Callsign for the repeater was found!\n");
return true;
}
if (GetValue(path+"_callsign", type, REPEATER, 3, 6)) {
if (GetValue("ircddb.login", estr, REPEATER, 3, 6)) {
fprintf(stderr, "no Callsign for the repeater was found!\n");
return true;
}
}
GetValue("timing_play_wait", estr, PLAY_WAIT, 1,10);
GetValue("timing_play_delay", estr, PLAY_DELAY, 15, 25);
return false;
}
};
cfg.GetValue("timing_play_wait", estr, PLAY_WAIT, 1,10);
cfg.GetValue("timing_play_delay", estr, PLAY_DELAY, 15, 25);
return false;
}
void calcPFCS(unsigned char rawbytes[58])
{
@ -161,11 +159,10 @@ int main(int argc, char *argv[])
std::string cfgfile(CFG_DIR);
cfgfile += "/qn.cfg";
CConfigure config;
if (config.Initialize(cfgfile.c_str()))
if (cfg.Initialize(cfgfile.c_str()))
return 1;
if (config.ReadCfgFile())
if (ReadCfgFile())
return 1;
if (REPEATER.size() > 6) {

@ -43,6 +43,8 @@ gateway_regen_header_d=true # regenerate headers from incoming data
gateway_send_qrgs_maps_d=true # send frequency, offset, coordinates and url to irc-server
gateway_external_ip_d='0.0.0.0' # this means accept a connection from any source
gateway_external_port_d=40000 # don't change
gateway_tolink_d='gate2link' # Unix sockets between qngateway and QnetLink
gateway_fromlink_d='link2gate' # all Unix sockets are on the file system, but hidden from view
##########################################################################################################################
#
@ -88,6 +90,12 @@ module_x_latitude=0 # you can leave this unspecified for a mobile rig
module_x_longitude=0 # like the latitude
module_x_desc1='' # maximum of 20 characters, most special symbols are not allowed
module_x_desc2='' # just like desc1
module_x_gate2modem0='gate2modem0' # Unix Sockets between a modem and the gateway
module_x_gate2modem1='gate2modem1' # 0 is for A, 1 is for B and 2 is for C
module_x_gate2modem2='gate2modem2'
module_x_modem2gate0='modem2gate0'
module_x_modem2gate1='modem2gate1'
module_x_modem2gate2='modem2gate2'
module_x_url='github.com/n7tae/g2_ircddb' # 80 characters max
##########################################################################################################################

Loading…
Cancel
Save

Powered by TurnKey Linux.