00001 00004 /* Copyright (C) 2006,2007,2008,2009 Olly Betts 00005 * Copyright (C) 2008 Lemur Consulting Ltd 00006 * 00007 * This program is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU General Public License as 00009 * published by the Free Software Foundation; either version 2 of the 00010 * License, or (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 00022 #include <config.h> 00023 #include "backendmanager_remote.h" 00024 #include "str.h" 00025 #include <cstdlib> 00026 #include <string> 00027 00028 BackendManagerRemote::BackendManagerRemote(const std::string & remote_type_) 00029 : remote_type(remote_type_) 00030 { 00031 if (!(false 00032 #ifdef XAPIAN_HAS_BRASS_BACKEND 00033 || remote_type == "brass" 00034 #endif 00035 #ifdef XAPIAN_HAS_CHERT_BACKEND 00036 || remote_type == "chert" 00037 #endif 00038 #ifdef XAPIAN_HAS_FLINT_BACKEND 00039 || remote_type == "flint" 00040 #endif 00041 )) { 00042 throw ("Unknown backend type \"" + remote_type + "\" specified for remote database"); 00043 } 00044 } 00045 00046 std::string 00047 BackendManagerRemote::get_writable_database_args(const std::string & name, 00048 const std::string & file) 00049 { 00050 last_wdb_name = name; 00051 00052 // Default to a long (5 minute) timeout so that tests won't fail just 00053 // because the host is slow or busy. 00054 std::string args = "-t300000 --writable "; 00055 00056 #ifdef XAPIAN_HAS_BRASS_BACKEND 00057 if (remote_type == "brass") { 00058 (void)getwritedb_brass(name, std::vector<std::string>(1, file)); 00059 args += ".brass/"; 00060 } 00061 #endif 00062 #ifdef XAPIAN_HAS_CHERT_BACKEND 00063 if (remote_type == "chert") { 00064 (void)getwritedb_chert(name, std::vector<std::string>(1, file)); 00065 args += ".chert/"; 00066 } 00067 #endif 00068 #ifdef XAPIAN_HAS_FLINT_BACKEND 00069 if (remote_type == "flint") { 00070 (void)getwritedb_flint(name, std::vector<std::string>(1, file)); 00071 args += ".flint/"; 00072 } 00073 #endif 00074 args += name; 00075 00076 return args; 00077 } 00078 00079 std::string 00080 BackendManagerRemote::get_remote_database_args(const std::vector<std::string> & files, 00081 unsigned int timeout) 00082 { 00083 std::string args = "-t"; 00084 args += str(timeout); 00085 args += ' '; 00086 #ifdef XAPIAN_HAS_BRASS_BACKEND 00087 if (remote_type == "brass") { 00088 args += createdb_brass(files); 00089 } 00090 #endif 00091 #ifdef XAPIAN_HAS_CHERT_BACKEND 00092 if (remote_type == "chert") { 00093 args += createdb_chert(files); 00094 } 00095 #endif 00096 #ifdef XAPIAN_HAS_FLINT_BACKEND 00097 if (remote_type == "flint") { 00098 args += createdb_flint(files); 00099 } 00100 #endif 00101 00102 return args; 00103 } 00104 00105 std::string 00106 BackendManagerRemote::get_writable_database_as_database_args() 00107 { 00108 std::string args = "-t300000 "; 00109 #ifdef XAPIAN_HAS_BRASS_BACKEND 00110 if (remote_type == "brass") { 00111 args += ".brass/"; 00112 } 00113 #endif 00114 #ifdef XAPIAN_HAS_CHERT_BACKEND 00115 if (remote_type == "chert") { 00116 args += ".chert/"; 00117 } 00118 #endif 00119 #ifdef XAPIAN_HAS_FLINT_BACKEND 00120 if (remote_type == "flint") { 00121 args += ".flint/"; 00122 } 00123 #endif 00124 args += last_wdb_name; 00125 00126 return args; 00127 } 00128 00129 std::string 00130 BackendManagerRemote::get_writable_database_again_args() 00131 { 00132 std::string args = "-t300000 --writable "; 00133 #ifdef XAPIAN_HAS_BRASS_BACKEND 00134 if (remote_type == "brass") { 00135 args += ".brass/"; 00136 } 00137 #endif 00138 #ifdef XAPIAN_HAS_CHERT_BACKEND 00139 if (remote_type == "chert") { 00140 args += ".chert/"; 00141 } 00142 #endif 00143 #ifdef XAPIAN_HAS_FLINT_BACKEND 00144 if (remote_type == "flint") { 00145 args += ".flint/"; 00146 } 00147 #endif 00148 args += last_wdb_name; 00149 00150 return args; 00151 }