1 /*
2  Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License, version 2.0,
6  as published by the Free Software Foundation.
7 
8  This program is also distributed with certain software (including
9  but not limited to OpenSSL) that is licensed under separate terms,
10  as designated in a particular file or component or in included license
11  documentation.  The authors of MySQL hereby grant you an additional
12  permission to link the program and your derivative works with the
13  separately licensed software that they have included with MySQL.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  GNU General Public License, version 2.0, for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
23 */
24 
25 #include "AsyncNdbContext.h"
26 
27 #include "adapter_global.h"
28 #include "js_wrapper_macros.h"
29 #include "Record.h"
30 #include "NativeMethodCall.h"
31 #include "NdbWrapperErrors.h"
32 
33 using namespace v8;
34 
35 V8WrapperFn createAsyncNdbContext;
36 V8WrapperFn shutdown;
37 V8WrapperFn destroy;
38 
39 /* Envelope
40 */
41 
42 class AsyncNdbContextEnvelopeClass : public Envelope {
43 public:
AsyncNdbContextEnvelopeClass()44   AsyncNdbContextEnvelopeClass() : Envelope("AsyncNdbContext") {
45     EscapableHandleScope scope(Isolate::GetCurrent());
46     addMethod("AsyncNdbContext", createAsyncNdbContext);
47     addMethod("shutdown", shutdown);
48     addMethod("delete", destroy);
49   }
50 };
51 
52 AsyncNdbContextEnvelopeClass AsyncNdbContextEnvelope;
53 
54 /* Constructor
55 */
createAsyncNdbContext(const Arguments & args)56 void createAsyncNdbContext(const Arguments &args) {
57   DEBUG_MARKER(UDEB_DEBUG);
58 
59   REQUIRE_CONSTRUCTOR_CALL();
60   REQUIRE_ARGS_LENGTH(1);
61 
62   JsValueConverter<Ndb_cluster_connection *> arg0(args[0]);
63   AsyncNdbContext * ctx = new AsyncNdbContext(arg0.toC());
64   Local<Value> wrapper = AsyncNdbContextEnvelope.wrap(ctx);
65   args.GetReturnValue().Set(wrapper);
66 }
67 
68 
69 /* shutdown()
70    IMMEDIATE
71 */
shutdown(const Arguments & args)72 void shutdown(const Arguments &args) {
73   DEBUG_MARKER(UDEB_DEBUG);
74   REQUIRE_ARGS_LENGTH(0);
75 
76   typedef NativeVoidMethodCall_0_<AsyncNdbContext> NCALL;
77   NCALL ncall(& AsyncNdbContext::shutdown, args);
78   ncall.run();
79   args.GetReturnValue().SetUndefined();
80 }
81 
82 /* Call destructor
83 */
destroy(const Arguments & args)84 void destroy(const Arguments &args) {
85   DEBUG_MARKER(UDEB_DEBUG);
86   REQUIRE_ARGS_LENGTH(0);
87 
88   AsyncNdbContext *c = unwrapPointer<AsyncNdbContext *>(args.Holder());
89   delete c;
90   args.GetReturnValue().SetUndefined();
91 }
92 
93 
AsyncNdbContext_initOnLoad(Handle<Object> target)94 void AsyncNdbContext_initOnLoad(Handle<Object> target) {
95   DEFINE_JS_FUNCTION(target, "AsyncNdbContext", createAsyncNdbContext);
96   DEFINE_JS_CONSTANT(target, MULTIWAIT_ENABLED);
97 #ifdef USE_OLD_MULTIWAIT_API
98   DEFINE_JS_CONSTANT(target, USE_OLD_MULTIWAIT_API);
99 #endif
100 }
101