Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [wakaama-dev] Use of lwm2m_context_t in lwm2m_object_t callback / "lwm2m_resource_value_changed" and write from other lwm2m server

Hi,

 

When faced with the same need, I past the lwm2m_context_t pointer in the object lwm2m_object_t::userData (directly on inside a struct). See code snippets below.

I did not face any reentrancy issues but I did not test specifically for it.

 

I agree a more elegant solution is needed.

 

Regards,

David Navarro

 

In the object code:

typedef struct

{

    int32_t value;

    char string[16];

    lwm2m_context_t * lwm2mH;

} object_data_t;

 

void set_object_handle(lwm2m_object_t * objP,

                       lwm2m_context_t * lwm2mH)

{

    ((object_data_t *)objP->userData)->lwm2mH = lwm2mH;

}

 

lwm2m_object_t * get_object()

{

    lwm2m_object_t * objP;

 

    objP = (lwm2m_object_t *)lwm2m_malloc(sizeof(lwm2m_object_t));

 

    if (NULL != objP)

    {

        memset(objP, 0, sizeof(lwm2m_object_t));

 

        objP->objID = 300;

        objP->readFunc = prv_read;

        objP->writeFunc = prv_write;

        objP->executeFunc = prv_execute;

        objP->userData = lwm2m_malloc(sizeof(object_data_t));

        if (NULL != objP->userData)

        {

            ((object_data_t*) objP->userData)->value = 1234;

            strcpy(((object_data_t*)objP->userData)->string, “hello");

        }

        else

        {

            lwm2m_free(objP);

            objP= NULL;

        }

    }

 

    return objP;

}

 

In the client:

    // Create Object

    objArray[5] = get_object();

    if (NULL == objArray[5]) return -1;

 

    // Initialize lwm2m with objects

    lwm2mH = lwm2m_init(hostname, 7, objArray, prv_buffer_send, NULL);

    if (NULL == lwm2mH) return -1;

 

    set_object_handle(objArray[5], lwm2mH);

 

    lwm2m_set_monitoring_callback(lwm2mH, prv_monitor_callback, NULL);

 

 

From: wakaama-dev-bounces@xxxxxxxxxxx [mailto:wakaama-dev-bounces@xxxxxxxxxxx] On Behalf Of Kraus Achim (INST/ESY4)
Sent: Thursday, 5 March, 2015 11:36
To: wakaama-dev@xxxxxxxxxxx
Subject: [wakaama-dev] Use of lwm2m_context_t in lwm2m_object_t callback / "lwm2m_resource_value_changed" and write from other lwm2m server

 

Hi all,

 

sometimes I’m faced a situation, in which I would like to call some lwm2m functions from a lwm2m_object_t callback.

e.g. when executing “/1/0/8” (LWM2M Server / Registration update trigger) or when a different LWM2M Server writes

values, which may be observed by a other LWM2M Server.

But calling lwm2m functions (e.g. “lwm2m_resource_value_changed”) would require a “lwm2m_context_t”, which is

not reachable via “lwm2m_object_t” and making it available via a “global variable” is not something, I would prefer.

I’m also not sure, if such a call of lwm2m functions from a callback is a good idea (reentrant?).

Currently I used the return values and move the “effective code” to the core (e.g. as it was for “lwm2m_resource_value_changed”).

 

So, any ideas, which design for such functionality would be best?

 

Mit freundlichen Grüßen / Best regards

 

Achim Kraus

 

Bosch Software Innovations GmbH

Communications (INST/ESY4)

Stuttgarter Straße 130

71332 Waiblingen

GERMANY

www.bosch-si.de

www.blog.bosch-si.com

 

achim.kraus@xxxxxxxxxxxx

 

Registered office: Berlin, Register court: Amtsgericht Charlottenburg, HRB 148411 B

Executives: Dr.-Ing. Rainer Kallenbach; Michael Hahn

 

 

---------------------------------------------------------------------
Intel Corporation SAS (French simplified joint stock company)
Registered headquarters: "Les Montalets"- 2, rue de Paris,
92196 Meudon Cedex, France
Registration Number:  302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.


Back to the top