149 views
in GUI Development by

Hi,

I want to store the history of screen traversed from root screen. For example If screen is switched from RootScreen--->HomeScreen--->MenuScreen--->SubMenuScreen like that. So I trying to implement a queue of double linked list to store the infos of the screen traversed. 

For that I've created a class node, having variables 'next' and 'prev' of type Application::node and data of type class. The variable "data" is meant to store the class of the screen traversed. And I've created one more class node_task having variables head and tail of type Application::node.

I've added a method inside Application::node_task to create a new node in the list, create_node method. The data is given as argument and it should create a new node and return the new_node. 
Return type : Application::node
Argument = class data;
Code snippet:
var Application::node new_node = new Application::node;
new_node.data = data;
new_node.next = null;
new_node.prev = null;
return new_node;


I've added one more method insert_at_head
Return type
: void
Argument = class data;
Code snippet:

var Application::node new_node;
new_node = create_node(data);

if(head == null)
{
  head = new_node;
  head.next = new_node.prev;
  tail = new_node;
  tail.prev = new_node.next;
}
else
{
  var Application::node temp = head;
  while(temp.next != null)
  {
    if(temp.data == data)
    {
      trace "attempted to add the same data twice";
      return;  
    }
    temp = temp.next;
  }
  new_node.next = head;
  head.prev = new_node;
  head = new_node;
}


so what happening exactly is that, everytime when insert_at_head method is called, it's updating the data variable and new_node but the head and tail is always null only

Can you please help me to fix this

1 Answer

0 votes
by
Hi,

based on the provided code snippets I do not see any issue - in principle the code should work...

Can you add some trace messages (e.g. for head and tail when the method insert_at_head() is entered and before it is left)? Maybe your head and tail variables are cleared outside?

Otherwise, can you provide a small example that demonstrates the issue you have (e.g. instead of the class data you can simple use a number) - then it will be easier to help you.

Best regards,
Manfred.
by
Hi Manfred,

I'm having one query. I'm trying to call the insert_at_head method inside a gui componenet class, like Application::node_queue_obj.insert_at_head(data) by creating a object of node_queue class
For the first time it's calling from Screen1, then the head should be null it's correct, working fine
For the second time, when I'm calling this insert_at_head method from Screen1, the head should have the address of the new_node created. But here, the head is been still null only.

So what I did, I've added the node_queue_obj in Device class and checked the DeviceClass Init constructor method. For the first time when prototyper is running, by that time only DeviceClass Init is called. So node_queue_obj head remains same, hence it's having the new_node address now.

So Is that possible for other classes Init method to be called only once, same like how DeviceClass is been performing
by

Hello,

I assume your node_queue is accessed as an autoobject in order to have one global instance of the node_queue class. This is very convenient, because autoobjects can be accessed from everywhere in your project.

Please consider the livetime of autoobjects. Everytime, the autoobject is no more in use, the instance will be deleted by the Garbage Collector. When the next screen accesses the node_queue, a new instance of the class will be created. Within the Prototyper on PC, the Garabage Collector is running after a couple of seconds - thus, you probably get sometimes the expected value and sometimes the content is lost after some seconds. 

In order to prevent the Garbage Collector from freeing an autoobject, please add a variable to the root class, set the type to your class Application::node_queue_class and the value to the instance (autoobject) of the class. 

I hope this helps....

Best regards,

Manfred.

 

by
Can you please share the sample code snippet of how to add this variable and set the value as auto object of a class in root class

How in DeviceClass is alone Init method is called only once and other classes it's not happening?
by

Can you add a variable to your Application Root object, declare the variable with type corresponding to the of the autoobject and initialize the variable with the autoobject. This will prevent the autoobject from being discarded.

How in DeviceClass is alone Init method is called only once and other classes it's not happening?

Sorry, but I do not understand this question... A device class is not handled different than other classes.

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

...