Skip to content

Commit

Permalink
Restyled by clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
restyled-commits authored and nivi-apple committed Oct 31, 2023
1 parent 0349632 commit 1ce1262
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ class LogProvider : public LogProviderDelegate

void SetCrashLogFileDesignator(const char * logFileName);

LogProvider() { };
LogProvider(){};

~LogProvider() { };
~LogProvider(){};

static inline LogProvider & getLogProvider() { return sInstance; }

Expand Down
11 changes: 7 additions & 4 deletions examples/all-clusters-app/linux/AppOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

#include "AppOptions.h"

#include <app/clusters/diagnostic-logs-server/diagnostic-logs-server.h>
#include <app/server/CommissioningWindowManager.h>
#include <app/server/Server.h>
#include <app/clusters/diagnostic-logs-server/diagnostic-logs-server.h>

using namespace chip::ArgParser;
using namespace chip::app::Clusters::DiagnosticLogs;
Expand Down Expand Up @@ -59,23 +59,26 @@ bool AppOptions::HandleOptions(const char * program, OptionSet * options, int id
ChipLogError(BDX, "kOptionEndUserSupportFilePath setting end user fd");
if (strlen(value) > kLogFileDesignatorMaxLen)
{
PrintArgError("%s: Invalid file path length. Must be less that %d: %d\n", program, kLogFileDesignatorMaxLen, strlen(value));
PrintArgError("%s: Invalid file path length. Must be less that %d: %d\n", program, kLogFileDesignatorMaxLen,
strlen(value));
}
strncpy(mEndUserSupportLogFileDesignator, value, strlen(value));
break;
}
case kOptionNetworkDiagnosticsFilePath: {
if (strlen(value) > kLogFileDesignatorMaxLen)
{
PrintArgError("%s: Invalid file path length. Must be less that %d: %d\n", program, kLogFileDesignatorMaxLen, strlen(value));
PrintArgError("%s: Invalid file path length. Must be less that %d: %d\n", program, kLogFileDesignatorMaxLen,
strlen(value));
}
strncpy(mNetworkDiagnosticsLogFileDesignator, value, strlen(value));
break;
}
case kOptionCrashFilePath: {
if (strlen(value) > kLogFileDesignatorMaxLen)
{
PrintArgError("%s: Invalid file path length. Must be less that %d: %d\n", program, kLogFileDesignatorMaxLen, strlen(value));
PrintArgError("%s: Invalid file path length. Must be less that %d: %d\n", program, kLogFileDesignatorMaxLen,
strlen(value));
}
strncpy(mCrashLogFileDesignator, value, strlen(value));
break;
Expand Down
1 change: 0 additions & 1 deletion examples/all-clusters-app/linux/main-common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,5 +278,4 @@ void emberAfDiagnosticLogsClusterInitCallback(chip::EndpointId endpoint)
LogProvider::getLogProvider().SetEndUserSupportLogFileDesignator(AppOptions::GetEndUserSupportLogFileDesignator());
LogProvider::getLogProvider().SetNetworkDiagnosticsLogFileDesignator(AppOptions::GetNetworkDiagnosticsLogFileDesignator());
LogProvider::getLogProvider().SetCrashLogFileDesignator(AppOptions::GetCrashLogFileDesignator());

}
12 changes: 5 additions & 7 deletions src/app/bdx/DiagnosticLogsBDXTransferHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ void DiagnosticLogsBDXTransferHandler::HandleTransferSessionOutput(TransferSessi

break;
}
case TransferSession::OutputEventType::kAcceptReceived:
{
case TransferSession::OutputEventType::kAcceptReceived: {
mLogSessionHandle = mDelegate->StartLogCollection(mIntent);

if (mLogSessionHandle == kInvalidLogSessionHandle)
Expand All @@ -160,8 +159,7 @@ void DiagnosticLogsBDXTransferHandler::HandleTransferSessionOutput(TransferSessi
DiagnosticLogsServer::Instance().HandleBDXResponse(CHIP_NO_ERROR);
}
// Fallthrough
case TransferSession::OutputEventType::kAckReceived:
{
case TransferSession::OutputEventType::kAckReceived: {
uint16_t blockSize = mTransfer.GetTransferBlockSize();
uint16_t bytesToRead = blockSize;

Expand Down Expand Up @@ -242,11 +240,11 @@ void DiagnosticLogsBDXTransferHandler::Reset()
if (mDelegate != nullptr)
{
mDelegate->EndLogCollection(mLogSessionHandle);
mDelegate = nullptr;
mDelegate = nullptr;
}
mLogSessionHandle = kInvalidLogSessionHandle;
mInitialized = false;
mNumBytesSent = 0;
mInitialized = false;
mNumBytesSent = 0;
}

#endif
5 changes: 2 additions & 3 deletions src/app/bdx/DiagnosticLogsBDXTransferHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ namespace DiagnosticLogs {
class DiagnosticLogsBDXTransferHandler : public chip::bdx::Initiator
{
public:
DiagnosticLogsBDXTransferHandler() {};
~DiagnosticLogsBDXTransferHandler() {};
DiagnosticLogsBDXTransferHandler(){};
~DiagnosticLogsBDXTransferHandler(){};

CHIP_ERROR Init();

Expand All @@ -52,7 +52,6 @@ class DiagnosticLogsBDXTransferHandler : public chip::bdx::Initiator
void Reset();

private:

void SendNextBlock(MutableByteSpan & buffer);

chip::Optional<chip::FabricIndex> mFabricIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ CHIP_ERROR DiagnosticLogsServer::HandleLogRequestForBDXProtocol(Messaging::Excha

VerifyOrReturnError(!(DiagnosticLogs::isLogProviderDelegateNull(logProviderDelegate, endpointId)), CHIP_ERROR_INCORRECT_STATE);

mDiagnosticLogsBDXTransferHandler = new DiagnosticLogsBDXTransferHandler();
CHIP_ERROR error = mDiagnosticLogsBDXTransferHandler->InitializeTransfer(
mDiagnosticLogsBDXTransferHandler = new DiagnosticLogsBDXTransferHandler();
CHIP_ERROR error = mDiagnosticLogsBDXTransferHandler->InitializeTransfer(
exchangeCtx, scopedPeerNodeId.GetFabricIndex(), scopedPeerNodeId.GetNodeId(), logProviderDelegate, intent, fileDesignator);
return error;
}
Expand All @@ -138,7 +138,7 @@ void DiagnosticLogsServer::HandleBDXResponse(CHIP_ERROR error)
}
else
{
SendErrorResponseAndReset(commandHandle, mRequestPath, StatusEnum::kNoLogs);
SendErrorResponseAndReset(commandHandle, mRequestPath, StatusEnum::kNoLogs);
}
}

Expand All @@ -148,16 +148,17 @@ void DiagnosticLogsServer::SetAsyncCommandHandleAndPath(CommandHandler * command
mRequestPath = commandPath;
}

void DiagnosticLogsServer::SendErrorResponseAndReset(chip::app::CommandHandler * commandHandler, chip::app::ConcreteCommandPath path, StatusEnum status)
void DiagnosticLogsServer::SendErrorResponseAndReset(chip::app::CommandHandler * commandHandler,
chip::app::ConcreteCommandPath path, StatusEnum status)
{
Commands::RetrieveLogsResponse::Type response;
if (commandHandler != nullptr)
{
response.status = status;
commandHandler->AddResponse(path, response);
}
//mDiagnosticLogsBDXTransferHandler->Reset();
//delete(mDiagnosticLogsBDXTransferHandler);
// mDiagnosticLogsBDXTransferHandler->Reset();
// delete(mDiagnosticLogsBDXTransferHandler);
}

#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ class DiagnosticLogsServer

bool IsBDXProtocolRequested(TransferProtocolEnum requestedProtocol);

void SendErrorResponseAndReset(chip::app::CommandHandler * commandHandler, chip::app::ConcreteCommandPath path, StatusEnum status);
void SendErrorResponseAndReset(chip::app::CommandHandler * commandHandler, chip::app::ConcreteCommandPath path,
StatusEnum status);

#endif

Expand Down
31 changes: 13 additions & 18 deletions src/darwin/Framework/CHIP/MTRDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1353,9 +1353,8 @@ - (void)_startTimerForDownload:(NSTimeInterval)timeout

dispatch_source_set_event_handler(_timerSource, ^{
dispatch_async(self.queue, ^{
if (self->_diagnosticLogsTransferHandler != nil)
{
self->_diagnosticLogsTransferHandler->AbortTransfer( chip::bdx::StatusCode::kUnknown);
if (self->_diagnosticLogsTransferHandler != nil) {
self->_diagnosticLogsTransferHandler->AbortTransfer(chip::bdx::StatusCode::kUnknown);
}
});
dispatch_source_cancel(self->_timerSource);
Expand Down Expand Up @@ -1398,28 +1397,26 @@ - (bool)_isErrorResponse:(MTRDiagnosticLogsClusterRetrieveLogsResponseParams * _
return (response == nil || (response.status != nil && [response.status intValue] != 0 && [response.status intValue] != 1) || response.logContent.length == 0);
}

-(void)_invokeCompletion:(void (^)(NSURL * _Nullable logResult, NSError * error))completion
filepath:(NSURL * _Nullable)filepath
queue:(dispatch_queue_t)queue
error:(NSError * _Nullable)error
- (void)_invokeCompletion:(void (^)(NSURL * _Nullable logResult, NSError * error))completion
filepath:(NSURL * _Nullable)filepath
queue:(dispatch_queue_t)queue
error:(NSError * _Nullable)error
{
if (self->_diagnosticLogsTransferHandler != nil)
{
delete(self->_diagnosticLogsTransferHandler);
if (self->_diagnosticLogsTransferHandler != nil) {
delete (self->_diagnosticLogsTransferHandler);
}
dispatch_async(queue, ^{
completion(filepath, error);
});
}

-(void)_invokeCompletionWithError:(void (^)(NSURL * _Nullable logResult, NSError * error))completion
queue:(dispatch_queue_t)queue
error:(NSError * _Nullable)error
- (void)_invokeCompletionWithError:(void (^)(NSURL * _Nullable logResult, NSError * error))completion
queue:(dispatch_queue_t)queue
error:(NSError * _Nullable)error
{
[self _invokeCompletion:completion filepath:nil queue:queue error:error];
}


- (void)_downloadLogOfType:(MTRDiagnosticLogType)type
timeout:(NSTimeInterval)timeout
queue:(dispatch_queue_t)queue
Expand All @@ -1441,8 +1438,7 @@ - (void)_downloadLogOfType:(MTRDiagnosticLogType)type
[self _invokeCompletionWithError:completion queue:queue error:[NSError errorWithDomain:MTRErrorDomain code:MTRErrorCodeInvalidState userInfo:nil]];
}

if (self->_diagnosticLogsTransferHandler != nullptr && self->_diagnosticLogsTransferHandler->IsInBDXSession())
{
if (self->_diagnosticLogsTransferHandler != nullptr && self->_diagnosticLogsTransferHandler->IsInBDXSession()) {
[self _invokeCompletionWithError:completion queue:queue error:[NSError errorWithDomain:MTRInteractionErrorDomain code:MTRInteractionErrorCodeBusy userInfo:nil]];
}

Expand All @@ -1465,8 +1461,7 @@ - (void)_downloadLogOfType:(MTRDiagnosticLogType)type

dispatch_async(self.queue, ^{
// Start a timer if a timeout is provided
if (timeout > 0)
{
if (timeout > 0) {
[self _startTimerForDownload:timeout];
}

Expand Down
17 changes: 7 additions & 10 deletions src/darwin/Framework/CHIP/MTRDiagnosticLogsTransferHandler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@
error = CHIP_ERROR_INTERNAL;
}
// Notify the MTRDevice via the callback that the BDX transfer has completed with error or success.
if (mCallback)
{
if (mCallback) {
mCallback(error != CHIP_NO_ERROR ? NO : YES);
}
Reset();
Expand Down Expand Up @@ -196,23 +195,21 @@
}
break;
case TransferSession::OutputEventType::kAckEOFReceived:
// Need to call OnTransferSessionEnd(event). Need to fix this and remove isBlockEOFSent.
break;
// Need to call OnTransferSessionEnd(event). Need to fix this and remove isBlockEOFSent.
break;
case TransferSession::OutputEventType::kMsgToSend:
err = OnMessageToSend(event);
if (event.msgTypeData.HasMessageType(MessageType::BlockAckEOF))
{
if (event.msgTypeData.HasMessageType(MessageType::BlockAckEOF)) {
// TODO: This is a hack for determinin that the Ack EOF is sent before cleaning up.
// Need to fix this.
isBlockEOFSent = true;
}
break;
case TransferSession::OutputEventType::kNone:
if (isBlockEOFSent)
{
if (isBlockEOFSent) {
OnTransferSessionEnd(event);
}
break;
}
break;
case TransferSession::OutputEventType::kQueryWithSkipReceived:
case TransferSession::OutputEventType::kQueryReceived:
case TransferSession::OutputEventType::kAckReceived:
Expand Down

0 comments on commit 1ce1262

Please sign in to comment.