Hi Kishen,

 

Let me propose new APIs to satisfy followings.

 

Two requirements

: Multi Thread Application Code requirement

: Easy-to use with consistent API signature

 

Problem

: Singleton CborEncoder Root object prevent creating payload in multithread
race condition.

   - Get Response, Notify in Server side and Client side cannot be handled
from different thread.
           It could be done by synchronization handling from App side but
not easy to use.

 

How to….

 

Server Side AS-IS

oc_rep_start_root_object();

oc_process_baseline_interface(request->resource);

oc_rep_set_boolean(root, state, state);

oc_rep_end_root_object();

oc_send_response(request, OC_STATUS_OK);

 

Server Side TO-BE

CborEncoder new_rep = oc_rep_create_root_object();  // New Additional :
make opaque type for CborEncoder to hide it

oc_process_baseline_interface(new_rep, request->resource); // New
Additional (with parameter adding)

oc_rep_set_boolean(new_rep, state, state);

oc_rep_end_root_object(new_rep);          // we can remove this call with
tinycbor update.

oc_send_response(request, new_rep, OC_STATUS_OK);        // New Additional
(with parameter adding), refer new_rep with g_encoder.

 

Client Side AS-IS

oc_init_post(a_light, light_server, NULL, &post2_light, LOW_QOS, NULL)

oc_rep_start_root_object();

oc_rep_set_boolean(root, state, state);

oc_rep_end_root_object();

oc_do_post();

 

Client Side TO-BE

// oc_init_post(a_light, light_server, NULL, &post2_light, LOW_QOS, NULL)
ß This can be skipped because params are set in new oc_do_post.

CborEncoder new_rep = oc_rep_create_root_object();

oc_rep_set_boolean(new_rep, state, state);

oc_rep_end_root_object(new_rep);          // we can remove this call with
tinycbor update.

oc_do_post(a_light, light_server, NULL, new_rep, &post2_light, LOW_QOS,
NULL); // New Additional (with parameter adding), refer new_rep with
g_encoder, This will make API consistent with oc_do_get(……)

 

--- Sumary New API List. ---

CborEncoder_opaque oc_rep_create_root_object()

oc_process_baseline_interface(new_rep, request->resource) // adding param

oc_send_response(request, new_rep, OC_STATUS_OK); // adding param

oc_do_post(…..) // adding param

_______________________________________________
iotivity-dev mailing list
iotivity-dev@lists.iotivity.org
https://lists.iotivity.org/mailman/listinfo/iotivity-dev

Reply via email to