-static struct timeval *afs_compute_timeout(void)
-{
- static struct timeval the_timeout;
- struct timeval now, next_chunk;
-
- if (afs_next() && mmd->audio_format >= 0) {
- /* only sleep a bit, nec*/
- the_timeout.tv_sec = 0;
- the_timeout.tv_usec = 100;
- return &the_timeout;
- }
- gettimeofday(&now, NULL);
- if (chk_barrier("eof", &now, &eof_barrier, &the_timeout, 1) < 0)
- return &the_timeout;
- if (chk_barrier("data send", &now, &data_send_barrier,
- &the_timeout, 1) < 0)
- return &the_timeout;
- if (mmd->audio_format < 0 || !afs_playing() || !audio_file)
- return NULL;
- afs_next_chunk_time(&next_chunk);
- if (chk_barrier(afl[mmd->audio_format].name, &now, &next_chunk,
- &the_timeout, 0) < 0)
- return &the_timeout;
- /* chunk is due or bof */
- the_timeout.tv_sec = 0;
- the_timeout.tv_usec = 0;
- return &the_timeout;
-}
-
-static void afs_eof(struct audio_format_handler *af)
-{
- struct timeval now;
- int i;
- char *tmp;
+static int call_callback(int fd, int query_shmid)
+{
+ void *query_shm, *result_shm;
+ struct callback_query *cq;
+ struct callback_result *cr;
+ struct osl_object query, result = {.data = NULL};
+ int result_shmid = -1, ret, ret2;
+
+ ret = shm_attach(query_shmid, ATTACH_RW, &query_shm);
+ if (ret < 0)
+ goto out;
+ cq = query_shm;
+ query.data = (char *)query_shm + sizeof(*cq);
+ query.size = cq->query_size;
+ ret = cq->handler(&query, &result);
+ ret2 = shm_detach(query_shm);
+ if (ret2 < 0 && ret >= 0)
+ ret = ret2;
+ if (ret < 0)
+ goto out;
+ ret = 0;
+ if (!result.data || !result.size)
+ goto out;
+ ret = shm_new(result.size + sizeof(struct callback_result));
+ if (ret < 0)
+ goto out;
+ result_shmid = ret;
+ ret = shm_attach(result_shmid, ATTACH_RW, &result_shm);
+ if (ret < 0)
+ goto out;
+ cr = result_shm;
+ cr->result_size = result.size;
+ memcpy(result_shm + sizeof(*cr), result.data, result.size);
+ ret = shm_detach(result_shm);
+ if (ret < 0)
+ goto out;
+ ret = result_shmid;
+out:
+ free(result.data);
+ ret2 = send_bin_buffer(fd, (char *)&ret, sizeof(int));
+ if (ret < 0 || ret2 < 0) {
+ if (result_shmid >= 0)
+ if (shm_destroy(result_shmid) < 0)
+ PARA_ERROR_LOG("destroy result failed\n");
+ if (ret >= 0)
+ ret = ret2;
+ }
+ return ret;
+}
+
+static void execute_server_command(void)
+{
+ char buf[8];
+ int ret = recv_bin_buffer(server_socket, buf, sizeof(buf) - 1);
+
+ if (ret <= 0) {
+ if (ret < 0)
+ PARA_ERROR_LOG("%s\n", PARA_STRERROR(-ret));
+ return;
+ }
+ buf[ret] = '\0';
+ PARA_DEBUG_LOG("received: %s\n", buf);
+ if (!strcmp(buf, "new")) {
+ ret = open_next_audio_file();
+ if (ret < 0) {
+ PARA_EMERG_LOG("%s\n", PARA_STRERROR(-ret));
+ unregister_tasks();
+ }
+ return;
+ }
+ PARA_ERROR_LOG("unknown command\n");
+
+}
+
+static void execute_afs_command(int fd, uint32_t expected_cookie)
+{
+ uint32_t cookie;
+ int query_shmid;
+ char buf[sizeof(cookie) + sizeof(query_shmid)];
+ int ret = recv_bin_buffer(fd, buf, sizeof(buf));