-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
25 changed files
with
1,894 additions
and
104 deletions.
There are no files selected for viewing
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
78 changes: 78 additions & 0 deletions
78
...les/all-clusters-app/all-clusters-common/include/diagnostic-logs-provider-delegate-impl.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* | ||
* Copyright (c) 2023 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <app/clusters/diagnostic-logs-server/diagnostic-logs-provider-delegate.h> | ||
#include <app/clusters/diagnostic-logs-server/diagnostic-logs-server.h> | ||
|
||
#include <fstream> | ||
|
||
namespace chip { | ||
namespace app { | ||
namespace Clusters { | ||
namespace DiagnosticLogs { | ||
|
||
/** | ||
* The application delegate to statically define the options. | ||
*/ | ||
|
||
class LogProvider : public LogProviderDelegate | ||
{ | ||
static LogSessionHandle sLogSessionHandle; | ||
static LogProvider sInstance; | ||
|
||
public: | ||
LogSessionHandle StartLogCollection(IntentEnum logType); | ||
|
||
uint64_t GetNextChunk(LogSessionHandle logSessionHandle, chip::MutableByteSpan & outBuffer, bool & outIsEOF); | ||
|
||
void EndLogCollection(LogSessionHandle logSessionHandle); | ||
|
||
uint64_t GetTotalNumberOfBytesConsumed(LogSessionHandle logSessionHandle); | ||
|
||
void SetEndUserSupportLogFileDesignator(const char * logFileName); | ||
|
||
void SetNetworkDiagnosticsLogFileDesignator(const char * logFileName); | ||
|
||
void SetCrashLogFileDesignator(const char * logFileName); | ||
|
||
LogProvider(){}; | ||
|
||
~LogProvider(){}; | ||
|
||
static inline LogProvider & getLogProvider() { return sInstance; } | ||
|
||
private: | ||
const char * GetLogFilePath(IntentEnum logType); | ||
|
||
char mEndUserSupportLogFileDesignator[kLogFileDesignatorMaxLen]; | ||
char mNetworkDiagnosticsLogFileDesignator[kLogFileDesignatorMaxLen]; | ||
char mCrashLogFileDesignator[kLogFileDesignatorMaxLen]; | ||
|
||
std::ifstream mFileStream; | ||
|
||
LogSessionHandle mLogSessionHandle; | ||
|
||
uint64_t mTotalNumberOfBytesConsumed; | ||
}; | ||
|
||
} // namespace DiagnosticLogs | ||
} // namespace Clusters | ||
} // namespace app | ||
} // namespace chip |
131 changes: 131 additions & 0 deletions
131
examples/all-clusters-app/all-clusters-common/src/diagnostic-logs-provider-delegate-impl.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,131 @@ | ||
/* | ||
* | ||
* Copyright (c) 2023 Project CHIP Authors | ||
* All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include "diagnostic-logs-provider-delegate-impl.h" | ||
#include <app/clusters/diagnostic-logs-server/diagnostic-logs-provider-delegate.h> | ||
#include <app/clusters/diagnostic-logs-server/diagnostic-logs-server.h> | ||
|
||
using namespace chip; | ||
using namespace chip::app::Clusters::DiagnosticLogs; | ||
|
||
constexpr uint16_t kChunkSizeZero = 0; | ||
|
||
LogProvider LogProvider::sInstance; | ||
|
||
LogSessionHandle LogProvider::sLogSessionHandle; | ||
|
||
LogSessionHandle LogProvider::StartLogCollection(IntentEnum logType) | ||
{ | ||
|
||
mTotalNumberOfBytesConsumed = 0; | ||
|
||
// Open the file of type | ||
const char * fileName = GetLogFilePath(logType); | ||
if (fileName != nullptr) | ||
{ | ||
mFileStream.open(fileName, std::ios_base::binary | std::ios_base::in); | ||
if (!mFileStream.good()) | ||
{ | ||
ChipLogError(BDX, "Failed to open the log file"); | ||
return kInvalidLogSessionHandle; | ||
} | ||
sLogSessionHandle++; | ||
mLogSessionHandle = sLogSessionHandle; | ||
} | ||
else | ||
{ | ||
mLogSessionHandle = kInvalidLogSessionHandle; | ||
} | ||
return mLogSessionHandle; | ||
} | ||
|
||
uint64_t LogProvider::GetNextChunk(LogSessionHandle logSessionHandle, chip::MutableByteSpan & outBuffer, bool & outIsEOF) | ||
{ | ||
if (logSessionHandle != mLogSessionHandle && outBuffer.size() == 0) | ||
{ | ||
return kChunkSizeZero; | ||
} | ||
|
||
if (!mFileStream.is_open()) | ||
{ | ||
ChipLogError(BDX, "File is not open"); | ||
return kChunkSizeZero; | ||
} | ||
|
||
mFileStream.seekg(static_cast<long long>(mTotalNumberOfBytesConsumed)); | ||
mFileStream.read(reinterpret_cast<char *>(outBuffer.data()), kLogContentMaxSize); | ||
|
||
if (!(mFileStream.good() || mFileStream.eof())) | ||
{ | ||
ChipLogError(BDX, "Failed to read the log file"); | ||
mFileStream.close(); | ||
return kChunkSizeZero; | ||
} | ||
|
||
uint64_t bytesRead = static_cast<uint64_t>(mFileStream.gcount()); | ||
outIsEOF = (mFileStream.peek() == EOF); | ||
|
||
mTotalNumberOfBytesConsumed += bytesRead; | ||
return bytesRead; | ||
} | ||
|
||
void LogProvider::EndLogCollection(LogSessionHandle logSessionHandle) | ||
{ | ||
if (logSessionHandle == mLogSessionHandle && mFileStream.is_open()) | ||
{ | ||
mFileStream.close(); | ||
} | ||
} | ||
|
||
uint64_t LogProvider::GetTotalNumberOfBytesConsumed(LogSessionHandle logSessionHandle) | ||
{ | ||
if (logSessionHandle == mLogSessionHandle) | ||
{ | ||
return mTotalNumberOfBytesConsumed; | ||
} | ||
return kChunkSizeZero; | ||
} | ||
|
||
const char * LogProvider::GetLogFilePath(IntentEnum logType) | ||
{ | ||
switch (logType) | ||
{ | ||
case IntentEnum::kEndUserSupport: | ||
return mEndUserSupportLogFileDesignator; | ||
case IntentEnum::kNetworkDiag: | ||
return mNetworkDiagnosticsLogFileDesignator; | ||
case IntentEnum::kCrashLogs: | ||
return mCrashLogFileDesignator; | ||
default: | ||
return nullptr; | ||
} | ||
} | ||
|
||
void LogProvider::SetEndUserSupportLogFileDesignator(const char * logFileName) | ||
{ | ||
strncpy(mEndUserSupportLogFileDesignator, logFileName, strlen(logFileName)); | ||
} | ||
|
||
void LogProvider::SetNetworkDiagnosticsLogFileDesignator(const char * logFileName) | ||
{ | ||
strncpy(mNetworkDiagnosticsLogFileDesignator, logFileName, strlen(logFileName)); | ||
} | ||
|
||
void LogProvider::SetCrashLogFileDesignator(const char * logFileName) | ||
{ | ||
strncpy(mCrashLogFileDesignator, logFileName, strlen(logFileName)); | ||
} |
Oops, something went wrong.