Revision: 7303
          http://playerstage.svn.sourceforge.net/playerstage/?rev=7303&view=rev
Author:   rtv
Date:     2009-01-26 22:41:12 +0000 (Mon, 26 Jan 2009)

Log Message:
-----------
simplified plugin loader and added more informative error output to it

Modified Paths:
--------------
    code/player/trunk/CMakeLists.txt
    code/player/trunk/client_libs/libplayerc/CMakeLists.txt
    code/player/trunk/cmake/internal/LibraryUtils.cmake
    code/player/trunk/cmake/internal/SearchForStuff.cmake
    code/player/trunk/libplayercore/plugins.cc
    code/player/trunk/server/server.cc

Modified: code/player/trunk/CMakeLists.txt
===================================================================
--- code/player/trunk/CMakeLists.txt    2009-01-26 00:45:25 UTC (rev 7302)
+++ code/player/trunk/CMakeLists.txt    2009-01-26 22:41:12 UTC (rev 7303)
@@ -46,11 +46,15 @@
 INCLUDE (${PLAYER_CMAKE_DIR}/internal/LibraryUtils.cmake)
 
 # Set some common include directories, including the binary dir to get config.h
-INCLUDE_DIRECTORIES (${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR} 
${PROJECT_BINARY_DIR}/libplayercore)
+INCLUDE_DIRECTORIES (${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR} 
${PROJECT_BINARY_DIR}/libplayercore /opt/local/include )
 # Extra directories where needed libraries, etc may be located (set by the 
user)
 INCLUDE_DIRECTORIES (${PLAYER_EXTRA_INCLUDE_DIRS})
 LINK_DIRECTORIES (${PLAYER_EXTRA_LIB_DIRS})
 
+# rtv hack
+link_directories( /opt/local/lib )
+include_directories( /opt/local/include )
+
 # If on Windows, only build the client libraries. (this won't actually work 
yet cause libplayerc needs some stuff from core)
 ADD_SUBDIRECTORY (client_libs)
 ADD_SUBDIRECTORY (libplayercore)

Modified: code/player/trunk/client_libs/libplayerc/CMakeLists.txt
===================================================================
--- code/player/trunk/client_libs/libplayerc/CMakeLists.txt     2009-01-26 
00:45:25 UTC (rev 7302)
+++ code/player/trunk/client_libs/libplayerc/CMakeLists.txt     2009-01-26 
22:41:12 UTC (rev 7303)
@@ -1,7 +1,10 @@
 ADD_SUBDIRECTORY (bindings)
 
-INCLUDE_DIRECTORIES (${PROJECT_SOURCE_DIR}/client_libs)
+INCLUDE_DIRECTORIES (${PROJECT_SOURCE_DIR}/client_libs /opt/local/include)
 
