[riot-notifications] [RIOT-OS/RIOT] net/coap: Add Link Format attributes to resources (#11328)

Ken Bannister notifications at github.com
Wed Apr 3 12:21:01 CEST 2019


> No, if NANOCOAP_CLIF_STATIC is defined one can't initialize only some fields without using the .field syntax.

I'm sorry I didn't test that myself. It is ugly to have to designated initializers everywhere.

An alternative, slightly more resource expensive approach is to define a separate array for resource extensions.

```
#ifdef NANOCOAP_CLIF_STATIC
    
typedef struct {
    const coap_resource_t *res;     /**< URI path of resource            */
    const char *clif_params;        /**< link format attributes @see Resource
                                         description section of net_gcoap */
} coap_resource_ext_t;
#endif
```

Used for example like this in the gcoap example:

```
static const coap_resource_t _resources[] = {
    { "/cli/stats", COAP_GET | COAP_PUT, _stats_handler, NULL },
    { "/riot/board", COAP_GET, _riot_board_handler, NULL, },
}

#ifdef NANOCOAP_CLIF_STATIC
static const coap_resource_ext_t _resource_exts[] = {
    &_resources[0], NULL,
    &_resources[1], "rt=\"info\";ct=0",
};
#endif
```

There might be other future uses for these extensions, so we could use other #ifdefs to trigger definition of _resource_exts as well. This likely would mean use of designated initializers in those definitions.

With this approach a function like `gcoap_get_resource_list()` would need to lookup an extension for each resource. But it should be simple/fast since it only compares pointers to the path and there are not many resources.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/pull/11328#issuecomment-479429918
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20190403/940110fc/attachment-0001.html>


More information about the notifications mailing list