]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - server.c
rename plm_dbtool.c to playlist_selector.c
[paraslash.git] / server.c
index c46966ea8e2343f38366b14f34d360dce6d67026..d881868c09cc826e561c2d7d49b5bb03de8fd4ea 100644 (file)
--- a/server.c
+++ b/server.c
@@ -21,8 +21,9 @@
 
 /** \mainpage Paraslash API Reference
  *
- *  Good starting points for reading are probably \ref dbtool, \ref sender,
- *  \ref receiver, \ref receiver_node, \ref filter, \ref filter_node.
+ *  Good starting points for reading are probably \ref audio_file_selector,
+ *  \ref sender, \ref receiver, \ref receiver_node, \ref filter, \ref
+ *  filter_node.
  *
  */
 
@@ -47,11 +48,11 @@ INIT_SERVER_ERRLISTS;
 /** shut down non-authorized connections after that many seconds */
 #define ALARM_TIMEOUT 10
 
-/* these are exported to afs/command/dbtool */
+/* these are exported to afs.c. command.c and to all selectors */
 struct misc_meta_data *mmd;
 /** the configuration of para_server
  *
- * It also contains the options for all database tools and all supported
+ * It also contains the options for all audio file selectors and all supported
  * senders.
 */
 struct gengetopt_args_info conf;
@@ -60,16 +61,16 @@ extern void http_send_init(struct sender *);
 extern void ortp_send_init(struct sender *);
 extern struct audio_format afl[];
 
-/** the list of supported database tools */
-struct dbtool dblist[] = {
+/** the list of supported audio file selectors */
+struct audio_file_selector dblist[] = {
        {
                .name = "random",
-               .init = random_dbtool_init,
+               .init = random_selector_init,
                .update_audio_file = NULL,
        },
        {
-               .name = "plm",
-               .init = plm_dbtool_init,
+               .name = "playlist",
+               .init = playlist_selector_init,
                .update_audio_file = NULL,
                .pre_select = NULL,
                .post_select = NULL,
@@ -77,7 +78,7 @@ struct dbtool dblist[] = {
 #ifdef HAVE_MYSQL
        {
                .name = "mysql",
-               .init = mysql_dbtool_init,
+               .init = mysql_selector_init,
                .update_audio_file = NULL,
                .pre_select = NULL,
                .post_select = NULL,
@@ -276,43 +277,27 @@ static void setup_signal_handling(void)
        }
 }
 
-static void init_dbtool(void)
+static void init_selector(void)
 {
-       int i;
+       int i, ret;
 
        mmd->dbt_change = -1; /* no change nec., set to new dbt num by com_cdt */
-       if (!dblist[1].name)
+       if (!conf.selector_given)
                goto random;
-       if (conf.dbtool_given) {
-               for (i = 0; dblist[i].name; i++) {
-                       if (strcmp(dblist[i].name, conf.dbtool_arg))
-                               continue;
-                       PARA_NOTICE_LOG("initializing %s database tool\n",
-                               dblist[i].name);
-                       if (dblist[i].init(&dblist[i]) < 0) {
-                               PARA_WARNING_LOG("init %s failed",
-                                       dblist[i].name);
-                               goto random;
-                       }
-                       mmd->dbt_num = i;
-                       return;
-               }
-               PARA_WARNING_LOG("%s", "no such dbtool, switching to random\n");
-               goto random;
-       }
-       /* use the first dbtool that works
-        * (assuming that random always works)
-        */
-       for (i = 1; dblist[i].name; i++) {
-               int ret = dblist[i].init(&dblist[i]);
-               if (ret >= 0) {
-                       PARA_INFO_LOG("initialized %s\n", dblist[i].name);
-                       mmd->dbt_num = i;
-                       return;
+       for (i = 0; dblist[i].name; i++) {
+               if (strcmp(dblist[i].name, conf.selector_arg))
+                       continue;
+               PARA_NOTICE_LOG("initializing %s audio file selector\n",
+                       dblist[i].name);
+               ret = dblist[i].init(&dblist[i]);
+               if (ret < 0) {
+                       PARA_WARNING_LOG("%s", PARA_STRERROR(-ret));
+                       break;
                }
-               PARA_CRIT_LOG("%s init failed: %s\n", dblist[i].name,
-                       PARA_STRERROR(-ret));
+               mmd->dbt_num = i;
+               return;
        }
+       PARA_WARNING_LOG("%s", "falling back to the random selector\n");
 random:
        mmd->dbt_num = 0;
        dblist[0].init(&dblist[0]); /* always successful */
@@ -367,7 +352,7 @@ static unsigned do_inits(int argc, char **argv)
        /* become daemon */
        if (conf.daemon_given)
                daemon_init();
-       init_dbtool();
+       init_selector();
        PARA_NOTICE_LOG("%s", "initializing audio file sender\n");
        /* audio file sender */
        afs_init();
@@ -397,7 +382,7 @@ static void handle_dbt_change(void)
                return;
        }
        /* init failed */
-       PARA_ERROR_LOG("%s -- switching to the random dbtool\n", PARA_STRERROR(-ret));
+       PARA_ERROR_LOG("%s -- switching to the random selector\n", PARA_STRERROR(-ret));
        dblist[0].init(&dblist[0]);
        mmd->dbt_num = 0;
 }
@@ -411,8 +396,8 @@ static void handle_sighup(void)
        close_log(logfile); /* gets reopened if necessary by parse_config */
        logfile = NULL;
        parse_config(1); /* reopens log */
-       mmd->dbt_change = mmd->dbt_num; /* do not change dbtool */
-       handle_dbt_change(); /* force reloading dbtool */
+       mmd->dbt_change = mmd->dbt_num; /* do not change selector */
+       handle_dbt_change(); /* reload selector */
 }
 
 static void status_refresh(void)