00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00025 #ifndef BRLAPI_INCLUDED
00026 #define BRLAPI_INCLUDED
00027
00028 #ifdef __cplusplus
00029 extern "C" {
00030 #endif
00031
00032 #define BRLAPI_WIN32 1
00033
00038 #define BRLAPI_RELEASE "0.5.2"
00039
00041 #define BRLAPI_MAJOR 0
00042
00044 #define BRLAPI_MINOR 5
00045
00047 #define BRLAPI_REVISION 2
00048
00051
00052 #include <sys/types.h>
00053
00054 #ifdef BRLAPI_WIN32
00055 #include <windows.h>
00056 #define BRLAPI_STDCALL __stdcall
00057 #else
00058 #define BRLAPI_STDCALL
00059 #endif
00060
00061 #ifdef _MSC_VER
00062 typedef __int64 uint64_t;
00063 typedef __int32 uint32_t;
00064 #define UINT64_C(x) (x ## Ui64)
00065 #define PRIx64 "I64x"
00066 typedef signed int ssize_t;
00067 #else
00068
00069
00070 #include <stdint.h>
00071
00072
00073 #include <unistd.h>
00074
00075 #include <inttypes.h>
00076 #endif
00077
00100 typedef struct brlapi_handle_t brlapi_handle_t;
00101
00103 size_t BRLAPI_STDCALL brlapi_getHandleSize(void);
00104
00118 #define BRLAPI_SOCKETPORTNUM 4101
00119 #define BRLAPI_SOCKETPORT "4101"
00120
00122 #define BRLAPI_SOCKETPATH "\\\\.\\pipe\\BrlAPI"
00123
00128 #define BRLAPI_ETCDIR "/etc"
00129
00133 #define BRLAPI_AUTHKEYFILE "brlapi.key"
00134
00136 #define BRLAPI_DEFAUTH BRLAPI_ETCDIR "/" BRLAPI_AUTHKEYFILE
00137
00138 #ifdef __MINGW32__
00139 typedef HANDLE brlapi_fileDescriptor;
00140 #else
00141 typedef int brlapi_fileDescriptor;
00142 #endif
00143
00174 typedef struct {
00182 char *auth;
00183
00192 char *host;
00193 } brlapi_connectionSettings_t;
00194
00195
00198 #define BRLAPI_SETTINGS_INITIALIZER { NULL, NULL }
00199
00200
00245 #ifndef BRLAPI_NO_SINGLE_SESSION
00246 brlapi_fileDescriptor BRLAPI_STDCALL brlapi_openConnection(const brlapi_connectionSettings_t *desiredSettings, brlapi_connectionSettings_t *actualSettings);
00247 #endif
00248 brlapi_fileDescriptor BRLAPI_STDCALL brlapi__openConnection(brlapi_handle_t *handle, const brlapi_connectionSettings_t *desiredSettings, brlapi_connectionSettings_t *actualSettings);
00249
00250
00257 #ifndef BRLAPI_NO_SINGLE_SESSION
00258 void BRLAPI_STDCALL brlapi_closeConnection(void);
00259 #endif
00260 void BRLAPI_STDCALL brlapi__closeConnection(brlapi_handle_t *handle);
00261
00277 #define BRLAPI_MAXNAMELENGTH 31
00278
00279
00291 #ifndef BRLAPI_NO_SINGLE_SESSION
00292 int BRLAPI_STDCALL brlapi_getDriverName(char *buffer, size_t size);
00293 #endif
00294 int BRLAPI_STDCALL brlapi__getDriverName(brlapi_handle_t *handle, char *buffer, size_t size);
00295
00296
00298 #ifndef BRLAPI_NO_SINGLE_SESSION
00299 int BRLAPI_STDCALL brlapi_getDisplaySize(unsigned int *x, unsigned int *y);
00300 #endif
00301 int BRLAPI_STDCALL brlapi__getDisplaySize(brlapi_handle_t *handle, unsigned int *x, unsigned int *y);
00302
00326
00353 #ifndef BRLAPI_NO_SINGLE_SESSION
00354 int BRLAPI_STDCALL brlapi_enterTtyMode(int tty, const char *driver);
00355 #endif
00356 int BRLAPI_STDCALL brlapi__enterTtyMode(brlapi_handle_t *handle, int tty, const char *driver);
00357
00367 #define BRLAPI_TTY_DEFAULT -1
00368
00369
00381 #ifndef BRLAPI_NO_SINGLE_SESSION
00382 int BRLAPI_STDCALL brlapi_enterTtyModeWithPath(int *ttys, int count, const char *driver);
00383 #endif
00384 int BRLAPI_STDCALL brlapi__enterTtyModeWithPath(brlapi_handle_t *handle, int *ttys, int count, const char *driver);
00385
00386
00393 #ifndef BRLAPI_NO_SINGLE_SESSION
00394 int BRLAPI_STDCALL brlapi_leaveTtyMode(void);
00395 #endif
00396 int BRLAPI_STDCALL brlapi__leaveTtyMode(brlapi_handle_t *handle);
00397
00398
00409 #ifndef BRLAPI_NO_SINGLE_SESSION
00410 int BRLAPI_STDCALL brlapi_setFocus(int tty);
00411 #endif
00412 int BRLAPI_STDCALL brlapi__setFocus(brlapi_handle_t *handle, int tty);
00413
00443
00458 #ifndef BRLAPI_NO_SINGLE_SESSION
00459 int BRLAPI_STDCALL brlapi_writeText(int cursor, const char *text);
00460 #endif
00461 int BRLAPI_STDCALL brlapi__writeText(brlapi_handle_t *handle, int cursor, const char *text);
00462
00463
00471 #ifndef BRLAPI_NO_SINGLE_SESSION
00472 int BRLAPI_STDCALL brlapi_writeDots(const unsigned char *dots);
00473 #endif
00474 int BRLAPI_STDCALL brlapi__writeDots(brlapi_handle_t *handle, const unsigned char *dots);
00475
00476
00478 typedef struct {
00479 int displayNumber ;
00480 unsigned int regionBegin ;
00481 unsigned int regionSize ;
00482 char *text ;
00483 int textSize ;
00484 unsigned char *andMask ;
00485 unsigned char *orMask ;
00486 int cursor ;
00487 char *charset ;
00488 } brlapi_writeArguments_t;
00489
00494 #define BRLAPI_DISPLAY_DEFAULT -1
00495
00500 #define BRLAPI_CURSOR_LEAVE -1
00501
00506 #define BRLAPI_CURSOR_OFF 0
00507
00508
00518 #define BRLAPI_WRITEARGUMENTS_INITIALIZER { BRLAPI_DISPLAY_DEFAULT, 0, 0, NULL, -1, NULL, NULL, BRLAPI_CURSOR_LEAVE, NULL }
00519
00520
00556 #ifndef BRLAPI_NO_SINGLE_SESSION
00557 int BRLAPI_STDCALL brlapi_write(const brlapi_writeArguments_t *arguments);
00558 #endif
00559 int BRLAPI_STDCALL brlapi__write(brlapi_handle_t *handle, const brlapi_writeArguments_t *arguments);
00560
00563 #include "brlapi_keycodes.h"
00564
00578
00580 typedef struct {
00581 unsigned int type ;
00582 unsigned int command ;
00583 unsigned int argument ;
00584 unsigned int flags ;
00585 } brlapi_expandedKeyCode_t;
00586
00587
00595 int BRLAPI_STDCALL brlapi_expandKeyCode (brlapi_keyCode_t code, brlapi_expandedKeyCode_t *expansion);
00596
00597
00599 typedef struct {
00600 const char *type ;
00601 const char *command ;
00602 unsigned int argument ;
00603 unsigned int flags ;
00604 const char *flag[64 - BRLAPI_KEY_FLAGS_SHIFT] ;
00605 brlapi_expandedKeyCode_t values ;
00606 } brlapi_describedKeyCode_t;
00607
00608
00616 int BRLAPI_STDCALL brlapi_describeKeyCode (brlapi_keyCode_t code, brlapi_describedKeyCode_t *description);
00617
00619 #define BRLAPI_UC_ROW 0x2800UL
00620
00624 #define BRLAPI_MAXKEYSETSIZE (BRLAPI_MAXPACKETSIZE / sizeof(brlapi_keyCode_t))
00625
00626
00693 #ifndef BRLAPI_NO_SINGLE_SESSION
00694 int BRLAPI_STDCALL brlapi_readKey(int wait, brlapi_keyCode_t *code);
00695 #endif
00696 int BRLAPI_STDCALL brlapi__readKey(brlapi_handle_t *handle, int wait, brlapi_keyCode_t *code);
00697
00699 typedef enum {
00700 brlapi_rangeType_all,
00701 brlapi_rangeType_type,
00702 brlapi_rangeType_command,
00703 brlapi_rangeType_key,
00704 brlapi_rangeType_code,
00705 } brlapi_rangeType_t;
00706
00707
00720 #ifndef BRLAPI_NO_SINGLE_SESSION
00721 int BRLAPI_STDCALL brlapi_ignoreKeys(brlapi_rangeType_t type, const brlapi_keyCode_t keys[], unsigned int count);
00722 #endif
00723 int BRLAPI_STDCALL brlapi__ignoreKeys(brlapi_handle_t *handle, brlapi_rangeType_t type, const brlapi_keyCode_t keys[], unsigned int count);
00724
00725
00738 #ifndef BRLAPI_NO_SINGLE_SESSION
00739 int BRLAPI_STDCALL brlapi_acceptKeys(brlapi_rangeType_t type, const brlapi_keyCode_t keys[], unsigned int count);
00740 #endif
00741 int BRLAPI_STDCALL brlapi__acceptKeys(brlapi_handle_t *handle, brlapi_rangeType_t type, const brlapi_keyCode_t keys[], unsigned int count);
00742
00743
00749 #ifndef BRLAPI_NO_SINGLE_SESSION
00750 int BRLAPI_STDCALL brlapi_ignoreAllKeys(void);
00751 #define brlapi_ignoreAllKeys() brlapi_ignoreKeys(brlapi_rangeType_all, NULL, 0)
00752 #endif
00753 int BRLAPI_STDCALL brlapi__ignoreAllKeys(brlapi_handle_t *handle);
00754 #define brlapi__ignoreAllKeys(handle) brlapi__ignoreKeys(handle, brlapi_rangeType_all, NULL, 0)
00755
00756
00765 #ifndef BRLAPI_NO_SINGLE_SESSION
00766 int BRLAPI_STDCALL brlapi_acceptAllKeys(void);
00767 #define brlapi_acceptAllKeys() brlapi_acceptKeys(brlapi_rangeType_all, NULL, 0)
00768 #endif
00769 int BRLAPI_STDCALL brlapi__acceptAllKeys(brlapi_handle_t *handle);
00770 #define brlapi__acceptAllKeys(handle) brlapi__acceptKeys(handle, brlapi_rangeType_all, NULL, 0)
00771
00776 typedef struct {
00777 brlapi_keyCode_t first;
00778 brlapi_keyCode_t last;
00779 } brlapi_range_t;
00780
00781
00792 #ifndef BRLAPI_NO_SINGLE_SESSION
00793 int BRLAPI_STDCALL brlapi_ignoreKeyRanges(brlapi_range_t ranges[], unsigned int count);
00794 #endif
00795 int BRLAPI_STDCALL brlapi__ignoreKeyRanges(brlapi_handle_t *handle, brlapi_range_t ranges[], unsigned int count);
00796
00797
00808 #ifndef BRLAPI_NO_SINGLE_SESSION
00809 int BRLAPI_STDCALL brlapi_acceptKeyRanges(brlapi_range_t ranges[], unsigned int count);
00810 #endif
00811 int BRLAPI_STDCALL brlapi__acceptKeyRanges(brlapi_handle_t *handle, brlapi_range_t ranges[], unsigned int count);
00837
00842 #ifndef BRLAPI_NO_SINGLE_SESSION
00843 int BRLAPI_STDCALL brlapi_enterRawMode(const char *driver);
00844 #endif
00845 int BRLAPI_STDCALL brlapi__enterRawMode(brlapi_handle_t *handle, const char *driver);
00846
00847
00850 #ifndef BRLAPI_NO_SINGLE_SESSION
00851 int BRLAPI_STDCALL brlapi_leaveRawMode(void);
00852 #endif
00853 int BRLAPI_STDCALL brlapi__leaveRawMode(brlapi_handle_t *handle);
00854
00855
00861 #ifndef BRLAPI_NO_SINGLE_SESSION
00862 ssize_t BRLAPI_STDCALL brlapi_sendRaw(const void *buffer, size_t size);
00863 #endif
00864 ssize_t BRLAPI_STDCALL brlapi__sendRaw(brlapi_handle_t *handle, const void *buffer, size_t size);
00865
00866
00873 #ifndef BRLAPI_NO_SINGLE_SESSION
00874 ssize_t BRLAPI_STDCALL brlapi_recvRaw(void *buffer, size_t size);
00875 #endif
00876 ssize_t BRLAPI_STDCALL brlapi__recvRaw(brlapi_handle_t *handle, void *buffer, size_t size);
00877
00878
00883 #ifndef BRLAPI_NO_SINGLE_SESSION
00884 int BRLAPI_STDCALL brlapi_suspendDriver(const char *driver);
00885 #endif
00886 int BRLAPI_STDCALL brlapi__suspendDriver(brlapi_handle_t *handle, const char *driver);
00887
00888
00892 #ifndef BRLAPI_NO_SINGLE_SESSION
00893 int BRLAPI_STDCALL brlapi_resumeDriver(void);
00894 #endif
00895 int BRLAPI_STDCALL brlapi__resumeDriver(brlapi_handle_t *handle);
00919
00920 #define BRLAPI_ERROR_SUCCESS 0
00921 #define BRLAPI_ERROR_NOMEM 1
00922 #define BRLAPI_ERROR_TTYBUSY 2
00923 #define BRLAPI_ERROR_DEVICEBUSY 3
00924 #define BRLAPI_ERROR_UNKNOWN_INSTRUCTION 4
00925 #define BRLAPI_ERROR_ILLEGAL_INSTRUCTION 5
00926 #define BRLAPI_ERROR_INVALID_PARAMETER 6
00927 #define BRLAPI_ERROR_INVALID_PACKET 7
00928 #define BRLAPI_ERROR_CONNREFUSED 8
00929 #define BRLAPI_ERROR_OPNOTSUPP 9
00930 #define BRLAPI_ERROR_GAIERR 10
00931 #define BRLAPI_ERROR_LIBCERR 11
00932 #define BRLAPI_ERROR_UNKNOWNTTY 12
00933 #define BRLAPI_ERROR_PROTOCOL_VERSION 13
00934 #define BRLAPI_ERROR_EOF 14
00935 #define BRLAPI_ERROR_EMPTYKEY 15
00936 #define BRLAPI_ERROR_DRIVERERROR 16
00937 #define BRLAPI_ERROR_AUTHENTICATION 17
00939
00940
00944 extern const char *brlapi_errlist[];
00945
00946
00948 extern const int brlapi_nerr;
00949
00950
00955 void BRLAPI_STDCALL brlapi_perror(const char *s);
00956
00957
00959 typedef struct {
00960 int brlerrno;
00961 int libcerrno;
00962 int gaierrno;
00963 const char *errfun;
00964 } brlapi_error_t;
00965
00974 brlapi_error_t * BRLAPI_STDCALL brlapi_error_location(void);
00975
00984 extern brlapi_error_t brlapi_error;
00985
00987 extern int brlapi_errno;
00989 extern int brlapi_libcerrno;
00991 extern int brlapi_gaierrno;
00993 extern const char *brlapi_errfun;
00994
00996 #define brlapi_error (*brlapi_error_location())
00997
00998 #define brlapi_errno (brlapi_error.brlerrno)
00999
01000 #define brlapi_libcerrno (brlapi_error.libcerrno)
01001
01002 #define brlapi_gaierrno (brlapi_error.gaierrno)
01003
01004 #define brlapi_errfun (brlapi_error.errfun)
01005
01006
01012 const char * BRLAPI_STDCALL brlapi_strerror(const brlapi_error_t *error);
01013
01015 typedef uint32_t brlapi_packetType_t;
01016
01017
01023 const char * BRLAPI_STDCALL brlapi_getPacketTypeName(brlapi_packetType_t type);
01024
01025
01037 #ifndef BRLAPI_NO_SINGLE_SESSION
01038 typedef void (BRLAPI_STDCALL *brlapi_exceptionHandler_t)(int error, brlapi_packetType_t type, const void *packet, size_t size);
01039 #endif
01040 typedef void (BRLAPI_STDCALL *brlapi__exceptionHandler_t)(brlapi_handle_t *handle, int error, brlapi_packetType_t type, const void *packet, size_t size);
01041
01042
01052 #ifndef BRLAPI_NO_SINGLE_SESSION
01053 int BRLAPI_STDCALL brlapi_strexception(char *buffer, size_t bufferSize, int error, brlapi_packetType_t type, const void *packet, size_t packetSize);
01054 #endif
01055 int BRLAPI_STDCALL brlapi__strexception(brlapi_handle_t *handle, char *buffer, size_t bufferSize, int error, brlapi_packetType_t type, const void *packet, size_t packetSize);
01056
01057
01066 #ifndef BRLAPI_NO_SINGLE_SESSION
01067 brlapi_exceptionHandler_t BRLAPI_STDCALL brlapi_setExceptionHandler(brlapi_exceptionHandler_t handler);
01068 #endif
01069 brlapi__exceptionHandler_t BRLAPI_STDCALL brlapi__setExceptionHandler(brlapi_handle_t *handle, brlapi__exceptionHandler_t handler);
01070
01071 #ifndef BRLAPI_NO_SINGLE_SESSION
01072 void BRLAPI_STDCALL brlapi_defaultExceptionHandler(int error, brlapi_packetType_t type, const void *packet, size_t size);
01073 #endif
01074 void BRLAPI_STDCALL brlapi__defaultExceptionHandler(brlapi_handle_t *handle, int error, brlapi_packetType_t type, const void *packet, size_t size);
01075
01078
01079 #ifdef BRLAPI_WIN32
01080 #ifndef BRLAPI_NO_SINGLE_SESSION
01081 int BRLAPI_STDCALL brlapi_writeTextWin(int cursor, const void *str, int wide);
01082 #endif
01083 int BRLAPI_STDCALL brlapi__writeTextWin(brlapi_handle_t *handle, int cursor, const void *str, int wide);
01084
01085 #ifndef BRLAPI_NO_SINGLE_SESSION
01086 int BRLAPI_STDCALL brlapi_writeWin(const brlapi_writeArguments_t *s, int wide);
01087 #endif
01088 int BRLAPI_STDCALL brlapi__writeWin(brlapi_handle_t *handle, const brlapi_writeArguments_t *s, int wide);
01089
01090 #ifdef UNICODE
01091 #ifndef BRLAPI_NO_SINGLE_SESSION
01092 #define brlapi_writeText(cursor, str) brlapi_writeTextWin(cursor, str, 1)
01093 #endif
01094 #define brlapi__writeText(handle, cursor, str) brlapi__writeTextWin(handle, cursor, str, 1)
01095
01096 #ifndef BRLAPI_NO_SINGLE_SESSION
01097 #define brlapi_write(s) brlapi_writeWin(s, 1)
01098 #endif
01099 #define brlapi__write(handle, s) brlapi__writeWin(handle, s, 1)
01100
01101 #else
01102
01103 #ifndef BRLAPI_NO_SINGLE_SESSION
01104 #define brlapi_writeText(cursor, str) brlapi_writeTextWin(cursor, str, 0)
01105 #endif
01106 #define brlapi__writeText(handle, cursor, str) brlapi__writeTextWin(handle, cursor, str, 0)
01107
01108 #ifndef BRLAPI_NO_SINGLE_SESSION
01109 #define brlapi_write(s) brlapi_writeWin(s, 0)
01110 #endif
01111 #define brlapi__write(handle, s) brlapi__writeWin(handle, s, 0)
01112
01113 #endif
01114 #endif
01115
01116 #ifndef BRLAPI_NO_DEPRECATED
01117
01129 #define brlapi_settings_t brlapi_connectionSettings_t
01130
01132 typedef struct {
01133 int displayNumber;
01134 unsigned int regionBegin;
01135 unsigned int regionSize;
01136 char *text;
01137 int textSize;
01138 unsigned char *attrAnd;
01139 unsigned char *attrOr;
01140 int cursor;
01141 char *charset;
01142 } brlapi_writeStruct;
01143 #define BRLAPI_WRITESTRUCT_INITIALIZER BRLAPI_WRITEARGUMENTS_INITIALIZER
01144
01145 #define brl_keycode_t brlapi_keyCode_t
01146 #define brl_type_t brlapi_packetType_t
01147
01148 #define BRLCOMMANDS NULL
01149 #define BRL_KEYCODE_MAX BRLAPI_KEY_MAX
01150
01151 #ifndef BRLAPI_NO_SINGLE_SESSION
01152 #define brlapi_initializeConnection brlapi_openConnection
01153 #define brlapi_getTty brlapi_enterTtyMode
01154 #define brlapi_getTtyPath brlapi_enterTtyModeWithPath
01155 #define brlapi_leaveTty brlapi_leaveTtyMode
01156 #define brlapi_unignoreKeyRange brlapi_acceptKeyRange
01157 #define brlapi_unignoreKeySet brlapi_acceptKeySet
01158 #define brlapi_getRaw brlapi_enterRawMode
01159 #define brlapi_leaveRaw brlapi_leaveRawMode
01160 #define brlapi_suspend brlapi_suspendDriver
01161 #define brlapi_resume brlapi_resumeDriver
01162 #endif
01163
01164 #define BRLERR_SUCCESS BRLAPI_ERROR_SUCCESS
01165 #define BRLERR_NOMEM BRLAPI_ERROR_NOMEM
01166 #define BRLERR_TTYBUSY BRLAPI_ERROR_TTYBUSY
01167 #define BRLERR_DEVICEBUSY BRLAPI_ERROR_DEVICEBUSY
01168 #define BRLERR_UNKNOWN_INSTRUCTION BRLAPI_ERROR_UNKNOWN_INSTRUCTION
01169 #define BRLERR_ILLEGAL_INSTRUCTION BRLAPI_ERROR_ILLEGAL_INSTRUCTION
01170 #define BRLERR_INVALID_PARAMETER BRLAPI_ERROR_INVALID_PARAMETER
01171 #define BRLERR_INVALID_PACKET BRLAPI_ERROR_INVALID_PACKET
01172 #define BRLERR_CONNREFUSED BRLAPI_ERROR_CONNREFUSED
01173 #define BRLERR_OPNOTSUPP BRLAPI_ERROR_OPNOTSUPP
01174 #define BRLERR_GAIERR BRLAPI_ERROR_GAIERR
01175 #define BRLERR_LIBCERR BRLAPI_ERROR_LIBCERR
01176 #define BRLERR_UNKNOWNTTY BRLAPI_ERROR_UNKNOWNTTY
01177 #define BRLERR_PROTOCOL_VERSION BRLAPI_ERROR_PROTOCOL_VERSION
01178 #define BRLERR_EOF BRLAPI_ERROR_EOF
01179 #define BRLERR_EMPTYKEY BRLAPI_ERROR_EMPTYKEY
01180 #define BRLERR_DRIVERERROR BRLAPI_ERROR_DRIVERERROR
01181
01183 #endif
01184
01185 #ifdef __cplusplus
01186 }
01187 #endif
01188
01189 #endif