LCOV - code coverage report
Current view: top level - harness - backendmanager.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core r Lines: 2 3 66.7 %
Date: 2011-08-21 Functions: 2 4 50.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* backendmanager.h
       2                 :            :  *
       3                 :            :  * Copyright 1999,2000,2001 BrightStation PLC
       4                 :            :  * Copyright 2002,2003,2004,2005,2006,2007,2008,2009,2010 Olly Betts
       5                 :            :  *
       6                 :            :  * This program is free software; you can redistribute it and/or
       7                 :            :  * modify it under the terms of the GNU General Public License as
       8                 :            :  * published by the Free Software Foundation; either version 2 of the
       9                 :            :  * License, or (at your option) any later version.
      10                 :            :  *
      11                 :            :  * This program is distributed in the hope that it will be useful,
      12                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14                 :            :  * GNU General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU General Public License
      17                 :            :  * along with this program; if not, write to the Free Software
      18                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
      19                 :            :  * USA
      20                 :            :  */
      21                 :            : 
      22                 :            : #ifndef OM_HGUARD_BACKENDMANAGER_H
      23                 :            : #define OM_HGUARD_BACKENDMANAGER_H
      24                 :            : 
      25                 :            : #include <xapian.h>
      26                 :            : #include <vector>
      27                 :            : 
      28                 :            : // Paths to xapian-tcpsrv and xapian-progsrv.
      29                 :            : #ifdef __WIN32__
      30                 :            : // Under __WIN32__ we want \ path separators since we pass this path to
      31                 :            : // CreateProcess().
      32                 :            : # ifdef _MSC_VER
      33                 :            : #  ifdef DEBUG
      34                 :            : #   define XAPIAN_BIN_PATH "..\\win32\\Debug\\"
      35                 :            : #  else
      36                 :            : #   define XAPIAN_BIN_PATH "..\\win32\\Release\\"
      37                 :            : #  endif
      38                 :            : # else
      39                 :            : #  define XAPIAN_BIN_PATH "..\\bin\\" // mingw
      40                 :            : # endif
      41                 :            : #else
      42                 :            : # define XAPIAN_BIN_PATH "../bin/"
      43                 :            : #endif
      44                 :            : #define XAPIAN_TCPSRV XAPIAN_BIN_PATH"xapian-tcpsrv"
      45                 :            : #define XAPIAN_PROGSRV XAPIAN_BIN_PATH"xapian-progsrv"
      46                 :            : 
      47                 :            : #if defined __SUNPRO_CC && __SUNPRO_CC - 0 < 0x580
      48                 :            : // Older versions of Sun's CC appears to need this to compile this file.
      49                 :            : class Xapian::WritableDatabase;
      50                 :            : #endif
      51                 :            : 
      52                 :            : class BackendManager {
      53                 :            :     /// The current data directory
      54                 :            :     std::string datadir;
      55                 :            : 
      56                 :            :     /// Index data from zero or more text files into a database.
      57                 :            :     void index_files_to_database(Xapian::WritableDatabase & database,
      58                 :            :                                  const std::vector<std::string> & files);
      59                 :            : 
      60                 :            :   protected:
      61                 :            :     bool create_dir_if_needed(const std::string &dirname);
      62                 :            : 
      63                 :            :     /** Virtual method implementing get_database().
      64                 :            :      *
      65                 :            :      *  If we just called this get_database() then each subclass which
      66                 :            :      *  defined it would also need to un-hide the non-virtual overloaded method
      67                 :            :      *  with "using get_database(const std::string&);" or similar.
      68                 :            :      */
      69                 :            :     virtual Xapian::Database do_get_database(const std::vector<std::string> &files);
      70                 :            : 
      71                 :            :     /** Virtual method implementing get_database_path().
      72                 :            :      *
      73                 :            :      *  If we just called this get_database_path() then each subclass which
      74                 :            :      *  defined it would also need to un-hide the non-virtual overloaded method
      75                 :            :      *  with "using get_database_path(const std::string&);" or similar.
      76                 :            :      */
      77                 :            :     virtual std::string do_get_database_path(const std::vector<std::string> &files);
      78                 :            : 
      79                 :            : #ifdef XAPIAN_HAS_INMEMORY_BACKEND
      80                 :            :     /// Get a writable inmemory database instance.
      81                 :            :     Xapian::WritableDatabase getwritedb_inmemory(const std::vector<std::string> &files);
      82                 :            : #endif
      83                 :            : 
      84                 :            : #ifdef XAPIAN_HAS_REMOTE_BACKEND
      85                 :            :     /// Get a remote database instance using xapian-progsrv.
      86                 :            :     Xapian::Database getdb_remoteprog(const std::vector<std::string> &files);
      87                 :            : 
      88                 :            :     /// Get a writable remote database instance using xapian-progsrv.
      89                 :            :     Xapian::WritableDatabase getwritedb_remoteprog(const std::vector<std::string> &files);
      90                 :            : 
      91                 :            :     /// Get a remote database instance using xapian-tcpsrv.
      92                 :            :     Xapian::Database getdb_remotetcp(const std::vector<std::string> &files);
      93                 :            : 
      94                 :            :     /// Get a writable remote database instance using xapian-tcpsrv.
      95                 :            :     Xapian::WritableDatabase getwritedb_remotetcp(const std::vector<std::string> &files);
      96                 :            : #endif
      97                 :            : 
      98                 :            : #ifdef XAPIAN_HAS_BRASS_BACKEND
      99                 :            :   protected:
     100                 :            :     std::string createdb_brass(const std::vector<std::string> &files);
     101                 :            : 
     102                 :            :   public:
     103                 :            :     /// Get a writable brass database instance.
     104                 :            :     Xapian::WritableDatabase getwritedb_brass(const std::string & name,
     105                 :            :                                               const std::vector<std::string> &files);
     106                 :            : 
     107                 :            :     /// Get the path of a writable brass database instance.
     108                 :            :     std::string getwritedb_brass_path(const std::string & name);
     109                 :            : #endif
     110                 :            : 
     111                 :            : #ifdef XAPIAN_HAS_CHERT_BACKEND
     112                 :            :   protected:
     113                 :            :     std::string createdb_chert(const std::vector<std::string> &files);
     114                 :            : 
     115                 :            :   public:
     116                 :            :     /// Get a writable chert database instance.
     117                 :            :     Xapian::WritableDatabase getwritedb_chert(const std::string & name,
     118                 :            :                                               const std::vector<std::string> &files);
     119                 :            : 
     120                 :            :     /// Get the path of a writable chert database instance.
     121                 :            :     std::string getwritedb_chert_path(const std::string & name);
     122                 :            : #endif
     123                 :            : 
     124                 :            : #ifdef XAPIAN_HAS_FLINT_BACKEND
     125                 :            :   protected:
     126                 :            :     std::string createdb_flint(const std::vector<std::string> &files);
     127                 :            : 
     128                 :            :   public:
     129                 :            :     /// Get a writable flint database instance.
     130                 :            :     Xapian::WritableDatabase getwritedb_flint(const std::string & name,
     131                 :            :                                               const std::vector<std::string> &files);
     132                 :            : 
     133                 :            :     /// Get the path of a writable flint database instance.
     134                 :            :     std::string getwritedb_flint_path(const std::string & name);
     135                 :            : #endif
     136                 :            : 
     137                 :            :   public:
     138                 :            :     /// Constructor - set up default state.
     139                 :          1 :     BackendManager() { }
     140                 :            : 
     141                 :            :     /** We have virtual methods and want to be able to delete derived classes
     142                 :            :      *  using a pointer to the base class, so we need a virtual destructor.
     143                 :            :      */
     144                 :            :     virtual ~BackendManager();
     145                 :            : 
     146                 :            :     /** Get the database type currently in use.
     147                 :            :      */
     148                 :            :     virtual std::string get_dbtype() const;
     149                 :            : 
     150                 :            :     /** Set the directory to store data in.
     151                 :            :      */
     152                 :          0 :     void set_datadir(const std::string &datadir_) { datadir = datadir_; }
     153                 :            : 
     154                 :            :     /** Get the directory to store data in.
     155                 :            :      */
     156                 :         54 :     const std::string & get_datadir() const { return datadir; }
     157                 :            : 
     158                 :            :     /// Get a database instance of the current type.
     159                 :            :     Xapian::Database get_database(const std::vector<std::string> &files);
     160                 :            : 
     161                 :            :     /// Get a database instance of the current type, single file case.
     162                 :            :     Xapian::Database get_database(const std::string &file);
     163                 :            : 
     164                 :            :     /** Get a database instance of the current type, generated case.
     165                 :            :      *
     166                 :            :      * @param dbname    The name of the database (base on your testcase name).
     167                 :            :      * @param gen       Generator function - should index data to the empty
     168                 :            :      *                  WritableDatabase provided.
     169                 :            :      * @param arg       String argument to pass to @a gen - it's up to you how
     170                 :            :      *                  to make use of this (or just ignore it if you don't need
     171                 :            :      *                  it).
     172                 :            :      */
     173                 :            :     Xapian::Database get_database(const std::string &dbname,
     174                 :            :                                   void (*gen)(Xapian::WritableDatabase&,
     175                 :            :                                               const std::string &),
     176                 :            :                                   const std::string &arg);
     177                 :            : 
     178                 :            :     /// Get the path of a database instance, if such a thing exists.
     179                 :            :     std::string get_database_path(const std::vector<std::string> &files);
     180                 :            : 
     181                 :            :     /// Get the path of a database instance, if such a thing exists (single file case).
     182                 :            :     std::string get_database_path(const std::string &file);
     183                 :            : 
     184                 :            :     /// Get the path of a generated database instance.
     185                 :            :     std::string get_database_path(const std::string &dbname,
     186                 :            :                                   void (*gen)(Xapian::WritableDatabase&,
     187                 :            :                                               const std::string &),
     188                 :            :                                   const std::string &arg);
     189                 :            : 
     190                 :            :     /// Get a writable database instance.
     191                 :            :     virtual Xapian::WritableDatabase get_writable_database(const std::string & name, const std::string & file);
     192                 :            : 
     193                 :            :     /// Get the path of a writable database instance, if such a thing exists.
     194                 :            :     virtual std::string get_writable_database_path(const std::string & name);
     195                 :            : 
     196                 :            :     /// Get a remote database instance with the specified timeout.
     197                 :            :     virtual Xapian::Database get_remote_database(const std::vector<std::string> & files, unsigned int timeout);
     198                 :            : 
     199                 :            :     /// Create a Database object for the last opened WritableDatabase.
     200                 :            :     virtual Xapian::Database get_writable_database_as_database();
     201                 :            : 
     202                 :            :     /// Create a WritableDatabase object for the last opened WritableDatabase.
     203                 :            :     virtual Xapian::WritableDatabase get_writable_database_again();
     204                 :            : 
     205                 :            :     /** Called after each test, to perform any necessary cleanup.
     206                 :            :      *
     207                 :            :      *  May be called more than once for a given test in some cases.
     208                 :            :      */
     209                 :            :     virtual void clean_up();
     210                 :            : 
     211                 :            :     /// Get the command line required to run xapian-progsrv.
     212                 :            :     static const char * get_xapian_progsrv_command();
     213                 :            : };
     214                 :            : 
     215                 :            : #endif /* OM_HGUARD_BACKENDMANAGER_H */

Generated by: LCOV version 1.8