1 /**
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0.
4 */
5
6 #include <jni.h>
7
8 #include <aws/io/channel_bootstrap.h>
9
10 #include "crt.h"
11 #include "java_class_ids.h"
12
13 #if _MSC_VER
14 # pragma warning(disable : 4204) /* non-constant aggregate initializer */
15 #endif
16
17 /* on 32-bit platforms, casting pointers to longs throws a warning we don't need */
18 #if UINTPTR_MAX == 0xffffffff
19 # if defined(_MSC_VER)
20 # pragma warning(push)
21 # pragma warning(disable : 4305) /* 'type cast': truncation from 'jlong' to 'jni_tls_ctx_options *' */
22 # else
23 # pragma GCC diagnostic push
24 # pragma GCC diagnostic ignored "-Wpointer-to-int-cast"
25 # pragma GCC diagnostic ignored "-Wint-to-pointer-cast"
26 # endif
27 #endif
28
29 JNIEXPORT
Java_software_amazon_awssdk_crt_io_ServerBootstrap_serverBootstrapNew(JNIEnv * env,jclass jni_class,jobject jni_bootstrap,jlong jni_elg)30 jlong JNICALL Java_software_amazon_awssdk_crt_io_ServerBootstrap_serverBootstrapNew(
31 JNIEnv *env,
32 jclass jni_class,
33 jobject jni_bootstrap,
34 jlong jni_elg) {
35 (void)jni_class;
36 aws_cache_jni_ids(env);
37
38 /* we're going to need this at some point. Keep it here until we do. */
39 (void)jni_bootstrap;
40 struct aws_event_loop_group *elg = (struct aws_event_loop_group *)jni_elg;
41
42 if (!elg) {
43 aws_jni_throw_runtime_exception(env, "ServerBootstrap.server_bootstrap_new: Invalid EventLoopGroup");
44 return (jlong)NULL;
45 }
46
47 struct aws_allocator *allocator = aws_jni_get_allocator();
48
49 struct aws_server_bootstrap *bootstrap = aws_server_bootstrap_new(allocator, elg);
50 if (!bootstrap) {
51 aws_jni_throw_runtime_exception(
52 env, "ServerBootstrap.server_bootstrap_new: Unable to allocate new aws_server_bootstrap");
53 return (jlong)NULL;
54 }
55
56 return (jlong)bootstrap;
57 }
58
59 JNIEXPORT
Java_software_amazon_awssdk_crt_io_ServerBootstrap_serverBootstrapDestroy(JNIEnv * env,jclass jni_class,jlong jni_bootstrap)60 void JNICALL Java_software_amazon_awssdk_crt_io_ServerBootstrap_serverBootstrapDestroy(
61 JNIEnv *env,
62 jclass jni_class,
63 jlong jni_bootstrap) {
64 (void)jni_class;
65 aws_cache_jni_ids(env);
66
67 struct aws_server_bootstrap *bootstrap = (struct aws_server_bootstrap *)jni_bootstrap;
68 if (!bootstrap) {
69 return;
70 }
71
72 aws_server_bootstrap_release(bootstrap);
73 }
74
75 #if UINTPTR_MAX == 0xffffffff
76 # if defined(_MSC_VER)
77 # pragma warning(pop)
78 # else
79 # pragma GCC diagnostic pop
80 # endif
81 #endif
82