aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2014-02-14 15:46:54 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2014-02-14 15:46:54 +0100
commitd6923be4bd2e198b4cba161e8040072128bd392c (patch)
treecf3e74d4685075b4836141c48a71507666074781 /src
parent77d77e5f4d60ed9d1f8346910f42fe2d61122f22 (diff)
downloaddabmux-d6923be4bd2e198b4cba161e8040072128bd392c.tar.gz
dabmux-d6923be4bd2e198b4cba161e8040072128bd392c.tar.bz2
dabmux-d6923be4bd2e198b4cba161e8040072128bd392c.zip
make DabComponent a class and make its label RC controllable
Diffstat (limited to 'src')
-rw-r--r--src/DabMux.cpp6
-rw-r--r--src/MuxElements.cpp94
-rw-r--r--src/MuxElements.h69
-rw-r--r--src/ParserCmdline.cpp4
-rw-r--r--src/ParserConfigfile.cpp5
-rw-r--r--src/utils.cpp6
-rw-r--r--src/utils.h4
7 files changed, 137 insertions, 51 deletions
diff --git a/src/DabMux.cpp b/src/DabMux.cpp
index 7bb44ba..b4a2a41 100644
--- a/src/DabMux.cpp
+++ b/src/DabMux.cpp
@@ -279,9 +279,9 @@ int main(int argc, char *argv[])
vector<DabService*>::iterator serviceProgramInd;
vector<DabService*>::iterator serviceDataInd;
vector<DabService*>::iterator servicePty;
- vector<dabComponent*>::iterator component = ensemble->components.end();
- vector<dabComponent*>::iterator componentIndicatorProgram;
- vector<dabComponent*>::iterator componentIndicatorData;
+ vector<DabComponent*>::iterator component = ensemble->components.end();
+ vector<DabComponent*>::iterator componentIndicatorProgram;
+ vector<DabComponent*>::iterator componentIndicatorData;
vector<dabSubchannel*>::iterator subchannel = ensemble->subchannels.end();
vector<dabSubchannel*>::iterator subchannelIndicator;
vector<dabOutput*>::iterator output;
diff --git a/src/MuxElements.cpp b/src/MuxElements.cpp
index 13ce096..1e3f5b2 100644
--- a/src/MuxElements.cpp
+++ b/src/MuxElements.cpp
@@ -153,10 +153,10 @@ vector<dabSubchannel*>::iterator getSubchannel(
);
}
-vector<dabComponent*>::iterator getComponent(
- vector<dabComponent*>& components,
+vector<DabComponent*>::iterator getComponent(
+ vector<DabComponent*>& components,
uint32_t serviceId,
- vector<dabComponent*>::iterator current)
+ vector<DabComponent*>::iterator current)
{
if (current == components.end()) {
current = components.begin();
@@ -175,14 +175,14 @@ vector<dabComponent*>::iterator getComponent(
}
-vector<dabComponent*>::iterator getComponent(
- vector<dabComponent*>& components,
+vector<DabComponent*>::iterator getComponent(
+ vector<DabComponent*>& components,
uint32_t serviceId) {
return getComponent(components, serviceId, components.end());
}
vector<DabService*>::iterator getService(
- dabComponent* component,
+ DabComponent* component,
vector<DabService*>& services)
{
vector<DabService*>::iterator service;
@@ -196,7 +196,7 @@ vector<DabService*>::iterator getService(
return service;
}
-bool dabComponent::isPacketComponent(vector<dabSubchannel*>& subchannels)
+bool DabComponent::isPacketComponent(vector<dabSubchannel*>& subchannels)
{
if (subchId > 63) {
etiLog.log(error,
@@ -218,11 +218,77 @@ bool dabComponent::isPacketComponent(vector<dabSubchannel*>& subchannels)
return true;
}
+void DabComponent::set_parameter(string parameter, string value)
+{
+ stringstream ss(value);
+ ss.exceptions ( stringstream::failbit | stringstream::badbit );
+
+ if (parameter == "label") {
+ vector<string> fields;
+ boost::split(fields, value, boost::is_any_of(","));
+ if (fields.size() != 2) {
+ throw ParameterError("Parameter 'label' must have format"
+ " 'label,shortlabel'");
+ }
+ int success = this->label.setLabel(fields[0], fields[1]);
+ stringstream ss;
+ switch (success)
+ {
+ case 0:
+ break;
+ case -1:
+ ss << m_name << " short label " <<
+ fields[1] << " is not subset of label '" <<
+ fields[0] << "'";
+ etiLog.level(warn) << ss.str();
+ throw ParameterError(ss.str());
+ case -2:
+ ss << m_name << " short label " <<
+ fields[1] << " is too long (max 8 characters)";
+ etiLog.level(warn) << ss.str();
+ throw ParameterError(ss.str());
+ case -3:
+ ss << m_name << " label " <<
+ fields[0] << " is too long (max 16 characters)";
+ etiLog.level(warn) << ss.str();
+ throw ParameterError(ss.str());
+ default:
+ ss << m_name << " short label definition: program error !";
+ etiLog.level(emerg) << ss.str();
+ throw ParameterError(ss.str());
+ }
+ }
+ else {
+ stringstream ss;
+ ss << "Parameter '" << parameter <<
+ "' is not exported by controllable " << get_rc_name();
+ throw ParameterError(ss.str());
+ }
+}
+
+string DabComponent::get_parameter(string parameter)
+{
+ stringstream ss;
+ if (parameter == "label") {
+ char l[17];
+ l[16] = '\0';
+ memcpy(l, label.text(), 16);
+ ss << l << "," << label.short_label();
+ }
+ else {
+ ss << "Parameter '" << parameter <<
+ "' is not exported by controllable " << get_rc_name();
+ throw ParameterError(ss.str());
+ }
+ return ss.str();
+
+}
+
unsigned char DabService::getType(dabEnsemble* ensemble)
{
vector<dabSubchannel*>::iterator subchannel;
- vector<dabComponent*>::iterator component =
+ vector<DabComponent*>::iterator component =
getComponent(ensemble->components, id);
if (component == ensemble->components.end()) {
return 4;
@@ -235,10 +301,10 @@ unsigned char DabService::getType(dabEnsemble* ensemble)
return (*subchannel)->type;
}
-unsigned char DabService::nbComponent(vector<dabComponent*>& components)
+unsigned char DabService::nbComponent(vector<DabComponent*>& components)
{
int nb = 0;
- vector<dabComponent*>::iterator current;
+ vector<DabComponent*>::iterator current;
for (current = components.begin(); current != components.end();
++current) {
@@ -268,23 +334,23 @@ void DabService::set_parameter(string parameter, string value)
case 0:
break;
case -1:
- ss << "Ensemble short label " <<
+ ss << m_name << " short label " <<
fields[1] << " is not subset of label '" <<
fields[0] << "'";
etiLog.level(warn) << ss.str();
throw ParameterError(ss.str());
case -2:
- ss << "Ensemble short label " <<
+ ss << m_name << " short label " <<
fields[1] << " is too long (max 8 characters)";
etiLog.level(warn) << ss.str();
throw ParameterError(ss.str());
case -3:
- ss << "Ensemble label " <<
+ ss << m_name << " label " <<
fields[0] << " is too long (max 16 characters)";
etiLog.level(warn) << ss.str();
throw ParameterError(ss.str());
default:
- ss << "Ensemble short label definition: program error !";
+ ss << m_name << " short label definition: program error !";
etiLog.level(emerg) << ss.str();
throw ParameterError(ss.str());
}
diff --git a/src/MuxElements.h b/src/MuxElements.h
index a0ee23a..41037b5 100644
--- a/src/MuxElements.h
+++ b/src/MuxElements.h
@@ -86,8 +86,9 @@ class DabLabel
};
-struct DabService;
-struct dabComponent;
+class DabService;
+class DabComponent;
+
struct dabSubchannel;
struct dabEnsemble {
uint16_t id;
@@ -95,7 +96,7 @@ struct dabEnsemble {
DabLabel label;
uint8_t mode;
vector<DabService*> services;
- vector<dabComponent*> components;
+ vector<DabComponent*> components;
vector<dabSubchannel*> subchannels;
};
@@ -163,20 +164,39 @@ struct dabPacketComponent {
};
-struct dabComponent {
- DabLabel label;
- uint32_t serviceId;
- uint8_t subchId;
- uint8_t type;
- uint8_t SCIdS;
- union {
- dabAudioComponent audio;
- dabDataComponent data;
- dabFidcComponent fidc;
- dabPacketComponent packet;
- };
+class DabComponent : public RemoteControllable
+{
+ public:
+ DabComponent(std::string uid) :
+ RemoteControllable("Component " + uid)
+ {
+ RC_ADD_PARAMETER(label, "Label and shortlabel [label,short]");
+ }
- bool isPacketComponent(vector<dabSubchannel*>& subchannels);
+ DabLabel label;
+ uint32_t serviceId;
+ uint8_t subchId;
+ uint8_t type;
+ uint8_t SCIdS;
+ union {
+ dabAudioComponent audio;
+ dabDataComponent data;
+ dabFidcComponent fidc;
+ dabPacketComponent packet;
+ };
+
+ bool isPacketComponent(vector<dabSubchannel*>& subchannels);
+
+ /* Remote control */
+ virtual void set_parameter(string parameter, string value);
+
+ /* Getting a parameter always returns a string. */
+ virtual string get_parameter(string parameter);
+
+
+ private:
+ const DabComponent& operator=(const DabComponent& other);
+ DabComponent(const DabComponent& other);
};
@@ -184,7 +204,8 @@ struct dabComponent {
class DabService : public RemoteControllable
{
public:
- DabService(std::string uid) : RemoteControllable(uid)
+ DabService(std::string uid) :
+ RemoteControllable("Service " + uid)
{
RC_ADD_PARAMETER(label, "Label and shortlabel [label,short]");
}
@@ -195,7 +216,7 @@ class DabService : public RemoteControllable
bool program;
unsigned char getType(dabEnsemble* ensemble);
- unsigned char nbComponent(vector<dabComponent*>& components);
+ unsigned char nbComponent(vector<DabComponent*>& components);
DabLabel label;
@@ -213,17 +234,17 @@ class DabService : public RemoteControllable
vector<dabSubchannel*>::iterator getSubchannel(
vector<dabSubchannel*>& subchannels, int id);
-vector<dabComponent*>::iterator getComponent(
- vector<dabComponent*>& components,
+vector<DabComponent*>::iterator getComponent(
+ vector<DabComponent*>& components,
uint32_t serviceId,
- vector<dabComponent*>::iterator current);
+ vector<DabComponent*>::iterator current);
-vector<dabComponent*>::iterator getComponent(
- vector<dabComponent*>& components,
+vector<DabComponent*>::iterator getComponent(
+ vector<DabComponent*>& components,
uint32_t serviceId);
vector<DabService*>::iterator getService(
- dabComponent* component,
+ DabComponent* component,
vector<DabService*>& services);
unsigned short getSizeCu(dabSubchannel* subchannel);
diff --git a/src/ParserCmdline.cpp b/src/ParserCmdline.cpp
index 2027bff..60ce118 100644
--- a/src/ParserCmdline.cpp
+++ b/src/ParserCmdline.cpp
@@ -103,7 +103,7 @@ bool parse_cmdline(char **argv,
{
vector<dabOutput*>::iterator output;
vector<dabSubchannel*>::iterator subchannel = ensemble->subchannels.end();
- vector<dabComponent*>::iterator component = ensemble->components.end();
+ vector<DabComponent*>::iterator component = ensemble->components.end();
vector<DabService*>::iterator service = ensemble->services.end();
dabProtection* protection = NULL;
@@ -171,7 +171,7 @@ bool parse_cmdline(char **argv,
goto EXIT;
}
- ensemble->components.push_back(new dabComponent);
+ ensemble->components.push_back(new DabComponent("?"));
component = ensemble->components.end() - 1;
subchannel = ensemble->subchannels.end();
diff --git a/src/ParserConfigfile.cpp b/src/ParserConfigfile.cpp
index a6bbe63..d5dba9e 100644
--- a/src/ParserConfigfile.cpp
+++ b/src/ParserConfigfile.cpp
@@ -333,7 +333,7 @@ void parse_configfile(string configuration_file,
}
/******************** READ COMPONENT PARAMETERS ************/
- map<string, dabComponent*> allcomponents;
+ map<string, DabComponent*> allcomponents;
ptree pt_components = pt.get_child("components");
for (ptree::iterator it = pt_components.begin(); it != pt_components.end(); ++it) {
string componentuid = it->first;
@@ -378,9 +378,8 @@ void parse_configfile(string configuration_file,
int packet_address = hexparse(pt_comp.get("address", "-1"));
uint8_t component_type = hexparse(pt_comp.get("type", "0"));
- dabComponent* component = new dabComponent();
+ DabComponent* component = new DabComponent(componentuid);
- memset(component, 0, sizeof(dabComponent));
component->serviceId = service->id;
component->subchId = subchannel->id;
component->SCIdS = SCIdS_per_service[service]++;
diff --git a/src/utils.cpp b/src/utils.cpp
index 157c3a7..deefa81 100644
--- a/src/utils.cpp
+++ b/src/utils.cpp
@@ -322,9 +322,9 @@ void printServices(vector<DabService*>& services)
}
}
-void printComponents(vector<dabComponent*>& components)
+void printComponents(vector<DabComponent*>& components)
{
- vector<dabComponent*>::const_iterator current;
+ vector<DabComponent*>::const_iterator current;
unsigned int index = 0;
for (current = components.begin(); current != components.end(); ++current) {
@@ -334,7 +334,7 @@ void printComponents(vector<dabComponent*>& components)
}
}
-void printComponent(dabComponent* component)
+void printComponent(DabComponent* component)
{
char label[17];
memcpy(label, component->label.text(), 16);
diff --git a/src/utils.h b/src/utils.h
index 8a9e264..2a91dbc 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -53,7 +53,7 @@ void printOutputs(vector<dabOutput*>& outputs);
void printServices(vector<DabService*>& services);
-void printComponents(vector<dabComponent*>& components);
+void printComponents(vector<DabComponent*>& components);
void printSubchannels(vector<dabSubchannel*>& subchannels);
@@ -61,5 +61,5 @@ void printSubchannels(vector<dabSubchannel*>& subchannels);
void printEnsemble(dabEnsemble* ensemble);
/* Print detailed component information */
-void printComponent(dabComponent* component);
+void printComponent(DabComponent* component);
#endif