glom r1386 - in trunk: . glom glom/libglom



Author: arminb
Date: Sun Jan 13 18:59:02 2008
New Revision: 1386
URL: http://svn.gnome.org/viewvc/glom?rev=1386&view=rev

Log:
2008-01-13  Armin Burgmeier  <armin openismus com>

	* configure.in: Disable the --with-postgres-utils options on Windows
	because it does not make sense to hardcode paths on Windows. We use
	Glib::find_program_in_path to locate the postgres executables.

	* glom/libglom/connectionpool.h:
	* glom/libglom/connectionpool.cc: Severial windows fixes: Don't use
	libepc, locate postgres programs using Glib::find_program_in_path,
	quote path to executables, use closesocket() instead of close().

	* glom/libglom/spawn_with_feedback.cc: Fixed typo.

	* glom/Makefile.am: Changed library linking order so linking developer
	mode on Windows succeeds.


Modified:
   trunk/ChangeLog
   trunk/configure.in
   trunk/glom/Makefile.am
   trunk/glom/libglom/connectionpool.cc
   trunk/glom/libglom/connectionpool.h
   trunk/glom/libglom/spawn_with_feedback.cc

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Sun Jan 13 18:59:02 2008
@@ -133,22 +133,25 @@
         [do not run the update-mime-database utility (mostly useful for package maintainers) ]))
 AM_CONDITIONAL(UPDATE_MIME_DATABASE, test "$enable_update_mime_database" != "no")
 
-# Ask user for path to the directory containing the postgresql utilities, such as the postmaster executable, so we can self-host postgresql databases:
-# We default to the path used by Ubuntu (Dapper and Edgy) so that the build works at least somewhere by default.
-AC_ARG_WITH(postgres-utils,
-    [ --with-postgres-utils=<path> path to the postmaster executable. e.g. /usr/lib/postgresql/8.2/bin],
-    [POSTGRES_UTILS_PATH=$with_postgres_utils],
-    [POSTGRES_UTILS_PATH=/usr/lib/postgresql/8.2/bin]
-)
-
-AC_SUBST(POSTGRES_UTILS_PATH)
-AC_DEFINE_UNQUOTED([POSTGRES_UTILS_PATH], ["${POSTGRES_UTILS_PATH}"], [Path to the postgres utilities, such as postmaster.])
-
-if test $enable_client_only != yes; then
-	# Check that the supplied (or default) path really contains the postgres utilities:
-	AC_CHECK_PROG(HAVE_POSTMASTER, postmaster, yes, no, ${POSTGRES_UTILS_PATH})
-	if test "x$HAVE_POSTMASTER" = "xno"; then
-	AC_MSG_ERROR([The postgres utilities could not be found in the path: ${POSTGRES_UTILS_PATH}. They are needed for self-hosting of Glom databases. Please make sure that Postgres is installed, and provide the correct path with the --with-postgres-utils option.])
+# Option not needed on Windows
+if test $win32 != true; then
+	# Ask user for path to the directory containing the postgresql utilities, such as the postmaster executable, so we can self-host postgresql databases:
+	# We default to the path used by Ubuntu (Dapper and Edgy) so that the build works at least somewhere by default.
+	AC_ARG_WITH(postgres-utils,
+	    [ --with-postgres-utils=<path> path to the postmaster executable. e.g. /usr/lib/postgresql/8.2/bin (ignored on Windows)],
+	    [POSTGRES_UTILS_PATH=$with_postgres_utils],
+	    [POSTGRES_UTILS_PATH=/usr/lib/postgresql/8.2/bin]
+	)
+
+	AC_SUBST(POSTGRES_UTILS_PATH)
+	AC_DEFINE_UNQUOTED([POSTGRES_UTILS_PATH], ["${POSTGRES_UTILS_PATH}"], [Path to the postgres utilities, such as postmaster.])
+
+	if test $enable_client_only != yes; then
+		# Check that the supplied (or default) path really contains the postgres utilities:
+		AC_CHECK_PROG(HAVE_POSTMASTER, postmaster, yes, no, ${POSTGRES_UTILS_PATH})
+		if test "x$HAVE_POSTMASTER" = "xno"; then
+		AC_MSG_ERROR([The postgres utilities could not be found in the path: ${POSTGRES_UTILS_PATH}. They are needed for self-hosting of Glom databases. Please make sure that Postgres is installed, and provide the correct path with the --with-postgres-utils option.])
+		fi
 	fi
 fi
 

Modified: trunk/glom/Makefile.am
==============================================================================
--- trunk/glom/Makefile.am	(original)
+++ trunk/glom/Makefile.am	Sun Jan 13 18:59:02 2008
@@ -64,7 +64,9 @@
               mode_design/fields/libmode_design_fields.a \
               mode_design/print_layouts/libmode_design_print_layouts.a \
               mode_design/users/libmode_design_users.a \
