forked from jerryscript-project/iotjs
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced the iotjs_handlewrap_t by using the uv_handle_t structure directly. For this a two new functions and two new macros were introduced: * iotjs_uv_handle_create * iotjs_uv_handle_close * IOTJS_UV_HANDLE_DATA * IOTJS_UV_HANDLE_EXTRA_DATA For more information about the methods and macros please see the iotjs_uv_handle.h file. Additionally binary code size is reduced a bit. IoT.js-DCO-1.0-Signed-off-by: Peter Gal pgal.u-szeged@partner.samsung.com
- Loading branch information
Showing
20 changed files
with
333 additions
and
614 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "iotjs_def.h" | ||
|
||
#include "iotjs_uv_handle.h" | ||
|
||
|
||
uv_handle_t* iotjs_uv_handle_create(size_t handle_size, | ||
const jerry_value_t jobject, | ||
JNativeInfoType* native_info, | ||
size_t extra_data_size) { | ||
IOTJS_ASSERT(jerry_value_is_object(jobject)); | ||
|
||
/* Make sure that the jerry_value_t is aligned */ | ||
size_t aligned_request_size = IOTJS_ALIGNUP(handle_size, 8u); | ||
|
||
char* request_memory = iotjs_buffer_allocate( | ||
aligned_request_size + sizeof(iotjs_uv_handle_data) + extra_data_size); | ||
uv_handle_t* uv_handle = (uv_handle_t*)request_memory; | ||
uv_handle->data = request_memory + aligned_request_size; | ||
|
||
IOTJS_UV_HANDLE_DATA(uv_handle)->jobject = jobject; | ||
IOTJS_UV_HANDLE_DATA(uv_handle)->on_close_cb = NULL; | ||
jerry_acquire_value(jobject); | ||
|
||
jerry_set_object_native_pointer(jobject, uv_handle, native_info); | ||
|
||
return uv_handle; | ||
} | ||
|
||
|
||
static void iotjs_uv_handle_close_processor(uv_handle_t* handle) { | ||
iotjs_uv_handle_data* handle_data = IOTJS_UV_HANDLE_DATA(handle); | ||
|
||
if (handle_data->on_close_cb != NULL) { | ||
handle_data->on_close_cb(handle); | ||
} | ||
|
||
// Decrease ref count of Javascript object. From now the object can be | ||
// reclaimed. | ||
jerry_release_value(handle_data->jobject); | ||
IOTJS_RELEASE(handle); | ||
} | ||
|
||
|
||
void iotjs_uv_handle_close(uv_handle_t* handle, OnCloseHandler close_handler) { | ||
if (handle == NULL || uv_is_closing(handle)) { | ||
DDLOG("Attempt to close uninitialized or already closed handle"); | ||
return; | ||
} | ||
|
||
iotjs_uv_handle_data* handle_data = IOTJS_UV_HANDLE_DATA(handle); | ||
handle_data->on_close_cb = close_handler; | ||
uv_close(handle, iotjs_uv_handle_close_processor); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* Copyright 2018-present Samsung Electronics Co., Ltd. and other contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef IOTJS_UV_HANDLE | ||
#define IOTJS_UV_HANDLE | ||
|
||
#include <uv.h> | ||
|
||
#include "iotjs_binding.h" | ||
|
||
typedef void (*OnCloseHandler)(uv_handle_t*); | ||
|
||
typedef struct { | ||
jerry_value_t jobject; | ||
OnCloseHandler on_close_cb; | ||
} iotjs_uv_handle_data; | ||
|
||
#define IOTJS_ALIGNUP(value, alignment) \ | ||
(((value) + ((alignment)-1)) & ~((alignment)-1)) | ||
|
||
/** | ||
* Allocate and initialize an uv_handle_t structure with a jerry callback and | ||
* extra data. | ||
* | ||
* The allocated memory has the following layout: | ||
* | ||
* |-------------| <- start of uv_handle_t* | ||
* | uv_handle_t | | ||
* | | | ||
* |-------------| | ||
* | PADDING | <- alignment padding | ||
* |-------------| <- start of the iotjs_uv_handle_data struct | ||
* | handle_data | | ||
* |-------------| <- start of the extra data if required | ||
* | extra | | ||
* |-------------| | ||
* | ||
*/ | ||
uv_handle_t* iotjs_uv_handle_create(size_t handle_size, | ||
const jerry_value_t jobject, | ||
JNativeInfoType* native_info, | ||
size_t extra_data_size); | ||
void iotjs_uv_handle_close(uv_handle_t* handle, OnCloseHandler close_handler); | ||
|
||
/** | ||
* Returns a pointer to the handle data struct referenced | ||
* by the uv_handle_t->data member. | ||
*/ | ||
#define IOTJS_UV_HANDLE_DATA(UV_HANDLE) \ | ||
((iotjs_uv_handle_data*)((UV_HANDLE)->data)) | ||
|
||
/** | ||
* Returns a char* pointer for any extra data. | ||
* | ||
* IMPORTANT! | ||
* Make sure that the extra data is correctly allocated by using the | ||
* iotjs_uv_handle_create method call. | ||
*/ | ||
#define IOTJS_UV_HANDLE_EXTRA_DATA(UV_HANDLE) \ | ||
((char*)((char*)((UV_HANDLE)->data) + sizeof(iotjs_uv_handle_data))) | ||
|
||
|
||
#endif /* IOTJS_UV_HANDLE */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.