mirror of
https://github.com/owntone/owntone-server.git
synced 2025-04-22 11:35:43 -04:00
Introduce libevent for running the main loop
Start the gradual libevent conversion.
This commit is contained in:
parent
3b4e0d8f74
commit
df0013a166
@ -63,6 +63,10 @@ PKG_CHECK_MODULES(SQLITE3, [ sqlite3 ],
|
|||||||
AC_DEFINE(HAVE_SQLITE3, 1, [define if sqlite3 is available]))
|
AC_DEFINE(HAVE_SQLITE3, 1, [define if sqlite3 is available]))
|
||||||
PKG_CHECK_MODULES(FFMPEG, [ libavcodec libavformat ])
|
PKG_CHECK_MODULES(FFMPEG, [ libavcodec libavformat ])
|
||||||
|
|
||||||
|
AC_CHECK_HEADER(event.h, , AC_MSG_ERROR([event.h not found]))
|
||||||
|
AC_CHECK_LIB([event_core], [event_init], [LIBEVENT_LIBS="-levent_core"], AC_MSG_ERROR([libevent not found]))
|
||||||
|
AC_SUBST(LIBEVENT_LIBS)
|
||||||
|
|
||||||
if test x$use_flac = xtrue; then
|
if test x$use_flac = xtrue; then
|
||||||
PKG_CHECK_MODULES(FLAC, [ flac ])
|
PKG_CHECK_MODULES(FLAC, [ flac ])
|
||||||
fi
|
fi
|
||||||
|
@ -17,7 +17,7 @@ endif
|
|||||||
|
|
||||||
|
|
||||||
mt_daapd_CPPFLAGS = @AVAHI_CFLAGS@ @SQLITE3_CFLAGS@ @FFMPEG_CFLAGS@ @TAGLIB_CFLAGS@
|
mt_daapd_CPPFLAGS = @AVAHI_CFLAGS@ @SQLITE3_CFLAGS@ @FFMPEG_CFLAGS@ @TAGLIB_CFLAGS@
|
||||||
mt_daapd_LDADD = @AVAHI_LIBS@ @SQLITE3_LIBS@ @FFMPEG_LIBS@ @FLAC_LIBS@ @TAGLIB_LIBS@ @LIBDL@
|
mt_daapd_LDADD = @AVAHI_LIBS@ @SQLITE3_LIBS@ @FFMPEG_LIBS@ @FLAC_LIBS@ @TAGLIB_LIBS@ @LIBEVENT_LIBS@ @LIBDL@
|
||||||
mt_daapd_LDFLAGS = -export-dynamic
|
mt_daapd_LDFLAGS = -export-dynamic
|
||||||
mt_daapd_SOURCES = main.c daapd.h rend.h webserver.c \
|
mt_daapd_SOURCES = main.c daapd.h rend.h webserver.c \
|
||||||
webserver.h configfile.c configfile.h err.c err.h \
|
webserver.h configfile.c configfile.h err.c err.h \
|
||||||
|
130
src/main.c
130
src/main.c
@ -94,8 +94,10 @@
|
|||||||
# include "getopt.h"
|
# include "getopt.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <event.h>
|
||||||
#include <libavformat/avformat.h>
|
#include <libavformat/avformat.h>
|
||||||
|
|
||||||
|
|
||||||
/** Seconds to sleep before checking for a shutdown or reload */
|
/** Seconds to sleep before checking for a shutdown or reload */
|
||||||
#define MAIN_SLEEP_INTERVAL 2
|
#define MAIN_SLEEP_INTERVAL 2
|
||||||
|
|
||||||
@ -259,6 +261,74 @@ void main_io_errhandler(int level, char *msg) {
|
|||||||
void main_ws_errhandler(int level, char *msg) {
|
void main_ws_errhandler(int level, char *msg) {
|
||||||
DPRINTF(level,L_WS,"%s",msg);
|
DPRINTF(level,L_WS,"%s",msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
mainloop_cb(int fd, short event, void *arg)
|
||||||
|
{
|
||||||
|
int old_song_count, song_count;
|
||||||
|
char **mp3_dir_array;
|
||||||
|
struct event *main_timer;
|
||||||
|
struct timeval tv;
|
||||||
|
static int rescan_counter = 0;
|
||||||
|
|
||||||
|
rescan_counter += MAIN_SLEEP_INTERVAL;
|
||||||
|
|
||||||
|
/* Handle signals */ /* JB: FIXME */
|
||||||
|
os_wait(0);
|
||||||
|
|
||||||
|
if (config.stop)
|
||||||
|
{
|
||||||
|
event_loopbreak();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
main_timer = (struct event *)arg;
|
||||||
|
evutil_timerclear(&tv);
|
||||||
|
tv.tv_sec = MAIN_SLEEP_INTERVAL;
|
||||||
|
evtimer_add(main_timer, &tv);
|
||||||
|
|
||||||
|
if ((conf_get_int("general", "rescan_interval", 0)
|
||||||
|
&& (rescan_counter > conf_get_int("general", "rescan_interval", 0))))
|
||||||
|
{
|
||||||
|
if ((conf_get_int("general", "always_scan", 0))
|
||||||
|
|| (config_get_session_count()))
|
||||||
|
{
|
||||||
|
config.reload = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DPRINTF(E_DBG, L_MAIN | L_SCAN | L_DB, "Skipped background scan... no users\n");
|
||||||
|
}
|
||||||
|
rescan_counter = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.reload)
|
||||||
|
{
|
||||||
|
db_get_song_count(NULL, &old_song_count);
|
||||||
|
|
||||||
|
DPRINTF(E_LOG, L_MAIN | L_DB | L_SCAN, "Rescanning database\n");
|
||||||
|
|
||||||
|
if (conf_get_array("general", "mp3_dir", &mp3_dir_array))
|
||||||
|
{
|
||||||
|
if (config.full_reload)
|
||||||
|
{
|
||||||
|
config.full_reload = 0;
|
||||||
|
db_force_rescan(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scan_init(mp3_dir_array))
|
||||||
|
{
|
||||||
|
DPRINTF(E_LOG, L_MAIN | L_DB | L_SCAN, "Error rescanning... bad path?\n");
|
||||||
|
}
|
||||||
|
conf_dispose_array(mp3_dir_array);
|
||||||
|
}
|
||||||
|
config.reload = 0;
|
||||||
|
|
||||||
|
db_get_song_count(NULL, &song_count);
|
||||||
|
DPRINTF(E_LOG, L_MAIN | L_DB | L_SCAN, "Scanned %d songs (was %d)\n",song_count, old_song_count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Kick off the daap server and wait for events.
|
* Kick off the daap server and wait for events.
|
||||||
*
|
*
|
||||||
@ -284,8 +354,7 @@ int main(int argc, char *argv[]) {
|
|||||||
int reload=0;
|
int reload=0;
|
||||||
int start_time;
|
int start_time;
|
||||||
int end_time;
|
int end_time;
|
||||||
int rescan_counter=0;
|
int song_count;
|
||||||
int old_song_count, song_count;
|
|
||||||
int force_non_root=0;
|
int force_non_root=0;
|
||||||
int skip_initial=1;
|
int skip_initial=1;
|
||||||
int kill_server=0;
|
int kill_server=0;
|
||||||
@ -299,6 +368,8 @@ int main(int argc, char *argv[]) {
|
|||||||
char txtrecord[255];
|
char txtrecord[255];
|
||||||
void *phandle;
|
void *phandle;
|
||||||
char *plugindir;
|
char *plugindir;
|
||||||
|
struct event *main_timer;
|
||||||
|
struct timeval tv;
|
||||||
|
|
||||||
int err;
|
int err;
|
||||||
char *apppath;
|
char *apppath;
|
||||||
@ -478,6 +549,16 @@ int main(int argc, char *argv[]) {
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Initialize libevent (after forking) */
|
||||||
|
event_init();
|
||||||
|
main_timer = (struct event *)malloc(sizeof(struct event));
|
||||||
|
if (!main_timer)
|
||||||
|
{
|
||||||
|
DPRINTF(E_FATAL, L_MAIN, "Out of memory\n");
|
||||||
|
os_deinit();
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
if(config.use_mdns) {
|
if(config.use_mdns) {
|
||||||
DPRINTF(E_LOG,L_MAIN,"Starting rendezvous daemon\n");
|
DPRINTF(E_LOG,L_MAIN,"Starting rendezvous daemon\n");
|
||||||
if(rend_init(runas)) {
|
if(rend_init(runas)) {
|
||||||
@ -615,45 +696,14 @@ int main(int argc, char *argv[]) {
|
|||||||
(!conf_get_int("scanning","skip_first",0)))
|
(!conf_get_int("scanning","skip_first",0)))
|
||||||
config.reload = 1; /* force a reload on start */
|
config.reload = 1; /* force a reload on start */
|
||||||
|
|
||||||
while(!config.stop) {
|
/* Set up main timer */
|
||||||
if((conf_get_int("general","rescan_interval",0) &&
|
evtimer_set(main_timer, mainloop_cb, main_timer);
|
||||||
(rescan_counter > conf_get_int("general","rescan_interval",0)))) {
|
evutil_timerclear(&tv);
|
||||||
if((conf_get_int("general","always_scan",0)) ||
|
tv.tv_sec = MAIN_SLEEP_INTERVAL;
|
||||||
(config_get_session_count())) {
|
evtimer_add(main_timer, &tv);
|
||||||
config.reload=1;
|
|
||||||
} else {
|
|
||||||
DPRINTF(E_DBG,L_MAIN|L_SCAN|L_DB,"Skipped bground scan... no users\n");
|
|
||||||
}
|
|
||||||
rescan_counter=0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(config.reload) {
|
/* Run the loop */
|
||||||
old_song_count = song_count;
|
event_dispatch();
|
||||||
start_time=(int) time(NULL);
|
|
||||||
|
|
||||||
DPRINTF(E_LOG,L_MAIN|L_DB|L_SCAN,"Rescanning database\n");
|
|
||||||
|
|
||||||
if(conf_get_array("general","mp3_dir",&mp3_dir_array)) {
|
|
||||||
if(config.full_reload) {
|
|
||||||
config.full_reload=0;
|
|
||||||
db_force_rescan(NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(scan_init(mp3_dir_array)) {
|
|
||||||
DPRINTF(E_LOG,L_MAIN|L_DB|L_SCAN,"Error rescanning... bad path?\n");
|
|
||||||
}
|
|
||||||
conf_dispose_array(mp3_dir_array);
|
|
||||||
}
|
|
||||||
config.reload=0;
|
|
||||||
db_get_song_count(NULL,&song_count);
|
|
||||||
DPRINTF(E_LOG,L_MAIN|L_DB|L_SCAN,"Scanned %d songs (was %d) in "
|
|
||||||
"%d seconds\n",song_count,old_song_count,
|
|
||||||
time(NULL)-start_time);
|
|
||||||
}
|
|
||||||
|
|
||||||
os_wait(MAIN_SLEEP_INTERVAL);
|
|
||||||
rescan_counter += MAIN_SLEEP_INTERVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
DPRINTF(E_LOG,L_MAIN,"Stopping gracefully\n");
|
DPRINTF(E_LOG,L_MAIN,"Stopping gracefully\n");
|
||||||
|
|
||||||
|
@ -358,6 +358,8 @@ void os_wait(int seconds) {
|
|||||||
int status;
|
int status;
|
||||||
struct sigaction sa_ign;
|
struct sigaction sa_ign;
|
||||||
struct sigaction sa_dfl;
|
struct sigaction sa_dfl;
|
||||||
|
|
||||||
|
if (seconds > 0)
|
||||||
sleep(seconds);
|
sleep(seconds);
|
||||||
|
|
||||||
sigpending(&intmask);
|
sigpending(&intmask);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user