diff options
-rw-r--r-- | src/ConfigParser.cpp | 89 | ||||
-rw-r--r-- | src/MuxElements.cpp | 5 | ||||
-rw-r--r-- | src/MuxElements.h | 8 |
3 files changed, 98 insertions, 4 deletions
diff --git a/src/ConfigParser.cpp b/src/ConfigParser.cpp index 6a359b7..af43421 100644 --- a/src/ConfigParser.cpp +++ b/src/ConfigParser.cpp @@ -3,7 +3,7 @@ 2011, 2012 Her Majesty the Queen in Right of Canada (Communications Research Center Canada) - Copyright (C) 2014, 2015 + Copyright (C) 2016 Matthias P. Braendli, matthias.braendli@mpb.li http://www.opendigitalradio.org @@ -142,6 +142,92 @@ uint16_t get_announcement_flag_from_ptree( return flags; } +// Parse the linkage section +void parse_linkage(boost::property_tree::ptree& pt, + std::shared_ptr<dabEnsemble> ensemble, + std::shared_ptr<BaseRemoteController> rc + ) +{ + using boost::property_tree::ptree; + using boost::property_tree::ptree_error; + + auto pt_linking = pt.get_child_optional("linking"); + if (pt_linking) + { + for (const auto& it : *pt_linking) { + const string setuid = it.first; + const ptree pt_set = it.second; + + uint16_t lsn = hexparse(pt_set.get("lsn", "0")); + if (lsn == 0) { + etiLog.level(error) << "LSN for linking set " << + setuid << " invalid or missing"; + throw runtime_error("Invalid service linking definition"); + } + + bool active = pt_set.get("active", false); + bool hard = pt_set.get("hard", true); + bool international = pt_set.get("international", false); + + string service_uid = pt_set.get("keyservice", ""); + if (service_uid.empty()) { + etiLog.level(error) << "Key Service for linking set " << + setuid << " invalid or missing"; + throw runtime_error("Invalid service linking definition"); + } + + auto linkageset = make_shared<LinkageSet>(setuid, lsn, hard, international); + linkageset->set_active(active); + + auto pt_list = pt_set.get_child_optional("list"); + if (not pt_list) { + etiLog.level(error) << "list missing in linking set " << + setuid; + throw runtime_error("Invalid service linking definition"); + } + + for (const auto& it : *pt_list) { + const string linkuid = it.first; + const ptree pt_link = it.second; + + ServiceLink link; + + string link_type = pt_link.get("type", ""); + if (link_type == "dab") link.type = ServiceLinkType::DAB; + else if (link_type == "fm") link.type = ServiceLinkType::FM; + else if (link_type == "drm") link.type = ServiceLinkType::DRM; + else if (link_type == "amss") link.type = ServiceLinkType::AMSS; + else { + etiLog.level(error) << "Invalid type " << link_type << + " for link " << linkuid; + throw runtime_error("Invalid service linking definition"); + } + + link.id = hexparse(pt_link.get("id", "0")); + if (link.id == 0) { + etiLog.level(error) << "id for link " << + linkuid << " invalid or missing"; + throw runtime_error("Invalid service linking definition"); + } + + if (international) { + link.ecc = hexparse(pt_link.get("ecc", "0")); + if (link.ecc == 0) { + etiLog.level(error) << "ecc for link " << + linkuid << " invalid or missing"; + throw runtime_error("Invalid service linking definition"); + } + } + else { + link.ecc = 0; + } + + linkageset->id_list.push_back(link); + } + } + } +} + void parse_ptree(boost::property_tree::ptree& pt, std::shared_ptr<dabEnsemble> ensemble, std::shared_ptr<BaseRemoteController> rc @@ -556,6 +642,7 @@ void parse_ptree(boost::property_tree::ptree& pt, } + parse_linkage(pt, ensemble, rc); } void setup_subchannel_from_ptree(DabSubchannel* subchan, diff --git a/src/MuxElements.cpp b/src/MuxElements.cpp index ad623b9..60f49be 100644 --- a/src/MuxElements.cpp +++ b/src/MuxElements.cpp @@ -672,6 +672,11 @@ LinkageSet::LinkageSet(string name, uint16_t lsn, bool hard, bool international) RC_ADD_PARAMETER(active, "Activate this linkage set [0 or 1]"); } +void LinkageSet::set_active(bool active) +{ + m_active = active; +} + void LinkageSet::set_parameter(const string& parameter, const string& value) { if (parameter == "active") { diff --git a/src/MuxElements.h b/src/MuxElements.h index ab97fd7..93c291f 100644 --- a/src/MuxElements.h +++ b/src/MuxElements.h @@ -423,7 +423,7 @@ class DabService : public RemoteControllable DabService(const DabService& other); }; -enum class ServiceLinkType {dab, fm, drm, amss}; +enum class ServiceLinkType {DAB, FM, DRM, AMSS}; /* Represent one link inside a linkage set */ struct ServiceLink { @@ -438,7 +438,10 @@ struct ServiceLink { */ class LinkageSet : public RemoteControllable { public: - LinkageSet(string name, uint16_t lsn, bool hard, bool international); + LinkageSet(std::string name, uint16_t lsn, bool hard, bool international); + void set_active(bool active); + + std::list<ServiceLink> id_list; private: /* Linkage Set Number is a 12-bit number that identifies the linkage @@ -452,7 +455,6 @@ class LinkageSet : public RemoteControllable { bool m_international; DabService *m_keyservice; - std::list<ServiceLink> id_list; /* Remote control */ virtual void set_parameter(const std::string& parameter, |