-              mode_design/script_library/libmode_design_script_library.a
+              mode_design/script_library/libmode_design_script_library.a \
+              translation/libtranslation.a \
+              relationships_overview/librelationshipsoverview.a
 endif
 
 glom_LDADD += navigation/libnavigation.a \
@@ -75,11 +77,6 @@
               utility_widgets/canvas/libutility_widgets_canvas.a \
               utility_widgets/cellrendererlist/libutility_widgets_cellrendererlist.a
 
-if !GLOM_ENABLE_CLIENT_ONLY
-glom_LDADD += translation/libtranslation.a \
-              relationships_overview/librelationshipsoverview.a
-endif
-
 glom_LDADD += python_embed/libpython_embed.a \
               $(top_builddir)/glom/libglom/libglom.la \
               $(GLOM_LIBS) $(PYTHON_LDFLAGS) $(MAEMO_LAUNCHER_LIBS)

Modified: trunk/glom/libglom/connectionpool.cc
==============================================================================
--- trunk/glom/libglom/connectionpool.cc	(original)
+++ trunk/glom/libglom/connectionpool.cc	Sun Jan 13 18:59:02 2008
@@ -49,6 +49,8 @@
 #include <sys/socket.h> 
 #include <sys/socket.h>
 #include <netinet/in.h> //For sockaddr_in
+#else
+#include <winsock2.h>
 #endif
 
 #include <signal.h> //To catch segfaults
@@ -61,6 +63,19 @@
 static EpcProtocol publish_protocol = EPC_PROTOCOL_HTTPS;
 #endif
 
+namespace
+{
+  std::string get_path_to_postgres_executable(const std::string& program)
+  {
+#ifdef G_OS_WIN32
+    return Glib::find_program_in_path(program + EXEEXT);
+#else
+    return Glib::build_filename(POSTGRES_UTILS_PATH, program + EXEEXT);
+#endif
+  }
+}
+
+
 namespace Glom
 {
 
@@ -375,10 +390,12 @@
             std::cout << "  Postgres Server version: " << get_postgres_server_version() << std::endl << std::endl;
 
 #ifndef GLOM_ENABLE_CLIENT_ONLY
+#ifndef G_OS_WIN32
            //Let other clients discover this server via avahi:
            //TODO: Only advertize if we are the first to open the document,
            //to avoid duplicates.
            avahi_start_publishing(); //Stopped in the signal_finished handler.
+#endif // !G_OS_WIN32
 #endif // !GLOM_ENABLE_CLIENT_ONLY
 
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
@@ -624,9 +641,11 @@
     m_refGdaConnection.clear();
 
 #ifndef GLOM_ENABLE_CLIENT_ONLY
+#ifndef G_OS_WIN32
     //TODO: this should only even be started if we are the first to open the .glom file:
     avahi_stop_publishing();
 #endif
+#endif
 
     //g_warning("ConnectionPool: connection closed");
   }
@@ -712,7 +731,12 @@
 }
 
 #ifndef GLOM_ENABLE_CLIENT_ONLY
+#ifdef G_OS_WIN32
+// TODO: This is probably mingw specific
+static __p_sig_fn_t previous_sig_handler = SIG_DFL;
+#else
 static sighandler_t previous_sig_handler = SIG_DFL; /* Arbitrary default */
+#endif
 
 /* This is a Linux/Unix signal handler, 
  * so we can respond to a crash.
@@ -774,7 +798,7 @@
   // -c config_file= specifies the configuration file
   // -k specifies a directory to use for the socket. This must be writable by us.
   // POSTGRES_POSTMASTER_PATH is defined in config.h, based on the configure.
-  const std::string command_postgres_start = POSTGRES_UTILS_PATH "/postmaster -D \"" + dbdir_data + "\" "
+  const std::string command_postgres_start = Glib::shell_quote(get_path_to_postgres_executable("postmaster")) + " -D \"" + dbdir_data + "\" "
                                   + " -p " + port_as_text 
                                   + " -h \"*\" " //Equivalent to listen_addresses in postgresql.conf. Listen to all IP addresses, so any client can connect (with a username+password)
                                   + " -c hba_file=\"" + dbdir + "/config/pg_hba.conf\""
@@ -782,7 +806,7 @@
                                   + " -k \"" + dbdir + "\""
                                   + " --external_pid_file=\"" + dbdir + "/pid\"";
 
-  const std::string command_check_postgres_has_started = POSTGRES_UTILS_PATH "/pg_ctl status -D \"" + dbdir_data + "\"";
+  const std::string command_check_postgres_has_started = Glib::shell_quote(get_path_to_postgres_executable("pg_ctl")) + " status -D \"" + dbdir_data + "\"";
 
   //For postgres 8.1, this is "postmaster is running".
   //For postgres 8.2, this is "server is running".
@@ -804,8 +828,10 @@
   m_self_hosting_active = true;
   set_try_other_ports(false); //Only try to connect to this known instance, instead of finding others.
 
+#ifndef G_OS_WIN32
   //Let clients discover this server via avahi:
   avahi_start_publishing();
+#endif // !G_OS_WIN32
 
   //If we crash while self-hosting (unlikely, hopefully) 
   //then try to stop the postgres instance instead of leaving it running as an orphan.
@@ -819,8 +845,10 @@
   if(!m_self_hosting_active)
     return; //Don't try to stop it if we have not started it.
 
+#ifndef G_OS_WIN32
   /* Stop advertising the self-hosting database server via avahi: */
   avahi_stop_publishing();
