]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
Merge branch 'dbtool_preselect'
authorAndre <maan@p133.(none)>
Tue, 21 Feb 2006 08:22:36 +0000 (09:22 +0100)
committerAndre <maan@p133.(none)>
Tue, 21 Feb 2006 08:22:36 +0000 (09:22 +0100)
1  2 
db.h
server.c

diff --combined db.h
index 34ea52d1d3423b678222332cea01e84afc22b122,328f7de8cd748814c67542f431c8ca83b782141e..69d4d9ed04308eb4a5c66505bcb03b3c4762a9c0
--- 1/db.h
--- 2/db.h
+++ b/db.h
@@@ -18,6 -18,8 +18,8 @@@
  
  /** \file db.h data structures common to all database tools */
  
+ #include <sys/select.h>
  int find_audio_files(const char *dirname, int (*f)(const char *, const char *));
  
  /**
@@@ -78,7 -80,7 +80,7 @@@ char **(*get_audio_file_list)(unsigned 
   * passed \a update_audio_file().
   *
   */
- void  (*update_audio_file)(char *audio_file);
+ void (*update_audio_file)(char *audio_file);
  /**
   *
   * shutdown this database tool and free all resources
   * This gets called whenever the database tool changes (via the cdt command),
   * or when para_server receives the HUP signal, or when para_server shuts down.
   * It is assumed to succeed.
- */
 */
  void (*shutdown)(void);
+ /**
+  *
+  * add file descriptors to fd_sets
+  *
+  * The pre_select function of the activated database tool gets called just
+  * before para_server enters its main select loop. The dbtool may add its own
+  * file descriptors to the \a rfds or the \a wfds set.
+  *
+  * If a file descriptor was added, \a max_fileno must be increased by
+  * this function, if neccessary.
+  *
+  * \sa select(2)
+  */
+ int (*pre_select)(fd_set *rfds, fd_set *wfds);
+ /**
+  * handle the file descriptors which are ready for I/O
+  *
+  * If the pre_select hook added one ore more file descriptors to the read or write
+  * set, this is the hook to check the result and do any I/O on those descriptors
+  * which are ready for reading/writing.
+  */
+ void (*post_select)(fd_set *rfds, fd_set *wfds);
  };
  
  int mysql_dbtool_init(struct dbtool*);
 -int dopey_dbtool_init(struct dbtool*);
 +int plm_dbtool_init(struct dbtool*);
 +int random_dbtool_init(struct dbtool*);
  
diff --combined server.c
index 73b8b057cfe6071535733292bde293986f72930d,8d9435337c904ab23801607c8895ed42423ca845..c185b3e189fcccc62870913c2ad1330868ec7e94
+++ b/server.c
@@@ -63,20 -63,19 +63,24 @@@ extern struct audio_format afl[]
  /** the list of supported database tools */
  struct dbtool dblist[] = {
        {
 -              .name = "dopey",
 -              .init = dopey_dbtool_init,
 +              .name = "random",
 +              .init = random_dbtool_init,
 +              .update_audio_file = NULL,
 +      },
 +      {
 +              .name = "plm",
 +              .init = plm_dbtool_init,
                .update_audio_file = NULL,
+               .pre_select = NULL,
+               .post_select = NULL,
        },
  #ifdef HAVE_MYSQL
        {
                .name = "mysql",
                .init = mysql_dbtool_init,
                .update_audio_file = NULL,
+               .pre_select = NULL,
+               .post_select = NULL,
        },
  #endif
        {
@@@ -307,7 -306,7 +311,7 @@@ static void init_dbtool(void
  
        mmd->dbt_change = -1; /* no change nec., set to new dbt num by com_cdt */
        if (!dblist[1].name)
 -              goto dopey;
 +              goto random;
        if (conf.dbtool_given) {
                for (i = 0; dblist[i].name; i++) {
                        if (strcmp(dblist[i].name, conf.dbtool_arg))
                        if (dblist[i].init(&dblist[i]) < 0) {
                                PARA_WARNING_LOG("init %s failed",
                                        dblist[i].name);
 -                              goto dopey;
 +                              goto random;
                        }
                        mmd->dbt_num = i;
                        return;
                }
 -              PARA_WARNING_LOG("%s", "no such dbtool, switching to dopey\n");
 -              goto dopey;
 +              PARA_WARNING_LOG("%s", "no such dbtool, switching to random\n");
 +              goto random;
        }
        /* use the first dbtool that works
 -       * (assuming that dopey always works)
 +       * (assuming that random always works)
         */
        for (i = 1; dblist[i].name; i++) {
                int ret = dblist[i].init(&dblist[i]);
                PARA_CRIT_LOG("%s init failed: %s\n", dblist[i].name,
                        PARA_STRERROR(-ret));
        }
 -dopey:
 +random:
        mmd->dbt_num = 0;
        dblist[0].init(&dblist[0]); /* always successful */
  }
@@@ -422,7 -421,7 +426,7 @@@ static void handle_dbt_change(void
                return;
        }
        /* init failed */
 -      PARA_ERROR_LOG("%s -- switching to dopey\n", PARA_STRERROR(-ret));
 +      PARA_ERROR_LOG("%s -- switching to the random dbtool\n", PARA_STRERROR(-ret));
        dblist[0].init(&dblist[0]);
        mmd->dbt_num = 0;
  }