void iotjs_uart_destroy_platform_data( iotjs_uart_platform_data_t* platform_data) { IOTJS_ASSERT(platform_data); iotjs_string_destroy(&platform_data->device_path); IOTJS_RELEASE(platform_data); }
// Recieved data to write from ClientRequest._write void iotjs_https_data_to_write(iotjs_https_t* https_data, iotjs_string_t read_chunk, const iotjs_jval_t* callback, const iotjs_jval_t* onwrite) { IOTJS_VALIDATED_STRUCT_METHOD(iotjs_https_t, https_data); if (_this->to_destroy_read_onwrite) { _this->to_destroy_read_onwrite = false; iotjs_string_destroy(&(_this->read_chunk)); iotjs_jval_destroy(&(_this->read_onwrite)); iotjs_jval_destroy(&(_this->read_callback)); } _this->read_chunk = read_chunk; _this->data_to_read = true; _this->read_callback = iotjs_jval_create_copied(callback); _this->read_onwrite = iotjs_jval_create_copied(onwrite); _this->to_destroy_read_onwrite = true; if (_this->request_done) { iotjs_https_call_read_onwrite_async(https_data); } else if (_this->is_stream_writable) { curl_easy_pause(_this->curl_easy_handle, CURLPAUSE_CONT); uv_timer_stop(&(_this->timeout)); uv_timer_start(&(_this->timeout), iotjs_https_uv_timeout_callback, 1, 0); } }
static void Print(iotjs_jhandler_t* jhandler, FILE* out_fd) { JHANDLER_CHECK_ARGS(1, string); iotjs_string_t msg = JHANDLER_GET_ARG(0, string); fprintf(out_fd, "%s", iotjs_string_data(&msg)); iotjs_string_destroy(&msg); }
static void iotjs_pwm_destroy(iotjs_pwm_t* pwm) { IOTJS_VALIDATED_STRUCT_DESTRUCTOR(iotjs_pwm_t, pwm); iotjs_jobjectwrap_destroy(&_this->jobjectwrap); #if defined(__linux__) iotjs_string_destroy(&_this->device); #endif IOTJS_RELEASE(pwm); }
// Cleanup before destructor void iotjs_https_cleanup(iotjs_https_t* https_data) { IOTJS_VALIDATED_STRUCT_METHOD(iotjs_https_t, https_data); _this->loop = NULL; uv_close((uv_handle_t*)&_this->timeout, (uv_close_cb)iotjs_https_uv_close_callback); uv_close((uv_handle_t*)&_this->socket_timeout, (uv_close_cb)iotjs_https_uv_close_callback); uv_close((uv_handle_t*)&_this->async_read_onwrite, (uv_close_cb)iotjs_https_uv_close_callback); iotjs_https_jcallback(https_data, IOTJS_MAGIC_STRING_ONEND, iotjs_jargs_get_empty(), false); iotjs_https_jcallback(https_data, IOTJS_MAGIC_STRING_ONCLOSED, iotjs_jargs_get_empty(), false); curl_multi_remove_handle(_this->curl_multi_handle, _this->curl_easy_handle); curl_easy_cleanup(_this->curl_easy_handle); _this->curl_easy_handle = NULL; curl_multi_cleanup(_this->curl_multi_handle); _this->curl_multi_handle = NULL; curl_slist_free_all(_this->header_list); if (_this->poll_data != NULL) iotjs_https_poll_close_all(_this->poll_data); if (_this->to_destroy_read_onwrite) { const iotjs_jargs_t* jarg = iotjs_jargs_get_empty(); const iotjs_jval_t* jthis = &(_this->jthis_native); IOTJS_ASSERT(iotjs_jval_is_function(&(_this->read_onwrite))); if (!iotjs_jval_is_undefined(&(_this->read_callback))) iotjs_make_callback(&(_this->read_callback), jthis, jarg); iotjs_make_callback(&(_this->read_onwrite), jthis, jarg); _this->to_destroy_read_onwrite = false; iotjs_string_destroy(&(_this->read_chunk)); iotjs_jval_destroy(&(_this->read_onwrite)); iotjs_jval_destroy(&(_this->read_callback)); } return; }
//----------------Utility Functions------------------ void iotjs_https_check_done(iotjs_https_t* https_data) { IOTJS_VALIDATED_STRUCT_METHOD(iotjs_https_t, https_data); char* done_url; CURLMsg* message; int pending; bool error = false; while ((message = curl_multi_info_read(_this->curl_multi_handle, &pending))) { switch (message->msg) { case CURLMSG_DONE: curl_easy_getinfo(message->easy_handle, CURLINFO_EFFECTIVE_URL, &done_url); break; default: error = true; } if (error) { iotjs_jargs_t jarg = iotjs_jargs_create(1); char error[] = "Unknown Error has occured."; iotjs_string_t jresult_string = iotjs_string_create_with_size(error, strlen(error)); iotjs_jargs_append_string(&jarg, &jresult_string); iotjs_https_jcallback(https_data, IOTJS_MAGIC_STRING_ONERROR, &jarg, false); iotjs_string_destroy(&jresult_string); iotjs_jargs_destroy(&jarg); } if (_this->stream_ended) { iotjs_https_cleanup(https_data); } else { if (_this->to_destroy_read_onwrite) { iotjs_https_call_read_onwrite_async(https_data); } _this->request_done = true; } break; } }
static void bridge_native_async_handler(uv_async_t* handle) { DDDLOG("%s\n", __func__); iotjs_call_jfunc_t* data = (iotjs_call_jfunc_t*)handle->data; bool result; iotjs_string_t output; result = bridge_native_call(IOTJS_MAGIC_STRING_TIZEN, data->fn_name, data->message, &output); if (data->cb) { data->cb((int)!result, iotjs_string_data(&output)); } iotjs_string_destroy(&output); // release uv_close((uv_handle_t*)&data->async, NULL); IOTJS_RELEASE(data->module); IOTJS_RELEASE(data->fn_name); IOTJS_RELEASE(data->message); IOTJS_RELEASE(data); }
// This function should be able to print utf8 encoded string // as utf8 is internal string representation in Jerryscript static jerry_value_t Print(const jerry_value_t* jargv, const jerry_length_t jargc, FILE* out_fd) { JS_CHECK_ARGS(1, string); iotjs_string_t msg = JS_GET_ARG(0, string); const char* str = iotjs_string_data(&msg); unsigned str_len = iotjs_string_size(&msg); unsigned idx = 0; if (iotjs_console_out) { int level = (out_fd == stdout) ? DBGLEV_INFO : DBGLEV_ERR; iotjs_console_out(level, "%s", str); } else { for (idx = 0; idx < str_len; idx++) { if (str[idx] != 0) { fprintf(out_fd, "%c", str[idx]); } else { fprintf(out_fd, "\\u0000"); } } } iotjs_string_destroy(&msg); return jerry_create_undefined(); }