Skip to content

Commit f05ebaa

Browse files
committed
DTXMessageTransmitterTest MultipleFragments
1 parent 855da6f commit f05ebaa

31 files changed

+969
-701
lines changed

include/idevice/blockingqueue.h

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
#define IDEVICE_BLOCKING_QUEUE_H
33

44
#include <chrono>
5-
#include <queue>
6-
#include <mutex>
75
#include <condition_variable>
8-
#include <functional> // std::function
6+
#include <functional> // std::function
7+
#include <mutex>
8+
#include <queue>
99

10-
#include "idevice/macro_def.h" // IDEVICE_DISALLOW_COPY_AND_ASSIGN
10+
#include "idevice/macro_def.h" // IDEVICE_DISALLOW_COPY_AND_ASSIGN
1111

1212
namespace idevice {
1313

@@ -19,29 +19,29 @@ class BlockingQueue {
1919
public:
2020
BlockingQueue() {}
2121
~BlockingQueue() {}
22-
22+
2323
IDEVICE_DISALLOW_COPY_AND_ASSIGN(BlockingQueue);
24-
24+
2525
/**
2626
* add(copy) a new element to the end of the queue
2727
* @param data new element
2828
*/
2929
void Push(const T& data) {
3030
std::unique_lock<std::mutex> lock(mutex_);
31-
queue_.push(data); // copy
31+
queue_.push(data); // copy
3232
not_empty_.notify_all();
3333
}
34-
34+
3535
/**
3636
* add(move) a new element to the end of the queue
3737
* @param data new element
3838
*/
3939
void Push(T&& data) {
4040
std::unique_lock<std::mutex> lock(mutex_);
41-
queue_.push(std::forward<T>(data)); // move
41+
queue_.push(std::forward<T>(data)); // move
4242
not_empty_.notify_all();
4343
}
44-
44+
4545
/**
4646
* take(move) the first element from the head of the queue
4747
* if the queue is empty, it will wait blocking.
@@ -52,11 +52,11 @@ class BlockingQueue {
5252
while (queue_.empty()) {
5353
not_empty_.wait(lock);
5454
}
55-
T data = std::move(queue_.front()); // move
55+
T data = std::move(queue_.front()); // move
5656
queue_.pop();
57-
return data; // move
57+
return data; // move
5858
}
59-
59+
6060
/**
6161
* waiting queue is not empty with a timeout
6262
* @param timeout_ms timeout
@@ -65,13 +65,14 @@ class BlockingQueue {
6565
bool WaitToTake(uint32_t timeout_ms) {
6666
std::unique_lock<std::mutex> lock(mutex_);
6767
while (queue_.empty()) {
68-
if (not_empty_.wait_for(lock, std::chrono::microseconds(timeout_ms)) == std::cv_status::timeout) {
68+
if (not_empty_.wait_for(lock, std::chrono::microseconds(timeout_ms)) ==
69+
std::cv_status::timeout) {
6970
return false;
7071
}
7172
}
7273
return true;
7374
}
74-
75+
7576
/**
7677
* checks whether the queue is empty
7778
* @return return true if the queue is empty
@@ -80,7 +81,7 @@ class BlockingQueue {
8081
std::unique_lock<std::mutex> lock(mutex_);
8182
return queue_.empty();
8283
}
83-
84+
8485
/**
8586
* clear the queue
8687
*/
@@ -96,21 +97,21 @@ class BlockingQueue {
9697
std::swap(queue_, empty);
9798
}
9899
}
99-
100+
100101
/**
101102
* Get size of the queue
102103
*/
103104
size_t Size() const { return queue_.size(); }
104-
105-
private:
105+
106+
private:
106107
mutable std::mutex mutex_;
107108
std::queue<T> queue_;
108109
std::condition_variable not_empty_;
109-
110-
}; // class BlockingQueue
110+
111+
}; // class BlockingQueue
111112

112113
} // namespace idevice
113114

114115
#include "idevice/macro_undef.h"
115116

116-
#endif // IDEVICE_BLOCKING_QUEUE_H
117+
#endif // IDEVICE_BLOCKING_QUEUE_H

include/idevice/bytebuffer.h

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,42 @@
22
#define IDEVICE_BYTE_BUFFER_H
33

44
#include <cstdint>
5+
#include <memory> // std::unique_ptr
56
#include <vector>
6-
#include <memory> // std::unique_ptr
77

8-
#include "idevice/macro_def.h" // IDEVICE_MEM_ALIGN, IDEVICE_DISALLOW_COPY_AND_ASSIGN
8+
#include "idevice/macro_def.h" // IDEVICE_MEM_ALIGN, IDEVICE_DISALLOW_COPY_AND_ASSIGN
99

