Using kii-core

If you implement the Thing SDK Embedded as a stand-alone SDK, the kii-core APIs allow you to use the Kii Cloud SDK even on a non-preemptive OS, which does not support automatic task switching. kii-core is included in the kii-core directory as a part of the source code of the Thing SDK Embedded.

You can use the Thing-IF SDK only on preemptive OSes.

The Thing SDK Embedded functions are blocking APIs. Therefore, those functions do not return control until the API completes. kii-core is designed to allow processes to be executed step by step so that you can use the same functionalities on non-preemptive and preemptive OSes.

Use each of the Thing SDK Embedded APIs and the kii-core APIs as below.

  • If the target OS supports only non-preemptive task control

    Time-consuming tasks on a non-preemptive OS need to voluntarily yield control to other tasks. Execute the kii-core APIs repeatedly so that you can complete the task gradually.

  • If the target OS supports preemptive task control

    The OS automatically switches tasks. Simply call the Thing SDK Embedded APIs to receive a result.

This guide does not cover how to use the kii-core APIs. Refer to the source code of the Thing SDK Embedded.

For example, kii_object.c implements kii_object_create_with_id() as below.

int ret = -1;
kii_error_code_t core_err;
kii_state_t state;

core_err = kii_core_create_new_object_with_id(
    &kii->kii_core,
    bucket,
    object_id,
    object_data,
    object_content_type);
if (core_err != KIIE_OK) {
  goto exit;
}
do {
  core_err = kii_core_run(&kii->kii_core);
  state = kii_core_get_state(&kii->kii_core);
} while (state != KII_STATE_IDLE);
if (core_err != KIIE_OK) {
  goto exit;
}
if(kii->kii_core.response_code < 200 || 300 <= kii->kii_core.response_code) {
  goto exit;
}

kii_core_create_new_object_with_id() and kii_core_run() in the above code are kii-core APIs. This code generates a request, advances the process with the do...while statement, and gets a result at the end.

You can learn how to implement the other APIs in the same way.