summaryrefslogtreecommitdiff
path: root/src/mongo/embedded/mongo_embedded/java/src/com/mongodb/embedded/capi/internal/CAPI.java
blob: 31a4b7a77a3bf062e2c1cb861b7da34fcde81f31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*-
 *    Copyright (C) 2018 MongoDB Inc.
 *
 *    This program is free software: you can redistribute it and/or  modify
 *    it under the terms of the GNU Affero General Public License, version 3,
 *    as published by the Free Software Foundation.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *    GNU Affero General Public License for more details.
 *
 *    You should have received a copy of the GNU Affero General Public License
 *    along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 *    As a special exception, the copyright holders give permission to link the
 *    code of portions of this program with the OpenSSL library under certain
 *    conditions as described in each individual source file and distribute
 *    linked combinations including the program with the OpenSSL library. You
 *    must comply with the GNU Affero General Public License in all respects
 *    for all of the code used other than as permitted herein. If you modify
 *    file(s) with this exception, you may extend this exception to your
 *    version of the file(s), but you are not obligated to do so. If you do not
 *    wish to do so, delete this exception statement from your version. If you
 *    delete this exception statement from all source files in the program,
 *    then also delete it in the license file.
 */

package com.mongodb.embedded.capi.internal;

import com.sun.jna.Callback;
import com.sun.jna.Memory;
import com.sun.jna.Native;
import com.sun.jna.NativeLong;
import com.sun.jna.Pointer;
import com.sun.jna.PointerType;
import com.sun.jna.Structure;
import com.sun.jna.ptr.NativeLongByReference;
import com.sun.jna.ptr.PointerByReference;

import java.util.Arrays;
import java.util.List;

//CHECKSTYLE:OFF
public class CAPI {

    public static class cstring extends PointerType {
        public cstring() {
            super();
        }

        public cstring(Pointer address) {
            super(address);
        }

        public cstring(String string) {
            Pointer m = new Memory(string.length() + 1);
            m.setString(0, string);
            setPointer(m);
        }

        public String toString() {
            return getPointer().getString(0);
        }
    }

    public static class mongo_embedded_v1_status extends PointerType {

        public mongo_embedded_v1_status() {
            super();
        }

        public mongo_embedded_v1_status(Pointer address) {
            super(address);
        }
    }

    public static class mongo_embedded_v1_lib extends PointerType {
        public mongo_embedded_v1_lib() {
            super();
        }

        public mongo_embedded_v1_lib(Pointer address) {
            super(address);
        }
    }

    public static class mongo_embedded_v1_instance extends PointerType {
        public mongo_embedded_v1_instance() {
            super();
        }

        public mongo_embedded_v1_instance(Pointer address) {
            super(address);
        }
    }

    public static class mongo_embedded_v1_client extends PointerType {
        public mongo_embedded_v1_client() {
            super();
        }

        public mongo_embedded_v1_client(Pointer address) {
            super(address);
        }
    }

    public static class mongo_embedded_v1_init_params extends Structure {
        public cstring yaml_config;
        public long log_flags;
        public mongo_embedded_v1_log_callback log_callback;
        public Pointer log_user_data;

        public mongo_embedded_v1_init_params() {
            super();
        }

        protected List<String> getFieldOrder() {
            return Arrays.asList("yaml_config", "log_flags", "log_callback",
                    "log_user_data");
        }

        public static class ByReference extends mongo_embedded_v1_init_params
                implements Structure.ByReference {
        }
    }

    public interface mongo_embedded_v1_log_callback extends Callback {
        void log(Pointer user_data, cstring message, cstring component, cstring context, int severity);
    }

    public static native mongo_embedded_v1_status mongo_embedded_v1_status_create();

    public static native void mongo_embedded_v1_status_destroy(mongo_embedded_v1_status status);

    public static native int mongo_embedded_v1_status_get_error(mongo_embedded_v1_status status);

    public static native cstring mongo_embedded_v1_status_get_explanation(mongo_embedded_v1_status status);

    public static native int mongo_embedded_v1_status_get_code(mongo_embedded_v1_status status);

    public static native mongo_embedded_v1_lib mongo_embedded_v1_lib_init(mongo_embedded_v1_init_params.ByReference init_params,
                                                                          mongo_embedded_v1_status status);

    public static native int mongo_embedded_v1_lib_fini(mongo_embedded_v1_lib lib, mongo_embedded_v1_status status);

    public static native mongo_embedded_v1_instance mongo_embedded_v1_instance_create(mongo_embedded_v1_lib lib, cstring yaml_config,
                                                                                      mongo_embedded_v1_status status);

    public static native int mongo_embedded_v1_instance_destroy(mongo_embedded_v1_instance instance, mongo_embedded_v1_status status);

    public static native mongo_embedded_v1_client mongo_embedded_v1_client_create(mongo_embedded_v1_instance instance,
                                                                                  mongo_embedded_v1_status status);

    public static native int mongo_embedded_v1_client_destroy(mongo_embedded_v1_client client, mongo_embedded_v1_status status);

    public static native int mongo_embedded_v1_client_invoke(mongo_embedded_v1_client client, Pointer input, NativeLong size,
                                                             PointerByReference output, NativeLongByReference output_size,
                                                             mongo_embedded_v1_status status);

    static {
        Native.register(CAPI.class, "mongo_embedded");
    }

}
//CHECKSTYLE:ON