Skip to content

Commit

Permalink
Do not directly manipulate the base class's Startup method
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca committed Dec 11, 2024
1 parent bb22e12 commit b735528
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/controller/tests/TestServerCommandDispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,13 @@ class DispatchTestDataModel : public CodegenDataModelProvider
// rather than depending on the code-generated one with undefined modifications.
CHIP_ERROR Startup(DataModel::InteractionModelContext context) override
{
ReturnErrorOnFailure(DataModel::Provider::Startup(context));

ReturnErrorOnFailure(CodegenDataModelProvider::Startup(context));
return CHIP_NO_ERROR;
}

protected:
// Override InitDataModel to do nothing.
void InitDataModel() override {}
};

class TestServerCommandDispatch : public chip::Test::AppContext
Expand Down
9 changes: 7 additions & 2 deletions src/data-model-providers/codegen/CodegenDataModelProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,7 @@ CHIP_ERROR CodegenDataModelProvider::Startup(DataModel::InteractionModelContext
}
}

// Call the Ember-specific InitDataModelHandler
InitDataModelHandler();
InitDataModel();

return CHIP_NO_ERROR;
}
Expand Down Expand Up @@ -883,6 +882,12 @@ ConcreteCommandPath CodegenDataModelProvider::NextGeneratedCommand(const Concret
return ConcreteCommandPath(before.mEndpointId, before.mClusterId, commandId);
}

void CodegenDataModelProvider::InitDataModel()
{
// Call the Ember-specific InitDataModelHandler
InitDataModelHandler();
}

std::optional<DataModel::DeviceTypeEntry> CodegenDataModelProvider::FirstDeviceType(EndpointId endpoint)
{
// Use the `Index` version even though `emberAfDeviceTypeListFromEndpoint` would work because
Expand Down
3 changes: 3 additions & 0 deletions src/data-model-providers/codegen/CodegenDataModelProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ class CodegenDataModelProvider : public DataModel::Provider

void Temporary_ReportAttributeChanged(const AttributePathParams & path) override;

protected:
virtual void InitDataModel();

private:
// Iteration is often done in a tight loop going through all values.
// To avoid N^2 iterations, cache a hint of where something is positioned
Expand Down

0 comments on commit b735528

Please sign in to comment.