-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
745 additions
and
42 deletions.
There are no files selected for viewing
16 changes: 0 additions & 16 deletions
16
app/src/main/aidl/cc/ioctl/nfcdevicehost/ipc/INfcControllerManager.aidl
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
app/src/main/aidl/cc/ioctl/nfcdevicehost/ipc/IRemoteRuntime.aidl
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
app/src/main/cpp/ncihostd/ipc/logbuffer/LocalLogBuffer.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// | ||
// Created by kinit on 2022-01-02. | ||
// | ||
|
||
#include "LocalLogBuffer.h" | ||
|
||
using namespace logbuffer; | ||
|
||
LocalLogBuffer &LocalLogBuffer::getInstance() { | ||
static LocalLogBuffer gwInstance; | ||
return gwInstance; | ||
} | ||
|
||
void LocalLogBuffer::append(const LogEntryRecord &entry) { | ||
LogEntryRecord log = entry; | ||
// fill in the sequence number | ||
log.id = mSequenceNumber++; | ||
std::scoped_lock lock(mMutex); | ||
mLogRecords.push_back(log); | ||
// drop the oldest log records if the buffer is full | ||
if (mLogRecords.size() > MAX_LOG_ENTRIES) { | ||
mLogRecords.pop_front(); | ||
} | ||
} | ||
|
||
std::vector<LogEntryRecord> LocalLogBuffer::getAllLogs() { | ||
std::scoped_lock lock(mMutex); | ||
std::vector<LogEntryRecord> logs; | ||
logs.reserve(mLogRecords.size()); | ||
for (const auto &log: mLogRecords) { | ||
logs.push_back(log); | ||
} | ||
return logs; | ||
} | ||
|
||
std::vector<LogEntryRecord> LocalLogBuffer::getLogsPartial(uint32_t start, uint32_t count) { | ||
std::scoped_lock lock(mMutex); | ||
if (mLogRecords.empty()) { | ||
return {}; | ||
} | ||
std::vector<LogEntryRecord> logs; | ||
// iterate the log records | ||
auto it = mLogRecords.cbegin(); | ||
while (it != mLogRecords.cend()) { | ||
if (auto &log = *it; log.id >= start) { | ||
// found the start index | ||
if (logs.size() >= count) { | ||
break; | ||
} | ||
// add the log to the result list | ||
logs.push_back(log); | ||
} | ||
it++; | ||
} | ||
return logs; | ||
} | ||
|
||
size_t LocalLogBuffer::getLogCount() const { | ||
return mLogRecords.size(); | ||
} | ||
|
||
void LocalLogBuffer::clear() noexcept { | ||
std::scoped_lock lock(mMutex); | ||
mLogRecords.clear(); | ||
} | ||
|
||
uint32_t LocalLogBuffer::getFirstLogEntryIndex() noexcept { | ||
std::scoped_lock lock(mMutex); | ||
if (mLogRecords.empty()) { | ||
return 0; | ||
} else { | ||
return mLogRecords.front().id; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// | ||
// Created by kinit on 2022-01-02. | ||
// | ||
|
||
#ifndef NCI_HOST_NATIVES_LOCALLOGBUFFER_H | ||
#define NCI_HOST_NATIVES_LOCALLOGBUFFER_H | ||
|
||
#include <cstdint> | ||
#include <vector> | ||
#include <deque> | ||
#include <mutex> | ||
#include <atomic> | ||
|
||
#include "rpcprotocol/log/LogEntryRecord.h" | ||
|
||
namespace logbuffer { | ||
|
||
class LocalLogBuffer { | ||
private: | ||
constexpr static size_t MAX_LOG_ENTRIES = 4096; | ||
|
||
LocalLogBuffer() = default; | ||
|
||
public: | ||
LocalLogBuffer(const LocalLogBuffer &) = delete; | ||
|
||
LocalLogBuffer &operator=(const LocalLogBuffer &) = delete; | ||
|
||
[[nodiscard]] static LocalLogBuffer &getInstance(); | ||
|
||
void append(const LogEntryRecord &entry); | ||
|
||
[[nodiscard]] std::vector<LogEntryRecord> getAllLogs(); | ||
|
||
[[nodiscard]] std::vector<LogEntryRecord> getLogsPartial(uint32_t start, uint32_t count); | ||
|
||
[[nodiscard]] uint32_t getFirstLogEntryIndex() noexcept; | ||
|
||
[[nodiscard]] size_t getLogCount() const; | ||
|
||
void clear() noexcept; | ||
|
||
private: | ||
std::deque<LogEntryRecord> mLogRecords; | ||
std::mutex mMutex; | ||
std::atomic_uint32_t mSequenceNumber = 1; | ||
}; | ||
|
||
} | ||
|
||
#endif //NCI_HOST_NATIVES_LOCALLOGBUFFER_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.