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 LIB_PREFIX
#define OTHER_LIBS $[if $[OSX_PLATFORM],subprocbuffer] #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 \ #define COMBINED_SOURCES \
$[TARGET]_composite1.cxx $[TARGET]_composite1.cxx

View File

@ -123,8 +123,8 @@ static void unload_dso();
// path. // path.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool bool
load_plugin(const string &p3d_plugin_filename, load_plugin(const string &p3d_plugin_filename, const string &contents_filename,
const string &contents_filename) { const string &download_url, const string &platform) {
string filename = p3d_plugin_filename; string filename = p3d_plugin_filename;
if (filename.empty()) { if (filename.empty()) {
// Look for the plugin along the path. // Look for the plugin along the path.
@ -293,7 +293,8 @@ load_plugin(const string &p3d_plugin_filename,
// Successfully loaded. // Successfully loaded.
plugin_loaded = true; 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. // Oops, failure to initialize.
cerr << "Failed to initialize plugin (wrong API version?)\n"; cerr << "Failed to initialize plugin (wrong API version?)\n";
unload_plugin(); 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; extern P3D_instance_handle_event_func *P3D_instance_handle_event;
string get_plugin_basename(); string get_plugin_basename();
bool load_plugin(const string &p3d_plugin_filename, bool
const string &contents_filename); load_plugin(const string &p3d_plugin_filename, const string &contents_filename,
const string &download_url, const string &platform);
void unload_plugin(); void unload_plugin();
bool is_plugin_loaded(); bool is_plugin_loaded();

View File

@ -26,6 +26,10 @@
#include "fileSpec.h" #include "fileSpec.h"
#include "get_tinyxml.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 #ifdef _WIN32
#include <shlobj.h> #include <shlobj.h>
#else #else
@ -120,14 +124,29 @@ P3DInstanceManager::
// redownloaded. // redownloaded.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool P3DInstanceManager:: bool P3DInstanceManager::
initialize(const string &contents_filename) { initialize(const string &contents_filename, const string &download_url,
const string &platform) {
_root_dir = find_root_dir(); _root_dir = find_root_dir();
_download_url = P3D_PLUGIN_DOWNLOAD; _download_url = download_url;
_platform = P3D_PLUGIN_PLATFORM; 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 nout << "_root_dir = " << _root_dir
<< ", contents = " << contents_filename
<< ", download = " << _download_url << ", download = " << _download_url
<< ", contents = " << contents_filename << "\n"; << ", platform = " << _platform
<< "\n";
if (_root_dir.empty()) { if (_root_dir.empty()) {
nout << "Could not find root directory.\n"; nout << "Could not find root directory.\n";

View File

@ -39,7 +39,9 @@ private:
~P3DInstanceManager(); ~P3DInstanceManager();
public: 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; inline bool is_initialized() const;

View File

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

View File

@ -79,7 +79,7 @@ extern "C" {
(below). This number will be incremented whenever there are changes (below). This number will be incremented whenever there are changes
to any of the interface specifications defined in this header to any of the interface specifications defined in this header
file. */ file. */
#define P3D_API_VERSION 5 #define P3D_API_VERSION 6
/************************ GLOBAL FUNCTIONS **************************/ /************************ GLOBAL FUNCTIONS **************************/
@ -95,12 +95,19 @@ extern "C" {
file that has already been downloaded and verified from the server. file that has already been downloaded and verified from the server.
If this is NULL, a new file will be downloaded as needed. 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 This function returns true if the core API is valid and uses a
compatible API, false otherwise. If it returns false, the host compatible API, false otherwise. If it returns false, the host
should not call any more functions in this API, and should should not call any more functions in this API, and should
immediately unload the DLL and (if possible) download a new one. */ immediately unload the DLL and (if possible) download a new one. */
typedef bool 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 /* This function should be called to unload the core API. It will
release all internally-allocated memory and return the core API to release all internally-allocated memory and return the core API to

View File

@ -26,6 +26,11 @@
#include "p3d_plugin.h" #include "p3d_plugin.h"
#include "p3d_lock.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 <iostream>
#include <fstream> #include <fstream>
#include <string> #include <string>

View File

@ -16,28 +16,12 @@
#$[]define P3D_PLUGIN_LOGFILE1 "$[subst \,\\,$[osfilename $[P3D_PLUGIN_LOGFILE1]]]" #$[]define P3D_PLUGIN_LOGFILE1 "$[subst \,\\,$[osfilename $[P3D_PLUGIN_LOGFILE1]]]"
#$[]define P3D_PLUGIN_LOGFILE2 "$[subst \,\\,$[osfilename $[P3D_PLUGIN_LOGFILE2]]]" #$[]define P3D_PLUGIN_LOGFILE2 "$[subst \,\\,$[osfilename $[P3D_PLUGIN_LOGFILE2]]]"
/* Temporary: the location at which p3dpython.exe can be found. Empty /* For development only: the location at which p3dpython.exe can be
string for the default. */ found. Empty string for the default. */
#$[]define P3D_PLUGIN_P3DPYTHON "$[subst \,\\,$[osfilename $[P3D_PLUGIN_P3DPYTHON]]]" #$[]define P3D_PLUGIN_P3DPYTHON "$[subst \,\\,$[osfilename $[P3D_PLUGIN_P3DPYTHON]]]"
/* Temporary: the location at which p3d_plugin.dll can be found. Empty /* For development only: the location at which p3d_plugin.dll/.so can
string for the default. */ be found. Empty string for the default. */
#$[]define P3D_PLUGIN_P3D_PLUGIN "$[subst \,\\,$[osfilename $[P3D_PLUGIN_P3D_PLUGIN]]]" #$[]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 #end p3d_plugin_config.h

View File

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

View File

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

View File

@ -42,11 +42,13 @@ public:
int run(int argc, char *argv[]); int run(int argc, char *argv[]);
private: 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 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); 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); TiXmlElement *xpackage);
void run_getters(); void run_getters();
void handle_request(P3D_request *request); void handle_request(P3D_request *request);