示例#1
0
static port_t *package_new(char *name, char *version)
{
	port_t *self;
	assert(name && version);
	self = port_new(name, version, NULL, list_new(), NULL);
	self->status = PRT_INSTALLED;
	return self;
}
示例#2
0
static int New(lua_State *L){
    if (lua_gettop(L) == 0){
        int portfd = port_new();
        if(portfd > 0){
            port_set_cb_packet(portfd, pb_port_cb_packet);
            lua_pushnumber(L, portfd);
            return 1;
        }
    }
    lua_pushboolean(L, false);
    return 1;
}
示例#3
0
int
main(int argc, char **argv)
{
	int c, background, unit;
	int pmin, pmax, rmin, rmax;
	char base[PATH_MAX], path[PATH_MAX];
	unsigned int mode, dup, mmc, vol;
	unsigned int hold, autovol, bufsz, round, rate;
	const char *str;
	struct aparams par;
	struct dev *d;
	struct port *p;
	struct listen *l;

	atexit(log_flush);

	/*
	 * global options defaults
	 */
	vol = 118;
	dup = 1;
	mmc = 0;
	hold = 0;
	autovol = 1;
	bufsz = 0;
	round = 0;
	rate = DEFAULT_RATE;
	unit = 0;
	background = 1;
	pmin = 0;
	pmax = 1;
	rmin = 0;
	rmax = 1;
	aparams_init(&par);
	mode = MODE_PLAY | MODE_REC;

	setsig();
	filelist_init();

	while ((c = getopt(argc, argv, "a:b:c:C:de:f:j:L:m:Mq:r:s:t:U:v:w:x:z:")) != -1) {
		switch (c) {
		case 'd':
			log_level++;
			background = 0;
			break;
		case 'U':
			if (listen_list)
				errx(1, "-U must come before -L");
			unit = strtonum(optarg, 0, 15, &str);
			if (str)
				errx(1, "%s: unit number is %s", optarg, str);
			break;
		case 'L':
			listen_new_tcp(optarg, AUCAT_PORT + unit);
			break;
		case 'm':
			mode = opt_mode();
			break;
		case 'j':
			dup = opt_onoff();
			break;
		case 't':
			mmc = opt_mmc();
			break;
		case 'c':
			opt_ch(&pmin, &pmax);
			break;
		case 'C':
			opt_ch(&rmin, &rmax);
			break;
		case 'e':
			opt_enc(&par);
			break;
		case 'r':
			rate = strtonum(optarg, RATE_MIN, RATE_MAX, &str);
			if (str)
				errx(1, "%s: rate is %s", optarg, str);
			break;
		case 'v':
			vol = strtonum(optarg, 0, MIDI_MAXCTL, &str);
			if (str)
				errx(1, "%s: volume is %s", optarg, str);
			break;
		case 's':
			if ((d = dev_list) == NULL) {
				d = mkdev(DEFAULT_DEV, &par, 0, bufsz, round, rate,
				    hold, autovol);
			}
			mkopt(optarg, d, pmin, pmax, rmin, rmax,
			    mode, vol, mmc, dup);
			break;
		case 'q':
			p = port_new(optarg, MODE_MIDIMASK, hold);
			if (!p)
				errx(1, "%s: can't open port", optarg);
			break;
		case 'a':
			hold = opt_onoff();
			break;
		case 'w':
			autovol = opt_onoff();
			break;
		case 'b':
			bufsz = strtonum(optarg, 1, RATE_MAX, &str);
			if (str)
				errx(1, "%s: buffer size is %s", optarg, str);
			break;
		case 'z':
			round = strtonum(optarg, 1, SHRT_MAX, &str);
			if (str)
				errx(1, "%s: block size is %s", optarg, str);
			break;
		case 'f':
			mkdev(optarg, &par, 0, bufsz, round, rate, hold, autovol);
			break;
		case 'M':
			/* XXX: for compatibility with aucat, remove this */
			break;
		default:
			fputs(usagestr, stderr);
			return 1;
		}
	}
	argc -= optind;
	argv += optind;
	if (argc > 0) {
		fputs(usagestr, stderr);
		return 1;
	}
	if (dev_list == NULL)
		mkdev(DEFAULT_DEV, &par, 0, bufsz, round, rate, hold, autovol);
	for (d = dev_list; d != NULL; d = d->next) {
		if (opt_byname("default", d->num))
			continue;
		mkopt("default", d, pmin, pmax, rmin, rmax,
		    mode, vol, mmc, dup);
	}
	getbasepath(base, sizeof(base));
	snprintf(path, PATH_MAX, "%s/%s%u", base, AUCAT_PATH, unit);
	listen_new_un(path);
	if (geteuid() == 0)
		privdrop();
	midi_init();
	for (p = port_list; p != NULL; p = p->next) {
		if (!port_init(p))
			return 1;
	}
	for (d = dev_list; d != NULL; d = d->next) {
		if (!dev_init(d))
			return 1;
	}
	for (l = listen_list; l != NULL; l = l->next) {
		if (!listen_init(l))
			return 1;
	}
	if (background) {
		log_flush();
		log_level = 0;
		if (daemon(0, 0) < 0)
			err(1, "daemon");
	}

	/*
	 * Loop, start audio.
	 */
	for (;;) {
		if (quit_flag)
			break;
		if (!file_poll())
			break;
	}
	while (listen_list != NULL)
		listen_close(listen_list);
	while (sock_list != NULL)
		sock_close(sock_list);
	while (opt_list != NULL)
		opt_del(opt_list);
	for (d = dev_list; d != NULL; d = d->next)
		dev_done(d);
	for (p = port_list; p != NULL; p = p->next)
		port_done(p);
	midi_done();
	while (file_poll())
		; /* nothing */
	while (dev_list)
		dev_del(dev_list);
	while (port_list)
		port_del(port_list);
	filelist_done();
	rmdir(base);
	unsetsig();
	return 0;
}
示例#4
0
list_t *ports_list_init(dict_t * repositories)
{
	list_t *self;
	FILE *cachefile;
	char *line, **splitted, *description, *cache_file;
	int nread, nsplit;
	size_t n;

	cache_file = xstrdup_printf("%s/%s", getenv("HOME"), CACHE_FILE);

	if (!is_file(cache_file) || cache_is_update(cache_file)) {
		if (cache_build(repositories)) {
			free(cache_file);
			return NULL;
		}
	}

	cachefile = fopen(cache_file, "r");
	free(cache_file);

	if (!cachefile)
		return NULL;

	self = list_new();
	line = NULL;
	nread = getline(&line, &n, cachefile);

	if (nread < 0) {
		cache_build(repositories);
		nread = getline(&line, &n, cachefile);
	}

	while (nread > 0) {
		*(line + strlen(line) - 1) = 0;
		description = strchr(line, '%') + 1;
		description = xstrndup(description, strlen(description) -
				       strlen(strchr(description, '%')));
		if (strlen(description) > 0)
			strreplace(&line, description, "", 1);
		strreplace(&line, "%%", "", 1);
		while (strstr(line, "  ") != NULL)
			strreplaceall(&line, "  ", " ");
		splitted = NULL;
		nsplit = strsplit(line, ' ', &splitted);
		list_append(self, port_new(splitted[0],
					   splitted[1],
					   dict_get(repositories,
						    splitted[2]),
					   list_new_from_array((void **)
							       &splitted[3],
							       nsplit - 3),
					   description));
		free(splitted[2]);
		free(splitted);
		nread = getline(&line, &n, cachefile);
	}
	if (line)
		free(line);
	fclose(cachefile);

	return self;
}