-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathDataSenderManagerWorkerThread.h
89 lines (72 loc) · 2.45 KB
/
DataSenderManagerWorkerThread.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
#pragma once
#include "DataSenderManager.h"
#include "DataSenderTypes.h"
#include "IConnectivityModule.h"
#include "Signal.h"
#include "Thread.h"
#include "Timer.h"
#include <atomic>
#include <cstdint>
#include <memory>
#include <mutex>
#include <vector>
namespace Aws
{
namespace IoTFleetWise
{
class DataSenderManagerWorkerThread
{
public:
DataSenderManagerWorkerThread( std::shared_ptr<IConnectivityModule> connectivityModule,
std::shared_ptr<DataSenderManager> dataSenderManager,
uint64_t persistencyUploadRetryIntervalMs,
std::vector<std::shared_ptr<DataSenderQueue>> dataToSendQueues );
~DataSenderManagerWorkerThread();
DataSenderManagerWorkerThread( const DataSenderManagerWorkerThread & ) = delete;
DataSenderManagerWorkerThread &operator=( const DataSenderManagerWorkerThread & ) = delete;
DataSenderManagerWorkerThread( DataSenderManagerWorkerThread && ) = delete;
DataSenderManagerWorkerThread &operator=( DataSenderManagerWorkerThread && ) = delete;
static const uint32_t MAX_NUMBER_OF_SIGNAL_TO_TRACE_LOG;
/**
* @brief Callback from the Inspection Engine to wake up this thread and
* publish the data to the cloud.
*/
void onDataReadyToPublish();
/**
* @brief Stops the internal thread if started and wait until it finishes
*
* @return true if the stop was successful
*/
bool stop();
/**
* @brief Starts the internal thread
*
* @return true if the start was successful
*/
bool start();
/**
* @brief Checks that the worker thread is healthy and consuming data.
*/
bool isAlive();
private:
// Stop the thread
bool shouldStop() const;
static void doWork( void *data );
std::vector<std::shared_ptr<DataSenderQueue>> mDataToSendQueues;
uint64_t mPersistencyUploadRetryIntervalMs{ 0 };
Thread mThread;
std::atomic<bool> mShouldStop{ false };
std::mutex mThreadMutex;
Signal mWait;
std::shared_ptr<DataSenderManager> mDataSenderManager;
std::shared_ptr<IConnectivityModule> mConnectivityModule;
#ifdef FWE_FEATURE_REMOTE_COMMANDS
std::shared_ptr<DataSenderQueue> mCommandResponses;
#endif
Timer mTimer;
Timer mRetrySendingPersistedDataTimer;
};
} // namespace IoTFleetWise
} // namespace Aws