From beb8851578bf0c2c7cf4614e7106d04ab8a30518 Mon Sep 17 00:00:00 2001 From: Tom Early Date: Sat, 22 Dec 2018 13:58:52 -0700 Subject: [PATCH] simplified cfg class --- Makefile | 28 +++++++------- ConfigureBase.cpp => QnetConfigure.cpp | 29 +++++++------- ConfigureBase.h => QnetConfigure.h | 18 ++++----- QnetRemote.cpp | 53 ++++++++++++-------------- defaults | 8 ++++ 5 files changed, 70 insertions(+), 66 deletions(-) rename ConfigureBase.cpp => QnetConfigure.cpp (89%) rename ConfigureBase.h => QnetConfigure.h (94%) diff --git a/Makefile b/Makefile index 76c8dc4..8fabab5 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/ConfigureBase.cpp b/QnetConfigure.cpp similarity index 89% rename from ConfigureBase.cpp rename to QnetConfigure.cpp index 7583bb2..3d4f813 100644 --- a/ConfigureBase.cpp +++ b/QnetConfigure.cpp @@ -18,18 +18,19 @@ #include #include -#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 &amap) +bool CQnetConfigure::ReadConfigFile(const char *configfile, std::map &amap) { FILE *fp = fopen(configfile, "r"); if (fp) { @@ -64,7 +65,7 @@ bool CConfigureBase::ReadConfigFile(const char *configfile, std::map #include -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 cfg; - - char *Trim(char *s); - bool ReadConfigFile(const char *file, std::map &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 defaults; + std::map cfg; + char *Trim(char *s); + bool ReadConfigFile(const char *file, std::map &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); diff --git a/QnetRemote.cpp b/QnetRemote.cpp index 8f94cac..7d72e14 100644 --- a/QnetRemote.cpp +++ b/QnetRemote.cpp @@ -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) { diff --git a/defaults b/defaults index 6847e00..0a50f56 100644 --- a/defaults +++ b/defaults @@ -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 ##########################################################################################################################