1010
namespace idevice {
1111

1212
class BufferMemory {
1313
public:
14-
BufferMemory() {
15-
}
14+
BufferMemory() {}
1615
~BufferMemory() {
1716
if (buffer_) {
1817
free(buffer_);
1918
}
2019
}
21-
20+
2221
IDEVICE_DISALLOW_COPY_AND_ASSIGN(BufferMemory);
23-
22+
2423
char* Allocate(size_t req_size) {
2524
if (capacity_ - size_ < req_size) {
2625
if (!Reserve(size_ + req_size)) {
2726
printf("Error: can not allocate memory, size=%zu\n", req_size);
2827
return nullptr;
2928
}
3029
}
31-
30+
3231
char* ptr = buffer_ + size_;
3332
size_ += req_size;
3433
return ptr;
3534
}
36-
37-
char* GetPtr(size_t offset) {
38-
return buffer_ + offset;
39-
}
40-
35+
36+
char* GetPtr(size_t offset) { return buffer_ + offset; }
37+
4138
size_t Size() const { return size_; }
4239
void SetSize(size_t size) { size_ = size; }
43-
40+
4441
private:
4542
bool Reserve(size_t capacity) {
4643
size_t new_capacity = IDEVICE_MEM_ALIGN(capacity, 128);
@@ -55,7 +52,7 @@ class BufferMemory {
5552
}
5653
return false;
5754
}
58-
55+
5956
char* buffer_ = nullptr;
6057
size_t size_ = 0;
6158
size_t capacity_ = 0;
@@ -68,7 +65,7 @@ class ByteBuffer {
6865
public:
6966
using DataType = uint8_t;
7067
using DataArray = std::vector<DataType>;
71-
68+
7269
/**
7370
* constructor
7471
* @param reserve_size reserve size
@@ -77,25 +74,23 @@ class ByteBuffer {
7774
buffer_->reserve(reserve_size);
7875
};
7976
~ByteBuffer() {}
80-
77+
8178
IDEVICE_DISALLOW_COPY_AND_ASSIGN(ByteBuffer);
82-
79+
8380
// allow move and assign
8481
ByteBuffer(ByteBuffer&& other) : buffer_(std::move(other.buffer_)) {}
8582
ByteBuffer& operator=(ByteBuffer&& other) {
8683
buffer_ = std::unique_ptr<DataArray>(std::move(other.buffer_));
8784
return *this;
8885
}
89-
86+
9087
/**
9188
* get a mutable pointer to the buffer
9289
* @param offset offset from head
9390
* @return the pointer to the buffer
9491
*/
95-
void* GetBuffer(size_t offset) {
96-
return reinterpret_cast<uint8_t*>(buffer_->data()) + offset;
97-
}
98-
92+
void* GetBuffer(size_t offset) { return reinterpret_cast<uint8_t*>(buffer_->data()) + offset; }
93+
9994
/**
10095
* get unmutable pointer to the buffer
10196
* @param offset offset from head
@@ -104,7 +99,7 @@ class ByteBuffer {
10499
const void* GetReadOnlyBuffer(size_t offset) {
105100
return reinterpret_cast<const uint8_t*>(buffer_->data()) + offset;
106101
}
107-
102+
108103
/**
109104
* read(copy) some data from the buffer
110105
* @param buffer the dest buffer
@@ -133,7 +128,7 @@ class ByteBuffer {
133128
}
134129
return true;
135130
}
136-
131+
137132
/**
138133
* write(copy) some data to the specified offset position of the buffer
139134
* @param buffer the src buffer
@@ -159,7 +154,7 @@ class ByteBuffer {
159154
}
160155
return true;
161156
}
162-
157+
163158
/**
164159
* write(copy) some data to the end of the buffer
165160
* @param buffer the src buffer
@@ -170,7 +165,7 @@ class ByteBuffer {
170165
size_t size_written;
171166
return Write(buffer, buffer_size, Size(), &size_written) && buffer_size == size_written;
172167
}
173-
168+
174169
/**
175170
* resize the buffer
176171
* @param new_size the new size
@@ -180,22 +175,20 @@ class ByteBuffer {
180175
buffer_->resize(new_size);
181176
return true;
182177
}
183-
178+
184179
/**
185180
* get the current size of buffer
186181
* @return the size
187182
*/
188-
size_t Size() const {
189-
return buffer_->size();
190-
}
183+
size_t Size() const { return buffer_->size(); }
191184

192185
private:
193186
uint32_t alignment_;
194187
std::unique_ptr<DataArray> buffer_;
195-
}; // class ByteBuffer
188+
}; // class ByteBuffer
196189

197190
} // namespace idevice
198191

199192
#include "idevice/macro_undef.h"
200193

201-
#endif // IDEVICE_BYTE_BUFFER_H
194+
#endif // IDEVICE_BYTE_BUFFER_H

include/idevice/dtxchannel.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef IDEVICE_DTXCHANNEL_H
22
#define IDEVICE_DTXCHANNEL_H
33

4-
#include <cstdint> // uint32_t
4+
#include <cstdint> // uint32_t
55
#include <string>
66

77
#include "idevice/dtxmessenger.h"
@@ -10,13 +10,14 @@ namespace idevice {
1010

1111
class DTXChannel /*: public DTXMessenger */ {
1212
public:
13-
DTXChannel(DTXMessenger* connection, const std::string& label, uint32_t channel_identifier) : connection_(connection), label_(label), channel_identifier_(channel_identifier) {}
13+
DTXChannel(DTXMessenger* connection, const std::string& label, uint32_t channel_identifier)
14+
: connection_(connection), label_(label), channel_identifier_(channel_identifier) {}
1415
DTXChannel() : DTXChannel(nullptr, "", 0) {}
1516
virtual ~DTXChannel() {}
1617

1718
// virtual bool SendMessageSync(std::shared_ptr<DTXMessage> msg, ReplyHandler callback) override;
1819
void SendMessageAsync(std::shared_ptr<DTXMessage> msg, DTXMessenger::ReplyHandler callback);
19-
20+
2021
const std::string& Label() const { return label_; }
2122
uint32_t ChannelIdentifier() const { return channel_identifier_; }
2223

@@ -25,8 +26,8 @@ class DTXChannel /*: public DTXMessenger */ {
2526
uint32_t channel_identifier_ = 0;
2627
DTXMessenger* connection_ = nullptr;
2728

28-
}; // class DTXChannel
29+
}; // class DTXChannel
2930

3031
} // namespace idevice
3132

32-
#endif // IDEVICE_DTXCHANNEL_H
33+
#endif // IDEVICE_DTXCHANNEL_H

0 commit comments

Comments
 (0)