| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* GATE PROJECT LICENSE: | ||
| 2 | +----------------------------------------------------------------------------+ | ||
| 3 | | Copyright(c) 2018-2025, Stefan Meislinger | | ||
| 4 | | All rights reserved. | | ||
| 5 | | | | ||
| 6 | | Redistribution and use in source and binary forms, with or without | | ||
| 7 | | modification, are permitted provided that the following conditions are met:| | ||
| 8 | | | | ||
| 9 | | 1. Redistributions of source code must retain the above copyright notice, | | ||
| 10 | | this list of conditions and the following disclaimer. | | ||
| 11 | | 2. Redistributions in binary form must reproduce the above copyright | | ||
| 12 | | notice, this list of conditions and the following disclaimer in the | | ||
| 13 | | documentation and/or other materials provided with the distribution. | | ||
| 14 | | | | ||
| 15 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"| | ||
| 16 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | ||
| 17 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | ||
| 18 | | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | | ||
| 19 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | ||
| 20 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | ||
| 21 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | ||
| 22 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | ||
| 23 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | ||
| 24 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | ||
| 25 | | THE POSSIBILITY OF SUCH DAMAGE. | | ||
| 26 | +----------------------------------------------------------------------------+ | ||
| 27 | */ | ||
| 28 | |||
| 29 | #include "gate/tech/msgqueues.h" | ||
| 30 | |||
| 31 | #include "gate/libraries.h" | ||
| 32 | #include "gate/results.h" | ||
| 33 | |||
| 34 | static gate_tech_zeromq_api_t zmq_api; | ||
| 35 | static gate_string_t const zmq_lib_name = GATE_STRING_INIT_STATIC("libzmq"); | ||
| 36 | static gate_library_t zmq_lib_handle = NULL; | ||
| 37 | static gate_atomic_int_t zmq_api_loaded = 0; | ||
| 38 | |||
| 39 | ✗ | gate_tech_zeromq_api_t const* gate_tech_zeromq_api(void) | |
| 40 | { | ||
| 41 | ✗ | gate_tech_zeromq_api_t const* ret = NULL; | |
| 42 | ✗ | gate_library_t lib = NULL; | |
| 43 | gate_result_t result; | ||
| 44 | ✗ | if (0 == gate_atomic_int_get(&zmq_api_loaded)) | |
| 45 | { | ||
| 46 | do | ||
| 47 | { | ||
| 48 | ✗ | GATE_BREAK_IF_FAILED(result = gate_library_open(&zmq_lib_name, &lib, 0)); | |
| 49 | |||
| 50 | ✗ | GATE_BREAK_IF_FAILED(result = gate_library_get_function_name(lib, "zmq_socket", &zmq_api.create)); | |
| 51 | ✗ | GATE_BREAK_IF_FAILED(result = gate_library_get_function_name(lib, "zmq_close", &zmq_api.close)); | |
| 52 | ✗ | GATE_BREAK_IF_FAILED(result = gate_library_get_function_name(lib, "zmq_setsockopt", &zmq_api.setopt)); | |
| 53 | ✗ | GATE_BREAK_IF_FAILED(result = gate_library_get_function_name(lib, "zmq_getsockopt", &zmq_api.getopt)); | |
| 54 | ✗ | GATE_BREAK_IF_FAILED(result = gate_library_get_function_name(lib, "zmq_bind", &zmq_api.bind)); | |
| 55 | ✗ | GATE_BREAK_IF_FAILED(result = gate_library_get_function_name(lib, "zmq_connect", &zmq_api.connect)); | |
| 56 | ✗ | GATE_BREAK_IF_FAILED(result = gate_library_get_function_name(lib, "zmq_unbind", &zmq_api.unbind)); | |
| 57 | ✗ | GATE_BREAK_IF_FAILED(result = gate_library_get_function_name(lib, "zmq_disconnect", &zmq_api.disconnect)); | |
| 58 | ✗ | GATE_BREAK_IF_FAILED(result = gate_library_get_function_name(lib, "zmq_send", &zmq_api.send)); | |
| 59 | ✗ | GATE_BREAK_IF_FAILED(result = gate_library_get_function_name(lib, "zmq_send_const", &zmq_api.send_const)); | |
| 60 | ✗ | GATE_BREAK_IF_FAILED(result = gate_library_get_function_name(lib, "zmq_recv", &zmq_api.recv)); | |
| 61 | ✗ | GATE_BREAK_IF_FAILED(result = gate_library_get_function_name(lib, "zmq_socket_monitor", &zmq_api.monitor)); | |
| 62 | |||
| 63 | ✗ | zmq_lib_handle = lib; | |
| 64 | ✗ | lib = NULL; | |
| 65 | ✗ | gate_atomic_int_set(&zmq_api_loaded, 1); | |
| 66 | } while (0); | ||
| 67 | ✗ | if (lib != NULL) | |
| 68 | { | ||
| 69 | ✗ | gate_library_close(lib); | |
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | ✗ | if (0 != gate_atomic_int_get(&zmq_api_loaded)) | |
| 74 | { | ||
| 75 | ✗ | ret = &zmq_api; | |
| 76 | } | ||
| 77 | ✗ | return ret; | |
| 78 | } | ||
| 79 | |||
| 80 | typedef struct | ||
| 81 | { | ||
| 82 | GATE_INTERFACE_VTBL(gate_msgqueue) const* vtbl; | ||
| 83 | |||
| 84 | gate_atomic_int_t ref_counter; | ||
| 85 | |||
| 86 | } gate_zmq_object_t; | ||
| 87 | |||
| 88 | |||
| 89 | ✗ | static char const* gate_zmq_get_interface_name(void* obj) | |
| 90 | { | ||
| 91 | (void)obj; | ||
| 92 | ✗ | return GATE_INTERFACE_NAME_MSGQUEUE; | |
| 93 | } | ||
| 94 | ✗ | static void gate_zmq_release(void* obj) | |
| 95 | { | ||
| 96 | ✗ | gate_zmq_object_t* self = (gate_zmq_object_t*)obj; | |
| 97 | ✗ | if (0 == gate_atomic_int_dec(&self->ref_counter)) | |
| 98 | { | ||
| 99 | |||
| 100 | } | ||
| 101 | ✗ | } | |
| 102 | ✗ | static int gate_zmq_retain(void* obj) | |
| 103 | { | ||
| 104 | ✗ | gate_zmq_object_t* self = (gate_zmq_object_t*)obj; | |
| 105 | ✗ | return gate_atomic_int_inc(&self->ref_counter); | |
| 106 | } | ||
| 107 | |||
| 108 | ✗ | static gate_result_t gate_zmq_start(void* obj) | |
| 109 | { | ||
| 110 | ✗ | gate_zmq_object_t* self = (gate_zmq_object_t*)obj; | |
| 111 | ✗ | gate_result_t ret = GATE_RESULT_NOTIMPLEMENTED; | |
| 112 | |||
| 113 | GATE_UNUSED_ARG(self); | ||
| 114 | ✗ | return ret; | |
| 115 | } | ||
| 116 | ✗ | static gate_result_t gate_zmq_stop(void* obj) | |
| 117 | { | ||
| 118 | ✗ | gate_zmq_object_t* self = (gate_zmq_object_t*)obj; | |
| 119 | ✗ | gate_result_t ret = GATE_RESULT_NOTIMPLEMENTED; | |
| 120 | |||
| 121 | GATE_UNUSED_ARG(self); | ||
| 122 | ✗ | return ret; | |
| 123 | } | ||
| 124 | |||
| 125 | ✗ | static gate_enumint_t gate_zmq_get_status(void* obj) | |
| 126 | { | ||
| 127 | ✗ | gate_zmq_object_t* self = (gate_zmq_object_t*)obj; | |
| 128 | ✗ | gate_result_t ret = 0; | |
| 129 | |||
| 130 | GATE_UNUSED_ARG(self); | ||
| 131 | ✗ | return ret; | |
| 132 | } | ||
| 133 | |||
| 134 | |||
| 135 | ✗ | static gate_result_t gate_zmq_add_target(void* obj, gate_string_t const* target_address, gate_msgqueue_target_id_t* ptr_target_id) | |
| 136 | { | ||
| 137 | ✗ | gate_zmq_object_t* self = (gate_zmq_object_t*)obj; | |
| 138 | ✗ | gate_result_t ret = GATE_RESULT_NOTIMPLEMENTED; | |
| 139 | |||
| 140 | GATE_UNUSED_ARG(self); | ||
| 141 | ✗ | return ret; | |
| 142 | } | ||
| 143 | |||
| 144 | ✗ | static gate_result_t gate_zmq_get_target(void* obj, gate_msgqueue_target_id_t target_id, gate_string_t* ptr_target_address) | |
| 145 | { | ||
| 146 | ✗ | gate_zmq_object_t* self = (gate_zmq_object_t*)obj; | |
| 147 | ✗ | gate_result_t ret = GATE_RESULT_NOTIMPLEMENTED; | |
| 148 | |||
| 149 | GATE_UNUSED_ARG(self); | ||
| 150 | ✗ | return ret; | |
| 151 | } | ||
| 152 | |||
| 153 | ✗ | static gate_result_t gate_zmq_resolve_target(void* obj, gate_string_t const* target_address, gate_msgqueue_target_id_t* ptr_target_id) | |
| 154 | { | ||
| 155 | ✗ | gate_zmq_object_t* self = (gate_zmq_object_t*)obj; | |
| 156 | ✗ | gate_result_t ret = GATE_RESULT_NOTIMPLEMENTED; | |
| 157 | |||
| 158 | GATE_UNUSED_ARG(self); | ||
| 159 | ✗ | return ret; | |
| 160 | } | ||
| 161 | |||
| 162 | ✗ | static gate_result_t gate_zmq_remove_target(void* obj, gate_msgqueue_target_id_t target_id) | |
| 163 | { | ||
| 164 | ✗ | gate_zmq_object_t* self = (gate_zmq_object_t*)obj; | |
| 165 | ✗ | gate_result_t ret = GATE_RESULT_NOTIMPLEMENTED; | |
| 166 | |||
| 167 | GATE_UNUSED_ARG(self); | ||
| 168 | ✗ | return ret; | |
| 169 | } | ||
| 170 | |||
| 171 | |||
| 172 | ✗ | static gate_result_t gate_zmq_publish(void* obj, gate_msgqueue_target_id_t target_id, gate_uint32_t message_type, void const* data, gate_size_t length) | |
| 173 | { | ||
| 174 | ✗ | gate_zmq_object_t* self = (gate_zmq_object_t*)obj; | |
| 175 | ✗ | gate_result_t ret = GATE_RESULT_NOTIMPLEMENTED; | |
| 176 | |||
| 177 | GATE_UNUSED_ARG(self); | ||
| 178 | ✗ | return ret; | |
| 179 | } | ||
| 180 | |||
| 181 | ✗ | static gate_result_t gate_zmq_subscribe(void* obj, gate_msgqueue_target_id_t target_id, gate_msgqueue_receiver_t receiver, void* user_param, gate_msgqueue_subscription_id_t* ptr_subscriber) | |
| 182 | { | ||
| 183 | ✗ | gate_zmq_object_t* self = (gate_zmq_object_t*)obj; | |
| 184 | ✗ | gate_result_t ret = GATE_RESULT_NOTIMPLEMENTED; | |
| 185 | |||
| 186 | GATE_UNUSED_ARG(self); | ||
| 187 | ✗ | return ret; | |
| 188 | } | ||
| 189 | |||
| 190 | ✗ | static gate_result_t gate_zmq_unsubscribe(void* obj, gate_msgqueue_subscription_id_t subscriber) | |
| 191 | { | ||
| 192 | ✗ | gate_zmq_object_t* self = (gate_zmq_object_t*)obj; | |
| 193 | ✗ | gate_result_t ret = GATE_RESULT_NOTIMPLEMENTED; | |
| 194 | |||
| 195 | GATE_UNUSED_ARG(self); | ||
| 196 | ✗ | return ret; | |
| 197 | } | ||
| 198 | |||
| 199 | |||
| 200 | static GATE_INTERFACE_VTBL(gate_msgqueue) gate_zmq_object_vtbl; | ||
| 201 | ✗ | static void gate_init_zmq_object_vtbl(void) | |
| 202 | { | ||
| 203 | ✗ | if (!gate_zmq_object_vtbl.get_interface_name) | |
| 204 | { | ||
| 205 | GATE_INTERFACE_VTBL(gate_msgqueue) const local_vtbl = | ||
| 206 | { | ||
| 207 | &gate_zmq_get_interface_name, | ||
| 208 | &gate_zmq_release, | ||
| 209 | &gate_zmq_retain, | ||
| 210 | |||
| 211 | &gate_zmq_start, | ||
| 212 | &gate_zmq_stop, | ||
| 213 | &gate_zmq_get_status, | ||
| 214 | |||
| 215 | &gate_zmq_add_target, | ||
| 216 | &gate_zmq_get_target, | ||
| 217 | &gate_zmq_resolve_target, | ||
| 218 | &gate_zmq_remove_target, | ||
| 219 | |||
| 220 | &gate_zmq_publish, | ||
| 221 | &gate_zmq_subscribe, | ||
| 222 | &gate_zmq_unsubscribe | ||
| 223 | }; | ||
| 224 | ✗ | gate_zmq_object_vtbl = local_vtbl; | |
| 225 | } | ||
| 226 | ✗ | } | |
| 227 | |||
| 228 | ✗ | gate_msgqueue_t* gate_tech_zeromq_create(void) | |
| 229 | { | ||
| 230 | ✗ | gate_msgqueue_t* ret = NULL; | |
| 231 | |||
| 232 | ✗ | return ret; | |
| 233 | } | ||
| 234 |