Skip to content

Commit

Permalink
Wrote shell of the provider delegate in the example app
Browse files Browse the repository at this point in the history
  • Loading branch information
nivi-apple committed Oct 16, 2023
1 parent 2d43920 commit 5fab9d8
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 9 deletions.
6 changes: 5 additions & 1 deletion examples/log-source-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ import("//build_overrides/build.gni")
import("//build_overrides/chip.gni")

executable("chip-log-source-app") {
sources = [ "main.cpp" ]
sources = [
"main.cpp",
"${chip_root}/examples/log-source-app/log-source-common/DiagnosticLogsProvider.cpp",
"${chip_root}/examples/log-source-app/log-source-common/DiagnosticLogsProvider.h",
]

deps = [
"${chip_root}/examples/log-source-app/log-source-common",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
*
* 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 <app-common/zap-generated/attributes/Accessors.h>
#include <app-common/zap-generated/callback.h>
#include "DiagnosticLogsProvider.h"

#include <app/util/config.h>

using namespace chip;
using namespace chip::app;
using namespace chip::app::Clusters::DiagnosticLogs;

LogSessionHandle DiagnosticLogsProvider::StartLogCollection(IntentEnum logType)
{
if (mIsInLogSession)
{
return kInvalidLogSessionHandle;
}
mIsInLogSession = true;

// use the log type to maybe read a different file
mLogType = logType;

// open a log file for reading
return ++(Instance().mLogSessionHandle);
}

void DiagnosticLogsProvider::GetNextChunk(LogSessionHandle logSessionHandle, chip::MutableByteSpan & outBuffer, bool & outIsEOF)
{
// check if the file is valid and return chunks. maintain numberofbytesread and skip that much into the file
}

void DiagnosticLogsProvider::EndLogCollection(LogSessionHandle logSessionHandle)
{
// close the file
mTotalNumberOfBytesConsumed = 0;
mIsInLogSession = false;
}

uint32_t DiagnosticLogsProvider::GetTotalNumberOfBytesConsumed()
{
return mTotalNumberOfBytesConsumed;
}
52 changes: 52 additions & 0 deletions examples/log-source-app/log-source-common/DiagnosticLogsProvider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
*
* 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>

class DiagnosticLogsProvider : public chip::app::Clusters::DiagnosticLogs::Delegate
{

public:
DiagnosticLogsProvider() { }

chip::app::Clusters::DiagnosticLogs::LogSessionHandle StartLogCollection(chip::app::Clusters::DiagnosticLogs::IntentEnum logType);

void GetNextChunk(chip::app::Clusters::DiagnosticLogs::LogSessionHandle logSessionHandle, chip::MutableByteSpan & outBuffer, bool & outIsEOF);

void EndLogCollection(chip::app::Clusters::DiagnosticLogs::LogSessionHandle logSessionHandle);

uint32_t GetTotalNumberOfBytesConsumed();

static DiagnosticLogsProvider & Instance()
{
static DiagnosticLogsProvider instance;
return instance;
}

~DiagnosticLogsProvider() = default;

protected:

chip::app::Clusters::DiagnosticLogs::IntentEnum mLogType;
chip::app::Clusters::DiagnosticLogs::LogSessionHandle mLogSessionHandle;
uint32_t mTotalNumberOfBytesConsumed;

bool mIsInLogSession;
};
2 changes: 1 addition & 1 deletion src/app/bdx/DiagnosticLogsBDXTransferHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class DiagnosticLogsBDXTransferHandler : public chip::bdx::Initiator

bool mInitialized;

uint32_t mNumBytesSent = 0;
uint32_t mNumBytesSent;

LogSessionHandle mLogSessionHandle;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,9 @@ class Delegate

virtual void EndLogCollection(LogSessionHandle logSessionHandle);

virtual uint16_t GetTotalNumberOfBytesConsumed();
virtual uint32_t GetTotalNumberOfBytesConsumed();

virtual ~Delegate() = default;

private:

IntentEnum mLogType;
LogSessionHandle mLogSessionHandle;
uint16_t mTotalNumberOfBytesConsumed;
};

} // namespace DiagnosticLogs
Expand Down

0 comments on commit 5fab9d8

Please sign in to comment.