// Call any property of ClientRequest._Incoming bool iotjs_https_jcallback(iotjs_https_t* https_data, const char* property, const iotjs_jargs_t* jarg, bool resultvalue) { iotjs_jval_t* jthis = iotjs_https_jthis_from_https(https_data); bool retval = true; if (iotjs_jval_is_null(jthis)) return retval; iotjs_jval_t jincoming = iotjs_jval_get_property(jthis, IOTJS_MAGIC_STRING__INCOMING); iotjs_jval_t cb = iotjs_jval_get_property(&jincoming, property); IOTJS_ASSERT(iotjs_jval_is_function(&cb)); if (!resultvalue) { iotjs_make_callback(&cb, &jincoming, jarg); } else { iotjs_jval_t result = iotjs_make_callback_with_result(&cb, &jincoming, jarg); retval = iotjs_jval_as_boolean(&result); iotjs_jval_destroy(&result); } iotjs_jval_destroy(&jincoming); iotjs_jval_destroy(&cb); return retval; }
static void iotjs_pwm_set_configuration(const iotjs_jval_t* jconfiguration, iotjs_pwm_t* pwm) { IOTJS_VALIDATED_STRUCT_METHOD(iotjs_pwm_t, pwm); iotjs_jval_t jpin = iotjs_jval_get_property(jconfiguration, IOTJS_MAGIC_STRING_PIN); _this->pin = iotjs_jval_as_number(&jpin); #if defined(__linux__) iotjs_jval_t jchip = iotjs_jval_get_property(jconfiguration, IOTJS_MAGIC_STRING_CHIP); _this->chip = iotjs_jval_as_number(&jchip); iotjs_jval_destroy(&jchip); #endif iotjs_jval_t jperiod = iotjs_jval_get_property(jconfiguration, IOTJS_MAGIC_STRING_PERIOD); if (iotjs_jval_is_number(&jperiod)) _this->period = iotjs_jval_as_number(&jperiod); iotjs_jval_t jduty_cycle = iotjs_jval_get_property(jconfiguration, IOTJS_MAGIC_STRING_DUTYCYCLE); if (iotjs_jval_is_number(&jduty_cycle)) _this->duty_cycle = iotjs_jval_as_number(&jduty_cycle); iotjs_jval_destroy(&jpin); iotjs_jval_destroy(&jperiod); iotjs_jval_destroy(&jduty_cycle); }
// 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); } }
iotjs_jval_t InitBuffer() { iotjs_jval_t buffer = iotjs_jval_create_function_with_dispatch(Buffer); iotjs_jval_t prototype = iotjs_jval_create_object(); iotjs_jval_t byte_length = iotjs_jval_create_function_with_dispatch(ByteLength); iotjs_jval_set_property_jval(&buffer, IOTJS_MAGIC_STRING_PROTOTYPE, &prototype); iotjs_jval_set_property_jval(&buffer, IOTJS_MAGIC_STRING_BYTELENGTH, &byte_length); iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_COMPARE, Compare); iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_COPY, Copy); iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_WRITE, Write); iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_HEXWRITE, HexWrite); iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_WRITEUINT8, WriteUInt8); iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_READUINT8, ReadUInt8); iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_SLICE, Slice); iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_TOSTRING, ToString); iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_TOHEXSTRING, ToHexString); iotjs_jval_destroy(&prototype); iotjs_jval_destroy(&byte_length); return buffer; }
void iotjs_binding_finalize() { iotjs_jval_destroy(&jundefined); iotjs_jval_destroy(&jnull); iotjs_jval_destroy(&jtrue); iotjs_jval_destroy(&jfalse); iotjs_jval_destroy(&jglobal); iotjs_jargs_destroy(&jargs_empty); }
size_t iotjs_bufferwrap_length(iotjs_bufferwrap_t* bufferwrap) { IOTJS_VALIDATED_STRUCT_METHOD(iotjs_bufferwrap_t, bufferwrap); #ifndef NDEBUG iotjs_jval_t jbuf = iotjs_bufferwrap_jbuffer(bufferwrap); iotjs_jval_t jlength = iotjs_jval_get_property(&jbuf, IOTJS_MAGIC_STRING_LENGTH); size_t length = iotjs_jval_as_number(&jlength); IOTJS_ASSERT(length == _this->length); iotjs_jval_destroy(&jbuf); iotjs_jval_destroy(&jlength); #endif return _this->length; }
void iotjs_jhandler_return_string_raw(iotjs_jhandler_t* jhandler, const char* ret) { IOTJS_VALIDATED_STRUCT_METHOD(iotjs_jhandler_t, jhandler); iotjs_jval_t jval = iotjs_jval_create_string_raw(ret); iotjs_jhandler_return_jval(jhandler, &jval); iotjs_jval_destroy(&jval); }
void iotjs_jval_set_property_string_raw(const iotjs_jval_t* jobj, const char* name, const char* v) { const IOTJS_VALIDATED_STRUCT_METHOD(iotjs_jval_t, jobj); iotjs_jval_t jval = iotjs_jval_create_string_raw(v); iotjs_jval_set_property_jval(jobj, name, &jval); iotjs_jval_destroy(&jval); }
void iotjs_jval_set_property_number(const iotjs_jval_t* jobj, const char* name, double v) { const IOTJS_VALIDATED_STRUCT_METHOD(iotjs_jval_t, jobj); iotjs_jval_t jval = iotjs_jval_create_number(v); iotjs_jval_set_property_jval(jobj, name, &jval); iotjs_jval_destroy(&jval); }
// Make a callback for the given `function` with `this_` binding and `args` // arguments. The next tick callbacks registered via `process.nextTick()` // will be called after the callback function `function` returns. void iotjs_make_callback(const iotjs_jval_t* jfunction, const iotjs_jval_t* jthis, const iotjs_jargs_t* jargs) { iotjs_jval_t result = iotjs_make_callback_with_result(jfunction, jthis, jargs); iotjs_jval_destroy(&result); }
static void iotjs_adc_set_configuration(iotjs_adc_t* adc, const iotjs_jval_t* jconfiguration) { #if defined(__linux__) IOTJS_VALIDATED_STRUCT_METHOD(iotjs_adc_t, adc); iotjs_jval_t jdevice = iotjs_jval_get_property(jconfiguration, IOTJS_MAGIC_STRING_DEVICE); _this->device = iotjs_jval_as_string(&jdevice); iotjs_jval_destroy(&jdevice); #elif defined(__NUTTX__) IOTJS_VALIDATED_STRUCT_METHOD(iotjs_adc_t, adc); iotjs_jval_t jpin = iotjs_jval_get_property(jconfiguration, IOTJS_MAGIC_STRING_PIN); _this->pin = iotjs_jval_as_number(&jpin); iotjs_jval_destroy(&jpin); #endif }
iotjs_bufferwrap_t* iotjs_bufferwrap_from_jbuffer(const iotjs_jval_t* jbuffer) { IOTJS_ASSERT(iotjs_jval_is_object(jbuffer)); iotjs_jval_t jbuiltin = iotjs_jval_get_property(jbuffer, IOTJS_MAGIC_STRING__BUILTIN); iotjs_bufferwrap_t* buffer = iotjs_bufferwrap_from_jbuiltin(&jbuiltin); iotjs_jval_destroy(&jbuiltin); return buffer; }
iotjs_jval_t InitAdc() { iotjs_jval_t jadc = iotjs_jval_create_object(); iotjs_jval_t jadcConstructor = iotjs_jval_create_function_with_dispatch(AdcConstructor); iotjs_jval_set_property_jval(&jadc, IOTJS_MAGIC_STRING_ADC, &jadcConstructor); iotjs_jval_t jprototype = iotjs_jval_create_object(); iotjs_jval_set_method(&jprototype, IOTJS_MAGIC_STRING_READ, Read); iotjs_jval_set_method(&jprototype, IOTJS_MAGIC_STRING_CLOSE, Close); iotjs_jval_set_property_jval(&jadcConstructor, IOTJS_MAGIC_STRING_PROTOTYPE, &jprototype); iotjs_jval_destroy(&jprototype); iotjs_jval_destroy(&jadcConstructor); return jadc; }
iotjs_jval_t InitSpi() { iotjs_jval_t jspi = iotjs_jval_create_object(); iotjs_jval_t jspiConstructor = iotjs_jval_create_function_with_dispatch(SpiConstructor); iotjs_jval_set_property_jval(&jspi, IOTJS_MAGIC_STRING_SPI, &jspiConstructor); iotjs_jval_t prototype = iotjs_jval_create_object(); iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_TRANSFERARRAY, TransferArray); iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_TRANSFERBUFFER, TransferBuffer); iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_CLOSE, Close); iotjs_jval_set_property_jval(&jspiConstructor, IOTJS_MAGIC_STRING_PROTOTYPE, &prototype); iotjs_jval_destroy(&prototype); iotjs_jval_destroy(&jspiConstructor); // SPI mode properties iotjs_jval_t jmode = iotjs_jval_create_object(); iotjs_jval_set_property_number(&jmode, IOTJS_MAGIC_STRING_0, kSpiMode_0); iotjs_jval_set_property_number(&jmode, IOTJS_MAGIC_STRING_1, kSpiMode_1); iotjs_jval_set_property_number(&jmode, IOTJS_MAGIC_STRING_2, kSpiMode_2); iotjs_jval_set_property_number(&jmode, IOTJS_MAGIC_STRING_3, kSpiMode_3); iotjs_jval_set_property_jval(&jspi, IOTJS_MAGIC_STRING_MODE_U, &jmode); iotjs_jval_destroy(&jmode); // SPI mode properties iotjs_jval_t jcs = iotjs_jval_create_object(); iotjs_jval_set_property_number(&jcs, IOTJS_MAGIC_STRING_NONE, kSpiCsNone); iotjs_jval_set_property_number(&jcs, IOTJS_MAGIC_STRING_HIGH, kSpiCsHigh); iotjs_jval_set_property_jval(&jspi, IOTJS_MAGIC_STRING_CHIPSELECT_U, &jcs); iotjs_jval_destroy(&jcs); // SPI order properties iotjs_jval_t jbit_order = iotjs_jval_create_object(); iotjs_jval_set_property_number(&jbit_order, IOTJS_MAGIC_STRING_MSB, kSpiOrderMsb); iotjs_jval_set_property_number(&jbit_order, IOTJS_MAGIC_STRING_LSB, kSpiOrderLsb); iotjs_jval_set_property_jval(&jspi, IOTJS_MAGIC_STRING_BITORDER_U, &jbit_order); iotjs_jval_destroy(&jbit_order); return jspi; }
void iotjs_jargs_replace(iotjs_jargs_t* jargs, uint16_t index, const iotjs_jval_t* x) { IOTJS_VALIDATED_STRUCT_METHOD(iotjs_jargs_t, jargs); IOTJS_ASSERT(index < _this->argc); iotjs_jval_destroy(&_this->argv[index]); _this->argv[index] = iotjs_jval_create_copied(x); }
void iotjs_jval_set_method(const iotjs_jval_t* jobj, const char* name, JHandlerType handler) { const IOTJS_VALIDATED_STRUCT_METHOD(iotjs_jval_t, jobj); IOTJS_ASSERT(iotjs_jval_is_object(jobj)); iotjs_jval_t jfunc = iotjs_jval_create_function(handler); iotjs_jval_set_property_jval(jobj, name, &jfunc); iotjs_jval_destroy(&jfunc); }
static int iotjs_spi_get_array_data(char** buf, const iotjs_jval_t* jarray) { iotjs_jval_t jlength = iotjs_jval_get_property(jarray, IOTJS_MAGIC_STRING_LENGTH); IOTJS_ASSERT(!iotjs_jval_is_undefined(&jlength)); size_t length = iotjs_jval_as_number(&jlength); IOTJS_ASSERT((int)length >= 0); *buf = iotjs_buffer_allocate(length); for (size_t i = 0; i < length; i++) { iotjs_jval_t jdata = iotjs_jval_get_property_by_index(jarray, i); (*buf)[i] = iotjs_jval_as_number(&jdata); iotjs_jval_destroy(&jdata); } iotjs_jval_destroy(&jlength); return (int)length; }
//--------------LibTUV Callbacks------------------ // Callback called on closing handles during cleanup void iotjs_https_uv_close_callback(uv_handle_t* handle) { iotjs_https_t* https_data = (iotjs_https_t*)handle->data; IOTJS_VALIDATED_STRUCT_METHOD(iotjs_https_t, https_data); _this->closing_handles = _this->closing_handles - 1; if (_this->closing_handles <= 0) { if (_this->poll_data != NULL) iotjs_https_poll_destroy(_this->poll_data); iotjs_jval_destroy(&_this->jthis_native); } }
// Calls next tick callbacks registered via `process.nextTick()`. bool iotjs_process_next_tick() { const iotjs_jval_t* process = iotjs_module_get(MODULE_PROCESS); iotjs_jval_t jon_next_tick = iotjs_jval_get_property(process, IOTJS_MAGIC_STRING__ONNEXTTICK); IOTJS_ASSERT(iotjs_jval_is_function(&jon_next_tick)); iotjs_jval_t jres = iotjs_jhelper_call_ok(&jon_next_tick, iotjs_jval_get_undefined(), iotjs_jargs_get_empty()); IOTJS_ASSERT(iotjs_jval_is_boolean(&jres)); bool ret = iotjs_jval_as_boolean(&jres); iotjs_jval_destroy(&jres); iotjs_jval_destroy(&jon_next_tick); return ret; }
// 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; }
void iotjs_process_emit_exit(int code) { const iotjs_jval_t* process = iotjs_module_get(MODULE_PROCESS); iotjs_jval_t jexit = iotjs_jval_get_property(process, IOTJS_MAGIC_STRING_EMITEXIT); IOTJS_ASSERT(iotjs_jval_is_function(&jexit)); iotjs_jargs_t jargs = iotjs_jargs_create(1); iotjs_jargs_append_number(&jargs, code); bool throws; iotjs_jval_t jres = iotjs_jhelper_call(&jexit, process, &jargs, &throws); iotjs_jargs_destroy(&jargs); iotjs_jval_destroy(&jres); iotjs_jval_destroy(&jexit); if (throws) { exit(2); } }
void iotjs_uncaught_exception(const iotjs_jval_t* jexception) { const iotjs_jval_t* process = iotjs_module_get(MODULE_PROCESS); iotjs_jval_t jonuncaughtexception = iotjs_jval_get_property(process, IOTJS_MAGIC_STRING__ONUNCAUGHTEXCEPTION); IOTJS_ASSERT(iotjs_jval_is_function(&jonuncaughtexception)); iotjs_jargs_t args = iotjs_jargs_create(1); iotjs_jargs_append_jval(&args, jexception); bool throws; iotjs_jval_t jres = iotjs_jhelper_call(&jonuncaughtexception, process, &args, &throws); iotjs_jargs_destroy(&args); iotjs_jval_destroy(&jres); iotjs_jval_destroy(&jonuncaughtexception); if (throws) { exit(2); } }
void iotjs_jhandler_return_jval(iotjs_jhandler_t* jhandler, const iotjs_jval_t* ret) { IOTJS_VALIDATED_STRUCT_METHOD(iotjs_jhandler_t, jhandler); #ifndef NDEBUG IOTJS_ASSERT(_this->finished == false); #endif iotjs_jval_destroy(&_this->jret); _this->jret = iotjs_jval_create_copied(ret); #ifndef NDEBUG _this->finished = true; #endif }
void iotjs_jhandler_throw(iotjs_jhandler_t* jhandler, const iotjs_jval_t* err) { IOTJS_VALIDATED_STRUCT_METHOD(iotjs_jhandler_t, jhandler); #ifndef NDEBUG IOTJS_ASSERT(_this->finished == false); #endif iotjs_jval_destroy(&_this->jret); _this->jret = iotjs_jval_create_copied(err); jerry_value_set_error_flag(&_this->jret.unsafe.value); #ifndef NDEBUG _this->finished = true; #endif }
void iotjs_jargs_destroy(iotjs_jargs_t* jargs) { IOTJS_VALIDATED_STRUCT_DESTRUCTOR(iotjs_jargs_t, jargs); IOTJS_ASSERT(_this->argv == NULL || _this->argc > 0); IOTJS_ASSERT(_this->argc <= _this->capacity); if (_this->capacity > 0) { for (unsigned i = 0; i < _this->argc; ++i) { iotjs_jval_destroy(&_this->argv[i]); } iotjs_buffer_release((char*)_this->argv); } else { IOTJS_ASSERT(_this->argv == NULL); } }
static void iotjs_adc_after_work(uv_work_t* work_req, int status) { iotjs_adc_reqwrap_t* req_wrap = iotjs_adc_reqwrap_from_request(work_req); iotjs_adc_reqdata_t* req_data = iotjs_adc_reqwrap_data(req_wrap); iotjs_jargs_t jargs = iotjs_jargs_create(2); bool result = req_data->result; if (status) { iotjs_jval_t error = iotjs_jval_create_error("System error"); iotjs_jargs_append_jval(&jargs, &error); iotjs_jval_destroy(&error); } else { switch (req_data->op) { case kAdcOpOpen: if (!result) { iotjs_jargs_append_error(&jargs, "Failed to open ADC device"); } else { iotjs_jargs_append_null(&jargs); } break; case kAdcOpRead: if (!result) { iotjs_jargs_append_error(&jargs, "Cannot read from ADC device"); } else { iotjs_jargs_append_null(&jargs); iotjs_jargs_append_number(&jargs, req_data->value); } break; case kAdcOpClose: if (!result) { iotjs_jargs_append_error(&jargs, "Cannot close ADC device"); } else { iotjs_jargs_append_null(&jargs); } break; default: { IOTJS_ASSERT(!"Unreachable"); break; } } } const iotjs_jval_t* jcallback = iotjs_adc_reqwrap_jcallback(req_wrap); iotjs_make_callback(jcallback, iotjs_jval_get_undefined(), &jargs); iotjs_jargs_destroy(&jargs); iotjs_adc_reqwrap_dispatched(req_wrap); }
static void iotjs_spi_set_configuration(iotjs_spi_t* spi, const iotjs_jval_t* joptions) { IOTJS_VALIDATED_STRUCT_METHOD(iotjs_spi_t, spi); #if defined(__linux__) iotjs_jval_t jdevice = iotjs_jval_get_property(joptions, IOTJS_MAGIC_STRING_DEVICE); _this->device = iotjs_jval_as_string(&jdevice); iotjs_jval_destroy(&jdevice); #elif defined(__NUTTX__) || defined(__TIZENRT__) iotjs_jval_t jbus = iotjs_jval_get_property(joptions, IOTJS_MAGIC_STRING_BUS); _this->bus = iotjs_jval_as_number(&jbus); iotjs_jval_destroy(&jbus); #endif iotjs_jval_t jmode = iotjs_jval_get_property(joptions, IOTJS_MAGIC_STRING_MODE); _this->mode = (SpiMode)iotjs_jval_as_number(&jmode); iotjs_jval_destroy(&jmode); iotjs_jval_t jchip_select = iotjs_jval_get_property(joptions, IOTJS_MAGIC_STRING_CHIPSELECT); _this->chip_select = (SpiChipSelect)iotjs_jval_as_number(&jchip_select); iotjs_jval_destroy(&jchip_select); iotjs_jval_t jmax_speed = iotjs_jval_get_property(joptions, IOTJS_MAGIC_STRING_MAXSPEED); _this->max_speed = iotjs_jval_as_number(&jmax_speed); iotjs_jval_destroy(&jmax_speed); iotjs_jval_t jbits_per_word = iotjs_jval_get_property(joptions, IOTJS_MAGIC_STRING_BITSPERWORD); _this->bits_per_word = (SpiOrder)iotjs_jval_as_number(&jbits_per_word); iotjs_jval_destroy(&jbits_per_word); iotjs_jval_t jbit_order = iotjs_jval_get_property(joptions, IOTJS_MAGIC_STRING_BITORDER); _this->bit_order = (SpiOrder)iotjs_jval_as_number(&jbit_order); iotjs_jval_destroy(&jbit_order); iotjs_jval_t jloopback = iotjs_jval_get_property(joptions, IOTJS_MAGIC_STRING_LOOPBACK); _this->loopback = iotjs_jval_as_boolean(&jloopback); iotjs_jval_destroy(&jloopback); }
iotjs_jval_t iotjs_bufferwrap_create_buffer(size_t len) { iotjs_jval_t* jglobal = iotjs_jval_get_global_object(); iotjs_jval_t jbuffer = iotjs_jval_get_property(jglobal, IOTJS_MAGIC_STRING_BUFFER); IOTJS_ASSERT(iotjs_jval_is_function(&jbuffer)); iotjs_jargs_t jargs = iotjs_jargs_create(1); iotjs_jargs_append_number(&jargs, len); iotjs_jval_t jres = iotjs_jhelper_call_ok(&jbuffer, iotjs_jval_get_undefined(), &jargs); IOTJS_ASSERT(iotjs_jval_is_object(&jres)); iotjs_jargs_destroy(&jargs); iotjs_jval_destroy(&jbuffer); return jres; }
iotjs_jval_t InitPwm() { iotjs_jval_t jpwm_constructor = iotjs_jval_create_function_with_dispatch(PWMConstructor); iotjs_jval_t jprototype = iotjs_jval_create_object(); iotjs_jval_set_method(&jprototype, IOTJS_MAGIC_STRING_SETPERIOD, SetPeriod); iotjs_jval_set_method(&jprototype, IOTJS_MAGIC_STRING_SETDUTYCYCLE, SetDutyCycle); iotjs_jval_set_method(&jprototype, IOTJS_MAGIC_STRING_SETENABLE, SetEnable); iotjs_jval_set_method(&jprototype, IOTJS_MAGIC_STRING_CLOSE, Close); iotjs_jval_set_property_jval(&jpwm_constructor, IOTJS_MAGIC_STRING_PROTOTYPE, &jprototype); iotjs_jval_destroy(&jprototype); return jpwm_constructor; }
iotjs_jval_t InitBlehcisocket() { iotjs_jval_t jblehcisocketCons = iotjs_jval_create_function_with_dispatch(BleHciSocketCons); iotjs_jval_t prototype = iotjs_jval_create_object(); iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_START, Start); iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_BINDRAW, BindRaw); iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_BINDUSER, BindUser); iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_BINDCONTROL, BindControl); iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_ISDEVUP, IsDevUp); iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_SETFILTER, SetFilter); iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_STOP, Stop); iotjs_jval_set_method(&prototype, IOTJS_MAGIC_STRING_WRITE, Write); iotjs_jval_set_property_jval(&jblehcisocketCons, IOTJS_MAGIC_STRING_PROTOTYPE, &prototype); iotjs_jval_destroy(&prototype); return jblehcisocketCons; }