qnvoice uses QnetConfigure

pull/12/head
Tom Early 7 years ago
parent 538b5942f0
commit 0053338b24

@ -37,7 +37,7 @@ SRCS = $(wildcard *.cpp) $(wildcard $(IRC)/*.cpp)
OBJS = $(SRCS:.cpp=.o) OBJS = $(SRCS:.cpp=.o)
DEPS = $(SRCS:.cpp=.d) DEPS = $(SRCS:.cpp=.d)
ALL_PROGRAMS=qnigateway qngateway qnlink qnremote qnvoice qnrelay qndvap qndvrptr qnitap ALL_PROGRAMS=qngateway qnlink qnremote qnvoice qnrelay qndvap qndvrptr qnitap
MDV_PROGRAMS=qngateway qnlink qnremote qnvoice qnrelay MDV_PROGRAMS=qngateway qnlink qnremote qnvoice qnrelay
DVP_PROGRAMS=qngateway qnlink qnremote qnvoice qndvap DVP_PROGRAMS=qngateway qnlink qnremote qnvoice qndvap
DVR_PROGRAMS=qngateway qnlink qnremote qnvoice qndvrptr DVR_PROGRAMS=qngateway qnlink qnremote qnvoice qndvrptr
@ -70,8 +70,8 @@ qndvrptr : QnetDVRPTR.o $(DSTROBJS) Random.o UnixDgramSocket.o QnetConfigure.o
qnremote : QnetRemote.o Random.o UnixDgramSocket.o QnetConfigure.o qnremote : QnetRemote.o Random.o UnixDgramSocket.o QnetConfigure.o
g++ $(CPPFLAGS) -o qnremote QnetRemote.o Random.o UnixDgramSocket.o QnetConfigure.o $(LDFLAGS) g++ $(CPPFLAGS) -o qnremote QnetRemote.o Random.o UnixDgramSocket.o QnetConfigure.o $(LDFLAGS)
qnvoice : QnetVoice.o Random.o qnvoice : QnetVoice.o Random.o QnetConfigure.o
g++ $(CPPFLAGS) -o qnvoice QnetVoice.o Random.o $(LDFLAGS) g++ $(CPPFLAGS) -o qnvoice QnetVoice.o Random.o QnetConfigure.o $(LDFLAGS)
%.o : %.cpp %.o : %.cpp
g++ $(CPPFLAGS) -MMD -MD -c $< -o $@ g++ $(CPPFLAGS) -MMD -MD -c $< -o $@

@ -22,84 +22,28 @@
#include <stdlib.h> #include <stdlib.h>
#include <string> #include <string>
#include <libconfig.h++> #include "QnetConfigure.h"
using namespace libconfig;
bool isamod[3] = { false, false, false }; bool isamod[3] = { false, false, false };
std::string announce_dir; std::string announce_dir;
std::string qnvoice_file; std::string qnvoice_file;
bool get_value(const Config &cfg, const char *path, int &value, int min, int max, int default_value)
{
if (cfg.lookupValue(path, value)) {
if (value < min || value > max)
value = default_value;
} else
value = default_value;
printf("%s = [%d]\n", path, value);
return true;
}
bool get_value(const Config &cfg, const char *path, double &value, double min, double max, double default_value)
{
if (cfg.lookupValue(path, value)) {
if (value < min || value > max)
value = default_value;
} else
value = default_value;
printf("%s = [%lg]\n", path, value);
return true;
}
bool get_value(const Config &cfg, const char *path, bool &value, bool default_value)
{
if (! cfg.lookupValue(path, value))
value = default_value;
printf("%s = [%s]\n", path, value ? "true" : "false");
return true;
}
bool get_value(const Config &cfg, const char *path, std::string &value, int min, int max, const char *default_value)
{
if (cfg.lookupValue(path, value)) {
int l = value.length();
if (l<min || l>max) {
printf("%s is invalid\n", path);
return false;
}
} else
value = default_value;
printf("%s = [%s]\n", path, value.c_str());
return true;
}
/* process configuration file */ /* process configuration file */
bool read_config(const char *cfgFile) bool read_config(const char *cfgFile)
{ {
Config cfg; CQnetConfigure cfg;
printf("Reading file %s\n", cfgFile); printf("Reading file %s\n", cfgFile);
// Read the file. If there is an error, report it and exit. if (cfg.Initialize(cfgFile))
try {
cfg.readFile(cfgFile);
} catch(const FileIOException &fioex) {
printf("Can't read %s\n", cfgFile);
return true; return true;
} catch(const ParseException &pex) {
printf("Parse error at %s:%d - %s\n", pex.getFile(), pex.getLine(), pex.getError());
return true;
}
for (short int m=0; m<3; m++) { for (int m=0; m<3; m++) {
std::string path = "module."; std::string path("module_");
path += m + 'a'; path.append(std::to_string(m));
std::string type; std::string type;
if (cfg.lookupValue(std::string(path+".type").c_str(), type)) { if (cfg.KeyExists(path)) {
if (strcasecmp(type.c_str(), "dvap") && strcasecmp(type.c_str(), "dvrptr") && strcasecmp(type.c_str(), "mmdvm") && cfg.GetValue(path, "", type, 1, 16);
strcasecmp(type.c_str(), "icom") && strcasecmp(type.c_str(), "itap")) { if (strcasecmp(type.c_str(), "dvap") && strcasecmp(type.c_str(), "dvrptr") && strcasecmp(type.c_str(), "mmdvm") && strcasecmp(type.c_str(), "itap")) {
printf("module type '%s' is invalid\n", type.c_str()); printf("module type '%s' is invalid\n", type.c_str());
return true; return true;
} }
@ -107,9 +51,9 @@ bool read_config(const char *cfgFile)
} }
} }
get_value(cfg, "file.announce_dir", announce_dir, 2, FILENAME_MAX, "/usr/local/etc"); std::string path("file_");
cfg.GetValue(path+"announce_dir", "", announce_dir, 2, FILENAME_MAX);
get_value(cfg, "file.qnvoice_file", qnvoice_file, 2, FILENAME_MAX, "/tmp/qnvoice.txt"); cfg.GetValue(path+"qnvoice_file", "", qnvoice_file, 2, FILENAME_MAX);
return false; return false;
} }
@ -134,13 +78,13 @@ int main(int argc, char *argv[])
printf(" <txtMsg> is an up to 20-character text message\n"); printf(" <txtMsg> is an up to 20-character text message\n");
return 0; return 0;
} }
char module = argv[1][0];
std::string cfgfile(CFG_DIR); std::string cfgfile(CFG_DIR);
cfgfile += "/qn.cfg"; cfgfile += "/qn.cfg";
if (read_config(cfgfile.c_str())) if (read_config(cfgfile.c_str()))
return 1; return 1;
char module = argv[1][0];
if (islower(module)) if (islower(module))
module = toupper(module); module = toupper(module);
if ((module != 'A') && (module != 'B') && (module != 'C')) { if ((module != 'A') && (module != 'B') && (module != 'C')) {

Loading…
Cancel
Save

Powered by TurnKey Linux.