static void logSentMsg(const uint8_t *data, size_t len) { if(flib_log_isActive(FLIB_LOGLEVEL_DEBUG)) { size_t msgStart = 0; while(msgStart < len) { uint8_t msglen = data[msgStart]; if(msgStart+msglen < len) { flib_log_d("[IPC OUT][%03u]%*.*s",(unsigned)msglen, (unsigned)msglen, (unsigned)msglen, data+msgStart+1); } else { uint8_t msglen2 = len-msgStart-1; flib_log_d("[IPC OUT][%03u/%03u]%*.*s",(unsigned)msglen2, (unsigned)msglen, (unsigned)msglen2, (unsigned)msglen2, data+msgStart+1); } msgStart += (uint8_t)data[msgStart]+1; } } }
int flib_init() { flib_log_d("Initializing frontlib"); if(SDLNet_Init()==-1) { flib_log_e("Error in SDLNet_Init: %s", SDLNet_GetError()); return -1; } return 0; }
void flib_ipcbase_destroy(flib_ipcbase *ipc) { if(ipc) { flib_acceptor_close(ipc->acceptor); flib_socket_close(ipc->sock); if(ipc->sock) { flib_log_d("IPC connection closed."); } free(ipc); } }
void flib_ipcbase_accept(flib_ipcbase *ipc) { if(!log_badargs_if(ipc==NULL) && !ipc->sock && ipc->acceptor) { ipc->sock = flib_socket_accept(ipc->acceptor, true); if(ipc->sock) { flib_log_d("IPC connection accepted."); flib_acceptor_close(ipc->acceptor); ipc->acceptor = NULL; } } }
static void receiveToBuffer(flib_ipcbase *ipc) { if(ipc->sock) { int size = flib_socket_nbrecv(ipc->sock, ipc->readBuffer+ipc->readBufferSize, sizeof(ipc->readBuffer)-ipc->readBufferSize); if(size>=0) { ipc->readBufferSize += size; } else { flib_log_d("IPC connection lost."); flib_socket_close(ipc->sock); ipc->sock = NULL; } } }
int flib_ini_enter_section(flib_ini *ini, const char *section) { int result = INI_ERROR_OTHER; if(ini) { free(ini->currentSection); ini->currentSection = NULL; } if(!log_badargs_if2(ini==NULL, section==NULL)) { if(!iniparser_find_entry(ini->inidict, section)) { flib_log_d("Ini section %s not found", section); result = INI_ERROR_NOTFOUND; } else { ini->currentSection = flib_strdupnull(section); if(ini->currentSection) { // Usually iniparser ignores case, but some section-handling functions don't, // so we set it to lowercase manually strToLower(ini->currentSection); result = 0; } } } return result; }
static void logRecvMsg(const uint8_t *data) { if(flib_log_isActive(FLIB_LOGLEVEL_DEBUG)) { uint8_t msglen = data[0]; flib_log_d("[IPC IN][%03u]%*.*s",(unsigned)msglen, (unsigned)msglen, (unsigned)msglen, data+1); } }
void flib_quit() { flib_log_d("Shutting down frontlib"); SDLNet_Quit(); }