53 views
in GUI Development by
Hello,

I want to store a slot, which should connected to a dynamically created object, in a container in the middleware.

Converting slot to handle fails, therefore it is not possible to store slot as handle. Is there any way to store slot address?

Kind Regards Jonas

1 Answer

0 votes
by
 
Best answer

Hello Jonas,

the typecast to handle will fail because slot is more than a simple pointer. It consists of multiple members referring the slot method and the object in context of which the method should be executed.

Generally storing objects (thus also slots and references to properties) as well as strings is not recommended. It will lead to runtime errors unless you carefully ensure to lock/unlock and share the corresponding entities. Without this, the Garbage Collection has no knowledge about the references existing in your middleware and may decide to release the entities. See also: Don't retain nor modify objects or strings.

Best regards

Paul Banach

by
Hello Paul,

the plan was to create a dynamically menu, where one can set number of entries and their behavior at runtime. The entries info should be set and stored when the menu is created, but the entries itself get created when menu is enlarged. Garbage Collection should not be a problem, because the storage in created in the Init and released in the Done method.

If it is not possible to store the slot info in any way I have to redesign the menu structure.
by

Hello Jonas,

assuming, the slots are stored in the Init() method and you don't forget to release any of the stored slots in the Done() method, the approach can work. However please note the limitation of this approach for the target system only. If you plan to use this functionality also in the Prototyper using own implemented Prototyper extensions (so-called Intrinsic Modules), this will not work. Intrinsic Modules can't use the Runtime Environment functionality of the Prototyper.

For the case you want to use this functionality in the target system only, then following would help you:

1. To store a slot in C code, declare the corresponding variables with the type XSlot. Its default value should be {0,0}. For example:

XSlot someSlot = { 0, 0 };

2. In the Init() method you can initialize the variable with a slot. For example:

$if !$prototyper
  // Get a reference to a slot method
  var slot theSlot = SlotMethod;

  // In native code store the slot reference in a C variable
  native ( theSlot )
  {
    extern XSlot someSlot;
    someSlot = theSlot;
  }
$endif

3. In the Done() method reset the C variable to be NULL again. In this case you can use the global EwNullSlot constant and assign it to the variable:

$if !$prototyper
  // In native code reset the slot reference.
  native
  {
    extern XSlot someSlot;
    someSlot = EwNullSlot;
  }
$endif

4. In your middleware (or whenever it is appropriate) you send a signal to the slot by using the function EwSignal(), EwPostSignal() or EwIdleSignal() (similar to the Chora statements signal, postsignal and idelsignal). For example:

// 'postsignal' to the slot stored in the variable 'someSlot'.
// Sender object is NULL.
EwPostSignal( someSlot, 0 );

Since this approach is beyond what we recommend, there is no official documentation for the above data types and functions. For more details you have to search in ewrte.h file from the build environment for those declarations.

I hope it helps you further. Don't forget to always correctly disconnect the slots or very difficult to find runtime errors will occur.

Best regards

Paul Banach

 

by
Thank you for your answer, Paul. This is not a suitable solution. I was searching for some easy cast method or something similar. Therefore I am going the way to create a struct in EW and storing the menu data in it.

Ask Embedded Wizard

Welcome to the question and answer site for Embedded Wizard users and UI developers.

Ask your question and receive answers from the Embedded Wizard support team or from other members of the community!

Embedded Wizard Website | Privacy Policy | Imprint

...