diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2017-01-28 16:14:08 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2017-01-28 16:14:08 +0100 |
commit | 000796dc3d909f179fb6586fae7e9ce986440576 (patch) | |
tree | a6b08f5866af7d5943052d18b7162ba3ed897d37 | |
parent | af782e67db704d1d58c265fb4e1ff12aa1526596 (diff) | |
download | dabmux-000796dc3d909f179fb6586fae7e9ce986440576.tar.gz dabmux-000796dc3d909f179fb6586fae7e9ce986440576.tar.bz2 dabmux-000796dc3d909f179fb6586fae7e9ce986440576.zip |
Avoid uninitialised fields, modernise DabService::nbComponent
-rw-r--r-- | src/DabMultiplexer.cpp | 3 | ||||
-rw-r--r-- | src/ManagementServer.h | 12 | ||||
-rw-r--r-- | src/MuxElements.cpp | 20 | ||||
-rw-r--r-- | src/MuxElements.h | 44 | ||||
-rw-r--r-- | src/dabOutput/dabOutput.h | 18 | ||||
-rw-r--r-- | src/dabOutput/edi/AFPacket.h | 2 | ||||
-rw-r--r-- | src/dabOutput/edi/TagItems.h | 38 | ||||
-rw-r--r-- | src/fig/FIG.h | 2 | ||||
-rw-r--r-- | src/utils.cpp | 2 | ||||
-rw-r--r-- | src/utils.h | 2 | ||||
-rw-r--r-- | src/zmqinput-keygen.c | 1 |
11 files changed, 65 insertions, 79 deletions
diff --git a/src/DabMultiplexer.cpp b/src/DabMultiplexer.cpp index 51a67e7..97336d1 100644 --- a/src/DabMultiplexer.cpp +++ b/src/DabMultiplexer.cpp @@ -75,6 +75,7 @@ DabMultiplexer::DabMultiplexer( sync(0x49C5F8), currentFrame(0), ensemble(std::make_shared<dabEnsemble>()), + m_clock_tai(), fig_carousel(ensemble) { RC_ADD_PARAMETER(frames, @@ -178,7 +179,7 @@ void DabMultiplexer::prepare() "connection?"; etiLog.level(error) << err_msg; - throw e; + throw; } } diff --git a/src/ManagementServer.h b/src/ManagementServer.h index 2b9b7b4..aade3d0 100644 --- a/src/ManagementServer.h +++ b/src/ManagementServer.h @@ -329,6 +329,9 @@ class ManagementServer m_thread.join(); } + ManagementServer(const ManagementServer& other) = delete; + ManagementServer& operator=(const ManagementServer& other) = delete; + void open(int listenport) { m_listenport = listenport; @@ -362,15 +365,12 @@ class ManagementServer zmq::context_t m_zmq_context; zmq::socket_t m_zmq_sock; - // no copying (because of the thread) - ManagementServer(const ManagementServer& other); - void serverThread(void); void handle_message(zmq::message_t& zmq_message); bool isInputRegistered(std::string& id); - int m_listenport; + int m_listenport = 0; // serverThread runs in a separate thread std::atomic<bool> m_running; @@ -401,10 +401,10 @@ class ManagementServer std::string getStateJSON(); // mutex for accessing the map - mutable boost::mutex m_statsmutex; + boost::mutex m_statsmutex; /******** Configuration Data *******/ - mutable boost::mutex m_configmutex; + boost::mutex m_configmutex; boost::property_tree::ptree m_pt; }; diff --git a/src/MuxElements.cpp b/src/MuxElements.cpp index 9dbe5fc..f8a3eb4 100644 --- a/src/MuxElements.cpp +++ b/src/MuxElements.cpp @@ -412,7 +412,7 @@ const string DabComponent::get_parameter(const string& parameter) const } -subchannel_type_t DabService::getType(std::shared_ptr<dabEnsemble> ensemble) const +subchannel_type_t DabService::getType(const std::shared_ptr<dabEnsemble> ensemble) const { vector<DabSubchannel*>::iterator subchannel; auto component = @@ -429,7 +429,7 @@ subchannel_type_t DabService::getType(std::shared_ptr<dabEnsemble> ensemble) con return (*subchannel)->type; } -bool DabService::isProgramme(std::shared_ptr<dabEnsemble> ensemble) const +bool DabService::isProgramme(const std::shared_ptr<dabEnsemble>& ensemble) const { bool ret = false; switch (getType(ensemble)) { @@ -452,18 +452,14 @@ bool DabService::isProgramme(std::shared_ptr<dabEnsemble> ensemble) const } -unsigned char DabService::nbComponent(vector<DabComponent*>& components) const +unsigned char DabService::nbComponent(const vector<DabComponent*>& components) const { - int nb = 0; - vector<DabComponent*>::iterator current; - - for (current = components.begin(); current != components.end(); - ++current) { - if ((*current)->serviceId == id) { - ++nb; - } + size_t count = std::count_if(components.begin(), components.end(), + [&](const DabComponent* c) { return c->serviceId == id;} ); + if (count > 0xFF) { + throw std::logic_error("Invalid number of components in service"); } - return nb; + return count; } void DabService::set_parameter(const string& parameter, diff --git a/src/MuxElements.h b/src/MuxElements.h index 968fb14..98e4741 100644 --- a/src/MuxElements.h +++ b/src/MuxElements.h @@ -85,9 +85,8 @@ const char * const annoucement_flags_names[] = { /* Class representing an announcement cluster for FIG 0/19 */ class AnnouncementCluster : public RemoteControllable { public: - AnnouncementCluster(std::string name) : - RemoteControllable(name), - m_active(false) + AnnouncementCluster(const std::string& name) : + RemoteControllable(name) { RC_ADD_PARAMETER(active, "Signal this announcement [0 or 1]"); @@ -100,8 +99,8 @@ class AnnouncementCluster : public RemoteControllable { "Stop signalling this announcement after a delay [ms]"); } - uint8_t cluster_id; - uint16_t flags; + uint8_t cluster_id = 0; + uint16_t flags = 0; std::string subchanneluid; std::string tostring(void) const; @@ -112,7 +111,7 @@ class AnnouncementCluster : public RemoteControllable { bool is_active(void); private: - bool m_active; + bool m_active = false; boost::optional< std::chrono::time_point< @@ -179,7 +178,7 @@ class DabLabel /* The flag field selects which label characters make * up the short label */ - uint16_t m_flag; + uint16_t m_flag = 0xFFFF; /* The m_label is not padded in any way */ std::string m_label; @@ -211,18 +210,20 @@ class dabEnsemble : public RemoteControllable { virtual const std::string get_parameter(const std::string& parameter) const; /* all fields are public, since this was a struct before */ - uint16_t id; - uint8_t ecc; + uint16_t id = 0; + uint8_t ecc = 0; DabLabel label; - uint8_t mode; + uint8_t mode = 0; /* Use the local time to calculate the lto */ - bool lto_auto; + bool lto_auto = true; - int lto; // local time offset in half-hours + int lto = 0; // local time offset in half-hours // range: -24 to +24 - int international_table; + // 1 corresponds to the PTy used in RDS + // 2 corresponds to program types used in north america + int international_table = 1; std::vector<std::shared_ptr<DabService> > services; std::vector<DabComponent*> components; @@ -383,7 +384,8 @@ class DabService : public RemoteControllable public: DabService(std::string& uid) : RemoteControllable(uid), - uid(uid) + uid(uid), + label() { RC_ADD_PARAMETER(label, "Label and shortlabel [label,short]"); RC_ADD_PARAMETER(pty, "Programme Type"); @@ -391,21 +393,21 @@ class DabService : public RemoteControllable std::string uid; - uint32_t id; - unsigned char pty; - unsigned char language; + uint32_t id = 0; + unsigned char pty = 0; + unsigned char language = 0; /* ASu (Announcement support) flags: this 16-bit flag field shall * specify the type(s) of announcements by which it is possible to * interrupt the reception of the service. The interpretation of this * field shall be as defined in TS 101 756, table 14. */ - uint16_t ASu; + uint16_t ASu = 0; std::vector<uint8_t> clusters; - subchannel_type_t getType(std::shared_ptr<dabEnsemble> ensemble) const; - bool isProgramme(std::shared_ptr<dabEnsemble> ensemble) const; - unsigned char nbComponent(std::vector<DabComponent*>& components) const; + subchannel_type_t getType(const std::shared_ptr<dabEnsemble> ensemble) const; + bool isProgramme(const std::shared_ptr<dabEnsemble>& ensemble) const; + unsigned char nbComponent(const std::vector<DabComponent*>& components) const; DabLabel label; diff --git a/src/dabOutput/dabOutput.h b/src/dabOutput/dabOutput.h index 11b78e6..2e5f489 100644 --- a/src/dabOutput/dabOutput.h +++ b/src/dabOutput/dabOutput.h @@ -59,17 +59,15 @@ struct edi_destination_t { }; struct edi_configuration_t { - edi_configuration_t() : - verbose(false) {} - unsigned chunk_len; // RSk, data length of each chunk - unsigned fec; // number of fragments that can be recovered - bool dump; // dump a file with the EDI packets - bool verbose; - bool enable_pft; // Enable protection and fragmentation - unsigned int tagpacket_alignment; + unsigned chunk_len = 207; // RSk, data length of each chunk + unsigned fec = 0; // number of fragments that can be recovered + bool dump = false; // dump a file with the EDI packets + bool verbose = false; + bool enable_pft = false; // Enable protection and fragmentation + unsigned int tagpacket_alignment = 0; std::vector<edi_destination_t> destinations; - unsigned int dest_port; // common destination port, because it's encoded in the transport layer - unsigned int latency_frames; // if nonzero, enable interleaver with a latency of latency_frames * 24ms + unsigned int dest_port = 0; // common destination port, because it's encoded in the transport layer + unsigned int latency_frames = 0; // if nonzero, enable interleaver with a latency of latency_frames * 24ms bool enabled() const { return destinations.size() > 0; } bool interleaver_enabled() const { return latency_frames > 0; } diff --git a/src/dabOutput/edi/AFPacket.h b/src/dabOutput/edi/AFPacket.h index 0ffd13f..b4ccef1 100644 --- a/src/dabOutput/edi/AFPacket.h +++ b/src/dabOutput/edi/AFPacket.h @@ -52,7 +52,7 @@ class AFPacketiser private: static const bool have_crc = true; - uint16_t seq; //counter that overflows at 0xFFFF + uint16_t seq = 0; //counter that overflows at 0xFFFF bool m_verbose; }; diff --git a/src/dabOutput/edi/TagItems.h b/src/dabOutput/edi/TagItems.h index fb876cc..856d25b 100644 --- a/src/dabOutput/edi/TagItems.h +++ b/src/dabOutput/edi/TagItems.h @@ -54,30 +54,20 @@ class TagStarPTR : public TagItem class TagDETI : public TagItem { public: - TagDETI() - { - // set optional fields to "not present" - atstf = 0; - rfudf = 0; - ficf = 0; - - rfa = 0; //shall be zero - rfu = 0; //mnsc is valid - } std::vector<uint8_t> Assemble(); /***** DATA in intermediary format ****/ // For the ETI Header: must be defined ! - uint8_t stat; - uint8_t mid; - uint8_t fp; - uint8_t rfa; - uint8_t rfu; - uint16_t mnsc; - uint16_t dflc; // modulo 5000 frame counter + uint8_t stat = 0; + uint8_t mid = 0; + uint8_t fp = 0; + uint8_t rfa = 0; + uint8_t rfu = 0; // MNSC is valid + uint16_t mnsc = 0; + uint16_t dflc = 0; // modulo 5000 frame counter // ATST (optional) - bool atstf; // presence of atst data + bool atstf = false; // presence of atst data /* UTCO: Offset (in seconds) between UTC and the Seconds value. The * value is expressed as an unsigned 8-bit quantity. As of February @@ -93,14 +83,14 @@ class TagDETI : public TagItem * where the TAI-UTC offset is given by the USNO bulletin using * the ClockTAI module. */ - uint8_t utco; + uint8_t utco = 0; void set_tai_utc_offset(int tai_utc_offset) { utco = tai_utc_offset - 32; } /* The number of SI seconds since 2000-01-01 T 00:00:00 UTC as an * unsigned 32-bit quantity */ - uint32_t seconds; + uint32_t seconds = 0; void set_seconds(std::chrono::system_clock::time_point t); @@ -110,16 +100,16 @@ class TagDETI : public TagItem * significant 8 bits of the TIST field of the incoming STI-D(LI) * frame, if required, may be carried in the RFAD field. */ - uint32_t tsta; + uint32_t tsta = 0xFFFFFF; // the FIC (optional) - bool ficf; + bool ficf = false; const unsigned char* fic_data; size_t fic_length; // rfu - bool rfudf; - uint32_t rfud; + bool rfudf = false; + uint32_t rfud = 0; }; diff --git a/src/fig/FIG.h b/src/fig/FIG.h index 2325252..416ae44 100644 --- a/src/fig/FIG.h +++ b/src/fig/FIG.h @@ -36,7 +36,7 @@ namespace FIC { class FIGRuntimeInformation { public: - FIGRuntimeInformation(std::shared_ptr<dabEnsemble> e) : + FIGRuntimeInformation(std::shared_ptr<dabEnsemble>& e) : currentFrame(0), ensemble(e), factumAnalyzer(false) {} diff --git a/src/utils.cpp b/src/utils.cpp index 4c08e8b..38e38ec 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -402,7 +402,7 @@ static void printLinking(const shared_ptr<dabEnsemble> ensemble) } } -void printEnsemble(const shared_ptr<dabEnsemble> ensemble) +void printEnsemble(const shared_ptr<dabEnsemble>& ensemble) { etiLog.log(info, "Ensemble"); etiLog.log(info, " id: 0x%lx (%lu)", ensemble->id, ensemble->id); diff --git a/src/utils.h b/src/utils.h index 94712cd..995e8b6 100644 --- a/src/utils.h +++ b/src/utils.h @@ -75,7 +75,7 @@ void printComponents(std::vector<DabComponent*>& components); void printSubchannels(std::vector<DabSubchannel*>& subchannels); /* Print information about the whole ensemble */ -void printEnsemble(const std::shared_ptr<dabEnsemble> ensemble); +void printEnsemble(const std::shared_ptr<dabEnsemble>& ensemble); /* Print detailed component information */ void printComponent(DabComponent* component); diff --git a/src/zmqinput-keygen.c b/src/zmqinput-keygen.c index ee0042e..cb7f9b2 100644 --- a/src/zmqinput-keygen.c +++ b/src/zmqinput-keygen.c @@ -24,7 +24,6 @@ #include <stdio.h> #include <stdint.h> #include <stdlib.h> -#include <zmq_utils.h> #include <zmq.h> #include <sys/types.h> #include <sys/stat.h> |