+link_directories( /opt/local/lib )
+
+
 SET (PLAYERC_EXTRA_LINK_LIBRARIES)
 SET (playercSrcs    playerc.h
                     mclient.c
@@ -57,7 +60,7 @@
 APPEND_TO_CACHED_LIST (PLAYERC_EXTRA_LINK_LIBRARIES "Libs to link to with 
playerc" z m)
 
 PLAYER_ADD_LIBRARY (playerc ${playercSrcs})
-ADD_DEPENDENCIES (playerc player_interfaces playerxdr_src)
+ADD_DEPENDENCIES (playerc player_interfaces playerxdr_src )
 TARGET_LINK_LIBRARIES (playerc playerxdr playerutils playererror 
${PLAYERC_EXTRA_LINK_LIBRARIES})
 IF (HAVE_JPEG)
     TARGET_LINK_LIBRARIES (playerc playerjpeg)

Modified: code/player/trunk/cmake/internal/LibraryUtils.cmake
===================================================================
--- code/player/trunk/cmake/internal/LibraryUtils.cmake 2009-01-26 00:45:25 UTC 
(rev 7302)
+++ code/player/trunk/cmake/internal/LibraryUtils.cmake 2009-01-26 22:41:12 UTC 
(rev 7303)
@@ -10,7 +10,9 @@
     SET_TARGET_PROPERTIES (${_name} PROPERTIES
                             VERSION ${PLAYER_VERSION}
                             SOVERSION ${PLAYER_API_VERSION}
-                            INSTALL_NAME_DIR @rpath
+# @rpath is not expanded on OS X, so I replaced this line with the version 
below [see patch 2318489]
+#                            INSTALL_NAME_DIR @rpath
+                            INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib"
                             INSTALL_RPATH 
"${INSTALL_RPATH};${CMAKE_INSTALL_PREFIX}/lib"
                             BUILD_WITH_INSTALL_RPATH TRUE)
     INSTALL (TARGETS ${_name} DESTINATION lib/)

Modified: code/player/trunk/cmake/internal/SearchForStuff.cmake
===================================================================
--- code/player/trunk/cmake/internal/SearchForStuff.cmake       2009-01-26 
00:45:25 UTC (rev 7302)
+++ code/player/trunk/cmake/internal/SearchForStuff.cmake       2009-01-26 
22:41:12 UTC (rev 7303)
@@ -1,5 +1,6 @@
 INCLUDE (${PLAYER_CMAKE_DIR}/PlayerUtils.cmake)
 
+
 INCLUDE (CheckFunctionExists)
 INCLUDE (CheckIncludeFiles)
 INCLUDE (CheckLibraryExists)
@@ -51,6 +52,13 @@
 SET (CMAKE_REQUIRED_INCLUDES)
 SET (CMAKE_REQUIRED_LIBRARIES)
 
+link_directories( /opt/local/lib )
+include_directories( /opt/local/include )
+
+INCLUDE(CheckIncludeFile)
+CHECK_INCLUDE_FILE( jpeglib.h HAVE_JPEG_HEADER )
+MESSAGE( "Result" ${HAVE_JPEG_HEADER} )
+
 CHECK_LIBRARY_EXISTS (jpeg jpeg_read_header "${PLAYER_EXTRA_LIB_DIRS}" 
HAVE_LIBJPEG)
 CHECK_INCLUDE_FILES ("stdio.h;jpeglib.h" HAVE_JPEGLIB_H)
 IF (HAVE_LIBJPEG AND HAVE_JPEGLIB_H)

Modified: code/player/trunk/libplayercore/plugins.cc
===================================================================
--- code/player/trunk/libplayercore/plugins.cc  2009-01-26 00:45:25 UTC (rev 
7302)
+++ code/player/trunk/libplayercore/plugins.cc  2009-01-26 22:41:12 UTC (rev 
7303)
@@ -55,36 +55,6 @@
 
 #include "plugins.h"
 
-class plugin_path_list
-{
-public:
-       plugin_path_list(plugin_path_list * parent)
-       {
-               memset(fullpath,0,sizeof(fullpath));
-               next = NULL;
-               if (parent)
-               {
-                       parent->next = this;
-               }
-       }
-
-       ~plugin_path_list()
-       {
-               delete next;
-       }
-
-       plugin_path_list * last()
-       {
-               plugin_path_list * ret = NULL;
-               for (ret = this; ret->next != NULL; ret = ret->next);
-               return ret;
-       }
-
-       char fullpath[PATH_MAX];
-       plugin_path_list * next;
-};
-
-
 // Try to load a given plugin, using a particular search algorithm.
 // Returns true on success and false on failure.
 lt_dlhandle
@@ -92,9 +62,9 @@
 {
 #if HAVE_LIBLTDL
   static int init_done = 0;
-
+  
   if( !init_done )
-  {
+        {
     int errors = 0;
     if((errors = lt_dlinit()))
     {
@@ -105,110 +75,67 @@
     else
       init_done = 1;
   }
-
-  lt_dlhandle handle=NULL;
-  plugin_path_list paths(NULL);
-
-  char* playerpath;
-  char* tmp;
-  char* cfgdir;
-  unsigned int i,j;
-
+ 
   // allocate a buffer to put the searched paths in so we can just display the 
error at the end
   // rather than during plugin loading
   // see if we got an absolute path
   if(pluginname[0] == '/' || pluginname[0] == '~')
-  {
-    strncpy(paths.fullpath,pluginname,PATH_MAX);
-  }
+        {
+               PLAYER_WARN1( "absolute path plugin %s", pluginname );
+        }
   else
-  {
-    // we got a relative path, so search for the module
-    // did the user set PLAYERPATH?
-    if((playerpath = getenv("PLAYERPATH")))
-    {
-      PLAYER_MSG1(1,"PLAYERPATH: %s\n", playerpath);
+        {
+               // we got a relative path, so set up a search path
+               char* playerpath = NULL;
 
-      // yep, now parse it, as a colon-separated list of directories
-      i=0;
-      while(i<strlen(playerpath))
-      {
-        j=i;
-        while(j<strlen(playerpath))
-        {
-          if(playerpath[j] == ':')
-          {
-            break;
-          }
-          j++;
-        }
-        plugin_path_list * path = paths.last();
-        new plugin_path_list(path);
-        strncpy(path->fullpath,playerpath+i,j-i);
-        strcat(path->fullpath,"/");
-        strcat(path->fullpath,pluginname);
-
-        i=j+1;
-      }
-    }
-
-    // try to load it from the directory where the config file is
-    if(cfgfile)
-    {
-      // Note that dirname() modifies the contents, so
-      // we need to make a copy of the filename.
-      tmp = strdup(cfgfile);
-      assert(tmp);
-      plugin_path_list * path = paths.last();
-      new plugin_path_list(path);
-      cfgdir = dirname(tmp);
-      if(cfgdir[0] != '/' && cfgdir[0] != '~')
-      {
-        char * ret = getcwd(path->fullpath, PATH_MAX);
-        if (ret == NULL)
-        {
-               PLAYER_ERROR("Failed to get working directory");
-               assert(false);
-               // TODO: handle this error properly
-        }
-        strncat(path->fullpath,"/", PATH_MAX);
-      }
-      strncat(path->fullpath,cfgdir, PATH_MAX);
-      strncat(path->fullpath,"/", PATH_MAX);
-      strncat(path->fullpath,pluginname, PATH_MAX);
-      free(tmp); // this should ha
-    }
-
-    // try to load it from prefix/lib
-    plugin_path_list * path = paths.last();
-    new plugin_path_list(path);
-    strncpy(path->fullpath,PLAYER_INSTALL_PREFIX, PATH_MAX);
-    strncat(path->fullpath,"/lib/", PATH_MAX);
-    strncat(path->fullpath,pluginname, PATH_MAX);
-
-    // just pass the libname to lt_dlopenext, to see if it can handle it
-    // (this may work when the plugin is installed in a default system
-    // location).
-    path = paths.last();
-    strncpy(path->fullpath,pluginname,PATH_MAX);
-
-    PLAYER_MSG1(3, "loading plugin %s", pluginname);
-  }
-  for (plugin_path_list *path = &paths;!handle && path;path = path->next)
-  {
-    if((handle = lt_dlopenext(path->fullpath)))
-    {
-      break;
-    }
-  }
-
+               // start with $PLAYERPATH, if set
+               if(( playerpath = getenv("PLAYERPATH")))
+                 {
+                        if( lt_dlsetsearchpath( playerpath ) ) 
+                               PLAYER_ERROR( "failed to initialize plugin path 
to $PLAYERPATH" );
+                 }
+               
+               // add the working directory            
+               char workingdir[PATH_MAX];
+               getcwd( workingdir, PATH_MAX );
+               if( lt_dladdsearchdir( workingdir  ) )
+                 PLAYER_ERROR1( "failed to add working directory %s to the 
plugin path", workingdir );
+               
+               // add the directory where the config file is
+               if(cfgfile)
+                 {
+                        // Note that dirname() modifies the contents on some
+                        // platforms, so we need to make a copy of the 
filename.
+                        char* tmp = strdup(cfgfile);
+                        assert(tmp);
+                        char* cfgdir = dirname(tmp);                    
+                        if( lt_dladdsearchdir( cfgdir ) )
+                               PLAYER_ERROR1( "failed to add config file 
directory %s to the plugin path", cfgdir );                    
+                        free(tmp);
+                 }
+               
+               // add $PLAYER_INSTALL_PREFIX/lib               
+               char installdir[ PATH_MAX ];     
+               strncpy( installdir, PLAYER_INSTALL_PREFIX, PATH_MAX);
+               strncat( installdir, "/lib/", PATH_MAX);                        
                        
+               if( lt_dladdsearchdir( installdir ) )
+                               PLAYER_ERROR1( "failed to add working directory 
%s to the plugin path", installdir );
+        }
+  
+  PLAYER_MSG1(3, "loading plugin %s", pluginname);
+  
+  lt_dlhandle handle = handle = lt_dlopenext( pluginname );
+  
   if(!handle)
-  {
-    PLAYER_ERROR1("failed to load plugin %s, tried paths:",pluginname);
-    for (plugin_path_list *path = &paths;path;path = path->next)
-      PLAYER_ERROR1("\t%s", path->fullpath);
-  }
-
+        {
+               PLAYER_ERROR1( "Failed to load plugin %s.",
+                                                       pluginname );
+               PLAYER_ERROR1( "libtool reports error: %s",
+                                                       lt_dlerror() );
+               PLAYER_ERROR1( "plugin search path: %s",
+                                                       lt_dlgetsearchpath() );
+        }
+  
   return handle;
 
 #else

Modified: code/player/trunk/server/server.cc
===================================================================
--- code/player/trunk/server/server.cc  2009-01-26 00:45:25 UTC (rev 7302)
+++ code/player/trunk/server/server.cc  2009-01-26 22:41:12 UTC (rev 7303)
@@ -373,7 +373,7 @@
 PrintCopyrightMsg()
 {
   fprintf(stderr,"\n* Part of the Player/Stage/Gazebo Project 
[http://playerstage.sourceforge.net].\n";);
-  fprintf(stderr, "* Copyright (C) 2000 - 2006 Brian Gerkey, Richard Vaughan, 
Andrew Howard,\n* Nate Koenig, and contributors.");
+  fprintf(stderr, "* Copyright (C) 2000 - 2009 Brian Gerkey, Richard Vaughan, 
Andrew Howard,\n* Nate Koenig, and contributors.");
   fprintf(stderr," Released under the GNU General Public License.\n");
   fprintf(stderr,"* Player comes with ABSOLUTELY NO WARRANTY.  This is free 
software, and you\n* are welcome to redistribute it under certain conditions; 
see COPYING\n* for details.\n\n");
 }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to