/* * libbrlapi - A library providing access to braille terminals for applications. * * Copyright (C) 2005-2021 by * Sébastien Hinderer * Samuel Thibault * All rights reserved. * * libbrlapi comes with ABSOLUTELY NO WARRANTY. * * This is free software, placed under the terms of the * GNU Lesser General Public License, as published by the Free Software * Foundation; either version 2.1 of the License, or (at your option) any * later version. Please see the file LICENSE-LGPL for details. * * Web Page: http://brltty.app/ * * This software is maintained by Dave Mielke . */ #include #include #include #include #include #include #define CAML_NAME_SPACE /* Don't import old names */ #include /* definition of the value type, and conversion macros */ #include /* miscellaneous memory-related functions and macros (for GC interface, in-place modification of structures, etc). */ #include /* allocation functions (to create structured Caml objects) */ #include /* functions for raising exceptions */ #include /* callback from C to Caml */ #include /* operations on custom blocks */ #include /* operations for writing user-defined serialization and deserialization functions for custom blocks */ #define BRLAPI_NO_DEPRECATED #include "brlapi.h" #include "brlapi_protocol.h" #ifndef MIN #define MIN(x, y) (xbrlerrno)); Store_field(camlError, 1, Val_int(err->libcerrno)); Store_field(camlError, 2, Val_int(err->gaierrno)); if (err->errfun!=NULL) Store_field(camlError, 3, caml_copy_string(err->errfun)); else Store_field(camlError, 3, caml_copy_string("")); return camlError; } CAMLprim value brlapiml_errorCode_of_error(value camlError) { CAMLparam1(camlError); CAMLlocal1(result); switch (Int_val(Field(camlError, 0))) { case BRLAPI_ERROR_NOMEM: result = Val_int(0); break; case BRLAPI_ERROR_TTYBUSY: result = Val_int(1); break; case BRLAPI_ERROR_DEVICEBUSY: result = Val_int(2); break; case BRLAPI_ERROR_UNKNOWN_INSTRUCTION: result = Val_int(3); break; case BRLAPI_ERROR_ILLEGAL_INSTRUCTION: result = Val_int(4); break; case BRLAPI_ERROR_INVALID_PARAMETER: result = Val_int(5); break; case BRLAPI_ERROR_INVALID_PACKET: result = Val_int(6); break; case BRLAPI_ERROR_CONNREFUSED: result = Val_int(7); break; case BRLAPI_ERROR_OPNOTSUPP: result = Val_int(8); break; case BRLAPI_ERROR_GAIERR: { result = caml_alloc(1, 0); Store_field(result, 0, Val_int(Field(camlError, 2))); }; break; case BRLAPI_ERROR_LIBCERR: { result = caml_alloc(1, 1); Store_field(result, 0, unix_error_of_code(Int_val(Field(camlError, 1)))); }; break; case BRLAPI_ERROR_UNKNOWNTTY: result = Val_int(9); break; case BRLAPI_ERROR_PROTOCOL_VERSION: result = Val_int(10); break; case BRLAPI_ERROR_EOF: result = Val_int(11); break; case BRLAPI_ERROR_EMPTYKEY: result = Val_int(12); break; case BRLAPI_ERROR_DRIVERERROR: result = Val_int(13); break; case BRLAPI_ERROR_AUTHENTICATION: result = Val_int(14); break; default: { result = caml_alloc(1, 2); Store_field(result, 0, Val_int(Field(camlError, 0))); } } CAMLreturn(result); } /* Function : raise_brlapi_error */ /* Raises the Brlapi_error exception */ static void raise_brlapi_error(void) { static const value *exception = NULL; CAMLparam0(); CAMLlocal1(res); if (exception==NULL) exception = caml_named_value("Brlapi_error"); res = caml_alloc(2,0); Store_field(res, 0, *exception); Store_field(res, 1, constrCamlError(&brlapi_error)); caml_raise(res); CAMLreturn0; } /* Function : raise_brlapi_exception */ /* Raises Brlapi_exception */ static void BRLAPI_STDCALL raise_brlapi_exception(int err, brlapi_packetType_t type, const void *packet, size_t size) { static const value *exception = NULL; int i; CAMLparam0(); CAMLlocal2(str, res); str = caml_alloc_string(size); for (i=0; i