Пример #1
0
struct Storage * _storage_init(int evt_dbname, int evt_size, int str_dbname, int str_size){
    int i=0;
    struct Storage* st = malloc(sizeof(struct Storage));
    st->evt_db = _db_init(evt_dbname, evt_size);
    st->str_db = _db_init(str_dbname, str_size);

    for(i=0;i<STR_MAX_NUM;i++){
        st->strlist[i] = NULL;
    }
    return st;

}
Пример #2
0
int main(int argc, char **argv)
{
    sqlite3 *db;
    int rc;
    char *sql;
    int is_fine = 1;

    if (access("demo.db", R_OK|W_OK)) {
        is_fine = 0;
    }

    rc = sqlite3_open("demo.db", &db);

    if(rc) {
        fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
        goto quit;
    }

    /* initialize db */
    if (!is_fine) {
        rc = _db_init(db);
        if (rc) {
            goto quit;
        }
    }

    _db_show_all(db);
    char name[32];
    db_get_account_name_by_id(db, name, 2);
    fprintf(stdout, "name of id %d is %s\n", 2, name);
    
    /* register hooks */
    char *data = "this is a hook test";
    sqlite3_commit_hook(db, _db_commit_hook, data);
    sqlite3_update_hook(db, _db_update_hook, data);
    sqlite3_set_authorizer(db, _db_auth_hook, data);

    puts("insert");
    sql = "insert into account (name,rank) values ('guest',2);";
    rc = sqlite3_exec(db, sql, NULL, NULL, NULL);
    _db_show_all(db);

    puts("update");
    sql = "update account set name='test' where id=4;";
    rc = sqlite3_exec(db, sql, NULL, NULL, NULL);
    _db_show_all(db);

    puts("delete");
    sql = "delete from account where name='test';";
    rc = sqlite3_exec(db, sql, NULL, NULL, NULL);
    _db_show_all(db);

quit:
    sqlite3_close(db);
    return 0;
}
Пример #3
0
extern "C" int cmain(int narg, char *arg[], char *envp[])
{
    int i,j,rc;
    HMODULE hDeviceLib;

    /* init pm comm. lib */
    //init(0);

    /* semaphore setup */
    rc = SetupSemaphore();
    if(rc)
    {
        if(rc == 2)
            printf("%s %s already running\n",_FreePM_Application_Name, _FreePM_Application_Vers);
        exit(rc);
    }
    //atexit(&FreePM_cleanup);
    //SetupSignals();

    rc = QueryProcessType();

    if(rc == 4)
        _FreePM_detachedMode = 1;

    /* init time */
    getCurrentTime();
    _FreePM_start = _FreePM_current_time;

    /* init debug */
    _db_init(_FreePMconfig.Log.log, FPMs_config.debugOptions);

    if(_FreePM_detachedMode)
    {
        debug(1, 0) ("Starting in detached mode %s version %s...\n",_FreePM_Application_Name, _FreePM_Application_Vers);
    } else {
        debug(1, 0) ("Starting %s version %s...\n",_FreePM_Application_Name, _FreePM_Application_Vers);
    }

    /* read config */
    FPMs_config.Read("fpmsrv.ini");
    /* init debug again */
    _db_init(_FreePMconfig.Log.log, FPMs_config.debugOptions);

    /* load device driver */

    debug(1, 0) ("Loading driver %s\n",FPMs_config.deviceName);

    if (!DosLoadModule(NULL, 0, FPMs_config.deviceName, &hDeviceLib))
    {
        debug(1, 0) ("Module loaded\n");
        if (DosQueryProcAddr(hDeviceLib, 0, "FPM_DeviceStart",
                             (PFN*)&FPM_DeviceStart))
        {
            debug(1, 0) ("Error initialize driver\n");
            exit(1);
        };
        debug(1, 0) ("Address found\n");

    } else {
        debug(1, 0) ("Error loading driver module\n");
        exit(1);
    }

    /* init pipes  */

    startServerThreads(&handler);

//  rc = session.AddDesktop(FPM_DEV_PMWIN,
//                           _FreePMconfig.desktop.nx,
//                           _FreePMconfig.desktop.ny,
//                           _FreePMconfig.desktop.bytesPerPixel,
//                           &_FreePMconfig.desktop.pp);
    debug(1, 0)("nx=%lu, ny=%lu, bpp=%lu\n", FPMs_config.DesktopNx,
                FPMs_config.DesktopNy,
                FPMs_config.BytesPerPel);
    rc = session.AddDesktop(FPM_DEV_PMWIN,
                            FPMs_config.DesktopNx,
                            FPMs_config.DesktopNy,
                            FPMs_config.BytesPerPel,
                            &_FreePMconfig.desktop.pp);

    debug(1, 1)("session.AddDesktop rc=%i\n",rc);

    debug(1, 1)("SRV main: Main idle loop\n");
    /* Main idle loop */
    /*
    debug(1, 1)("LSthreads.n %d\n", LSthreads.n);
    debug(1, 1)("LSthreads.Nclients %d\n", LSthreads.Nclients);
    debug(1, 1)("LSthreads.n %d\n", LSthreads.n); */

    for(i=0; ; i++)
    {
        for(j=0; j< LSthreads.n; j++)
        {
            debug(1, 1)("(%i,%i) ",LSthreads.thread_id[j],LSthreads.state[j] );
        }
        debug(1, 1)("%i   \r",LSthreads.Nclients);

        fflush(stdout);
        DosSleep(100);
    }

    rc = session.DelDesktop(0);

    debug(1, 1)("session.DelDesktop(0) rc=%i\n",rc);

    debug(1, 1) ("Normal Shutting down...\n");
    exit(0);
}