+/* audio-cmd.c: Sends commands to music player.
+
+ Copyright (C) 2019 Michael Zucchi
+
+ This program is free software: you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
#include <string.h>
#include <stdio.h>
+/* dbindex.c: Database frontend for music file database.
+
+ Copyright (C) 2019 Michael Zucchi
+
+ This program is free software: you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
+/* dbindex.h: Database abstraction api.
+
+ Copyright (C) 2019 Michael Zucchi
+
+ This program is free software: you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
#include "ez-blob.h"
+/* disk-indexer.c: Indexes music files.
+
+ Copyright (C) 2019 Michael Zucchi
+
+ This program is free software: you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
#include <sys/types.h>
#include <sys/stat.h>
+/* disk-monitor.c: Monitors uevents for removable disks.
+
+ Copyright (C) 2019 Michael Zucchi
+
+ This program is free software: you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
/*
disk-monitor
-
+
FIXME:
make a setuid-root binary
wrap in as-root {
- ...
+ ...
mount/unmount
}
ez_node en;
char *dev;
-
+
struct dbdisk disk;
};
static void mdisk_free(void *mp) {
struct mdisk *m = mp;
-
+
free(m->dev);
-
+
free(m->disk.uuid);
free(m->disk.label);
free(m->disk.type);
free(m->disk.mount);
-
+
free(m);
}
for (i=0;i<n;i++) {
const char *name, *value;
size_t size;
-
+
blkid_probe_get_value(p, i, &name, &value, &size);
printf(" %s: ", name);
fwrite(value, size, 1, stdout);
static void partition_add(struct monitor *m, const char *dev) {
blkid_probe p = NULL;
int res;
-
+
printf("Add partition: %s\n", dev);
-
+
p = blkid_new_probe_from_filename(dev);
if (!p) {
perror("probe new");
blkid_probe_enable_partitions(p, 0);
blkid_probe_enable_superblocks(p, 1);
-
+
res = blkid_do_safeprobe(p);
if (res != 0)
goto fail;
int ptype, puuid, plabel;
const char *type, *uuid, *label;
size_t type_size, uuid_size, label_size;
-
+
ptype = (blkid_probe_lookup_value(p, "TYPE", &type, &type_size) == 0);
puuid = (blkid_probe_lookup_value(p, "UUID", &uuid, &uuid_size) == 0);
plabel = (blkid_probe_lookup_value(p, "LABEL", &label, &label_size) == 0);
-
+
if (ptype && puuid) {
char *mountp = malloc(m->mount_base_size + uuid_size + 2);
struct mdisk *md = malloc(sizeof(*md));
memset(md, 0, sizeof(*md));
-
+
md->dev = strdup(dev);
md->disk.uuid = strdup(uuid);
md->disk.type = strdup(type);
};
struct mdisk *md;
int res;
-
+
printf("Remove partition: %s\n", dev);
md = ez_set_remove(m->mounts, &mde);
partition_notify(m, NOTIFY_DISK_REMOVE, md);
res = umount2(md->disk.mount, MNT_DETACH);
-
+
if (res == 0) {
printf(" unmount %s @ %s\n", md->dev, md->disk.mount);
} else {
struct oldnode {
ez_node ln;
-
+
dev_t dev;
char *mount;
};
// scan to see if any partitions are already mounted
static void partition_check(struct monitor *m) {
DIR *dir = opendir(m->mount_base);
-
+
if (dir) {
struct stat dstat;
struct stat estat;
ez_list old = EZ_INIT_LIST(old);
fstat(dfd, &dstat);
-
+
while (e = readdir(dir)) {
if (fstatat(dfd, e->d_name, &estat, AT_SYMLINK_NOFOLLOW) == 0
&& S_ISDIR(estat.st_mode)
ez_list_addtail(&old, onode);
}
}
-
+
closedir(dir);
if (!ez_list_empty(&old)){
char devname[strlen("/dev/") + strlen(e->d_name) + 1];
sprintf(devname, "/dev/%s", e->d_name);
-
+
partition_add(m, devname);
ez_node_remove(w);
free(w->mount);
struct iovec iov;
bind(s, (void *)&addr, sizeof(addr));
-
+
iov.iov_base = data;
iov.iov_len = 8192;
m->mounts = ez_set_new(mdisk_hash, mdisk_equals, mdisk_free);
res = mkdir(m->mount_base, 0777);
m->indexer = notify_writer_new(NOTIFY_INDEXER);
-
+
partition_check(m);
printf("Monitoring uevents\n");
-
+
while ((res = recvmsg(s, &msg, 0)) >= 0) {
// ignore snot from udevd
if (strcmp(data, "libudev") == 0)
continue;
-
+
char *x = data, *e = data+res;
char *action;
char *dev;
} else if (strncmp(x, "DEVTYPE=", 8) == 0) {
type = x+8;
}
-
+
x += strlen(x) + 1;
}
//printf("\n");
-
+
if (dev && type && strcmp(type, "partition") == 0) {
char name[strlen(dev) + strlen("/dev/") + 1];
notify_close(m->indexer);
free(m->mount_base);
ez_set_free(m->mounts);
-
+
close(s);
}
+/* input-monitor.c: Monitors keyboard input.
+
+ Copyright (C) 2019 Michael Zucchi
+
+ This program is free software: you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
/**
This monitors the keyboard.
/dev/input/by-id/usb-2.4G_Wireless_Receiver-event-kbd
-
+
enter: 28 KEY_ENTER
home: 102 KEY_HOME
static int cmp_key(const void *ap, const void *bp) {
int needle = *((uint16_t *)ap);
const struct keymap *hay = bp;
-
+
return needle - hay->code;
}
goto fail1;
m->player = notify_writer_new(NOTIFY_PLAYER);
-
+
return m;
fail1:
close(m->keyfd);
fail:
free(m);
-
+
return NULL;
}
if (ev->value) {
if (key->action == NOTIFY_PLAY_SEEK) {
struct notify_play_seek msg;
-
+
switch (key->mode) {
case 0:
msg.mode = 0;
} else {
notify_msg_send(m->player, key->action, 0, NULL);
}
-
+
if (key->flags & GEN_REPEAT) {
printf("start repeat\n");
m->repeat = *ev;
case KEY_F2: // cross
case KEY_F3: // circle
case KEY_F4: // triangle
-
+
case KEY_HOME: // house button
-
+
case KEY_UP: // face panel up
case KEY_DOWN: // face panel down
case KEY_LEFT: // face panel left
case KEY_TV: // 'output' button
break;
-
+
}
*/
void monitor(struct monitor *m) {
struct pollfd polla[2];
struct input_event ev;
-
+
// NB: if the player isn't running this will block
-
+
polla[0].fd = m->keyfd;
polla[0].events = POLLIN;
polla[1].fd = m->mousefd;
for (int i=0;i<2;i++) {
if (polla[i].revents & POLLERR)
return;
-
+
if (polla[i].revents & POLLIN ){
read(polla[i].fd, &ev, sizeof(ev));
monitor_event(m, &ev);
}
}
} else if (res == 0) {
- monitor_event(m, &m->repeat);
+ monitor_event(m, &m->repeat);
}
}
}
-/*
- Copyright (C) 2019 Michael Zucchi
+/* music-player.c: Music player server.
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
+ Copyright (C) 2019,2020 Michael Zucchi
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ This program is free software: you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <https://www.gnu.org/licenses/>.
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
*/
#include <libavformat/avformat.h>
+/* notify.c: Service IPC via POSIX message queues.
+
+ Copyright (C) 2019 Michael Zucchi
+
+ This program is free software: you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
#include <fcntl.h>
#include <sys/stat.h>
+/* notify.c: Service IPC API via POSIX message queues.
+
+ Copyright (C) 2019 Michael Zucchi
+
+ This program is free software: you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
#ifndef _NOTIFY_H
#define _NOTIFY_H