+#endif // !G_OS_WIN32
 
   const std::string dbdir_uri = m_self_hosting_data_uri;
   const std::string dbdir = Glib::filename_from_uri(dbdir_uri);
@@ -838,7 +866,7 @@
   // POSTGRES_POSTMASTER_PATH is defined in config.h, based on the configure.
   // We use "-m fast" instead of the default "-m smart" because that waits for clients to disconnect (and sometimes never succeeds).
   // TODO: Warn about connected clients on other computers? Warn those other users?
-  const std::string command_postgres_stop = POSTGRES_UTILS_PATH "/pg_ctl -D \"" + dbdir_data + "\" stop -m fast";
+  const std::string command_postgres_stop = Glib::shell_quote(get_path_to_postgres_executable("pg_ctl")) + " -D \"" + dbdir_data + "\" stop -m fast";
   const bool result = Glom::Spawn::execute_command_line_and_wait(command_postgres_stop, _("Stopping Database Server"));
   if(!result)
   {
@@ -938,10 +966,10 @@
     return false;
   }
 
-  const std::string temp_pwfile = "/tmp/glom_initdb_pwfile";
+  const std::string temp_pwfile = Glib::build_filename(Glib::get_tmp_dir(), "glom_initdb_pwfile");
   create_text_file(temp_pwfile, get_password());
 
-  const std::string command_initdb = POSTGRES_UTILS_PATH "/initdb -D \"" + dbdir_data + "\"" +
+  const std::string command_initdb = Glib::shell_quote(get_path_to_postgres_executable("initdb")) + " -D \"" + dbdir_data + "\"" +
                                         " -U " + username + " --pwfile=\"" + temp_pwfile + "\""; 
   //Note that --pwfile takes the password from the first line of a file. It's an alternative to supplying it when prompted on stdin.
   const bool result = Glom::Spawn::execute_command_line_and_wait(command_initdb, _("Creating Database Data"));
@@ -1044,15 +1072,23 @@
 
     const int result = bind(fd, (sockaddr*)&sa, sizeof(sa));
     if((result == 0) || ((result < 0)
+#ifdef G_OS_WIN32
+    && (WSAGetLastError() != WSAEADDRINUSE)
+#else // G_OS_WIN32
 #ifdef EADDRINUSE //Some BSDs don't have this.
     && (errno != EADDRINUSE)
 #endif 
 #ifdef EPORTINUSE //Linux doesn't have this.
     && (errno != EPORTINUSE)
 #endif
+#endif // !G_OS_WIN32
     ))
     {
+#ifdef G_OS_WIN32
+      closesocket(fd);
+#else
       close(fd);
+#endif
 
       //std::cout << "debug: ConnectionPool::discover_first_free_port(): Found: returning " << port_to_try << std::endl;
       return port_to_try;
@@ -1065,7 +1101,11 @@
     ++port_to_try;
   }
 
+#ifdef G_OS_WIN32
+  closesocket(fd);
+#else
   close(fd);
+#endif
 
   std::cerr << "debug: ConnectionPool::discover_first_free_port(): No port was available." << std::endl;
   return 0;
