1 /** @file backendmanager.h
2 * @brief Base class for backend handling in test harness
4 /* Copyright 1999,2000,2001 BrightStation PLC
5 * Copyright 2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2017,2018 Olly Betts
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23 #ifndef OM_HGUARD_BACKENDMANAGER_H
24 #define OM_HGUARD_BACKENDMANAGER_H
29 // Paths to xapian-tcpsrv and xapian-progsrv.
31 // Under __WIN32__ we want \ path separators since we pass this path to
33 # define XAPIAN_BIN_PATH "..\\bin\\"
34 # define EXE_SUFFIX ".exe"
36 # define XAPIAN_BIN_PATH "../bin/"
39 #define XAPIAN_TCPSRV XAPIAN_BIN_PATH "xapian-tcpsrv" EXE_SUFFIX
40 #define XAPIAN_PROGSRV XAPIAN_BIN_PATH "xapian-progsrv" EXE_SUFFIX
42 class BackendManager
{
43 /// The current data directory
47 /// Index data from zero or more text files into a database.
48 void index_files_to_database(Xapian::WritableDatabase
& database
,
49 const std::vector
<std::string
> & files
);
51 bool create_dir_if_needed(const std::string
&dirname
);
53 /** Virtual method implementing get_database().
55 * If we just called this get_database() then each subclass which
56 * defined it would also need to un-hide the non-virtual overloaded method
57 * with "using get_database(const std::string&);" or similar.
59 virtual Xapian::Database
do_get_database(const std::vector
<std::string
> &files
);
61 /** Virtual method implementing get_database_path().
63 * If we just called this get_database_path() then each subclass which
64 * defined it would also need to un-hide the non-virtual overloaded method
65 * with "using get_database_path(const std::string&);" or similar.
67 virtual std::string
do_get_database_path(const std::vector
<std::string
> &files
);
69 #ifdef XAPIAN_HAS_REMOTE_BACKEND
70 /// Get a remote database instance using xapian-progsrv.
71 Xapian::Database
getdb_remoteprog(const std::vector
<std::string
> &files
);
73 /// Get a writable remote database instance using xapian-progsrv.
74 Xapian::WritableDatabase
getwritedb_remoteprog(const std::vector
<std::string
> &files
);
76 /// Get a remote database instance using xapian-tcpsrv.
77 Xapian::Database
getdb_remotetcp(const std::vector
<std::string
> &files
);
79 /// Get a writable remote database instance using xapian-tcpsrv.
80 Xapian::WritableDatabase
getwritedb_remotetcp(const std::vector
<std::string
> &files
);
86 BackendManager(const std::string
& datadir_
)
87 : datadir(datadir_
) {}
89 /** We have virtual methods and want to be able to delete derived classes
90 * using a pointer to the base class, so we need a virtual destructor.
92 virtual ~BackendManager();
94 /** Get the database type currently in use.
96 virtual std::string
get_dbtype() const;
98 /** Get the directory to store data in.
100 const std::string
& get_datadir() const { return datadir
; }
102 /// Get a database instance of the current type.
103 Xapian::Database
get_database(const std::vector
<std::string
> &files
);
105 /// Get a database instance of the current type, single file case.
106 Xapian::Database
get_database(const std::string
&file
);
108 /** Get a database instance of the current type, generated case.
110 * @param dbname The name of the database (base on your testcase name).
111 * @param gen Generator function - should index data to the empty
112 * WritableDatabase provided.
113 * @param arg String argument to pass to @a gen - it's up to you how
114 * to make use of this (or just ignore it if you don't need
117 Xapian::Database
get_database(const std::string
&dbname
,
118 void (*gen
)(Xapian::WritableDatabase
&,
119 const std::string
&),
120 const std::string
&arg
);
122 /// Get the path of a database instance, if such a thing exists.
123 std::string
get_database_path(const std::vector
<std::string
> &files
);
125 /// Get the path of a database instance, if such a thing exists (single file case).
126 std::string
get_database_path(const std::string
&file
);
128 /// Get the path of a generated database instance.
129 std::string
get_database_path(const std::string
&dbname
,
130 void (*gen
)(Xapian::WritableDatabase
&,
131 const std::string
&),
132 const std::string
&arg
);
134 /// Get a writable database instance.
135 virtual Xapian::WritableDatabase
get_writable_database(const std::string
& name
, const std::string
& file
);
137 /// Get the path of a writable database instance, if such a thing exists.
138 virtual std::string
get_writable_database_path(const std::string
& name
);
140 /// Get the path to use for generating a database, if supported.
141 virtual std::string
get_generated_database_path(const std::string
& name
);
143 /// Get a remote database instance with the specified timeout.
144 virtual Xapian::Database
get_remote_database(const std::vector
<std::string
> & files
, unsigned int timeout
);
146 /// Create a Database object for the last opened WritableDatabase.
147 virtual Xapian::Database
get_writable_database_as_database();
149 /// Create a WritableDatabase object for the last opened WritableDatabase.
150 virtual Xapian::WritableDatabase
get_writable_database_again();
152 /// Get the path of the last opened WritableDatabase.
153 virtual std::string
get_writable_database_path_again();
155 /** Called after each test, to perform any necessary cleanup.
157 * May be called more than once for a given test in some cases.
159 virtual void clean_up();
161 /// Get the command line required to run xapian-progsrv.
162 static const char * get_xapian_progsrv_command();
165 #endif /* OM_HGUARD_BACKENDMANAGER_H */