diff options
Diffstat (limited to 'src/ConfigParser.cpp')
-rw-r--r-- | src/ConfigParser.cpp | 134 |
1 files changed, 32 insertions, 102 deletions
diff --git a/src/ConfigParser.cpp b/src/ConfigParser.cpp index 443e26d..6092e66 100644 --- a/src/ConfigParser.cpp +++ b/src/ConfigParser.cpp @@ -125,15 +125,8 @@ int hexparse(std::string input) void parse_ptree(boost::property_tree::ptree& pt, - vector<dabOutput*> &outputs, - dabEnsemble* ensemble, - bool* enableTist, - unsigned* FICL, - bool* factumAnalyzer, - unsigned long* limit, - BaseRemoteController** rc, - int* mgmtserverport, - edi_configuration_t* edi + boost::shared_ptr<dabEnsemble> ensemble, + boost::shared_ptr<BaseRemoteController> rc ) { using boost::property_tree::ptree; @@ -150,38 +143,11 @@ void parse_ptree(boost::property_tree::ptree& pt, ensemble->mode = 0; } - if (ensemble->mode == 3) { - *FICL = 32; - } - else { - *FICL = 24; - } - - /* Number of frames to generate */ - *limit = pt_general.get("nbframes", 0); - /* Enable Logging to syslog conditionally */ if (pt_general.get<bool>("syslog", false)) { etiLog.register_backend(new LogToSyslog()); // TODO don't leak the LogToSyslog backend } - *factumAnalyzer = pt_general.get("writescca", false); - - *enableTist = pt_general.get("tist", false); - - *mgmtserverport = pt_general.get<int>("managementport", - pt_general.get<int>("statsserverport", 0) ); - - /************** READ REMOTE CONTROL PARAMETERS *************/ - ptree pt_rc = pt.get_child("remotecontrol"); - int telnetport = pt_rc.get<int>("telnetport", 0); - - if (telnetport != 0) { - *rc = new RemoteControllerTelnet(telnetport); - } - else { - *rc = new RemoteControllerDummy(); - } /******************** READ ENSEMBLE PARAMETERS *************/ ptree pt_ensemble = pt.get_child("ensemble"); @@ -254,19 +220,35 @@ void parse_ptree(boost::property_tree::ptree& pt, /******************** READ SERVICES PARAMETERS *************/ - map<string, DabService*> allservices; + map<string, shared_ptr<DabService> > allservices; /* For each service, we keep a separate SCIdS counter */ - map<DabService*, int> SCIdS_per_service; + map<shared_ptr<DabService>, int> SCIdS_per_service; ptree pt_services = pt.get_child("services"); for (ptree::iterator it = pt_services.begin(); it != pt_services.end(); ++it) { string serviceuid = it->first; ptree pt_service = it->second; - DabService* service = new DabService(serviceuid); - ensemble->services.push_back(service); - service->enrol_at(**rc); + + shared_ptr<DabService> service; + + bool service_already_existing = false; + + for (auto srv : ensemble->services) + { + if (srv->uid == serviceuid) { + service = srv; + service_already_existing = true; + break; + } + } + + if (not service_already_existing) { + auto new_srv = make_shared<DabService>(serviceuid); + ensemble->services.push_back(new_srv); + service = new_srv; + } int success = -5; @@ -332,13 +314,13 @@ void parse_ptree(boost::property_tree::ptree& pt, ptree pt_subchans = pt.get_child("subchannels"); for (ptree::iterator it = pt_subchans.begin(); it != pt_subchans.end(); ++it) { string subchanuid = it->first; - dabSubchannel* subchan = new dabSubchannel(); + dabSubchannel* subchan = new dabSubchannel(subchanuid); ensemble->subchannels.push_back(subchan); try { setup_subchannel_from_ptree(subchan, it->second, ensemble, - subchanuid, *rc); + subchanuid, rc); } catch (runtime_error &e) { etiLog.log(error, @@ -365,7 +347,7 @@ void parse_ptree(boost::property_tree::ptree& pt, string componentuid = it->first; ptree pt_comp = it->second; - DabService* service; + shared_ptr<DabService> service; try { // Those two uids serve as foreign keys to select the service+subchannel string service_uid = pt_comp.get<string>("service"); @@ -407,8 +389,6 @@ void parse_ptree(boost::property_tree::ptree& pt, DabComponent* component = new DabComponent(componentuid); - component->enrol_at(**rc); - component->serviceId = service->id; component->subchId = subchannel->id; component->SCIdS = SCIdS_per_service[service]++; @@ -495,65 +475,13 @@ void parse_ptree(boost::property_tree::ptree& pt, } - /******************** READ OUTPUT PARAMETERS ***************/ - map<string, dabOutput*> alloutputs; - ptree pt_outputs = pt.get_child("outputs"); - for (ptree::iterator it = pt_outputs.begin(); it != pt_outputs.end(); ++it) { - string outputuid = it->first; - - if (outputuid == "edi") { - ptree pt_edi = pt_outputs.get_child("edi"); - - edi->enabled = true; - - edi->dest_addr = pt_edi.get<string>("destination"); - edi->dest_port = pt_edi.get<unsigned int>("port"); - edi->source_port = pt_edi.get<unsigned int>("sourceport"); - - edi->dump = pt_edi.get<bool>("dump"); - edi->enable_pft = pt_edi.get<bool>("enable_pft"); - edi->verbose = pt_edi.get<bool>("verbose"); - } - else { - string uri = pt_outputs.get<string>(outputuid); - - size_t proto_pos = uri.find("://"); - if (proto_pos == std::string::npos) { - stringstream ss; - ss << "Output with uid " << outputuid << " no protocol defined!"; - throw runtime_error(ss.str()); - } - - char* uri_c = new char[512]; - memset(uri_c, 0, 512); - uri.copy(uri_c, 511); - - uri_c[proto_pos] = '\0'; - - char* outputName = uri_c + proto_pos + 3; - - dabOutput* output = new dabOutput(uri_c, outputName); - outputs.push_back(output); - - // keep outputs in map, and check for uniqueness of the uid - if (alloutputs.count(outputuid) == 0) { - alloutputs[outputuid] = output; - } - else { - stringstream ss; - ss << "output with uid " << outputuid << " not unique!"; - throw runtime_error(ss.str()); - } - } - } - } void setup_subchannel_from_ptree(dabSubchannel* subchan, boost::property_tree::ptree &pt, - dabEnsemble* ensemble, + boost::shared_ptr<dabEnsemble> ensemble, string subchanuid, - BaseRemoteController* rc) + boost::shared_ptr<BaseRemoteController> rc) { using boost::property_tree::ptree; using boost::property_tree::ptree_error; @@ -857,7 +785,7 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan, if (nonblock) { switch (subchan->type) { #ifdef HAVE_FORMAT_PACKET - case 3: + case Packet: if (operations == dabInputPacketFileOperations) { operations = dabInputFifoOperations; #ifdef HAVE_FORMAT_EPM @@ -873,7 +801,7 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan, break; #endif // defined(HAVE_FORMAT_PACKET) #ifdef HAVE_FORMAT_MPEG - case 0: + case Audio: if (operations == dabInputMpegFileOperations) { operations = dabInputMpegFifoOperations; } else if (operations == dabInputDabplusFileOperations) { @@ -886,6 +814,8 @@ void setup_subchannel_from_ptree(dabSubchannel* subchan, } break; #endif // defined(HAVE_FORMAT_MPEG) + case DataDmb: + case Fidc: default: stringstream ss; ss << "Subchannel with uid " << subchanuid << |