Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

windows: Use windows API calls instead of libtool. #1490

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/mapnik/plugin.hpp
Expand Up @@ -29,8 +29,13 @@
// stl
#include <string>

#if defined(_WINDOWS)
# include <windows.h>
# define lt_dlhandle HMODULE
#else
// ltdl
#include <ltdl.h>
#endif

namespace mapnik
{
Expand Down
28 changes: 28 additions & 0 deletions src/datasource_cache.cpp
Expand Up @@ -31,7 +31,9 @@
#include <boost/algorithm/string.hpp>

// ltdl
#if !defined(_WINDOWS)
#include <ltdl.h>
#endif

// stl
#include <algorithm>
Expand All @@ -48,12 +50,16 @@ bool is_input_plugin (std::string const& filename)

datasource_cache::datasource_cache()
{
#if !defined(_WINDOWS)
if (lt_dlinit()) throw std::runtime_error("lt_dlinit() failed");
#endif
}

datasource_cache::~datasource_cache()
{
#if !defined(_WINDOWS)
lt_dlexit();
#endif
}

datasource_ptr datasource_cache::create(const parameters& params, bool bind)
Expand All @@ -80,20 +86,33 @@ datasource_ptr datasource_cache::create(const parameters& params, bool bind)
if ( ! itr->second->handle())
{
throw std::runtime_error(std::string("Cannot load library: ") +
#ifdef _WINDOWS
itr->second->name());
#else
lt_dlerror());
#endif // _WINDOWS
}

#ifdef _WINDOWS
create_ds* create_datasource =
reinterpret_cast<create_ds*>(GetProcAddress(itr->second->handle(), "create"));
#else
// http://www.mr-edd.co.uk/blog/supressing_gcc_warnings
#ifdef __GNUC__
__extension__
#endif
create_ds* create_datasource =
reinterpret_cast<create_ds*>(lt_dlsym(itr->second->handle(), "create"));
#endif // _WINDOWS

if (! create_datasource)
{
throw std::runtime_error(std::string("Cannot load symbols: ") +
#ifdef _WINDOWS
"plugin is lacking compatible interface");
#else
lt_dlerror());
#endif // _WINDOWS
}

#ifdef MAPNIK_LOG
Expand Down Expand Up @@ -174,15 +193,24 @@ bool datasource_cache::register_datasource(std::string const& str)
bool success = false;
try
{
#ifdef _WINDOWS
lt_dlhandle module = LoadLibraryA(str.c_str());
#else
lt_dlhandle module = lt_dlopen(str.c_str());
#endif // _WINDOWS
if (module)
{
#ifdef _WINDOWS
datasource_name* ds_name =
reinterpret_cast<datasource_name*>(GetProcAddress(module, "datasource_name"));
#else
// http://www.mr-edd.co.uk/blog/supressing_gcc_warnings
#ifdef __GNUC__
__extension__
#endif
datasource_name* ds_name =
reinterpret_cast<datasource_name*>(lt_dlsym(module, "datasource_name"));
#endif // _WINDOWS
if (ds_name && insert(ds_name(),module))
{
MAPNIK_LOG_DEBUG(datasource_cache) << "datasource_cache: Registered=" << ds_name();
Expand Down
36 changes: 36 additions & 0 deletions src/load_map.cpp
Expand Up @@ -67,6 +67,10 @@
#include <iostream>
#include <sstream>

#ifdef _WINDOWS
#include <Windows.h>
#endif

using boost::tokenizer;

using std::endl;
Expand Down Expand Up @@ -130,6 +134,27 @@ class map_parser : boost::noncopyable {
std::map<std::string,font_set> fontsets_;
};

#ifdef _WINDOWS
std::string wstring2string(const std::wstring& s)
{
int slength = (int)s.length() + 1;
int len = ::WideCharToMultiByte(CP_ACP, 0, s.c_str(), slength, 0, 0, 0, 0);
boost::scoped_array<char> buf_ptr(new char [len+1]);
::WideCharToMultiByte(CP_ACP, 0, s.c_str(), slength, buf_ptr.get(), len, 0, 0);
std::string r(buf_ptr.get());
return r;
}

std::wstring utf8ToWide( const std::string& str )
{
int len = ::MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, 0, 0);
boost::scoped_array<wchar_t> buf_ptr(new wchar_t [len+1]);
::MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, buf_ptr.get(), len);
std::wstring rt(buf_ptr.get());
return rt;
}
#endif

//#include <mapnik/internal/dump_xml.hpp>
void load_map(Map & map, std::string const& filename, bool strict)
{
Expand Down Expand Up @@ -680,7 +705,18 @@ void map_parser::parse_layer(Map & map, xml_node const& node)
{
std::string name = paramIter->get_attr<std::string>("name");
std::string value = paramIter->get_text();
#ifdef _WINDOWS
if (name == "file")
{
params[name] = wstring2string(utf8ToWide(value));
}
else
{
params[name] = value;
}
#else
params[name] = value;
#endif
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/plugin.cpp
Expand Up @@ -21,7 +21,6 @@
*****************************************************************************/

#include <mapnik/plugin.hpp>
#include <ltdl.h>

namespace mapnik
{
Expand All @@ -33,7 +32,11 @@ PluginInfo::~PluginInfo()
{
if (module_)
{
lt_dlclose(module_),module_=0;
#if defined(_WINDOWS)
FreeLibrary(module_);
#else
lt_dlclose(module_);
#endif
}
}

Expand Down