Skip to content

Commit 4231cf9

Browse files
Merge pull request #19 from OwnZones/per/remove_construct_destruct_logging_change_to_c++_casting
Removed logging when objects are constructed and destructed
2 parents 3f72183 + b01c78c commit 4231cf9

16 files changed

+135
-132
lines changed

ElasticFrameProtocol.cpp

Lines changed: 108 additions & 115 deletions
Large diffs are not rendered by default.

ElasticFrameProtocol.h

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include <vector>
3333
#include <iostream>
3434
#include <sstream>
35-
#include <climits>
3635
#include <cmath>
3736
#include <thread>
3837
#include <map>
@@ -46,7 +45,6 @@
4645
#include <bitset>
4746
#include <mutex>
4847
#include <atomic>
49-
#include <algorithm>
5048
#include <deque>
5149
#include <condition_variable>
5250
#include <chrono>
@@ -64,7 +62,7 @@ extern "C" {
6462
#define UNIT_TESTS
6563

6664
///The size of the circular buffer. Must be contiguous set bits defining the size 0b1111111111111 == 8191
67-
#define CIRCULAR_BUFFER_SIZE 0b1111111111111
65+
constexpr uint16_t CIRCULAR_BUFFER_SIZE = 0b1111111111111;
6866

6967
/// Flag defines used py EFP
7068
#define NO_FLAGS 0b00000000 // Normal operation
@@ -75,8 +73,9 @@ extern "C" {
7573
#define PRIORITY_P3 0b01100000 // God-mode priority (not implemented)
7674
#define UNDEFINED_FLAG 0b10000000 // TBD
7775

78-
#define EFP_MAJOR_VERSION 0
79-
#define EFP_MINOR_VERSION 4
76+
constexpr uint8_t EFP_MAJOR_VERSION = 0;
77+
constexpr uint8_t EFP_MINOR_VERSION = 4;
78+
constexpr uint16_t EFP_VERSION = static_cast<uint16_t>(EFP_MAJOR_VERSION) << 8 | EFP_MINOR_VERSION;
8079

8180
// Bitwise operations are used on members therefore the namespace is wrapping enum instead of 'enum class'
8281
/// Definition of the data types supported by EFP
@@ -220,7 +219,7 @@ class ElasticFrameProtocolSender {
220219
virtual ~ElasticFrameProtocolSender();
221220

222221
///Return the version of the current implementation (Uint16)((8 MSB Major) + (8 LSB Minor))
223-
uint16_t getVersion() { return ((uint16_t)EFP_MAJOR_VERSION << 8) | (uint16_t)EFP_MINOR_VERSION; }
222+
static uint16_t getVersion() { return EFP_VERSION; }
224223

225224
/**
226225
* Converts the original data from a vector to EFP packets/fragments
@@ -343,7 +342,7 @@ class ElasticFrameProtocolSender {
343342
private:
344343
//Private methods ----- START ------
345344
// Used by the C - API
346-
void sendData(const std::vector<uint8_t> &rSubPacket, uint8_t lStreamID, ElasticFrameProtocolContext* pCTX);
345+
void sendData(const std::vector<uint8_t> &rSubPacket, uint8_t lStreamID, ElasticFrameProtocolContext* pCTX) const;
347346
//Private methods ----- END ------
348347

349348
// Internal lists and variables ----- START ------
@@ -439,8 +438,7 @@ class ElasticFrameProtocolReceiver {
439438
virtual ~ElasticFrameProtocolReceiver();
440439

441440
///Return the version of the current implementation
442-
uint16_t getVersion() { return ((uint16_t)EFP_MAJOR_VERSION << 8) | (uint16_t)EFP_MINOR_VERSION; }
443-
441+
static uint16_t getVersion() { return EFP_VERSION; }
444442
/**
445443
* Function assembling received fragments from a vector
446444
*
@@ -593,7 +591,7 @@ class ElasticFrameProtocolReceiver {
593591
ElasticFrameMessages stopReceiver();
594592

595593
// C-API callback. If C++ is used this is a dummy callback
596-
void gotData(pFramePtr &rPacket, ElasticFrameProtocolContext* pCTX);
594+
void gotData(pFramePtr &rPacket, ElasticFrameProtocolContext* pCTX) const;
597595

598596
// Method unpacking Type1 fragments
599597
ElasticFrameMessages unpackType1(const uint8_t *pSubPacket, size_t lPacketSize, uint8_t lFromSource);

efp_c_api/main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void send_data_callback(const uint8_t *data, size_t size, uint8_t stream_id, voi
4242
}
4343

4444
void receive_embedded_data_callback(uint8_t *data, size_t size, uint8_t data_type, uint64_t pts, void* ctx) {
45-
printf("Got embedded data: %zu bytes size and of type %d pts: %llu\n", size, data_type, pts);
45+
printf("Got embedded data: %zu bytes size and of type %d pts: %lu\n", size, data_type, pts);
4646
//In this example we know it's a string, print it.
4747
printf("Data: %s \n", data);
4848
printf("Context: %d \n\n", *(int*)ctx);
@@ -72,8 +72,8 @@ void receive_data_callback(uint8_t *data,
7272
printf("mFrameSize: %zu\n", size);
7373
printf("mDataContent: %d\n", data_content);
7474
printf("mBroken: %d\n", broken);
75-
printf("mPts: %llu\n", pts);
76-
printf("mDts: %llu\n", dts);
75+
printf("mPts: %lu\n", pts);
76+
printf("mDts: %lu\n", dts);
7777
printf("mCode: %d\n", code);
7878
printf("mStreamID: %d\n", stream_id);
7979
printf("mSource: %d\n", source);
@@ -180,4 +180,4 @@ int main() {
180180
}
181181

182182
return 0;
183-
}
183+
}

logger.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ if (g == (LOGG_NOTIFY & (LOGG_MASK))) {a << "Notification: ";} \
2121
else if (g == (LOGG_WARN & (LOGG_MASK))) {a << "Warning: ";} \
2222
else if (g == (LOGG_ERROR & (LOGG_MASK))) {a << "Error: ";} \
2323
else if (g == (LOGG_FATAL & (LOGG_MASK))) {a << "Fatal: ";} \
24-
if (a.str().length()) { \
24+
if (!a.str().empty()) { \
2525
if (l) {a << __FILE__ << " " << __LINE__ << " ";} \
2626
a << f << std::endl; \
2727
std::cout << a.str(); \
@@ -31,4 +31,4 @@ std::cout << a.str(); \
3131
#define EFP_LOGGER(l,g,f)
3232
#endif
3333

34-
#endif
34+
#endif

unitTests/UnitTest14.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <gtest/gtest.h>
22

3+
#include <algorithm>
34
#include <memory>
45

56
#include "ElasticFrameProtocol.h"

unitTests/UnitTest15.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <gtest/gtest.h>
22

3+
#include <algorithm>
34
#include <memory>
45

56
#include "ElasticFrameProtocol.h"

unitTests/UnitTest16.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <gtest/gtest.h>
22

3+
#include <algorithm>
34
#include <memory>
45
#include <random>
56

unitTests/UnitTest17.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <gtest/gtest.h>
22

3+
#include <algorithm>
34
#include <memory>
45

56
#include "ElasticFrameProtocol.h"

unitTests/UnitTest19.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <gtest/gtest.h>
22

3+
#include <algorithm>
34
#include <memory>
45

56
#include "ElasticFrameProtocol.h"

unitTests/UnitTest21.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <gtest/gtest.h>
22

3+
#include <algorithm>
34
#include <memory>
45

56
#include "ElasticFrameProtocol.h"

0 commit comments

Comments
 (0)