From d6923be4bd2e198b4cba161e8040072128bd392c Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Fri, 14 Feb 2014 15:46:54 +0100 Subject: make DabComponent a class and make its label RC controllable --- src/DabMux.cpp | 6 ++-- src/MuxElements.cpp | 94 ++++++++++++++++++++++++++++++++++++++++-------- src/MuxElements.h | 69 ++++++++++++++++++++++------------- src/ParserCmdline.cpp | 4 +-- src/ParserConfigfile.cpp | 5 ++- src/utils.cpp | 6 ++-- src/utils.h | 4 +-- 7 files changed, 137 insertions(+), 51 deletions(-) (limited to 'src') 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::iterator serviceProgramInd; vector::iterator serviceDataInd; vector::iterator servicePty; - vector::iterator component = ensemble->components.end(); - vector::iterator componentIndicatorProgram; - vector::iterator componentIndicatorData; + vector::iterator component = ensemble->components.end(); + vector::iterator componentIndicatorProgram; + vector::iterator componentIndicatorData; vector::iterator subchannel = ensemble->subchannels.end(); vector::iterator subchannelIndicator; vector::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::iterator getSubchannel( ); } -vector::iterator getComponent( - vector& components, +vector::iterator getComponent( + vector& components, uint32_t serviceId, - vector::iterator current) + vector::iterator current) { if (current == components.end()) { current = components.begin(); @@ -175,14 +175,14 @@ vector::iterator getComponent( } -vector::iterator getComponent( - vector& components, +vector::iterator getComponent( + vector& components, uint32_t serviceId) { return getComponent(components, serviceId, components.end()); } vector::iterator getService( - dabComponent* component, + DabComponent* component, vector& services) { vector::iterator service; @@ -196,7 +196,7 @@ vector::iterator getService( return service; } -bool dabComponent::isPacketComponent(vector& subchannels) +bool DabComponent::isPacketComponent(vector& subchannels) { if (subchId > 63) { etiLog.log(error, @@ -218,11 +218,77 @@ bool dabComponent::isPacketComponent(vector& subchannels) return true; } +void DabComponent::set_parameter(string parameter, string value) +{ + stringstream ss(value); + ss.exceptions ( stringstream::failbit | stringstream::badbit ); + + if (parameter == "label") { + vector 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::iterator subchannel; - vector::iterator component = + vector::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& components) +unsigned char DabService::nbComponent(vector& components) { int nb = 0; - vector::iterator current; + vector::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 services; - vector components; + vector components; vector 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& 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& 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& components); + unsigned char nbComponent(vector& components); DabLabel label; @@ -213,17 +234,17 @@ class DabService : public RemoteControllable vector::iterator getSubchannel( vector& subchannels, int id); -vector::iterator getComponent( - vector& components, +vector::iterator getComponent( + vector& components, uint32_t serviceId, - vector::iterator current); + vector::iterator current); -vector::iterator getComponent( - vector& components, +vector::iterator getComponent( + vector& components, uint32_t serviceId); vector::iterator getService( - dabComponent* component, + DabComponent* component, vector& 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::iterator output; vector::iterator subchannel = ensemble->subchannels.end(); - vector::iterator component = ensemble->components.end(); + vector::iterator component = ensemble->components.end(); vector::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 allcomponents; + map 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& services) } } -void printComponents(vector& components) +void printComponents(vector& components) { - vector::const_iterator current; + vector::const_iterator current; unsigned int index = 0; for (current = components.begin(); current != components.end(); ++current) { @@ -334,7 +334,7 @@ void printComponents(vector& 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& outputs); void printServices(vector& services); -void printComponents(vector& components); +void printComponents(vector& components); void printSubchannels(vector& subchannels); @@ -61,5 +61,5 @@ void printSubchannels(vector& subchannels); void printEnsemble(dabEnsemble* ensemble); /* Print detailed component information */ -void printComponent(dabComponent* component); +void printComponent(DabComponent* component); #endif -- cgit v1.2.3