aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2014-02-14 11:14:41 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2014-02-14 11:14:41 +0100
commit6b9857cb1b2ab6b58e6e42df4b0cce54448b10a0 (patch)
treea59216616d9fd1d0c6468bdc300f9b6c9b6a04e1
parent00f1d412ad410eca7e4032686b907c5e8f7915ec (diff)
downloaddabmux-6b9857cb1b2ab6b58e6e42df4b0cce54448b10a0.tar.gz
dabmux-6b9857cb1b2ab6b58e6e42df4b0cce54448b10a0.tar.bz2
dabmux-6b9857cb1b2ab6b58e6e42df4b0cce54448b10a0.zip
improve handling of labels
-rw-r--r--src/DabMux.cpp30
-rw-r--r--src/DabMux.h6
-rw-r--r--src/MuxElements.cpp86
-rw-r--r--src/MuxElements.h56
-rw-r--r--src/ParserCmdline.cpp156
-rw-r--r--src/ParserConfigfile.cpp188
-rw-r--r--src/ParserConfigfile.h7
-rw-r--r--src/utils.cpp25
8 files changed, 278 insertions, 276 deletions
diff --git a/src/DabMux.cpp b/src/DabMux.cpp
index 5fb9c17..b7095c6 100644
--- a/src/DabMux.cpp
+++ b/src/DabMux.cpp
@@ -3,8 +3,8 @@
2011, 2012 Her Majesty the Queen in Right of Canada (Communications
Research Center Canada)
- Includes modifications
- 2012, Matthias P. Braendli, matthias.braendli@mpb.li
+ Copyright (C) 2014
+ Matthias P. Braendli, matthias.braendli@mpb.li
*/
/*
This file is part of ODR-DabMux.
@@ -269,9 +269,8 @@ int main(int argc, char *argv[])
dabEnsemble* ensemble = new dabEnsemble;
- strncpy(ensemble->label.text, DEFAULT_ENSEMBLE_LABEL, 16);
+ ensemble->label.setLabel(DEFAULT_ENSEMBLE_LABEL, DEFAULT_ENSEMBLE_SHORT_LABEL);
ensemble->mode = DEFAULT_DAB_MODE;
- ensemble->label.flag = DEFAULT_ENSEMBLE_SHORT_LABEL;
ensemble->id = DEFAULT_ENSEMBLE_ID;
ensemble->ecc = DEFAULT_ENSEMBLE_ECC;
@@ -1470,11 +1469,11 @@ int main(int argc, char *argv[])
fig1_0->EId = htons(ensemble->id);
index = index + 4;
- memcpy(&etiFrame[index], ensemble->label.text, 16);
+ memcpy(&etiFrame[index], ensemble->label.text(), 16);
index = index + 16;
- etiFrame[index++] = ((char *) &ensemble->label.flag)[1];
- etiFrame[index++] = ((char *) &ensemble->label.flag)[0];
+ etiFrame[index++] = ensemble->label.flag() >> 8;
+ etiFrame[index++] = ensemble->label.flag() & 0xFF;
figSize += 22;
break;
@@ -1601,7 +1600,7 @@ int main(int argc, char *argv[])
if (alterneFIB < ensemble->services.size()) {
service = ensemble->services.begin() + alterneFIB;
- // FIG type 1/1, SI, Service label, une instance par sous-canal
+ // FIG type 1/1, SI, Service label, one instance per subchannel
if ((*service)->getType(ensemble) == 0) {
fig1_1 = (FIGtype1_1 *) & etiFrame[index];
@@ -1626,12 +1625,11 @@ int main(int argc, char *argv[])
index += 6;
figSize += 6;
}
- memcpy(&etiFrame[index], (*service)->label.text, 16);
+ memcpy(&etiFrame[index], (*service)->label.text(), 16);
index += 16;
figSize += 16;
-
- etiFrame[index++] = ((char *) &(*service)->label.flag)[1];
- etiFrame[index++] = ((char *) &(*service)->label.flag)[0];
+ etiFrame[index++] = (*service)->label.flag() >> 8;
+ etiFrame[index++] = (*service)->label.flag() & 0xFF;
figSize += 2;
} else if (alterneFIB <
ensemble->services.size() + ensemble->components.size()) {
@@ -1641,7 +1639,7 @@ int main(int argc, char *argv[])
subchannel =
getSubchannel(ensemble->subchannels, (*component)->subchId);
- if ((*component)->label.text[0] != 0) {
+ if ((*component)->label.text()[0] != 0) {
if ((*service)->getType(ensemble) == 0) { // Programme
FIGtype1_4_programme *fig1_4;
fig1_4 = (FIGtype1_4_programme*)&etiFrame[index];
@@ -1674,12 +1672,12 @@ int main(int argc, char *argv[])
index += 7;
figSize += 7;
}
- memcpy(&etiFrame[index], (*component)->label.text, 16);
+ memcpy(&etiFrame[index], (*component)->label.text(), 16);
index += 16;
figSize += 16;
- etiFrame[index++] = ((char *) &(*component)->label.flag)[1];
- etiFrame[index++] = ((char *) &(*component)->label.flag)[0];
+ etiFrame[index++] = (*component)->label.flag() >> 8;
+ etiFrame[index++] = (*component)->label.flag() & 0xFF;
figSize += 2;
}
}
diff --git a/src/DabMux.h b/src/DabMux.h
index 8811771..eeff13d 100644
--- a/src/DabMux.h
+++ b/src/DabMux.h
@@ -3,8 +3,8 @@
2011 Her Majesty the Queen in Right of Canada (Communications
Research Center Canada)
- Includes modifications
- 2012, Matthias P. Braendli, matthias.braendli@mpb.li
+ Copyright (C) 2014
+ Matthias P. Braendli, matthias.braendli@mpb.li
This file declares several structures used in the multiplexer,
and defines default values for some parameters.
@@ -57,7 +57,7 @@
// Etiquettes des sous-canaux et de l'ensemble, 16 characteres incluant les
// espaces
#define DEFAULT_ENSEMBLE_LABEL "ODR Dab Mux"
-#define DEFAULT_ENSEMBLE_SHORT_LABEL 0xe000
+#define DEFAULT_ENSEMBLE_SHORT_LABEL "ODRMux"
#define DEFAULT_ENSEMBLE_ID 0xc000
#define DEFAULT_ENSEMBLE_ECC 0xa1
diff --git a/src/MuxElements.cpp b/src/MuxElements.cpp
index aa5a401..3ac63e3 100644
--- a/src/MuxElements.cpp
+++ b/src/MuxElements.cpp
@@ -42,6 +42,92 @@ const unsigned short Sub_Channel_SizeTable[64] = {
using namespace std;
+int DabLabel::setLabel(const std::string& text)
+{
+ int len = text.length();
+ if (len > 16)
+ return -3;
+
+ memset(m_text, 0, 16);
+ memcpy(m_text, text.c_str(), len);
+
+ return 0;
+}
+
+int DabLabel::setLabel(const std::string& text, const std::string& short_label)
+{
+ DabLabel newlabel;
+
+ memset(newlabel.m_text, 0, 16);
+ int len = text.length();
+ if (len > 16)
+ return -3;
+ memcpy(newlabel.m_text, text.c_str(), len);
+
+ /* First check if we can actually create the short label */
+ int flag = newlabel.setShortLabel(short_label);
+ if (flag < 0)
+ return flag;
+
+ // short label is valid.
+ memcpy(this->m_text, newlabel.m_text, len);
+ this->m_flag = flag & 0xFFFF;
+
+ return 0;
+}
+
+/* The label.flag is a 16bit mask that tells which label
+ * characters are to be used for the short label
+ *
+ * From EN 300 401, clause 5.2.2.2.1:
+ *
+ * Character flag field: this 16-bit flag field shall indicate which of the
+ * characters of the character field are to be
+ * displayed in an abbreviated form of the label, as follows:
+ * bi: (i = 0, ... ,15);
+ * 0: not to be displayed in abbreviated label;
+ * 1: to be displayed in abbreviated label.
+ * NOTE: Not more than 8 of the bi may be set to "1".
+ *
+ * returns: the flag (16 bits) on success
+ * -1 if the short_label is not a representable
+ * -2 if the short_label is too long
+ */
+int DabLabel::setShortLabel(const std::string& slabel)
+{
+ char* end;
+ const char* lab;
+ uint16_t flag;
+ flag = strtoul(slabel.c_str(), &end, 0);
+ if (*end != 0) {
+ lab = slabel.c_str();
+ flag = 0;
+ for (int i = 0; i < 32; ++i) {
+ if (*lab == this->m_text[i]) {
+ flag |= 0x8000 >> i;
+ if (*(++lab) == 0) {
+ break;
+ }
+ }
+ }
+ if (*lab != 0) {
+ return -1;
+ }
+ }
+ int count = 0;
+ for (int i = 0; i < 16; ++i) {
+ if (flag & (1 << i)) {
+ ++count;
+ }
+ }
+ if (count > 8) {
+ return -2;
+ }
+
+ return flag;
+}
+
+
vector<dabSubchannel*>::iterator getSubchannel(
vector<dabSubchannel*>& subchannels, int id)
{
diff --git a/src/MuxElements.h b/src/MuxElements.h
index 09f969d..9658fb2 100644
--- a/src/MuxElements.h
+++ b/src/MuxElements.h
@@ -3,8 +3,8 @@
2011, 2012 Her Majesty the Queen in Right of Canada (Communications
Research Center Canada)
- Includes modifications
- 2012, Matthias P. Braendli, matthias.braendli@mpb.li
+ Copyright (C) 2014
+ Matthias P. Braendli, matthias.braendli@mpb.li
This file defines all data structures used in DabMux to represent
and save ensemble data.
@@ -29,6 +29,7 @@
#define _MUX_ELEMENTS
#include <vector>
+#include <string>
#include <functional>
#include <algorithm>
#include <stdint.h>
@@ -52,9 +53,32 @@ struct dabOutput {
};
-struct dabLabel {
- char text[16];
- uint16_t flag;
+class DabLabel
+{
+ public:
+ /* Set a new label and short label.
+ * returns: 0 on success
+ * -1 if the short_label is not a representable
+ * -2 if the short_label is too long
+ * -3 if the text is too long
+ */
+ int setLabel(const std::string& text, const std::string& short_label);
+
+ /* Same as above, but sets the flag to 0xff00, truncating at 8
+ * characters.
+ *
+ * returns: 0 on success
+ * -3 if the text is too long
+ */
+ int setLabel(const std::string& text);
+
+ const char* text() const { return m_text; }
+ uint16_t flag() const { return m_flag; }
+
+ private:
+ char m_text[16];
+ uint16_t m_flag;
+ int setShortLabel(const std::string& slabel);
};
@@ -64,7 +88,7 @@ struct dabSubchannel;
struct dabEnsemble {
uint16_t id;
uint8_t ecc;
- dabLabel label;
+ DabLabel label;
uint8_t mode;
vector<dabService*> services;
vector<dabComponent*> components;
@@ -136,7 +160,7 @@ struct dabPacketComponent {
struct dabComponent {
- dabLabel label;
+ DabLabel label;
uint32_t serviceId;
uint8_t subchId;
uint8_t type;
@@ -153,15 +177,17 @@ struct dabComponent {
-struct dabService {
- dabLabel label;
- uint32_t id;
- unsigned char pty;
- unsigned char language;
- bool program;
+struct dabService
+{
+ uint32_t id;
+ unsigned char pty;
+ unsigned char language;
+ bool program;
- unsigned char getType(dabEnsemble* ensemble);
- unsigned char nbComponent(vector<dabComponent*>& components);
+ unsigned char getType(dabEnsemble* ensemble);
+ unsigned char nbComponent(vector<dabComponent*>& components);
+
+ DabLabel label;
};
vector<dabSubchannel*>::iterator getSubchannel(
diff --git a/src/ParserCmdline.cpp b/src/ParserCmdline.cpp
index 4da495b..9985d9a 100644
--- a/src/ParserCmdline.cpp
+++ b/src/ParserCmdline.cpp
@@ -111,6 +111,9 @@ bool parse_cmdline(char **argv,
int scids_temp = 0;
+ const char* error_at = "";
+ int success;
+
char* progName = strrchr(argv[0], '/');
if (progName == NULL) {
progName = argv[0];
@@ -153,10 +156,7 @@ bool parse_cmdline(char **argv,
service = ensemble->services.end() - 1;
output = outputs.end();
- memset((*service)->label.text, 0, 16);
- sprintf((*service)->label.text, "CRC-Service%i",
- (int)ensemble->services.size());
- (*service)->label.flag = 0xe01f;
+ (*service)->label.setLabel("Service", "Serv");
(*service)->id = DEFAULT_SERVICE_ID + ensemble->services.size();
(*service)->pty = 0;
(*service)->language = 0;
@@ -178,9 +178,7 @@ bool parse_cmdline(char **argv,
protection = NULL;
output = outputs.end();
- memset(*component, 0, sizeof(dabComponent));
- memset((*component)->label.text, 0, 16);
- (*component)->label.flag = 0xffff;
+ (*component)->label.setLabel("Component", "Comp");
(*component)->serviceId = (*service)->id;
(*component)->subchId = (*(ensemble->subchannels.end() - 1))->id;
(*component)->SCIdS = scids_temp++;
@@ -399,20 +397,12 @@ bool parse_cmdline(char **argv,
goto EXIT;
}
if (service == ensemble->services.end()) {
- memset(ensemble->label.text, 0, 16);
- strncpy(ensemble->label.text, optarg, 16);
- ensemble->label.flag = 0xff00;
+ ensemble->label.setLabel(optarg);
} else if (component != ensemble->components.end()) {
- memset((*component)->label.text, 0, 16);
- strncpy((*component)->label.text, optarg, 16);
- (*component)->label.flag = 0xff00;
+ (*component)->label.setLabel(optarg);
} else { // Service
- memset((*service)->label.text, 0, 16);
- strncpy((*service)->label.text, optarg, 16);
- (*service)->label.flag = 0xff00;
+ (*service)->label.setLabel(optarg);
}
- // TODO Check strlen before doing short label
- // TODO Check if short label already set
break;
case 'V':
goto EXIT;
@@ -423,108 +413,40 @@ bool parse_cmdline(char **argv,
printUsage(progName);
goto EXIT;
}
+
if (service == ensemble->services.end()) {
- char* end;
- ensemble->label.flag = strtoul(optarg, &end, 0);
- if (*end != 0) {
- end = optarg;
- ensemble->label.flag = 0;
- for (int i = 0; i < 32; ++i) {
- if (*end == ensemble->label.text[i]) {
- ensemble->label.flag |= 0x8000 >> i;
- if (*(++end) == 0) {
- break;
- }
- }
- }
- if (*end != 0) {
- etiLog.log(error,
- "Error at '%c' in ensemble short label '%s'!\n"
- "Not in label '%s'!\n",
- *end, optarg, ensemble->label.text);
- goto EXIT;
- }
- }
- int count = 0;
- for (int i = 0; i < 16; ++i) {
- if (ensemble->label.flag & (1 << i)) {
- ++count;
- }
- }
- if (count > 8) {
- etiLog.log(error,
- "Ensemble short label too long!\n"
- "Must be < 8 characters.\n");
+ success = ensemble->label.setLabel(ensemble->label.text(), optarg);
+ error_at = "Ensemble";
+ }
+ else if (component != ensemble->components.end()) {
+ success = (*component)->label.setLabel(ensemble->label.text(), optarg);
+ error_at = "Component";
+ }
+ else {
+ success = (*service)->label.setLabel(ensemble->label.text(), optarg);
+ error_at = "Service";
+ }
+
+ switch (success)
+ {
+ case 0:
+ break;
+ case -1:
+ etiLog.level(error) << error_at << " short label " <<
+ optarg << " is not subset of label '" <<
+ ensemble->label.text() << "'";
goto EXIT;
- }
- } else if (component != ensemble->components.end()) {
- char* end;
- (*component)->label.flag = strtoul(optarg, &end, 0);
- if (*end != 0) {
- end = optarg;
- (*component)->label.flag = 0;
- for (int i = 0; i < 32; ++i) {
- if (*end == (*component)->label.text[i]) {
- (*component)->label.flag |= 0x8000 >> i;
- if (*(++end) == 0) {
- break;
- }
- }
- }
- if (*end != 0) {
- etiLog.log(error,
- "Error at '%c' in component short label '%s'!\n"
- "Not in label '%s'!\n",
- *end, optarg, (*component)->label.text);
- goto EXIT;
- }
- }
- int count = 0;
- for (int i = 0; i < 16; ++i) {
- if ((*component)->label.flag & (1 << i)) {
- ++count;
- }
- }
- if (count > 8) {
- etiLog.log(error,
- "Service '%s' short label too long!\n"
- "Must be < 8 characters.\n", (*component)->label.text);
+ case -2:
+ etiLog.level(error) << error_at << " short label " <<
+ optarg << " is too long (max 8 characters)";
goto EXIT;
- }
- } else {
- char* end;
- (*service)->label.flag = strtoul(optarg, &end, 0);
- if (*end != 0) {
- end = optarg;
- (*service)->label.flag = 0;
- for (int i = 0; i < 32; ++i) {
- if (*end == (*service)->label.text[i]) {
- (*service)->label.flag |= 0x8000 >> i;
- if (*(++end) == 0) {
- break;
- }
- }
- }
- if (*end != 0) {
- etiLog.log(error,
- "Error at '%c' in service short label '%s'!\n"
- "Not in label '%s'!\n",
- *end, optarg, (*service)->label.text);
- goto EXIT;
- }
- }
- int count = 0;
- for (int i = 0; i < 16; ++i) {
- if ((*service)->label.flag & (1 << i)) {
- ++count;
- }
- }
- if (count > 8) {
- etiLog.log(error,
- "Service '%s' short label too long!\n"
- "Must be < 8 characters.\n", (*service)->label.text);
+ case -3:
+ etiLog.level(error) << error_at << " label " <<
+ ensemble->label.text() << " is too long (max 16 characters)";
goto EXIT;
- }
+ default:
+ etiLog.level(error) << error_at << " short label definition: program error !";
+ abort();
}
break;
case 'i':
@@ -828,5 +750,5 @@ bool parse_cmdline(char **argv,
return true;
EXIT:
return false;
-
}
+
diff --git a/src/ParserConfigfile.cpp b/src/ParserConfigfile.cpp
index 9939e22..9262ed3 100644
--- a/src/ParserConfigfile.cpp
+++ b/src/ParserConfigfile.cpp
@@ -3,8 +3,8 @@
2011, 2012 Her Majesty the Queen in Right of Canada (Communications
Research Center Canada)
- Written by
- Matthias P. Braendli, matthias.braendli@mpb.li, 2012
+ Copyright (C) 2014
+ Matthias P. Braendli, matthias.braendli@mpb.li
The command-line parser reads settings from a configuration file
whose definition is given in doc/example.config
@@ -121,58 +121,6 @@ int hexparse(std::string input)
}
-/* The label.flag is a 16bit mask that tells which label
- * characters are to be used for the short label
- *
- * From EN 300 401, clause 5.2.2.2.1:
- *
- * Character flag field: this 16-bit flag field shall indicate which of the
- * characters of the character field are to be
- * displayed in an abbreviated form of the label, as follows:
- * bi: (i = 0, ... ,15);
- * 0: not to be displayed in abbreviated label;
- * 1: to be displayed in abbreviated label.
- * NOTE: Not more than 8 of the bi may be set to "1".
- */
-void set_short_label(dabLabel& label, std::string& slabel,
- const char* applies_to)
-{
- char* end;
- const char* lab;
- label.flag = strtoul(slabel.c_str(), &end, 0);
- if (*end != 0) {
- lab = slabel.c_str();
- label.flag = 0;
- for (int i = 0; i < 32; ++i) {
- if (*lab == label.text[i]) {
- label.flag |= 0x8000 >> i;
- if (*(++lab) == 0) {
- break;
- }
- }
- }
- if (*lab != 0) {
- stringstream ss;
- ss << "Error : " << applies_to << " short label '" << slabel <<
- "' not subset of '" << label.text << "' !\n";
- throw runtime_error(ss.str());
- }
- }
- int count = 0;
- for (int i = 0; i < 16; ++i) {
- if (label.flag & (1 << i)) {
- ++count;
- }
- }
- if (count > 8) {
- stringstream ss;
- ss << applies_to << " '" << slabel << "' short label too long!\n"
- "Must be less than 8 characters.\n";
- throw runtime_error(ss.str());
- }
-
-}
-
void parse_configfile(string configuration_file,
vector<dabOutput*> &outputs,
dabEnsemble* ensemble,
@@ -242,16 +190,31 @@ void parse_configfile(string configuration_file,
/* Extended Country Code */
ensemble->ecc = hexparse(pt_ensemble.get("ecc", "0"));
- string label = pt_ensemble.get("label", "");
- memset(ensemble->label.text, 0, 16);
- label.copy(ensemble->label.text, 16);
- ensemble->label.flag = 0xff00;
-
- try {
- string label = pt_ensemble.get<string>("shortlabel");
- set_short_label(ensemble->label, label, "Ensemble");
+ string label = pt_ensemble.get<string>("label");
+ string short_label = pt_ensemble.get<string>("shortlabel");
+ int success = ensemble->label.setLabel(label, short_label);
+ switch (success)
+ {
+ case 0:
+ break;
+ case -1:
+ etiLog.level(error) << "Ensemble short label " <<
+ short_label << " is not subset of label '" <<
+ label << "'";
+ throw runtime_error("ensemble label definition error");
+ case -2:
+ etiLog.level(error) << "Ensemble short label " <<
+ short_label << " is too long (max 8 characters)";
+ throw runtime_error("ensemble label definition error");
+ case -3:
+ etiLog.level(error) << "Ensemble label " <<
+ label << " is too long (max 16 characters)";
+ throw runtime_error("ensemble label definition error");
+ default:
+ etiLog.level(error) <<
+ "Ensemble short label definition: program error !";
+ abort();
}
- catch (ptree_error &e) { }
/******************** READ SERVICES PARAMETERS *************/
@@ -269,25 +232,30 @@ void parse_configfile(string configuration_file,
dabService* service = new dabService();
ensemble->services.push_back(service);
- memset(service->label.text, 0, 16);
- try {
- string servicelabel = pt_service.get<string>("label");
- servicelabel.copy(service->label.text, 16);
- }
- catch (ptree_error &e)
+ string servicelabel = pt_service.get<string>("label");
+ string serviceshortlabel = pt_service.get<string>("shortlabel");
+ int success = service->label.setLabel(label, short_label);
+ switch (success)
{
- sprintf(service->label.text, "CRC-Service%i",
- (int)ensemble->services.size());
- }
- service->label.flag = 0xe01f;
-
- try {
- string label = pt_service.get<string>("shortlabel");
- set_short_label(service->label, label, "Service");
- }
- catch (ptree_error &e) {
- etiLog.log(warn,
- "Service with uid %s has no short label.\n", serviceuid.c_str());
+ case 0:
+ break;
+ case -1:
+ etiLog.level(error) << "Service short label " <<
+ serviceshortlabel << " is not subset of label '" <<
+ servicelabel << "'";
+ throw runtime_error("service label definition error");
+ case -2:
+ etiLog.level(error) << "Service short label " <<
+ serviceshortlabel << " is too long (max 8 characters)";
+ throw runtime_error("service label definition error");
+ case -3:
+ etiLog.level(error) << "Service label " <<
+ servicelabel << " is too long (max 16 characters)";
+ throw runtime_error("service label definition error");
+ default:
+ etiLog.level(error) <<
+ "Service short label definition: program error !";
+ abort();
}
stringstream def_serviceid;
@@ -322,7 +290,8 @@ void parse_configfile(string configuration_file,
ensemble->subchannels.push_back(subchan);
try {
- setup_subchannel_from_ptree(subchan, it->second, ensemble, subchanuid, rc);
+ setup_subchannel_from_ptree(subchan, it->second, ensemble,
+ subchanuid, rc);
}
catch (runtime_error &e) {
etiLog.log(error,
@@ -391,44 +360,49 @@ void parse_configfile(string configuration_file,
dabComponent* component = new dabComponent();
memset(component, 0, sizeof(dabComponent));
- memset(component->label.text, 0, 16);
- component->label.flag = 0xffff;
component->serviceId = service->id;
component->subchId = subchannel->id;
component->SCIdS = SCIdS_per_service[service]++;
component->type = component_type;
- try {
- string label = pt_comp.get<string>("label");
-
- memset(component->label.text, 0, 16);
- label.copy(component->label.text, 16);
- component->label.flag = 0xff00;
- }
- catch (ptree_error &e) {
- etiLog.log(warn,
- "Service with uid %s has no label.\n", componentuid.c_str());
- }
-
- try {
- string label = pt_comp.get<string>("shortlabel");
- set_short_label(component->label, label, "Component");
- }
- catch (ptree_error &e) {
- etiLog.log(warn,
- "Component with uid %s has no short label.\n", componentuid.c_str());
+ string componentlabel = pt_comp.get<string>("label");
+ string componentshortlabel = pt_comp.get<string>("shortlabel");
+ int success = component->label.setLabel(label, short_label);
+ switch (success)
+ {
+ case 0:
+ break;
+ case -1:
+ etiLog.level(error) << "Component short label " <<
+ componentshortlabel << " is not subset of label '" <<
+ componentlabel << "'";
+ throw runtime_error("component label definition error");
+ case -2:
+ etiLog.level(error) << "Component short label " <<
+ componentshortlabel << " is too long (max 8 characters)";
+ throw runtime_error("component label definition error");
+ case -3:
+ etiLog.level(error) << "Component label " <<
+ componentlabel << " is too long (max 16 characters)";
+ throw runtime_error("component label definition error");
+ default:
+ etiLog.level(error) <<
+ "Component short label definition: program error !";
+ abort();
}
if (figType != -1) {
if (! component->isPacketComponent(ensemble->subchannels)) {
stringstream ss;
- ss << "Component with uid " << componentuid << " is not packet, cannot have figtype defined !";
+ ss << "Component with uid " << componentuid <<
+ " is not packet, cannot have figtype defined !";
throw runtime_error(ss.str());
}
if (figType >= (1<<12)) {
stringstream ss;
- ss << "Component with uid " << componentuid << ": figtype '" << figType << "' is too large !";
+ ss << "Component with uid " << componentuid <<
+ ": figtype '" << figType << "' is too large !";
throw runtime_error(ss.str());
}
@@ -438,14 +412,14 @@ void parse_configfile(string configuration_file,
if (packet_address != -1) {
if (! component->isPacketComponent(ensemble->subchannels)) {
stringstream ss;
- ss << "Component with uid " << componentuid << " is not packet, cannot have address defined !";
+ ss << "Component with uid " << componentuid <<
+ " is not packet, cannot have address defined !";
throw runtime_error(ss.str());
}
component->packet.address = packet_address;
}
-
ensemble->components.push_back(component);
}
diff --git a/src/ParserConfigfile.h b/src/ParserConfigfile.h
index 11817e3..f987542 100644
--- a/src/ParserConfigfile.h
+++ b/src/ParserConfigfile.h
@@ -3,8 +3,8 @@
2011, 2012 Her Majesty the Queen in Right of Canada (Communications
Research Center Canada)
- Written by
- Matthias P. Braendli, matthias.braendli@mpb.li, 2012
+ Copyright (C) 2014
+ Matthias P. Braendli, matthias.braendli@mpb.li
The command-line parser reads settings from a configuration file
whose definition is given in doc/example.config
@@ -33,9 +33,6 @@
#include "MuxElements.h"
#include <boost/property_tree/ptree.hpp>
-void set_short_label(dabLabel& label, std::string& slabel,
- const char* applies_to);
-
void parse_configfile(std::string configuration_file,
vector<dabOutput*> &outputs,
dabEnsemble* ensemble,
diff --git a/src/utils.cpp b/src/utils.cpp
index 149d369..b837009 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -303,7 +303,7 @@ void printServices(vector<dabService*>& services)
for (current = services.begin(); current != services.end(); ++current) {
char label[17];
- memcpy(label, (*current)->label.text, 16);
+ memcpy(label, (*current)->label.text(), 16);
label[16] = 0;
etiLog.log(info, "Service %i\n", index);
@@ -312,12 +312,12 @@ void printServices(vector<dabService*>& services)
{
LogLine line = etiLog.level(info);
for (int i = 0; i < 32; ++i) {
- if ((*current)->label.flag & 0x8000 >> i) {
- line << (*current)->label.text[i];
+ if ((*current)->label.flag() & 0x8000 >> i) {
+ line << label[i];
}
}
}
- etiLog.log(info, " (0x%x)\n", (*current)->label.flag);
+ etiLog.log(info, " (0x%x)\n", (*current)->label.flag());
etiLog.log(info, " id: 0x%lx (%lu)\n",
(*current)->id, (*current)->id);
etiLog.log(info, " pty: 0x%x (%u)\n",
@@ -343,7 +343,7 @@ void printComponents(vector<dabComponent*>& components)
void printComponent(dabComponent* component)
{
char label[17];
- memcpy(label, component->label.text, 16);
+ memcpy(label, component->label.text(), 16);
label[16] = 0;
if (label[0] == 0) {
sprintf(label, "<none>");
@@ -359,12 +359,12 @@ void printComponent(dabComponent* component)
{
LogLine line = etiLog.level(info);
for (int i = 0; i < 32; ++i) {
- if (component->label.flag & 0x8000 >> i) {
- line << component->label.text[i];
+ if (component->label.flag() & 0x8000 >> i) {
+ line << label[i];
}
}
}
- etiLog.log(info, " (0x%x)\n", component->label.flag);
+ etiLog.log(info, " (0x%x)\n", component->label.flag());
etiLog.log(info, " service component type: 0x%x (%u)\n",
component->type, component->type);
etiLog.log(info, " (packet) id: %u\n",
@@ -443,7 +443,7 @@ void printSubchannels(vector<dabSubchannel*>& subchannels)
void printEnsemble(dabEnsemble* ensemble)
{
char label[17];
- memcpy(label, ensemble->label.text, 16);
+ memcpy(label, ensemble->label.text(), 16);
label[16] = 0;
etiLog.log(info, "Ensemble\n");
@@ -456,14 +456,13 @@ void printEnsemble(dabEnsemble* ensemble)
LogLine line = etiLog.level(info);
line << " short label: ";
for (int i = 0; i < 32; ++i) {
- if (ensemble->label.flag & 0x8000 >> i) {
- line << ensemble->label.text[i];
+ if (ensemble->label.flag() & 0x8000 >> i) {
+ line << label[i];
}
}
}
- etiLog.log(info, " (0x%x)\n", ensemble->label.flag);
+ etiLog.log(info, " (0x%x)\n", ensemble->label.flag());
etiLog.log(info, " mode: %u\n", ensemble->mode);
}
-