1 /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 #include "iotjs_def.h"
17 #include "iotjs_reqwrap.h"
20 void iotjs_reqwrap_initialize(iotjs_reqwrap_t* reqwrap,
21 const iotjs_jval_t* jcallback,
23 IOTJS_VALIDATED_STRUCT_CONSTRUCTOR(iotjs_reqwrap_t, reqwrap);
24 IOTJS_ASSERT(iotjs_jval_is_function(jcallback));
25 _this->jcallback = iotjs_jval_create_copied(jcallback);
26 _this->request = request;
27 _this->request->data = reqwrap;
31 void iotjs_reqwrap_destroy(iotjs_reqwrap_t* reqwrap) {
32 IOTJS_VALIDATED_STRUCT_DESTRUCTOR(iotjs_reqwrap_t, reqwrap);
33 iotjs_jval_destroy(&_this->jcallback);
37 static void iotjs_reqwrap_validate(iotjs_reqwrap_t* reqwrap) {
38 IOTJS_VALIDATED_STRUCT_METHOD(iotjs_reqwrap_t, reqwrap);
39 IOTJS_ASSERT(_this->request->data == reqwrap);
43 const iotjs_jval_t* iotjs_reqwrap_jcallback(iotjs_reqwrap_t* reqwrap) {
44 IOTJS_VALIDATED_STRUCT_METHOD(iotjs_reqwrap_t, reqwrap);
45 iotjs_reqwrap_validate(reqwrap);
46 return &_this->jcallback;
50 uv_req_t* iotjs_reqwrap_req(iotjs_reqwrap_t* reqwrap) {
51 IOTJS_VALIDATED_STRUCT_METHOD(iotjs_reqwrap_t, reqwrap);
52 iotjs_reqwrap_validate(reqwrap);
53 return _this->request;
57 iotjs_reqwrap_t* iotjs_reqwrap_from_request(uv_req_t* req) {
58 iotjs_reqwrap_t* reqwrap = req->data;
59 iotjs_reqwrap_validate(reqwrap);