Skip to content

Commit

Permalink
Seperate InitDataModel out
Browse files Browse the repository at this point in the history
  • Loading branch information
yufengwangca committed Dec 6, 2024
1 parent 5385f19 commit 5a8af59
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/app/codegen-data-model-provider/CodegenDataModelProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,13 @@ DefaultAttributePersistenceProvider gDefaultAttributePersistence;

} // namespace

void CodegenDataModelProvider::InitDataModel()
{
// Call the Ember-specific InitDataModelHandler
InitDataModelHandler();
ChipLogProgress(AppServer, "CodegenDataModelHandler initialized.");
}

CHIP_ERROR CodegenDataModelProvider::Startup(DataModel::InteractionModelContext context)
{
ReturnErrorOnFailure(DataModel::Provider::Startup(context));
Expand All @@ -438,9 +445,6 @@ CHIP_ERROR CodegenDataModelProvider::Startup(DataModel::InteractionModelContext
}
}

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

return CHIP_NO_ERROR;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ class CodegenDataModelProvider : public DataModel::Provider
};

public:
/// Initialize the data model internal code to be ready to send and receive data model messages.
void InitDataModel() override;

/// clears out internal caching. Especially useful in unit tests,
/// where path caching does not really apply (the same path may result in different outcomes)
void Reset()
Expand Down
3 changes: 3 additions & 0 deletions src/app/data-model-provider/Provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class Provider : public ProviderMetadataTree
public:
virtual ~Provider() = default;

// Initialize the data model internal code to be ready to send and receive data model messages.
virtual void InitDataModel() {}

// `context` pointers will be guaranteed valid until Shutdown is called()
virtual CHIP_ERROR Startup(InteractionModelContext context)
{
Expand Down
17 changes: 13 additions & 4 deletions src/app/server/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,17 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams)
SuccessOrExit(err = mAttributePersister.Init(mDeviceStorage));
SetSafeAttributePersistenceProvider(&mAttributePersister);

// SetDataModelProvider() actually initializes/starts the provider. We need
// to preserve the following ordering guarantees:
//
// 1) Provider initialization (under SetDataModelProvider) happens after
// SetSafeAttributePersistenceProvider, since the provider can then use
// the safe persistence provider to implement and initialize its own attribute persistence logic.
// 2) For now, provider initialization happens before InitDataModelHandler(), which depends
// on atttribute persistence being already set up before it runs. Longer-term, the logic from
// InitDataModelHandler should just move into the codegen provider.
app::InteractionModelEngine::GetInstance()->SetDataModelProvider(initParams.dataModelProvider);

{
FabricTable::InitParams fabricTableInitParams;
fabricTableInitParams.storage = mDeviceStorage;
Expand Down Expand Up @@ -290,10 +301,8 @@ CHIP_ERROR Server::Init(const ServerInitParams & initParams)
}
#endif // CHIP_CONFIG_ENABLE_SERVER_IM_EVENT

// Set the data model provider, initializing it in the process. This must
// happen after SetSafeAttributePersistenceProvider to ensure the provider
// can utilize the safe persistence provider for its attribute storage.
app::InteractionModelEngine::GetInstance()->SetDataModelProvider(initParams.dataModelProvider);
// This initializes clusters, so should come after lower level initialization.
app::InteractionModelEngine::GetInstance()->GetDataModelProvider()->InitDataModel();

#if defined(CHIP_APP_USE_ECHO)
err = InitEchoHandler(&mExchangeMgr);
Expand Down
2 changes: 2 additions & 0 deletions src/app/tests/test-interaction-model-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ class TestImCustomDataModel : public DataModel::Provider
public:
static TestImCustomDataModel & Instance();

void InitDataModel() override {}

CHIP_ERROR Shutdown() override { return CHIP_NO_ERROR; }

DataModel::ActionReturnStatus ReadAttribute(const DataModel::ReadAttributeRequest & request,
Expand Down

0 comments on commit 5a8af59

Please sign in to comment.