void restore_resume_state (void) { DB_output_t *output = plug_get_output (); if (conf_get_int ("resume_last_session", 0) && output->state () == OUTPUT_STATE_STOPPED) { int plt = conf_get_int ("resume.playlist", -1); int track = conf_get_int ("resume.track", -1); float pos = conf_get_float ("resume.position", -1); int paused = conf_get_int ("resume.paused", 0); trace ("resume: track %d pos %f playlist %d\n", track, pos, plt); if (plt >= 0 && track >= 0 && pos >= 0) { streamer_lock (); // need to hold streamer thread to make the resume operation atomic streamer_set_current_playlist (plt); streamer_set_nextsong (track, paused ? 2 : 3); streamer_set_seek (pos); streamer_unlock (); } } }
END_TEST START_TEST (test_conf_default) { configuration *conf; int ret; int i; unsigned int u; char c; int bt; int bf; float f; const char *s; int valid; conf = conf_create (); fail_unless (conf != 0); ret = conf_add_group (conf, NULL, head_group); fail_unless (ret == 0); ret = conf_add_group (conf, "agroup", head_group); fail_unless (ret == 0); i = conf_get_int (conf, NULL, "h_int", &valid); fail_unless (valid == 1); fail_unless (i == 1, "Got %d expected %d", i, 1); u = conf_get_uint (conf, NULL, "h_uint", &valid); fail_unless (valid == 1); fail_unless (u == 10); c = conf_get_char (conf, NULL, "h_char", &valid); fail_unless (valid == 1); fail_unless (c == 'A'); bf = conf_get_bool (conf, NULL, "h_bool_false", &valid); fail_unless (valid == 1); fail_unless (bf == 0); bt = conf_get_bool (conf, NULL, "h_bool_true", &valid); fail_unless (valid == 1); fail_unless (bt == 1); f = conf_get_float (conf, NULL, "h_float", &valid); fail_unless (valid == 1); fail_unless (abs (f - 5.5f) < 0.0001f, "Got %f expected %f", f, 5.5f); s = conf_get_string (conf, NULL, "h_string", &valid); fail_unless (valid == 1); fail_unless (strcasecmp (s, "default") == 0); i = conf_get_int (conf, "agroup", "h_int", &valid); fail_unless (valid == 1); fail_unless (i == 1, "Got %d expected %d", i, 1); u = conf_get_uint (conf, "agroup", "h_uint", &valid); fail_unless (valid == 1); fail_unless (u == 10); c = conf_get_char (conf, "agroup", "h_char", &valid); fail_unless (valid == 1); fail_unless (c == 'A'); bf = conf_get_bool (conf, "agroup", "h_bool_false", &valid); fail_unless (valid == 1); fail_unless (bf == 0); bt = conf_get_bool (conf, "agroup", "h_bool_true", &valid); fail_unless (valid == 1); fail_unless (bt == 1); f = conf_get_float (conf, "agroup", "h_float", &valid); fail_unless (valid == 1); fail_unless (abs (f - 5.5f) < 0.0001f, "Got %f expected %f", f, 5.5f); s = conf_get_string (conf, "agroup", "h_string", &valid); fail_unless (valid == 1); fail_unless (strcasecmp (s, "default") == 0); conf_free (conf); }
END_TEST START_TEST (test_conf_errors) { configuration *conf; int ret; int i; unsigned int u; char c; int bt; int bf; float f; const char *s; int valid; /* * Test Add group errors. */ conf = conf_create (); fail_unless (conf != 0); /* Add group to non conf. */ ret = conf_add_group (NULL, NULL, head_group); fail_unless (ret == -1); conf_free (conf); /* Add two groups with no group name under root. */ conf = conf_create (); fail_unless (conf != 0); ret = conf_add_group (conf, NULL, head_group); fail_unless (ret == 0); ret = conf_add_group (conf, NULL, head_group); fail_unless (ret == -1); conf_free (conf); /* Add group with bad parameter type. */ conf = conf_create (); fail_unless (conf != 0); ret = conf_add_group (conf, NULL, bad_1_group); fail_unless (ret < 0); conf_free (conf); /* * Test load errors. */ conf = conf_create (); fail_unless (conf != 0); /* Load with no groups. */ ret = conf_load (conf, CONFDIR "test.conf"); fail_unless (ret == -1); /* Test filename. */ ret = conf_add_group (conf, "a group", head_group); fail_unless (ret == 0); ret = conf_load (conf, NULL); fail_unless (ret == -1); ret = conf_load (conf, "/dev/null/something"); fail_unless (ret == -1); /* Test group names. */ ret = conf_load (conf, CONFDIR "test_bad1.conf"); fail_unless (ret < 0); ret = conf_load (conf, CONFDIR "test_bad2.conf"); fail_unless (ret < 0); ret = conf_load (conf, CONFDIR "test_bad3.conf"); fail_unless (ret < 0); ret = conf_load (conf, CONFDIR "test_bad4.conf"); fail_unless (ret < 0); ret = conf_load (conf, CONFDIR "test_bad5.conf"); fail_unless (ret < 0); ret = conf_load (conf, CONFDIR "test_bad6.conf"); fail_unless (ret < 0); ret = conf_load (conf, CONFDIR "test_bad7.conf"); fail_unless (ret < 0); ret = conf_load (conf, CONFDIR "test_bad8.conf"); fail_unless (ret < 0); ret = conf_load (conf, CONFDIR "test_bad9.conf"); fail_unless (ret < 0); ret = conf_load (conf, CONFDIR "test_bad10.conf"); fail_unless (ret != 0); ret = conf_add_group (conf, NULL, head_group); fail_unless (ret == 0); ret = conf_load (conf, CONFDIR "test_bad11.conf"); fail_unless (ret == -15, "%d", ret); ret = conf_load (conf, CONFDIR "test_bad12.conf"); fail_unless (ret == -13); ret = conf_load (conf, CONFDIR "test_bad13.conf"); fail_unless (ret != -14); ret = conf_load (conf, CONFDIR "test_bad14.conf"); fail_unless (ret == -17, "%d", ret); conf_free (conf); /* Test getting values */ conf = conf_create (); fail_unless (conf != 0); ret = conf_add_group (conf, "a group", head_group); fail_unless (ret == 0); i = conf_get_int (conf, NULL, "h_int", &valid); fail_unless (valid == 0); u = conf_get_uint (conf, NULL, "h_uint", &valid); fail_unless (valid == 0); c = conf_get_char (conf, NULL, "h_char", &valid); fail_unless (valid == 0); bf = conf_get_bool (conf, NULL, "h_bool_false", &valid); fail_unless (valid == 0); bt = conf_get_bool (conf, NULL, "h_bool_true", &valid); fail_unless (valid == 0); f = conf_get_float (conf, NULL, "h_float", &valid); fail_unless (valid == 0); s = conf_get_string (conf, NULL, "h_string", &valid); fail_unless (valid == 0); i = conf_get_int (conf, "a group", "X_int", &valid); fail_unless (valid == 0); u = conf_get_uint (conf, "a group", "X_uint", &valid); fail_unless (valid == 0); c = conf_get_char (conf, "a group", "X_char", &valid); fail_unless (valid == 0); bf = conf_get_bool (conf, "a group", "X_bool_false", &valid); fail_unless (valid == 0); bt = conf_get_bool (conf, "a group", "X_bool_true", &valid); fail_unless (valid == 0); f = conf_get_float (conf, "a group", "X_float", &valid); fail_unless (valid == 0); s = conf_get_string (conf, "a group", "X_string", &valid); fail_unless (valid == 0); conf_free (conf); }
END_TEST START_TEST (test_conf_file) { configuration *conf; int ret; int i; unsigned int u; char c; int bt; int bf; float f; const char *s; int valid; conf = conf_create (); fail_unless (conf != 0); ret = conf_add_group (conf, NULL, head_group); fail_unless (ret == 0); ret = conf_add_group (conf, "agroup", head_group); fail_unless (ret == 0); ret = conf_add_group (conf, "c group", head_group); fail_unless (ret == 0); ret = conf_add_group (conf, "b group", head_group); fail_unless (ret == 0); ret = conf_add_group (conf, "e group", head_group); fail_unless (ret == 0); ret = conf_add_group (conf, "d group", head_group); fail_unless (ret == 0); ret = conf_load (conf, CONFDIR "test.conf"); fail_unless (ret == 0, "ret = %d", ret); i = conf_get_int (conf, NULL, "h_int", &valid); fail_unless (valid == 1); fail_unless (i == 10, "Got %d expected %d", i, 10); u = conf_get_uint (conf, NULL, "h_uint", &valid); fail_unless (valid == 1); fail_unless (u == 55, "Got %u expected %u", u, 55); c = conf_get_char (conf, NULL, "h_char", &valid); fail_unless (valid == 1); fail_unless (c == 'B', "Got %c expected %c", c, 'B'); bf = conf_get_bool (conf, NULL, "h_bool_false", &valid); fail_unless (valid == 1); fail_unless (bf == 0, "Got %d expected %d", bf, 0); bt = conf_get_bool (conf, NULL, "h_bool_true", &valid); fail_unless (valid == 1); fail_unless (bt == 1, "Got %d expected %d", i, 1); f = conf_get_float (conf, NULL, "h_float", &valid); fail_unless (valid == 1); fail_unless (abs (f - 15.5f) < 0.0001f, "Got %f expected %f", f, 15.5f); s = conf_get_string (conf, NULL, "h_string", &valid); fail_unless (valid == 1); fail_unless (strcasecmp (s, "Not Default") == 0, "Got %d expected 'Not Default", i); i = conf_get_int (conf, "agroup", "h_int", &valid); fail_unless (valid == 1); fail_unless (i == 10, "Got %d expected %d", i, 10); u = conf_get_uint (conf, "agroup", "h_uint", &valid); fail_unless (valid == 1); fail_unless (u == 75, "Got %u expected %u", u, 75); c = conf_get_char (conf, "agroup", "h_char", &valid); fail_unless (valid == 1); fail_unless (c == 'B', "Got %c expected %c", c, 'B'); bf = conf_get_bool (conf, "agroup", "h_bool_false", &valid); fail_unless (valid == 1); fail_unless (bf == 0, "Got %d expected %d", bf, 0); bt = conf_get_bool (conf, "agroup", "h_bool_true", &valid); fail_unless (valid == 1); fail_unless (bt == 1, "Got %d expected %d", i, 1); f = conf_get_float (conf, "agroup", "h_float", &valid); fail_unless (valid == 1); fail_unless (abs (f - 15.5f) < 0.0001f, "Got %f expected %f", f, 15.5f); s = conf_get_string (conf, "agroup", "h_string", &valid); fail_unless (valid == 1); fail_unless (strcasecmp (s, "Not") == 0, "Got '%s' expected 'Not'", s); i = conf_get_int (conf, "b group", "h_int", &valid); fail_unless (valid == 1); fail_unless (i == 10, "Got %d expected %d", i, 10); u = conf_get_uint (conf, "b group", "h_uint", &valid); fail_unless (valid == 1); fail_unless (u == 85, "Got %u expected %u", u, 85); c = conf_get_char (conf, "b group", "h_char", &valid); fail_unless (valid == 1); fail_unless (c == 'B', "Got %c expected %c", c, 'B'); bf = conf_get_bool (conf, "b group", "h_bool_false", &valid); fail_unless (valid == 1); fail_unless (bf == 0, "Got %d expected %d", bf, 0); bt = conf_get_bool (conf, "b group", "h_bool_true", &valid); fail_unless (valid == 1); fail_unless (bt == 1, "Got %d expected %d", i, 1); f = conf_get_float (conf, "b group", "h_float", &valid); fail_unless (valid == 1); fail_unless (abs (f + 25.5f) < 0.0001f, "Got %f expected %f", f, -25.5f); s = conf_get_string (conf, "b group", "h_string", &valid); fail_unless (valid == 1); fail_unless (strcasecmp (s, "Not Default") == 0, "Got %d expected 'Not Default", i); i = conf_get_int (conf, "c group", "h_int", &valid); fail_unless (valid == 1); fail_unless (i == -16, "Got %d expected %d", i, -16); u = conf_get_uint (conf, "c group", "h_uint", &valid); fail_unless (valid == 1); fail_unless (u == 16, "Got %u expected %u", u, 16); c = conf_get_char (conf, "c group", "h_char", &valid); fail_unless (valid == 1); fail_unless (c == '\0', "Got %c expected %c", c, '\0'); bf = conf_get_bool (conf, "c group", "h_bool_false", &valid); fail_unless (valid == 1); fail_unless (bf == 0, "Got %d expected %d", bf, 0); bt = conf_get_bool (conf, "c group", "h_bool_true", &valid); fail_unless (valid == 1); fail_unless (bt == 1, "Got %d expected %d", i, 1); f = conf_get_float (conf, "c group", "h_float", &valid); fail_unless (valid == 1); fail_unless (abs (f - 15.5f) < 0.0001f, "Got %f expected %f", f, 15.5f); s = conf_get_string (conf, "c group", "h_string", &valid); fail_unless (valid == 1); fail_unless (strcasecmp (s, " Not Default") == 0, "Got %d expected 'Not Default", s); i = conf_get_int (conf, "d group", "h_int", &valid); fail_unless (valid == 1); fail_unless (i == 100, "Got %d expected %d", i, 100); u = conf_get_uint (conf, "d group", "h_uint", &valid); fail_unless (valid == 1); fail_unless (u == 100, "Got %u expected %u", u, 100); c = conf_get_char (conf, "d group", "h_char", &valid); fail_unless (valid == 1); fail_unless (c == '\07', "Got %c expected %c", c, '\07'); bf = conf_get_bool (conf, "d group", "h_bool_false", &valid); fail_unless (valid == 1); fail_unless (bf == 0, "Got %d expected %d", bf, 0); bt = conf_get_bool (conf, "d group", "h_bool_true", &valid); fail_unless (valid == 1); fail_unless (bt == 1, "Got %d expected %d", i, 1); f = conf_get_float (conf, "d group", "h_float", &valid); fail_unless (valid == 1); fail_unless (abs (f - 100.0f) < 0.0001f, "Got %f expected %f", f, +100.0f); s = conf_get_string (conf, "d group", "h_string", &valid); fail_unless (valid == 1); fail_unless (strcasecmp (s, "\b\v\t\n\r\f\a\\\?\'\"\x10\010") == 0, "Got %d expected 'Not Default", s); i = conf_get_int (conf, "e group", "h_int", &valid); fail_unless (valid == 1); fail_unless (i == -100, "Got %d expected %d", i, -100); u = conf_get_uint (conf, "e group", "h_uint", &valid); fail_unless (valid == 1); fail_unless (u == 0, "Got %u expected %u", u, 0); c = conf_get_char (conf, "e group", "h_char", &valid); fail_unless (valid == 1); fail_unless (c == '\t', "Got %c expected %c", c, '\t'); bf = conf_get_bool (conf, "e group", "h_bool_false", &valid); fail_unless (valid == 1); fail_unless (bf == 0, "Got %d expected %d", bf, 0); bt = conf_get_bool (conf, "e group", "h_bool_true", &valid); fail_unless (valid == 1); fail_unless (bt == 1, "Got %d expected %d", i, 1); f = conf_get_float (conf, "e group", "h_float", &valid); fail_unless (valid == 1); fail_unless (abs (f + 100) < 0.0001f, "Got %f expected %f", f, -100.0f); s = conf_get_string (conf, "e group", "h_string", &valid); fail_unless (valid == 1); fail_unless (strlen (s) == 0, "Got '%s' expected ''", s); conf_free (conf); }
void ui_init(int w,int h,int x,int y){ start_time=get_msec(); setup_modifiers(); _w=w; _h=h; winX=x; winY=y; dpy=XOpenDisplay(""); screen=DefaultScreen(dpy); root=DefaultRootWindow(dpy); XMatchVisualInfo(dpy, screen, 32, TrueColor, &visualinfo); uk_log("Iniitializing UI"); uk_log("Win @ (%i,%i,%i,%i)",x,y,w,h); attr.colormap = XCreateColormap( dpy, root, visualinfo.visual, AllocNone) ; attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask; attr.background_pixmap = None ; attr.border_pixel = 0 ; uk_log("root=%x\n",root); uk_log("%i %i %i %i\n",x,y,w,h); win=XCreateWindow(dpy,root, x,y,w,h, 0, visualinfo.depth, InputOutput, visualinfo.visual, CWColormap|CWEventMask|CWBackPixmap|CWBorderPixel, &attr); XWindowAttributes wa; XGetWindowAttributes(dpy,win,&wa); gc = XCreateGC(dpy,win,0,0); double_buffer=XCreatePixmap(dpy,win,wa.width,wa.height,wa.depth); XColor black=_rgb2XColor(255,255,255); XAllocColor(dpy,attr.colormap,&black); XSetForeground(dpy,gc,black.pixel); XFillRectangle(dpy,double_buffer,gc,0,0,wa.width,wa.height); d=double_buffer; uk_log("Created pixmap = %x",double_buffer); XGetWindowAttributes(dpy,win,&wa); load_font(); uk_log("window = %x root = %x",win,root); _set_on_top(dpy,win); _set_sticky(dpy,win); _set_alpha(dpy,win,conf_get_float("alpha",ALPHA)); XMapWindow(dpy,win); XMoveWindow(dpy,win,x,y); // Try to make borderless _make_borderless(dpy,win); // Bind to what stuff? unsigned long eventmask; eventmask=StructureNotifyMask|SubstructureNotifyMask; uk_log("event mask = x%x",eventmask); XSelectInput(dpy,root,eventmask); XFlush(dpy); kbio.start=kbio.stop=kbio.n=0; _setupkeymap(); grabkeys(); // grabkeyboard(); }
/* * read_slurm_cgroup_conf - load the Slurm cgroup configuration from the * cgroup.conf file. * RET SLURM_SUCCESS if no error, otherwise an error code */ extern int read_slurm_cgroup_conf(slurm_cgroup_conf_t *slurm_cgroup_conf) { s_p_options_t options[] = { {"CgroupAutomount", S_P_BOOLEAN}, {"CgroupMountpoint", S_P_STRING}, {"CgroupSubsystems", S_P_STRING}, {"CgroupReleaseAgentDir", S_P_STRING}, {"ConstrainCores", S_P_BOOLEAN}, {"TaskAffinity", S_P_BOOLEAN}, {"ConstrainRAMSpace", S_P_BOOLEAN}, {"AllowedRAMSpace", S_P_STRING}, {"MaxRAMPercent", S_P_STRING}, {"MinRAMSpace", S_P_UINT32}, {"ConstrainSwapSpace", S_P_BOOLEAN}, {"AllowedSwapSpace", S_P_STRING}, {"MaxSwapPercent", S_P_STRING}, {"ConstrainCores", S_P_BOOLEAN}, {"MemoryLimitEnforcement", S_P_BOOLEAN}, {"MemoryLimitThreshold", S_P_STRING}, {"ConstrainDevices", S_P_BOOLEAN}, {"AllowedDevicesFile", S_P_STRING}, {NULL} }; s_p_hashtbl_t *tbl = NULL; char *conf_path = NULL; struct stat buf; /* Set initial values */ if (slurm_cgroup_conf == NULL) { return SLURM_ERROR; } _clear_slurm_cgroup_conf(slurm_cgroup_conf); /* Get the cgroup.conf path and validate the file */ conf_path = get_extra_conf_path("cgroup.conf"); if ((conf_path == NULL) || (stat(conf_path, &buf) == -1)) { debug2("%s: No cgroup.conf file (%s)", __func__, conf_path); } else { debug("Reading cgroup.conf file %s", conf_path); tbl = s_p_hashtbl_create(options); if (s_p_parse_file(tbl, NULL, conf_path, false) == SLURM_ERROR) { fatal("Could not open/read/parse cgroup.conf file %s", conf_path); } /* cgroup initialisation parameters */ if (!s_p_get_boolean(&slurm_cgroup_conf->cgroup_automount, "CgroupAutomount", tbl)) slurm_cgroup_conf->cgroup_automount = false; if (!s_p_get_string(&slurm_cgroup_conf->cgroup_mountpoint, "CgroupMountpoint", tbl)) slurm_cgroup_conf->cgroup_mountpoint = xstrdup(DEFAULT_CGROUP_BASEDIR); s_p_get_string(&slurm_cgroup_conf->cgroup_subsystems, "CgroupSubsystems", tbl); s_p_get_string(&slurm_cgroup_conf->cgroup_release_agent, "CgroupReleaseAgentDir", tbl); if (! slurm_cgroup_conf->cgroup_release_agent) slurm_cgroup_conf->cgroup_release_agent = xstrdup("/etc/slurm/cgroup"); /* cgroup prepend directory */ #ifndef MULTIPLE_SLURMD slurm_cgroup_conf->cgroup_prepend = xstrdup("/slurm"); #else slurm_cgroup_conf->cgroup_prepend = xstrdup("/slurm_%n"); #endif /* Cores constraints related conf items */ if (!s_p_get_boolean(&slurm_cgroup_conf->constrain_cores, "ConstrainCores", tbl)) slurm_cgroup_conf->constrain_cores = false; if (!s_p_get_boolean(&slurm_cgroup_conf->task_affinity, "TaskAffinity", tbl)) slurm_cgroup_conf->task_affinity = false; /* RAM and Swap constraints related conf items */ if (!s_p_get_boolean(&slurm_cgroup_conf->constrain_ram_space, "ConstrainRAMSpace", tbl)) slurm_cgroup_conf->constrain_ram_space = false; conf_get_float (tbl, "AllowedRAMSpace", &slurm_cgroup_conf->allowed_ram_space); conf_get_float (tbl, "MaxRAMPercent", &slurm_cgroup_conf->max_ram_percent); if (!s_p_get_boolean(&slurm_cgroup_conf->constrain_swap_space, "ConstrainSwapSpace", tbl)) slurm_cgroup_conf->constrain_swap_space = false; conf_get_float (tbl, "AllowedSwapSpace", &slurm_cgroup_conf->allowed_swap_space); conf_get_float (tbl, "MaxSwapPercent", &slurm_cgroup_conf->max_swap_percent); s_p_get_uint32 (&slurm_cgroup_conf->min_ram_space, "MinRAMSpace", tbl); /* Memory limits */ if (!s_p_get_boolean(&slurm_cgroup_conf->memlimit_enforcement, "MemoryLimitEnforcement", tbl)) slurm_cgroup_conf->memlimit_enforcement = false; conf_get_float (tbl, "MemoryLimitThreshold", &slurm_cgroup_conf->memlimit_threshold); /* Devices constraint related conf items */ if (!s_p_get_boolean(&slurm_cgroup_conf->constrain_devices, "ConstrainDevices", tbl)) slurm_cgroup_conf->constrain_devices = false; s_p_get_string(&slurm_cgroup_conf->allowed_devices_file, "AllowedDevicesFile", tbl); if (! slurm_cgroup_conf->allowed_devices_file) slurm_cgroup_conf->allowed_devices_file = xstrdup("/etc/slurm/cgroup_allowed_devices_file.conf"); s_p_hashtbl_destroy(tbl); } xfree(conf_path); return SLURM_SUCCESS; }
/** * Parse the core configuration file and update baresip core config * * @param cfg Baresip core config to update * @param conf Configuration file to parse * * @return 0 if success, otherwise errorcode */ int config_parse_conf(struct config *cfg, const struct conf *conf) { struct pl pollm, as, ap; enum poll_method method; struct vidsz size = {0, 0}; struct pl txmode; uint32_t v; int err = 0; if (!cfg || !conf) return EINVAL; /* Core */ if (0 == conf_get(conf, "poll_method", &pollm)) { if (0 == poll_method_type(&method, &pollm)) { err = poll_method_set(method); if (err) { warning("config: poll method (%r) set: %m\n", &pollm, err); } } else { warning("config: unknown poll method (%r)\n", &pollm); } } /* SIP */ (void)conf_get_str(conf, "sip_listen", cfg->sip.local, sizeof(cfg->sip.local)); (void)conf_get_str(conf, "sip_certificate", cfg->sip.cert, sizeof(cfg->sip.cert)); (void)conf_get_str(conf, "sip_cafile", cfg->sip.cafile, sizeof(cfg->sip.cafile)); /* Call */ (void)conf_get_u32(conf, "call_local_timeout", &cfg->call.local_timeout); (void)conf_get_u32(conf, "call_max_calls", &cfg->call.max_calls); /* Audio */ (void)conf_get_str(conf, "audio_path", cfg->audio.audio_path, sizeof(cfg->audio.audio_path)); (void)conf_get_csv(conf, "audio_player", cfg->audio.play_mod, sizeof(cfg->audio.play_mod), cfg->audio.play_dev, sizeof(cfg->audio.play_dev)); (void)conf_get_csv(conf, "audio_source", cfg->audio.src_mod, sizeof(cfg->audio.src_mod), cfg->audio.src_dev, sizeof(cfg->audio.src_dev)); (void)conf_get_csv(conf, "audio_alert", cfg->audio.alert_mod, sizeof(cfg->audio.alert_mod), cfg->audio.alert_dev, sizeof(cfg->audio.alert_dev)); (void)conf_get_u32(conf, "ausrc_srate", &cfg->audio.srate_src); (void)conf_get_u32(conf, "auplay_srate", &cfg->audio.srate_play); (void)conf_get_u32(conf, "ausrc_channels", &cfg->audio.channels_src); (void)conf_get_u32(conf, "auplay_channels", &cfg->audio.channels_play); if (0 == conf_get(conf, "audio_source", &as) && 0 == conf_get(conf, "audio_player", &ap)) cfg->audio.src_first = as.p < ap.p; if (0 == conf_get(conf, "audio_txmode", &txmode)) { if (0 == pl_strcasecmp(&txmode, "poll")) cfg->audio.txmode = AUDIO_MODE_POLL; else if (0 == pl_strcasecmp(&txmode, "thread")) cfg->audio.txmode = AUDIO_MODE_THREAD; else { warning("unsupported audio txmode (%r)\n", &txmode); } } (void)conf_get_bool(conf, "audio_level", &cfg->audio.level); conf_get_aufmt(conf, "ausrc_format", &cfg->audio.src_fmt); conf_get_aufmt(conf, "auplay_format", &cfg->audio.play_fmt); conf_get_aufmt(conf, "auenc_format", &cfg->audio.enc_fmt); conf_get_aufmt(conf, "audec_format", &cfg->audio.dec_fmt); /* Video */ (void)conf_get_csv(conf, "video_source", cfg->video.src_mod, sizeof(cfg->video.src_mod), cfg->video.src_dev, sizeof(cfg->video.src_dev)); (void)conf_get_csv(conf, "video_display", cfg->video.disp_mod, sizeof(cfg->video.disp_mod), cfg->video.disp_dev, sizeof(cfg->video.disp_dev)); if (0 == conf_get_vidsz(conf, "video_size", &size)) { cfg->video.width = size.w; cfg->video.height = size.h; } (void)conf_get_u32(conf, "video_bitrate", &cfg->video.bitrate); (void)conf_get_float(conf, "video_fps", &cfg->video.fps); (void)conf_get_bool(conf, "video_fullscreen", &cfg->video.fullscreen); conf_get_vidfmt(conf, "videnc_format", &cfg->video.enc_fmt); /* AVT - Audio/Video Transport */ if (0 == conf_get_u32(conf, "rtp_tos", &v)) cfg->avt.rtp_tos = v; (void)conf_get_range(conf, "rtp_ports", &cfg->avt.rtp_ports); if (0 == conf_get_range(conf, "rtp_bandwidth", &cfg->avt.rtp_bw)) { cfg->avt.rtp_bw.min *= 1000; cfg->avt.rtp_bw.max *= 1000; } (void)conf_get_bool(conf, "rtcp_mux", &cfg->avt.rtcp_mux); (void)conf_get_range(conf, "jitter_buffer_delay", &cfg->avt.jbuf_del); (void)conf_get_bool(conf, "rtp_stats", &cfg->avt.rtp_stats); (void)conf_get_u32(conf, "rtp_timeout", &cfg->avt.rtp_timeout); if (err) { warning("config: configure parse error (%m)\n", err); } /* Network */ #if HAVE_INET6 (void)conf_get_bool(conf, "prefer_ipv6", &cfg->net.prefer_ipv6); #endif (void)conf_apply(conf, "dns_server", dns_server_handler, &cfg->net); (void)conf_get_str(conf, "net_interface", cfg->net.ifname, sizeof(cfg->net.ifname)); /* BFCP */ (void)conf_get_str(conf, "bfcp_proto", cfg->bfcp.proto, sizeof(cfg->bfcp.proto)); /* SDP */ (void)conf_get_bool(conf, "sdp_ebuacip", &cfg->sdp.ebuacip); return err; }
static void *hamlib_loop(void *args) { struct timespec sleep; gdouble freq = 0.0; rmode_t mode = RIG_MODE_USB; gint ret; gchar *str; sleep.tv_sec = 0; sleep.tv_nsec = 100000000L; /* 100ms */ for (;;) { nanosleep(&sleep, NULL); // need_freq = (hamlib_waterfall || hamlib_qsodata || hamlib_qsy); // need_mode = need_freq; /* see if we are being canceled */ if (hamlib_exit) break; if (need_freq) { freq_t f; G_LOCK(hamlib_mutex); ret = rig_get_freq(rig, RIG_VFO_CURR, &f); G_UNLOCK(hamlib_mutex); if (ret != RIG_OK) { str = g_strdup_printf(_("rig_get_freq failed: %s"), rigerror(ret)); statusbar_set("mainstatusbar", str); g_free(str); continue; } freq = (gdouble) f; } /* see if we are being canceled */ if (hamlib_exit) break; if (need_mode) { pbwidth_t width; G_LOCK(hamlib_mutex); ret = rig_get_mode(rig, RIG_VFO_CURR, &mode, &width); G_UNLOCK(hamlib_mutex); if (ret != RIG_OK) { str = g_strdup_printf(_("rig_get_mode failed: %s"), rigerror(ret)); statusbar_set("mainstatusbar", str); g_free(str); continue; } } if (hamlib_qsy) { gfloat f = conf_get_float("hamlib/cfreq"); hamlib_qsy = FALSE; G_LOCK(hamlib_mutex); ret = rig_set_freq(rig, RIG_VFO_CURR, ((gdouble) freq) + trx_get_freq() - f); G_UNLOCK(hamlib_mutex); if (ret != RIG_OK) { str = g_strdup_printf(_("rig_set_freq failed: %s"), rigerror(ret)); statusbar_set("mainstatusbar", str); g_free(str); continue; } waterfall_set_frequency(waterfall, f); } if (hamlib_waterfall) { waterfall_set_carrier_frequency(waterfall, freq); if (mode == RIG_MODE_LSB) waterfall_set_lsb(waterfall, TRUE); else waterfall_set_lsb(waterfall, FALSE); } if (hamlib_qsodata) { gchar *str, *fmt; if (mode == RIG_MODE_LSB) freq -= trx_get_freq(); else freq += trx_get_freq(); switch (hamlib_res) { case 2: fmt = "%.6f"; break; case 1: fmt = "%.3f"; break; case 0: default: fmt = "%.0f"; break; } str = g_strdup_printf(fmt, freq / 1000000.0); gdk_threads_enter(); qsodata_set_band_mode(QSODATA_BAND_ENTRY); qsodata_set_freq(str); gdk_threads_leave(); g_free(str); } /* see if we are being canceled */ if (hamlib_exit) break; } if (hamlib_waterfall) { waterfall_set_carrier_frequency(waterfall, 0.0); waterfall_set_lsb(waterfall, FALSE); } if (hamlib_qsodata) { gdk_threads_enter(); qsodata_set_band_mode(QSODATA_BAND_COMBO); qsodata_set_freq(""); gdk_threads_leave(); } /* this will exit the hamlib thread */ return NULL; }
int main (int argc, char *argv[]) { int portable = 0; #if STATICLINK int staticlink = 1; #else int staticlink = 0; #endif #if PORTABLE portable = 1; if (!realpath (argv[0], dbinstalldir)) { strcpy (dbinstalldir, argv[0]); } char *e = strrchr (dbinstalldir, '/'); if (e) { *e = 0; } else { fprintf (stderr, "couldn't determine install folder from path %s\n", argv[0]); exit (-1); } #else if (!realpath (argv[0], dbinstalldir)) { strcpy (dbinstalldir, argv[0]); } char *e = strrchr (dbinstalldir, '/'); if (e) { *e = 0; struct stat st; char checkpath[PATH_MAX]; snprintf (checkpath, sizeof (checkpath), "%s/.ddb_portable", dbinstalldir); if (!stat (checkpath, &st)) { if (S_ISREG (st.st_mode)) { portable = 1; } } } if (!portable) { strcpy (dbinstalldir, PREFIX); } #endif #ifdef __GLIBC__ signal (SIGSEGV, sigsegv_handler); #endif setlocale (LC_ALL, ""); setlocale (LC_NUMERIC, "C"); #ifdef ENABLE_NLS // fprintf (stderr, "enabling gettext support: package=" PACKAGE ", dir=" LOCALEDIR "...\n"); if (portable) { char localedir[PATH_MAX]; snprintf (localedir, sizeof (localedir), "%s/locale", dbinstalldir); bindtextdomain (PACKAGE, localedir); } else { bindtextdomain (PACKAGE, LOCALEDIR); } bind_textdomain_codeset (PACKAGE, "UTF-8"); textdomain (PACKAGE); #endif fprintf (stderr, "starting deadbeef " VERSION "%s%s\n", staticlink ? " [static]" : "", portable ? " [portable]" : ""); srand (time (NULL)); #ifdef __linux__ prctl (PR_SET_NAME, "deadbeef-main", 0, 0, 0, 0); #endif #if PORTABLE_FULL if (snprintf (confdir, sizeof (confdir), "%s/config", dbinstalldir) > sizeof (confdir)) { fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir); return -1; } strcpy (dbconfdir, confdir); #else char *homedir = getenv ("HOME"); if (!homedir) { fprintf (stderr, "unable to find home directory. stopping.\n"); return -1; } char *xdg_conf_dir = getenv ("XDG_CONFIG_HOME"); if (xdg_conf_dir) { if (snprintf (confdir, sizeof (confdir), "%s", xdg_conf_dir) > sizeof (confdir)) { fprintf (stderr, "fatal: XDG_CONFIG_HOME value is too long: %s\n", xdg_conf_dir); return -1; } } else { if (snprintf (confdir, sizeof (confdir), "%s/.config", homedir) > sizeof (confdir)) { fprintf (stderr, "fatal: HOME value is too long: %s\n", homedir); return -1; } } if (snprintf (dbconfdir, sizeof (dbconfdir), "%s/deadbeef", confdir) > sizeof (dbconfdir)) { fprintf (stderr, "fatal: out of memory while configuring\n"); return -1; } mkdir (confdir, 0755); #endif if (portable) { if (snprintf (dbdocdir, sizeof (dbdocdir), "%s/doc", dbinstalldir) > sizeof (dbdocdir)) { fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir); return -1; } #ifdef HAVE_COCOAUI char respath[PATH_MAX]; cocoautil_get_resources_path (respath, sizeof (respath)); if (snprintf (dbplugindir, sizeof (dbplugindir), "%s", respath) > sizeof (dbplugindir)) { fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir); return -1; } #else if (snprintf (dbplugindir, sizeof (dbplugindir), "%s/plugins", dbinstalldir) > sizeof (dbplugindir)) { fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir); return -1; } #endif if (snprintf (dbpixmapdir, sizeof (dbpixmapdir), "%s/pixmaps", dbinstalldir) > sizeof (dbpixmapdir)) { fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir); return -1; } mkdir (dbplugindir, 0755); } else { if (snprintf (dbdocdir, sizeof (dbdocdir), "%s", DOCDIR) > sizeof (dbdocdir)) { fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir); return -1; } if (snprintf (dbplugindir, sizeof (dbplugindir), "%s/deadbeef", LIBDIR) > sizeof (dbplugindir)) { fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir); return -1; } if (snprintf (dbpixmapdir, sizeof (dbpixmapdir), "%s/share/deadbeef/pixmaps", PREFIX) > sizeof (dbpixmapdir)) { fprintf (stderr, "fatal: too long install path %s\n", dbinstalldir); return -1; } } for (int i = 1; i < argc; i++) { // help, version and nowplaying are executed with any filter if (!strcmp (argv[i], "--help") || !strcmp (argv[i], "-h")) { print_help (); return 0; } else if (!strcmp (argv[i], "--version")) { fprintf (stderr, "DeaDBeeF " VERSION " Copyright © 2009-2013 Alexey Yakovenko\n"); return 0; } else if (!strcmp (argv[i], "--gui")) { if (i == argc-1) { break; } i++; strncpy (use_gui_plugin, argv[i], sizeof(use_gui_plugin) - 1); use_gui_plugin[sizeof(use_gui_plugin) - 1] = 0; } } trace ("installdir: %s\n", dbinstalldir); trace ("confdir: %s\n", confdir); trace ("docdir: %s\n", dbdocdir); trace ("plugindir: %s\n", dbplugindir); trace ("pixmapdir: %s\n", dbpixmapdir); mkdir (dbconfdir, 0755); int size = 0; char *cmdline = prepare_command_line (argc, argv, &size); // try to connect to remote player int s, len; struct sockaddr_un remote; if ((s = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { perror("socket"); exit(1); } memset (&remote, 0, sizeof (remote)); remote.sun_family = AF_UNIX; #if USE_ABSTRACT_SOCKET_NAME memcpy (remote.sun_path, server_id, sizeof (server_id)); len = offsetof(struct sockaddr_un, sun_path) + sizeof (server_id)-1; #else char *socketdirenv = getenv ("DDB_SOCKET_DIR"); snprintf (remote.sun_path, sizeof (remote.sun_path), "%s/socket", socketdirenv ? socketdirenv : dbconfdir); len = offsetof(struct sockaddr_un, sun_path) + strlen (remote.sun_path); #endif if (connect(s, (struct sockaddr *)&remote, len) == 0) { // pass args to remote and exit if (send(s, cmdline, size, 0) == -1) { perror ("send"); exit (-1); } // end of message shutdown(s, SHUT_WR); int sz = -1; char *out = read_entire_message(s, &sz); if (sz == -1) { fprintf (stderr, "failed to pass args to remote!\n"); exit (-1); } else { // check if that's nowplaying response const char np[] = "nowplaying "; const char err[] = "error "; if (!strncmp (out, np, sizeof (np)-1)) { const char *prn = &out[sizeof (np)-1]; fwrite (prn, 1, strlen (prn), stdout); } else if (!strncmp (out, err, sizeof (err)-1)) { const char *prn = &out[sizeof (err)-1]; fwrite (prn, 1, strlen (prn), stderr); } else if (sz > 0 && out[0]) { fprintf (stderr, "%s\n", out); } } if (out) { free (out); } close (s); exit (0); } // else { // perror ("INFO: failed to connect to existing session:"); // } close(s); // become a server if (server_start () < 0) { exit (-1); } // hack: report nowplaying if (!strcmp (cmdline, "--nowplaying")) { char nothing[] = "nothing"; fwrite (nothing, 1, sizeof (nothing)-1, stdout); return 0; } pl_init (); conf_init (); conf_load (); // required by some plugins at startup if (use_gui_plugin[0]) { conf_set_str ("gui_plugin", use_gui_plugin); } conf_set_str ("deadbeef_version", VERSION); volume_set_db (conf_get_float ("playback.volume", 0)); // volume need to be initialized before plugins start messagepump_init (); // required to push messages while handling commandline if (plug_load_all ()) { // required to add files to playlist from commandline exit (-1); } pl_load_all (); plt_set_curr_idx (conf_get_int ("playlist.current", 0)); // execute server commands in local context int noloadpl = 0; if (argc > 1) { int res = server_exec_command_line (cmdline, size, NULL, 0); // some of the server commands ran on 1st instance should terminate it if (res == 2) { noloadpl = 1; } else if (res > 0) { exit (0); } else if (res < 0) { exit (-1); } } free (cmdline); #if 0 signal (SIGTERM, sigterm_handler); atexit (atexit_handler); // helps to save in simple cases #endif streamer_init (); plug_connect_all (); messagepump_push (DB_EV_PLUGINSLOADED, 0, 0, 0); if (!noloadpl) { restore_resume_state (); } server_tid = thread_start (server_loop, NULL); mainloop_tid = thread_start (mainloop_thread, NULL); DB_plugin_t *gui = plug_get_gui (); if (gui) { gui->start (); } fprintf (stderr, "gui plugin has quit; waiting for mainloop thread to finish\n"); thread_join (mainloop_tid); // terminate server and wait for completion if (server_tid) { server_terminate = 1; thread_join (server_tid); server_tid = 0; } // save config pl_save_all (); conf_save (); // delete legacy session file { char sessfile[1024]; // $HOME/.config/deadbeef/session if (snprintf (sessfile, sizeof (sessfile), "%s/deadbeef/session", confdir) < sizeof (sessfile)) { unlink (sessfile); } } // stop receiving messages from outside server_close (); // plugins might still hold references to playitems, // and query configuration in background // so unload everything 1st before final cleanup plug_disconnect_all (); plug_unload_all (); // at this point we can simply do exit(0), but let's clean up for debugging pl_free (); // may access conf_* conf_free (); fprintf (stderr, "messagepump_free\n"); messagepump_free (); fprintf (stderr, "plug_cleanup\n"); plug_cleanup (); fprintf (stderr, "hej-hej!\n"); return 0; }