16 views
in System Integration by

Hello Everyone.
I want to ask what are the best practices to access and/or modify data from "native" code. Let me explain with an example :
In my C++ source code I have many methods that look like the following :

void DeviceExamsModelClass::GetAvailableExams()
{
	etl::vector<SDKEnums::AudExamType, SDKEnums::ExamTypesNumber> availableExams = m_examsManager->GetAvailableExams(); 

	for (uint8_t i = 0; i < availableExams.size(); i++)
	{
		// APPROACH 1
		DeviceExamsVMUnitDeviceExamsVMClass__UpdateAvailableExams(m_ExamsVM, (XInt32)availableExams.at(i), i); // Use EmWi function to access ViewModel data
		
		// APPROACH 2
		m_ExamsVM->AvailableExams[i] = (XInt32)availableExams.at(i); // Directly write data in ViewModel's array
	}
}

I am using a Model / View / ViewModel architecture. 

In Embebbed Wizard I declare and implement "ViewModel" classes, which contain all the methods and variables needed to exchange data between the Model and the View.
To provide data to the GUI in the Model's source code I usually call a ViewModel function ( "APPROACH 1" in the code snippet). 

With this approach I needto write a method for every possible data exchange between model and view, which can result a little pedantic.

I found that I can directly access ViewModel's variables ( "APPROACH 2" in the code snippet). This allows me to make ViewModels slimmer, and I appreciate that most of the data access responsibilities remain in the model.

 

I would like to know if this approach is safe/advisable, what are its possible disadvantages or problems, and if it is better to continue using the "classic" approach that connects Model and ViewModel with a dedicated method

 

Thanks in advance and Best regards,

Dario.

1 Answer

0 votes
ago by

Hello Dario,

From technical point of view Embedded Wizard generates C code so accessing it from native code is possible and safe in most cases. It expects however some knowledge about how the generated code is structured. Therefore we don't explain nor officially recommend this approach.

Nevertheless if you want to follow this approach, my recommendation would be to implement the desired expression in Chora (e.g. access to the variable) and then analyze/copy the generated code to your native code.

Please note, that when accessing the generated code (e.g. variables) directly there are still restrictions to take in account. See:

Take care in multi-threading environments

Be careful when exchanging strings

Don't retain nor modify objects or strings

I hope it helps you further.

Best regards

Paul Banach

ago by
Thank you Paul for the clear and complete answer.

After reading the articles you linked and analyzing the generated code I understand why it is not a recommended method, and I will continue the development with the safer "classic" approach.

Best Regards.
Dario

Embedded Wizard Website | Privacy Policy | Imprint

...