Dear Community User! We have started the migration process.
This community is now in READ ONLY mode.
Read more: Important information on the platform change.

cancel
Showing results for 
Search instead for 
Did you mean: 
SOLVED

Datalayer hierarchy in c++

Datalayer hierarchy in c++

osamaayoub
Established Member

Hello,

I am trying to create a hierarchy of nodes and folder in the datalayer and I am facing an issue with that.

When I create a folder on the datalayer which contains only nodes of different types, it goes smoothely without any problem. The problem starts when I want to create a Folder that contains nodes and other folders which also contains nodes.

The goal hierarchy:

  • Root
    • node1 (boolean node)
    • parent1
      • child1 (boolean node)

I tried several ways of doing that as follows: (The arguments of RegisterNodes are the name of the node, type and array length, I customized it to achieve certain goals)

Trial1:

auto Object = new ProviderNodeAllData(dlProvider, "Root", true);
Object->RegisterNodes("node1", "bool8", 0);
Object = new ProviderNodeAllData(dlProvider, "Root", true);
Object->RegisterNodes("Parent1/Child1", "bool8", 0);

Trial2:

 auto Object = new ProviderNodeAllData(dlProvider, "Root", true);
 Object->RegisterNodes("node1", "bool8", 0);
 Object = new ProviderNodeAllData(dlProvider, "Root/Parent1", true);
 Object->RegisterNodes("child1", "bool8", 0);

Trial3:

auto Object = new ProviderNodeAllData(dlProvider, "Root", true);
Object->RegisterNodes("node1", "bool8", 0);
auto Object2 = new ProviderNodeAllData(dlProvider, "Root/Parent1", true);
Object2->RegisterNodes("child1", "bool8", 0);

 Trial4:

auto Object = new ProviderNodeAllData(dlProvider, "Root", true);
Object->RegisterNodes("node1", "bool8", 0);
auto Object2 = new ProviderNodeAllData(dlProvider, "Root", true);
Object2->RegisterNodes("Parent1/child1", "bool8", 0);

 The issue is as shown in the picture, the folder doesn't have metadata:

osamaayoub_0-1665394712046.png

 

Here is a part of registerNodes function:

void ProviderNodeAllData::RegisterNodes(std::string name, std::string type, int32_t ArrayLength)
{

  comm::datalayer::DlResult result;
  comm::datalayer::Variant data;

  result = _provider->registerNode(_addressBase + "**", this);
  //These if statments checks the datatype of the node to be registered and create that node for non arrays
  if(type == "bool8" && ArrayLength == 0){
    result = data.setValue(false);
    createDataContainer(result, name, data);
.
.
.
.
}

 

Your help is highly appreciated.

Regards,

Osama

5 REPLIES 5

nickH
Community Moderator
Community Moderator

Hello Osama, 

the problem in the Data Layer are the missing metadata for your folder. Metadata for nodes can be provided as follows (see documentation) :

  • Via the ‪onMetadata()‬ of a ‪ProviderNodes‬
  • Or via a metadata database (MDDB)

 

In the sample samples-cpp/datalayer.register.node you can see an example where this is done via the metadata database. A metadata database is provided via CSV file. I changed the sample and tested it for a similar structure like you have (see screenshot). 

2022-10-11_10h52_11.png

 

You can try out my main.cpp and metadata.csv if you paste it into the sdk-sample (sample-cpp/datalayer.register.node).

Best regards, 

Nick

 

osamaayoub
Established Member

Thank you for your reply it is indeed helpful, I would prefer to use the first method without involving .csv files. Shouldn't the function:

comm::datalayer::Variant ProviderNodeAllData::createMetadata(const comm::datalayer::Variant &data, const std::string &address)

Shouldn't it take care of creating the metadata by itself? I can see that it is called when a new ProviderNodeAllData object is created.

I can also see inside createMetadata that it detect that the node parent1 is a folder class which is "7" and when it runs everything goes just fine. If I should use onMetadata() manually, is there something similar in the samples that I missed? 

Hello again,

I discovered the main reason behind the problem which is: The _addressBase is not being added correctly when I go deeper in the structure because of this line in RegisterNodes function

 

result = _provider->registerNode(_addressBase + "**", this);

 

So I changed it to:

 

result = _provider->registerNode(_addressBase , this);

 

To update the address base and get the metaData correctly when I have a deep structure.

Thank you so much for your help, it lead me to look deeper into onMetaData() which solved the problem for me.

 

Cheers,

Osama

nickH
Community Moderator
Community Moderator

Great to read that you discovered the problem. And many thanks for sharing the solution!

Regards, 

Nick

osamaayoub
Established Member

One last thing, the line of code that I changed is actually from the samples-cpp allDataProvider, I don't know if it is left like this intentionally or not, but I would suggest to add a comment there so no one would have such an issue later 🙂

Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist