Giter Club home page Giter Club logo

Comments (6)

lguohan avatar lguohan commented on July 17, 2024

to avoid complex failure handling behavior (in case you set multiple attributes but one of them has failure), the set api (all set APIs) can only set one attribute.

from sai.

OPetryshyn avatar OPetryshyn commented on July 17, 2024

I'd expect to see 4 different functions:

setAttribute
setAttributesList
getAttribute
getAttributesList

Let the SAI user to choose how to set/get attribute(s)

from sai.

kcudnik avatar kcudnik commented on July 17, 2024

There is no need for get "list" since current get function can get 1 or n attributes at once. As for set, as @lguohan said, it's by design to support only 1 attribute on set. Also if you need set with multiple attributes it's easy for user to implement that and handle failures in the way user want.

Can you give a valid example when setting more attributes at once have more benefits/advantage than setting them one after another ?

from sai.

OPetryshyn avatar OPetryshyn commented on July 17, 2024

ok, Ex.
I want to set 5 attributes and I need to check each one step by step. I just want to check if value is set correctly.


int i;
sai_object_id *attr_ids = (sai_object_id*) calloc(5, sizeof(sai_object_id));
uint32_t *attr_values = (uint32_t*) calloc(5, sizeof(uint32_t));
sai_object_id_t port_id;
sai_attribute_t attr;

memset(&port_id, 0, sizeof (port_id));
memset(&attr, 0, sizeof (attr));

//Let`s set some values to these arrays.
for (i = 0; i < 5; ++i)
{
attr_ids = i;
attr_values = i;
}

for (i = 0; i < 5; ++i)
{
//Setting one attribute
    attr.id = attr_ids[i];
    attr.value.u32 = attr_values[i];
    err = set_port_attribute(port_id, &attr);
    if (err) printf("Error %i\n", i);

//Resetting attr value
    attr.value.u32  = 0xFFFFFFFF;

//Getting one attribute with a hardcoded attr_count to 1,
// because I need to check only one current value. Isn`t it confusing?
// Also take a look on this function name - "get_port_attribute",
// assuming to work only with one attribute.
    err = get_port_attribute(port_id, 1, &attr);
    if (err) printf("Error %i\n", i);

//Checking value of the current attribute
    if (attr.value.u32 != attr_values[i]) printf("Error value is wrong! %i\n", i); 
}
free(attr_values);
free(attr_ids);

from sai.

OPetryshyn avatar OPetryshyn commented on July 17, 2024

In case of setting list of attributes in a function, one advantage is to check if this function will return no error. So I`m expecting that all the values are set correctly. But there is no such API in SAI, user needs to make it, create some loop and call set function step by step.

from sai.

kcudnik avatar kcudnik commented on July 17, 2024

This is fine when all attributtes will be set succesfully, but when one of them fails then behaviou can be ether fail right away and not set other attributes or continue set, but when continuing, more attributes can fail. So setting 1 attribute give user control on what he wants to do in case of failure. I think i dont fully understand your example

from sai.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.