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