/* Opens a connection with BrlAPI's server */ static int brl_construct(BrailleDisplay *brl, char **parameters, const char *device) { brlapi_connectionSettings_t settings; settings.host = parameters[PARM_HOST]; settings.auth = parameters[PARM_AUTH]; CHECK((brlapi_openConnection(&settings, &settings)>=0), out); logMessage(LOG_DEBUG, "Connected to %s using %s", settings.host, settings.auth); CHECK((brlapi_enterTtyModeWithPath(NULL, 0, NULL)>=0), out0); logMessage(LOG_DEBUG, "Got tty successfully"); CHECK((brlapi_getDisplaySize(&brl->textColumns, &brl->textRows)==0), out1); logMessage(LOG_DEBUG,"Found out display size: %dx%d", brl->textColumns, brl->textRows); displaySize = brl->textColumns*brl->textRows; prevData = malloc(displaySize); CHECK((prevData!=NULL), out1); prevText = malloc(displaySize * sizeof(wchar_t)); CHECK((prevText!=NULL), out2); prevShown = 0; restart = 0; logMessage(LOG_DEBUG, "Memory allocated, returning 1"); return 1; out2: free(prevData); out1: brlapi_leaveTtyMode(); out0: brlapi_closeConnection(); out: logMessage(LOG_DEBUG, "Something went wrong, returning 0"); return 0; }
int main (int argc, char *argv[]) { ProgramExitStatus exitStatus = PROG_EXIT_SUCCESS; brlapi_fileDescriptor fd; settings.host = NULL; settings.auth = NULL; { static const OptionsDescriptor descriptor = { OPTION_TABLE(programOptions), .applicationName = "apitest" }; PROCESS_OPTIONS(descriptor, argc, argv); } fprintf(stderr, "Connecting to BrlAPI... "); if ((fd=brlapi_openConnection(&settings, &settings)) != (brlapi_fileDescriptor)(-1)) { fprintf(stderr, "done (fd=%"PRIfd")\n", fd); fprintf(stderr,"Connected to %s using auth %s\n", settings.host, settings.auth); if (opt_showName) { showDriverName(); } if (opt_showSize) { showDisplaySize(); } if (opt_showDots) { showDots(); } if (opt_learnMode) { enterLearnMode(); } if (opt_showKeyCodes) { showKeyCodes(); } if (opt_suspendMode) { suspendDriver(); } brlapi_closeConnection(); fprintf(stderr, "Disconnected\n"); } else { fprintf(stderr, "failed to connect to %s using auth %s",settings.host, settings.auth); brlapi_perror(""); exitStatus = PROG_EXIT_FATAL; } return exitStatus; }
/* Frees memory and closes the connection with BrlAPI */ static void brl_destruct(BrailleDisplay *brl) { free(prevData); free(prevText); brlapi_closeConnection(); }
BDevice::~BDevice() { brlapi_closeConnection(); }
int main(int argc, char *argv[]) { transferfun *transfer; char driverName[13]; int stilloptions=1; char *home; brlapi_settings_t brlapi_settings; transfer=CheckSendOrRecv(argv[0]); /* first use options file */ if ((home=getenv("HOME"))) { char vstprc[strlen(home)+strlen(VSTPRC)+2]; strcpy(vstprc,home); strcat(vstprc,"/" VSTPRC); Parse(vstprc); } /* a first pass to check options and record them, before doing anything */ CheckOptions(argc--,argv++); /* ok, one can try to open the socket */ brlapi_settings.host = socketport; brlapi_settings.auth = keyname; if (brlapi_initializeConnection(&brlapi_settings,NULL)<0) { brlapi_perror("Couldn't initialize connection with BrlAPI"); exit(RET_ECONN); } if (brlapi_getDriverName(driverName, sizeof(driverName))<12) { brlapi_perror("Couldn't get driver name"); brlapi_closeConnection(); exit(RET_ECONN); } if (strcmp(driverName,"VisioBraille")) { fprintf(stderr,"braille driver is not VisioBraille\n"); brlapi_closeConnection(); exit(RET_ECONN); } if (brlapi_enterRawMode("VisioBraille")<0) { fprintf(stderr,"Couldn't get raw mode\n"); brlapi_closeConnection(); exit(RET_ECONN); } signal(SIGINT,handleint); signal(SIGTERM,handleint); #ifdef SIGHUP signal(SIGHUP,handleint); #endif /* SIGHUP */ #ifdef SIGQUIT signal(SIGQUIT,handleint); #endif /* SIGQUIT */ #ifdef SIGPIPE signal(SIGPIPE,handleint); #endif /* SIGPIPE */ #ifdef SIGALRM signal(SIGALRM,transfer_timeout); #endif /* SIGALRM */ if (visiobases_dir && chdir(visiobases_dir)<0) { perror(visiobases_dir); fprintf(stderr,"couldn't chdir to download dir, please use -d if you want to store files in .\n"); exit(RET_EUNIX); } for(;argc;argc--, argv++) { /* is it an option ? */ if (stilloptions) if (argv[0][0]=='-') { switch (argv[0][1]) { case '-': stilloptions=0; continue; case 's': /* already parsed */ case 'k': case 'm': argc--; argv++; case 'b': case 'n': case 'f': case 'i': case 'd': default: continue; } } /* no, a file name, let's try to transfer it */ transfer(argv[0]); } printf("transfers finished\n"); transfer_finish(transfer); brlapi_leaveRawMode(); /* can't do much it it fails ! */ brlapi_closeConnection(); return 0; }
/* if something nasty occured, try to clean */ void transfer_abort(int exitnum) { brlapi_sendRaw(VB_RESET,strlen(VB_RESET)); brlapi_leaveRaw(); brlapi_closeConnection(); exit(exitnum); }
void eutp_abort(int exitstatus) { brlapi_leaveRawMode(); brlapi_closeConnection(); exit(exitstatus); }
/* ** Closes the connection to BRLAPI */ int brl_close(void) { brlapi_leaveRawMode(); brlapi_closeConnection(); return 0; }