@@ -1085,10 +1125,16 @@
 bool ConnectionPool::check_postgres_is_available_with_warning()
 {
   //EXEEXT is defined in the Makefile.am
-  const std::string binpath = Glib::build_filename(POSTGRES_UTILS_PATH, "postmaster" EXEEXT);
-  const Glib::ustring uri_binpath = Glib::filename_to_uri(binpath);
-  if(Bakery::App_WithDoc::file_exists(uri_binpath))
-    return true;
+  const std::string binpath = get_path_to_postgres_executable("postmaster");
+  // TODO: At least on Windows we should probably also check for initdb and
+  // pg_ctl. Perhaps it would also be a good idea to access these files as
+  // long as glom runs so they cannot be (re)moved.
+  if(!binpath.empty())
+  {
+    const Glib::ustring uri_binpath = Glib::filename_to_uri(binpath);
+    if(Bakery::App_WithDoc::file_exists(uri_binpath))
+      return true;
+  }
   else
   {
     #ifdef DISTRO_SPECIFIC_POSTGRES_INSTALL_IMPLEMENTED
@@ -1233,6 +1279,7 @@
 #endif // !GLOM_ENABLE_CLIENT_ONLY
 
 #ifndef GLOM_ENABLE_CLIENT_ONLY
+#ifndef G_OS_WIN32
 //static
 EpcContents* ConnectionPool::on_publisher_document_requested(EpcPublisher* publisher, const gchar* key, gpointer user_data)
 {
@@ -1401,11 +1448,13 @@
 
   std::cout << "debug: ConnectionPool::avahi_stop_publishing" << std::endl;
 
-
+#ifndef G_OS_WIN32
   epc_publisher_quit(m_epc_publisher);
+#endif // !G_OS_WIN32
   g_object_unref(m_epc_publisher);
   m_epc_publisher = NULL;
 }
+#endif // !G_OS_WIN32
 
 void ConnectionPool::set_get_document_func(const SlotGetDocument& slot)
 {

Modified: trunk/glom/libglom/connectionpool.h
==============================================================================
--- trunk/glom/libglom/connectionpool.h	(original)
+++ trunk/glom/libglom/connectionpool.h	Sun Jan 13 18:59:02 2008
@@ -196,12 +196,14 @@
   typedef sigc::slot<Document_Glom*> SlotGetDocument; 
   void set_get_document_func(const SlotGetDocument& slot);
 
+#ifndef G_OS_WIN32
   static EpcContents* on_publisher_document_requested (EpcPublisher* publisher, const gchar* key, gpointer user_data);
   static gboolean on_publisher_document_authentication(EpcAuthContext* context, const gchar* user_name, gpointer user_data);
 
   static void on_epc_progress_begin(const gchar *title, gpointer user_data);
   static void on_epc_progress_update(gdouble progress, const gchar* message, gpointer user_data);
   static void on_epc_progress_end(gpointer user_data);
+#endif // !G_OS_WIN32
 
 
   /** Check whether PostgreSQL is really available for self-hosting,
@@ -245,12 +247,14 @@
   static int discover_first_free_port(int start_port, int end_port);
 
   Document_Glom* get_document();
-#endif // !GLOM_ENABLE_CLIENT_ONLY
 
+#ifndef G_OS_WIN32
   /** Advertize self-hosting via avahi:
    */
   void avahi_start_publishing();
   void avahi_stop_publishing();
+#endif // !G_OS_WIN32
+#endif // !GLOM_ENABLE_CLIENT_ONLY
 
 protected:
 

Modified: trunk/glom/libglom/spawn_with_feedback.cc
==============================================================================
--- trunk/glom/libglom/spawn_with_feedback.cc	(original)
+++ trunk/glom/libglom/spawn_with_feedback.cc	Sun Jan 13 18:59:02 2008
@@ -54,7 +54,7 @@
   }
   catch(const Glib::SpawnError& ex)
   {
-    std::cerr << "Glom:: execute_command_line_on_thread_create() Exception while calling lib::spawn_command_line_sync(): " << ex.what() << std::endl;
+    std::cerr << "Glom:: execute_command_line_on_thread_create() Exception while calling Glib::spawn_command_line_sync(): " << ex.what() << std::endl;
   }
 #else
   // TODO: I guess we can't find out whether this failed.
@@ -189,7 +189,6 @@
   std::auto_ptr<Dialog_ProgressCreating> dialog_progress;
   dialog_progress.reset(dialog_temp);
 
-
   std::cout << std::endl << "debug: command_line: " << command << std::endl << std::endl;
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   // Execute the first thread asynchronously (so we don't wait for it):
@@ -199,7 +198,7 @@
   }
   catch(const Glib::SpawnError& ex)
   {
-    std::cerr << "Glom::Spawn::pulse_until_second_command_succeed() Exception while calling lib::spawn_command_line_async(): " << ex.what() << std::endl;
+    std::cerr << "Glom::Spawn::pulse_until_second_command_succeed() Exception while calling Glib::spawn_command_line_async(): " << ex.what() << std::endl;
   }
 #else
   // TODO: I guess we can't find out whether this failed.
@@ -241,7 +240,7 @@
     }
     catch(const Glib::SpawnError& ex)
     {
-      std::cerr << "Glom::execute_command_line_and_wait_until_second_command_returns_success() Exception while calling lib::spawn_command_line_sync(): " << ex.what() << std::endl;
+      std::cerr << "Glom::execute_command_line_and_wait_until_second_command_returns_success() Exception while calling Glib::spawn_command_line_sync(): " << ex.what() << std::endl;
     }
 #else
     // TODO: I guess we can't find out whether this failed.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]