/* If the key exists, append separator and value, if not set it to value */ g_error append_param_str(const char *section, const char *key, const char *separator, const char *value) { char *newvalue; const char *oldvalue; oldvalue = get_param_str(section,key,NULL); if (oldvalue) { /* Append to an existing value */ newvalue = alloca(strlen(oldvalue)+strlen(separator)+strlen(value)+1); strcpy(newvalue,oldvalue); strcat(newvalue,separator); strcat(newvalue,value); return set_param_str(section,key,newvalue); } return set_param_str(section,key,value); }
/* Our main program, wrapped with exception handling */ g_error protected_main(int argc, char **argv) { g_error e; struct request_data r; struct pgrequest req; struct pgreqd_handlestruct hs; u32 file_size; void *file_data; FILE *f; handle wt, wt_instance; /* Here we're adding our own config parameters to pgserver's * configuration database. (Below we tell it to init without * loading /etc/pgserver.conf and ~/.pgserverrc) * Since the config database isn't pgserver-specific, it could * be used for general configuration of the host app. * See pgserver/configfile.h for the interface. */ /* Force the sdlgl video driver. * This driver handles OpenGL initialization, shutdown, * and page flipping by itself. It will default to 640x480, * but you can use standard picogui config vars to change that * or to enable fullscreen mode. * If you just want to render to an existing OpenGL context, * you can use the "glcontext" driver here instead */ e = set_param_str("pgserver", "video", "sdlgl"); errorcheck; /* Load a slightly hacked up lucid theme */ e = set_param_str("pgserver", "themes", "gl_lucid.th"); errorcheck; /* Use the Freetype2 OpenGL font engine */ e = set_param_str("pgserver", "font_engine", "ftgl"); errorcheck; /* Standard picogui fonts */ e = set_param_str("font-ftgl", "path", "../../../fonts"); errorcheck; /* No need for sprite dragging */ e = set_param_str("pgserver", "dragsolid", "1"); errorcheck; /* Custom title */ e = set_param_str("video-sdlgl", "caption", "PicoGUI server embedding test"); errorcheck; /* Redraw frames continuously instead of just when something changes */ e = set_param_str("opengl", "continuous", "1"); errorcheck; /* Define a configuration without using the usual config files. * Command line processing is optional as well, though it's useful * to have in this demo. * See pgserver/init.h for more info. */ e = pgserver_init(PGINIT_NO_CONFIGFILE,argc,argv); errorcheck; /* OpenGL init for our scene */ Initialize(640, 480); /* Now we'll do a small test of pgserver, loading and displaying a widget * template. Note that normally this shouldn't need to call request_exec * directly- either a different process or thread should connect to the * pgserver, or support for request_exec should be added to cli_c so we * can use normal API functions instead of packing everything ourselves. */ /* Read in a compiled widget template */ f = fopen("test.wt","rb"); fseek(f,0,SEEK_END); file_size = ftell(f); rewind(f); e = g_malloc((void**)&file_data, file_size); errorcheck; fread(file_data,1,file_size,f); fclose(f); /* Load the compiled WT */ memset(&r,0,sizeof(r)); r.in.req = &req; req.type = htons(PGREQ_MKTEMPLATE); req.size = htonl(file_size); r.in.data = file_data; e = request_exec(&r); errorcheck; wt = r.out.ret; if (r.out.free_response_data) g_free(r.out.response_data); g_free(file_data); /* Instantiate the compiled WT */ hs.h = htonl(wt); memset(&r,0,sizeof(r)); r.in.req = &req; req.type = htons(PGREQ_DUP); req.size = htonl(sizeof(hs)); r.in.data = &hs; e = request_exec(&r); errorcheck; wt_instance = r.out.ret; if (r.out.free_response_data) g_free(r.out.response_data); /* Update, necessary for this to appear on screen */ memset(&r,0,sizeof(r)); r.in.req = &req; req.type = htons(PGREQ_UPDATE); e = request_exec(&r); errorcheck; if (r.out.free_response_data) g_free(r.out.response_data); /* Run our main loop until something signals it to stop... * This could be anything that calls pgserver_mainloop_stop, including * interrupts from drivers or the user. */ pgserver_mainloop_start(); while (pgserver_mainloop_is_running()) { /* This is our custom scene that we'll render beneath the GUI. * If the theme has no 'holes' for this to show through, you can see it * by using CTRL-ALT-Q to move the camera then CTRL-ALT-G to disable the grid. */ Draw(); /* PicoGUI's main loop, where it processes network, input, and rendering */ e = pgserver_mainloop_iteration(); errorcheck; } /* Shut down all subsystems and perform memory leak detection */ e = pgserver_shutdown(); errorcheck; return success; }
/* Parse a command line, and add it to the config file database. * If the command line was invalid or the user requested help, a help string * will be printed and an error will be returned. */ g_error commandline_parse(int argc, char **argv) { int c; g_error e; while (1) { c = getopt(argc,argv,"hlnv:m:i:t:c:-:s:"); if (c==-1) break; switch (c) { case 'n': /* Ignore config data */ configfile_free(); break; case '-': /* config option */ { char *section, *key, *value; /* Treat --help as an exception */ if (!strcmp(optarg,"help")) return commandline_help(); if ((key = strchr(optarg,'.'))) { *key = 0; key++; section = optarg; } else { /* Default section */ key = optarg; section = "pgserver"; } if ((value = strchr(key,'='))) { *value = 0; value++; } else /* Default value */ value = "1"; e = set_param_str(section,key,value); errorcheck; } break; case 'v': /* Video driver */ e = set_param_str("pgserver","video",optarg); errorcheck; break; case 'm': /* Video mode */ e = set_param_str("pgserver","mode",optarg); errorcheck; break; case 's': /* Session manager */ e = set_param_str("pgserver","session",optarg); errorcheck; break; case 'c': /* Config file */ e = configfile_parse(optarg); errorcheck; break; case 'l': /* List */ e = commandline_list(); errorcheck; break; case 'i': /* Input */ e = append_param_str("pgserver","input"," ",optarg); errorcheck; break; case 't': /* Theme */ e = append_param_str("pgserver","themes"," ",optarg); errorcheck; break; default: /* Need help */ return commandline_help(); } } if (optind < argc) /* extra options */ return commandline_help(); return success; }
int store_hwe (vector hwtable, struct hwentry * dhwe) { struct hwentry * hwe; if (find_hwe_strmatch(hwtable, dhwe)) return 0; if (!(hwe = alloc_hwe())) return 1; if (!dhwe->vendor || !(hwe->vendor = set_param_str(dhwe->vendor))) goto out; if (!dhwe->product || !(hwe->product = set_param_str(dhwe->product))) goto out; if (dhwe->revision && !(hwe->revision = set_param_str(dhwe->revision))) goto out; if (dhwe->uid_attribute && !(hwe->uid_attribute = set_param_str(dhwe->uid_attribute))) goto out; if (dhwe->features && !(hwe->features = set_param_str(dhwe->features))) goto out; if (dhwe->hwhandler && !(hwe->hwhandler = set_param_str(dhwe->hwhandler))) goto out; if (dhwe->selector && !(hwe->selector = set_param_str(dhwe->selector))) goto out; if (dhwe->checker_name && !(hwe->checker_name = set_param_str(dhwe->checker_name))) goto out; if (dhwe->prio_name && !(hwe->prio_name = set_param_str(dhwe->prio_name))) goto out; if (dhwe->prio_args && !(hwe->prio_args = set_param_str(dhwe->prio_args))) goto out; if (dhwe->alias_prefix && !(hwe->alias_prefix = set_param_str(dhwe->alias_prefix))) goto out; hwe->pgpolicy = dhwe->pgpolicy; hwe->pgfailback = dhwe->pgfailback; hwe->rr_weight = dhwe->rr_weight; hwe->no_path_retry = dhwe->no_path_retry; hwe->minio = dhwe->minio; hwe->minio_rq = dhwe->minio_rq; hwe->pg_timeout = dhwe->pg_timeout; hwe->flush_on_last_del = dhwe->flush_on_last_del; hwe->fast_io_fail = dhwe->fast_io_fail; hwe->dev_loss = dhwe->dev_loss; hwe->user_friendly_names = dhwe->user_friendly_names; hwe->retain_hwhandler = dhwe->retain_hwhandler; hwe->detect_prio = dhwe->detect_prio; if (dhwe->bl_product && !(hwe->bl_product = set_param_str(dhwe->bl_product))) goto out; if (!vector_alloc_slot(hwtable)) goto out; vector_set_slot(hwtable, hwe); return 0; out: free_hwe(hwe); return 1; }