int initialize_db () { int rc = 1; struct stat buf; int i = 0; FILE *fp; fp = stdout; fprintf (fp, "Begun initialize_db\n"); fprintf (fp, "1...Initializing database from path...%s\n", DATABASE); i = stat (DATABASE, &buf); fprintf (fp, "2...Initializing database...:%d\n", i); if ((i < 0) || (buf.st_size == 0)) { fprintf (fp, "Initializing database...\n"); rc = open_sqlite (DATABASE); if (rc == 0) { fprintf (fp, "Create database failure!\n"); } close_sqlite (); } fprintf (fp, "Ended initialize_db\n"); return rc; }
/*********************************************************************************************** MAIN MENU FOR RETAIL ***********************************************************************************************/ int main (void) { struct tm intim; int Ret_val; double amount; unsigned char str[100] = ""; pthread_t syncT; pthread_attr_t attr; int newprio; struct sched_param param; int ret; //fp = fopen (logFile, "w+"); fp = stdout; fprintf(fp,"Begun main()"); fflush(fp); lk_open (); prn_open (); mscr_open (); lk_dispinit (); lk_dispclr(); strcpy(DATABASE,"/mnt/jffs2/fps.sqlite"); initialize_db (); open_sqlite (DATABASE); strcpy(CONFIG_FILE, get_config("CONFIG_FILE",tmpbuf,"0")); //Need OFFICE ID From config file before init_globals read_config (CONFIG_FILE); strcpy(OFFICE_ID,getVal("office_id")); // Get from config file strcpy(SESSION_ID,""); fprintf(fp,"office_id:",OFFICE_ID); fflush(fp); init_globals(); strcpy(IP,getVal("remote_url")); strcpy(shop_id,getVal("shop")); strcpy(terminal,getVal("terminal")); strcpy(tempFile,"/mnt/jffs2/dat"); strcpy(svr_username,getVal("server_user")); strcpy(svr_password,getVal("server_pwd")); setAuthType(); if(strcmp(toUpper(getVal("show_splash")),"TRUE")==0) { lk_disptext (1, 0, " PDS ", 1); lk_disptext (3, 0, " Govt of AP", 0); lk_disptext (4, 0, " Version:0.9", 0); lk_disptext (5, 0, " Enter to continue", 0); lk_getkey (); lk_dispclr (); } if(strcmp(toUpper(getVal("commMode")),"ETHERNET") == 0) ip_setup (); strcpy(background,getVal("background")); pthread_attr_init(&attr); pthread_attr_setschedpolicy(&attr, SCHED_OTHER); newprio = 1; param.sched_priority = newprio; pthread_attr_setschedparam(&attr,¶m); if(strcmp(background,"true")==0) { fprintf(fp,"Starting a background thread"); fflush(fp); if (pthread_create (&syncT, &attr, syncThread, NULL) != 0) fprintf (stderr, "Error creating the thread"); } while(1) { ret = login(); printFlag = FALSE; if(ret==USER) main_menu(); else if(ret == ADMIN) admin_menu(); else { lk_dispclr(); lk_disptext (2, 0, "Invalid credentials", 0); lk_getkey (); lk_dispclr (); } } prn_close (); // closing printer lk_close (); // closing pinpad mscr_close (); // closing magnetic swipe close_sqlite (); fprintf(fp,"Ended main()"); fflush(fp); return SUCCESS; }
static int l_db_gc(lua_State* L) { DB * db = checkdb(L, 1); close_sqlite(db); return 0; }