Skip to content

Commit

Permalink
provide implementation for plugin versioning #154
Browse files Browse the repository at this point in the history
  • Loading branch information
hobu committed Jul 5, 2013
1 parent e0bf546 commit 8866afe
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 7 deletions.
5 changes: 4 additions & 1 deletion include/pdal/Utils.hpp
Expand Up @@ -193,7 +193,10 @@ class PDAL_DLL Utils

}

static void registerPlugin(void* stageFactoryPtr, std::string const& filename, std::string const& method);
static void* registerPlugin( void* stageFactoryPtr,
std::string const& filename,
std::string const& registerMethodName,
std::string const& versionMethodName);

static char* getenv(const char* env);
static std::string getenv(std::string const& name);
Expand Down
1 change: 1 addition & 0 deletions include/pdal/pdal_config.hpp
Expand Up @@ -66,6 +66,7 @@ PDAL_DLL int GetVersionPatch();




} // namespace pdal

#endif
9 changes: 9 additions & 0 deletions include/pdal/pdal_error.hpp
Expand Up @@ -299,6 +299,15 @@ class python_error : public std::runtime_error
{}
};

class plugin_error : public std::runtime_error
{
public:
plugin_error(std::string const& msg)
: std::runtime_error(msg)
{}
};


} // namespace pdal

#endif // PDAL_EXCEPTION_HPP_INCLUDED
9 changes: 9 additions & 0 deletions include/pdal/pdal_macros.hpp
Expand Up @@ -107,4 +107,13 @@
} \
PDAL_C_END

#define SET_PLUGIN_VERSION(DriverName) \
PDAL_C_START PDAL_DLL int PDALRegister_version_##DriverName() \
{ \
return PDAL_PLUGIN_VERSION; \
} \
PDAL_C_END


#endif

2 changes: 2 additions & 0 deletions pdal_defines.h.in
Expand Up @@ -17,6 +17,8 @@

#define PDAL_VERSION_STRING "@PDAL_VERSION_STRING@"

#define PDAL_PLUGIN_VERSION 1

/* (note this will look yucky until we get to major>=1) */
#define PDAL_VERSION_INTEGER ((PDAL_VERSION_MAJOR*100*100)+(PDAL_VERSION_MINOR*100)+PDAL_VERSION_PATCH)

Expand Down
11 changes: 8 additions & 3 deletions src/StageFactory.cpp
Expand Up @@ -527,7 +527,6 @@ void StageFactory::loadPlugins()
{
using namespace boost::filesystem;

typedef boost::tokenizer<boost::char_separator<char> > tokenizer;

std::string driver_path("PDAL_DRIVER_PATH");
std::string pluginDir = Utils::getenv(driver_path);
Expand Down Expand Up @@ -636,8 +635,14 @@ void StageFactory::registerPlugin(std::string const& filename)
}
}

std::string methodName = "PDALRegister_" + boost::algorithm::ireplace_first_copy(basename.string(), "libpdal_plugin_", "");
Utils::registerPlugin((void*)this, filename, methodName);
std::string base = basename.string();

std::string registerMethodName = "PDALRegister_" + \
boost::algorithm::ireplace_first_copy(base, "libpdal_plugin_", "");

std::string versionMethodName = "PDALRegister_version_" + base.substr( base.find_last_of("_")+1, base.size());

Utils::registerPlugin((void*)this, filename, registerMethodName, versionMethodName);

}

Expand Down
24 changes: 21 additions & 3 deletions src/Utils.cpp
Expand Up @@ -75,20 +75,38 @@ double Utils::random(double minimum, double maximum)
return t;
}

void Utils::registerPlugin(void* stageFactoryPtr, std::string const& filename, std::string const& method)
void* Utils::registerPlugin( void* stageFactoryPtr,
std::string const& filename,
std::string const& registerMethod,
std::string const& versionMethod)
{
void* pRegister;
void* pVersion;

pRegister = Utils::getDLLSymbol(filename, method);
pVersion = Utils::getDLLSymbol(filename, versionMethod);

int plugins_version = ((int (*)()) pVersion)();

if (plugins_version != PDAL_PLUGIN_VERSION)
{
std::ostringstream oss;
oss << "Unable to register shared library '" << filename << "' with method name '" << registerMethod << "' version of plugin, '" << plugins_version << "' did not match PDALs version '" << PDAL_PLUGIN_VERSION << "'";
throw pdal_error(oss.str());
}


pRegister = Utils::getDLLSymbol(filename, registerMethod);
if (pRegister != NULL)
{
((void (*)(void*)) pRegister)(stageFactoryPtr);
} else
{
std::ostringstream oss;
oss << "Unable to register shared library '" << filename << "' with method name '" << method << "'";
oss << "Unable to register shared library '" << filename << "' with method name '" << registerMethod << "'";
throw pdal_error(oss.str());
}

return pRegister;
}


Expand Down

0 comments on commit 8866afe

Please sign in to comment.