integrate DTOOL_PLATFORM etc

This commit is contained in:
David Rose 2009-08-03 19:43:48 +00:00
parent 9908148679
commit 6ebcfc5f89
12 changed files with 99 additions and 65 deletions

View File

@ -9,12 +9,6 @@
#define LIB_PREFIX
#define OTHER_LIBS $[if $[OSX_PLATFORM],subprocbuffer]
// We need this because we don't
// include dtool_config.h.
#if $[HAVE_X11]
#define EXTRA_CDEFS HAVE_X11
#endif
#define COMBINED_SOURCES \
$[TARGET]_composite1.cxx

View File

@ -123,8 +123,8 @@ static void unload_dso();
// path.
////////////////////////////////////////////////////////////////////
bool
load_plugin(const string &p3d_plugin_filename,
const string &contents_filename) {
load_plugin(const string &p3d_plugin_filename, const string &contents_filename,
const string &download_url, const string &platform) {
string filename = p3d_plugin_filename;
if (filename.empty()) {
// Look for the plugin along the path.
@ -293,7 +293,8 @@ load_plugin(const string &p3d_plugin_filename,
// Successfully loaded.
plugin_loaded = true;
if (!P3D_initialize(P3D_API_VERSION, contents_filename.c_str())) {
if (!P3D_initialize(P3D_API_VERSION, contents_filename.c_str(),
download_url.c_str(), platform.c_str())) {
// Oops, failure to initialize.
cerr << "Failed to initialize plugin (wrong API version?)\n";
unload_plugin();

View File

@ -58,8 +58,9 @@ extern P3D_instance_feed_url_stream_func *P3D_instance_feed_url_stream;
extern P3D_instance_handle_event_func *P3D_instance_handle_event;
string get_plugin_basename();
bool load_plugin(const string &p3d_plugin_filename,
const string &contents_filename);
bool
load_plugin(const string &p3d_plugin_filename, const string &contents_filename,
const string &download_url, const string &platform);
void unload_plugin();
bool is_plugin_loaded();

View File

@ -26,6 +26,10 @@
#include "fileSpec.h"
#include "get_tinyxml.h"
// We can include this header file to get the DTOOL_PLATFORM
// definition, even though we don't link with dtool.
#include "dtool_platform.h"
#ifdef _WIN32
#include <shlobj.h>
#else
@ -120,14 +124,29 @@ P3DInstanceManager::
// redownloaded.
////////////////////////////////////////////////////////////////////
bool P3DInstanceManager::
initialize(const string &contents_filename) {
initialize(const string &contents_filename, const string &download_url,
const string &platform) {
_root_dir = find_root_dir();
_download_url = P3D_PLUGIN_DOWNLOAD;
_platform = P3D_PLUGIN_PLATFORM;
_download_url = download_url;
if (_download_url.empty()) {
_download_url = P3D_PLUGIN_DOWNLOAD;
}
_platform = platform;
if (_platform.empty()) {
_platform = DTOOL_PLATFORM;
}
// Ensure that the download URL ends with a slash.
if (!_download_url.empty() && _download_url[_download_url.size() - 1] != '/') {
_download_url += "/";
}
nout << "_root_dir = " << _root_dir
<< ", contents = " << contents_filename
<< ", download = " << _download_url
<< ", contents = " << contents_filename << "\n";
<< ", platform = " << _platform
<< "\n";
if (_root_dir.empty()) {
nout << "Could not find root directory.\n";

View File

@ -39,7 +39,9 @@ private:
~P3DInstanceManager();
public:
bool initialize(const string &contents_xml_filename);
bool initialize(const string &contents_filename,
const string &download_url,
const string &platform);
inline bool is_initialized() const;

View File

@ -38,7 +38,8 @@ ostream *nout_stream;
bool
P3D_initialize(int api_version, const char *contents_filename) {
P3D_initialize(int api_version, const char *contents_filename,
const char *download_url, const char *platform) {
if (api_version != P3D_API_VERSION) {
// Can't accept an incompatible version.
return false;
@ -54,6 +55,14 @@ P3D_initialize(int api_version, const char *contents_filename) {
contents_filename = "";
}
if (download_url == NULL){
download_url = "";
}
if (platform == NULL) {
platform = "";
}
#ifdef P3D_PLUGIN_LOGFILE2
string logfilename = P3D_PLUGIN_LOGFILE2;
#else
@ -83,7 +92,7 @@ P3D_initialize(int api_version, const char *contents_filename) {
}
P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr();
bool result = inst_mgr->initialize(contents_filename);
bool result = inst_mgr->initialize(contents_filename, download_url, platform);
RELEASE_LOCK(_api_lock);
return result;
}

View File

@ -79,7 +79,7 @@ extern "C" {
(below). This number will be incremented whenever there are changes
to any of the interface specifications defined in this header
file. */
#define P3D_API_VERSION 5
#define P3D_API_VERSION 6
/************************ GLOBAL FUNCTIONS **************************/
@ -95,12 +95,19 @@ extern "C" {
file that has already been downloaded and verified from the server.
If this is NULL, a new file will be downloaded as needed.
If download_url is not NULL or empty, it specifies the root URL of
the download server; otherwise, the compiled-in default is used.
If platform is not NULL or empty, it specifies the current platform
string; otherwise, the compiled-in default is used.
This function returns true if the core API is valid and uses a
compatible API, false otherwise. If it returns false, the host
should not call any more functions in this API, and should
immediately unload the DLL and (if possible) download a new one. */
typedef bool
P3D_initialize_func(int api_version, const char *contents_filename);
P3D_initialize_func(int api_version, const char *contents_filename,
const char *download_url, const char *platform);
/* This function should be called to unload the core API. It will
release all internally-allocated memory and return the core API to

View File

@ -26,6 +26,11 @@
#include "p3d_plugin.h"
#include "p3d_lock.h"
// It's a good idea to pick up this header file, even though we don't
// actually link with dtool. This header file defines useful
// system-wide config settings.
#include "dtool_config.h"
#include <iostream>
#include <fstream>
#include <string>

View File

@ -16,28 +16,12 @@
#$[]define P3D_PLUGIN_LOGFILE1 "$[subst \,\\,$[osfilename $[P3D_PLUGIN_LOGFILE1]]]"
#$[]define P3D_PLUGIN_LOGFILE2 "$[subst \,\\,$[osfilename $[P3D_PLUGIN_LOGFILE2]]]"
/* Temporary: the location at which p3dpython.exe can be found. Empty
string for the default. */
/* For development only: the location at which p3dpython.exe can be
found. Empty string for the default. */
#$[]define P3D_PLUGIN_P3DPYTHON "$[subst \,\\,$[osfilename $[P3D_PLUGIN_P3DPYTHON]]]"
/* Temporary: the location at which p3d_plugin.dll can be found. Empty
string for the default. */
/* For development only: the location at which p3d_plugin.dll/.so can
be found. Empty string for the default. */
#$[]define P3D_PLUGIN_P3D_PLUGIN "$[subst \,\\,$[osfilename $[P3D_PLUGIN_P3D_PLUGIN]]]"
/* The string that corresponds to this particular platform. */
#if $[not $[P3D_PLUGIN_PLATFORM]]
#if $[WINDOWS_PLATFORM]
#define P3D_PLUGIN_PLATFORM win32
#elif $[UNIX_PLATFORM]
#if $[eq $[shell uname -m], x86_64]
#define P3D_PLUGIN_PLATFORM linux.amd64
#else
#define P3D_PLUGIN_PLATFORM linux.i386
#endif
#else
#define P3D_PLUGIN_PLATFORM osx.i386
#endif
#endif
#$[]define P3D_PLUGIN_PLATFORM "$[P3D_PLUGIN_PLATFORM]"
#end p3d_plugin_config.h

View File

@ -20,6 +20,10 @@
#include "find_root_dir.h"
#include "mkdir_complete.h"
// We can include this header file to get the DTOOL_PLATFORM
// definition, even though we don't link with dtool.
#include "dtool_platform.h"
#include <fstream>
#include <string.h> // strcmp()
@ -711,7 +715,7 @@ read_contents_file(const string &contents_filename) {
const char *name = xpackage->Attribute("name");
if (name != NULL && strcmp(name, "coreapi") == 0) {
const char *platform = xpackage->Attribute("platform");
if (platform != NULL && strcmp(platform, P3D_PLUGIN_PLATFORM) == 0) {
if (platform != NULL && strcmp(platform, DTOOL_PLATFORM) == 0) {
get_core_api(xpackage);
return true;
}
@ -723,7 +727,7 @@ read_contents_file(const string &contents_filename) {
// Couldn't find the coreapi package description.
nout << "No coreapi package defined in contents file for "
<< P3D_PLUGIN_PLATFORM << "\n";
<< DTOOL_PLATFORM << "\n";
return false;
}
@ -932,7 +936,7 @@ do_load_plugin() {
}
#endif // P3D_PLUGIN_P3D_PLUGIN
if (!load_plugin(pathname, "")) {
if (!load_plugin(pathname, "", "", "")) {
nout << "Unable to launch core API in " << pathname << "\n";
return;
}

View File

@ -18,6 +18,10 @@
#include "find_root_dir.h"
#include "p3d_plugin_config.h"
// We can include this header file to get the DTOOL_PLATFORM
// definition, even though we don't link with dtool.
#include "dtool_platform.h"
#include <sstream>
#ifdef _WIN32
#include <windows.h>
@ -54,8 +58,8 @@ run(int argc, char *argv[]) {
extern int optind;
const char *optstr = "u:p:fl:t:s:o:h";
string root_url = P3D_PLUGIN_DOWNLOAD;
string this_platform = P3D_PLUGIN_PLATFORM;
string download_url = P3D_PLUGIN_DOWNLOAD;
string this_platform = DTOOL_PLATFORM;
bool force_download = false;
Filename output_filename;
@ -68,7 +72,7 @@ run(int argc, char *argv[]) {
while (flag != EOF) {
switch (flag) {
case 'u':
root_url = optarg;
download_url = optarg;
break;
case 'p':
@ -130,11 +134,11 @@ run(int argc, char *argv[]) {
}
// Make sure it ends with a slash.
if (!root_url.empty() && root_url[root_url.length() - 1] != '/') {
root_url += '/';
if (!download_url.empty() && download_url[download_url.length() - 1] != '/') {
download_url += '/';
}
if (!get_plugin(root_url, this_platform, force_download)) {
if (!get_plugin(download_url, this_platform, force_download)) {
cerr << "Unable to load Panda3D plugin.\n";
return 1;
}
@ -284,16 +288,16 @@ run(int argc, char *argv[]) {
// true on success, false on failure.
////////////////////////////////////////////////////////////////////
bool Panda3D::
get_plugin(const string &root_url, const string &this_platform, bool force_download) {
get_plugin(const string &download_url, const string &this_platform, bool force_download) {
// First, look for the existing contents.xml file.
Filename contents_filename = Filename(Filename::from_os_specific(_root_dir), "contents.xml");
if (!force_download && read_contents_file(contents_filename, root_url, this_platform)) {
if (!force_download && read_contents_file(contents_filename, download_url, this_platform)) {
// Got the file, and it's good.
return true;
}
// Couldn't read it, so go get it.
string url = root_url;
string url = download_url;
url += "contents.xml";
cerr << "Getting URL " << url << "\n";
@ -305,7 +309,7 @@ get_plugin(const string &root_url, const string &this_platform, bool force_downl
return false;
}
return read_contents_file(contents_filename, root_url, this_platform);
return read_contents_file(contents_filename, download_url, this_platform);
}
////////////////////////////////////////////////////////////////////
@ -316,7 +320,7 @@ get_plugin(const string &root_url, const string &this_platform, bool force_downl
// possible. Returns true on success, false on failure.
////////////////////////////////////////////////////////////////////
bool Panda3D::
read_contents_file(Filename contents_filename, const string &root_url,
read_contents_file(Filename contents_filename, const string &download_url,
const string &this_platform) {
ifstream in;
contents_filename.set_text();
@ -336,7 +340,8 @@ read_contents_file(Filename contents_filename, const string &root_url,
if (name != NULL && strcmp(name, "coreapi") == 0) {
const char *xplatform = xpackage->Attribute("platform");
if (xplatform != NULL && strcmp(xplatform, this_platform.c_str()) == 0) {
return get_core_api(contents_filename, root_url, xpackage);
return get_core_api(contents_filename, download_url, this_platform,
xpackage);
}
}
@ -359,13 +364,13 @@ read_contents_file(Filename contents_filename, const string &root_url,
// if necessary.
////////////////////////////////////////////////////////////////////
bool Panda3D::
get_core_api(const Filename &contents_filename, const string &root_url,
TiXmlElement *xpackage) {
get_core_api(const Filename &contents_filename, const string &download_url,
const string &this_platform, TiXmlElement *xpackage) {
_core_api_dll.load_xml(xpackage);
if (!_core_api_dll.quick_verify(_root_dir)) {
// The DLL file needs to be downloaded. Go get it.
string url = root_url;
string url = download_url;
url += _core_api_dll.get_filename();
Filename pathname = Filename::from_os_specific(_core_api_dll.get_pathname(_root_dir));
@ -398,7 +403,8 @@ get_core_api(const Filename &contents_filename, const string &root_url,
}
#endif // P3D_PLUGIN_P3D_PLUGIN
if (!load_plugin(pathname, contents_filename.to_os_specific())) {
if (!load_plugin(pathname, contents_filename.to_os_specific(),
download_url, this_platform)) {
cerr << "Unable to launch core API in " << pathname << "\n" << flush;
return false;
}
@ -670,11 +676,11 @@ usage() {
<< " -u url\n"
<< " Specify the URL of the Panda3D download server. The default is\n"
<< " " << P3D_PLUGIN_DOWNLOAD << "\n\n"
<< " \"" << P3D_PLUGIN_DOWNLOAD << "\" .\n\n"
<< " -p platform\n"
<< " Specify the platform to masquerade as. The default is "
<< P3D_PLUGIN_PLATFORM << "\n\n";
<< " Specify the platform to masquerade as. The default is \""
<< DTOOL_PLATFORM << "\" .\n\n";
}
////////////////////////////////////////////////////////////////////

View File

@ -42,11 +42,13 @@ public:
int run(int argc, char *argv[]);
private:
bool get_plugin(const string &root_url, const string &this_platform,
bool get_plugin(const string &download_url, const string &this_platform,
bool force_download);
bool read_contents_file(Filename contents_filename, const string &root_url,
bool read_contents_file(Filename contents_filename,
const string &download_url,
const string &this_platform);
bool get_core_api(const Filename &contents_filename, const string &root_url,
bool get_core_api(const Filename &contents_filename,
const string &download_url, const string &this_platform,
TiXmlElement *xpackage);
void run_getters();
void handle_request(P3D_request *request);