From dcc5447688f10ffc583364b14776b633b4def285 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 9 Oct 2009 23:54:45 +0000 Subject: [PATCH] plugin version --- direct/src/p3d/FileSpec.py | 2 +- direct/src/plugin/fileSpec.I | 11 ++++ direct/src/plugin/fileSpec.h | 1 + direct/src/plugin/load_plugin.cxx | 5 ++ direct/src/plugin/load_plugin.h | 1 + direct/src/plugin/p3dInstance.cxx | 19 ++++++ direct/src/plugin/p3dInstanceManager.I | 80 ++++++++++++++++++++++++ direct/src/plugin/p3dInstanceManager.cxx | 27 ++++++++ direct/src/plugin/p3dInstanceManager.h | 19 ++++++ direct/src/plugin/p3dMainObject.cxx | 2 + direct/src/plugin/p3d_plugin.cxx | 20 ++++++ direct/src/plugin/p3d_plugin.h | 9 +++ direct/src/plugin_npapi/ppInstance.cxx | 12 ++++ direct/src/plugin_standalone/panda3d.cxx | 11 ++++ dtool/Package.pp | 8 ++- dtool/PandaVersion.pp | 8 +++ dtool/src/dtoolutil/pandaVersion.h.pp | 7 +++ 17 files changed, 239 insertions(+), 3 deletions(-) diff --git a/direct/src/p3d/FileSpec.py b/direct/src/p3d/FileSpec.py index 09885d751a..4aa19eeba2 100644 --- a/direct/src/p3d/FileSpec.py +++ b/direct/src/p3d/FileSpec.py @@ -64,7 +64,7 @@ class FileSpec: if self.size: xelement.SetAttribute('size', str(self.size)) if self.timestamp: - xelement.SetAttribute('timestamp', str(self.timestamp)) + xelement.SetAttribute('timestamp', str(int(self.timestamp))) if self.hash: xelement.SetAttribute('hash', self.hash) diff --git a/direct/src/plugin/fileSpec.I b/direct/src/plugin/fileSpec.I index f511ff8ac7..88ade091d6 100755 --- a/direct/src/plugin/fileSpec.I +++ b/direct/src/plugin/fileSpec.I @@ -56,6 +56,17 @@ get_size() const { return _size; } +//////////////////////////////////////////////////////////////////// +// Function: FileSpec::get_timestamp +// Access: Public +// Description: Returns the expected last-modify timestamp of this +// file on disk. +//////////////////////////////////////////////////////////////////// +inline time_t FileSpec:: +get_timestamp() const { + return _timestamp; +} + //////////////////////////////////////////////////////////////////// // Function: FileSpec::get_actual_file // Access: Public diff --git a/direct/src/plugin/fileSpec.h b/direct/src/plugin/fileSpec.h index 27a409fc76..09ecfe1913 100755 --- a/direct/src/plugin/fileSpec.h +++ b/direct/src/plugin/fileSpec.h @@ -39,6 +39,7 @@ public: inline void set_filename(const string &filename); inline string get_pathname(const string &package_dir) const; inline size_t get_size() const; + inline time_t get_timestamp() const; bool quick_verify(const string &package_dir); bool quick_verify_pathname(const string &pathname); diff --git a/direct/src/plugin/load_plugin.cxx b/direct/src/plugin/load_plugin.cxx index 1d6486ccbf..fe77deabfa 100755 --- a/direct/src/plugin/load_plugin.cxx +++ b/direct/src/plugin/load_plugin.cxx @@ -36,6 +36,7 @@ static const string default_plugin_filename = "p3d_plugin"; P3D_initialize_func *P3D_initialize; P3D_finalize_func *P3D_finalize; +P3D_set_plugin_version_func *P3D_set_plugin_version; P3D_set_super_mirror_func *P3D_set_super_mirror; P3D_new_instance_func *P3D_new_instance; P3D_instance_start_func *P3D_instance_start; @@ -188,6 +189,7 @@ load_plugin(const string &p3d_plugin_filename, // Now get all of the function pointers. P3D_initialize = (P3D_initialize_func *)get_func(module, "P3D_initialize"); P3D_finalize = (P3D_finalize_func *)get_func(module, "P3D_finalize"); + P3D_set_plugin_version = (P3D_set_plugin_version_func *)get_func(module, "P3D_set_plugin_version"); P3D_set_super_mirror = (P3D_set_super_mirror_func *)get_func(module, "P3D_set_super_mirror"); P3D_new_instance = (P3D_new_instance_func *)get_func(module, "P3D_new_instance"); P3D_instance_start = (P3D_instance_start_func *)get_func(module, "P3D_instance_start"); @@ -228,6 +230,7 @@ load_plugin(const string &p3d_plugin_filename, // Ensure that all of the function pointers have been found. if (P3D_initialize == NULL || P3D_finalize == NULL || + P3D_set_plugin_version == NULL || P3D_set_super_mirror == NULL || P3D_new_instance == NULL || P3D_instance_start == NULL || @@ -268,6 +271,7 @@ load_plugin(const string &p3d_plugin_filename, << "Some function pointers not found:" << "\nP3D_initialize = " << P3D_initialize << "\nP3D_finalize = " << P3D_finalize + << "\nP3D_set_plugin_version = " << P3D_set_plugin_version << "\nP3D_set_super_mirror = " << P3D_set_super_mirror << "\nP3D_new_instance = " << P3D_new_instance << "\nP3D_instance_start = " << P3D_instance_start @@ -362,6 +366,7 @@ unload_dso() { P3D_initialize = NULL; P3D_finalize = NULL; + P3D_set_plugin_version = NULL; P3D_set_super_mirror = NULL; P3D_new_instance = NULL; P3D_instance_start = NULL; diff --git a/direct/src/plugin/load_plugin.h b/direct/src/plugin/load_plugin.h index 7de6aa79bb..0432411029 100755 --- a/direct/src/plugin/load_plugin.h +++ b/direct/src/plugin/load_plugin.h @@ -22,6 +22,7 @@ using namespace std; extern P3D_initialize_func *P3D_initialize; extern P3D_finalize_func *P3D_finalize; +extern P3D_set_plugin_version_func *P3D_set_plugin_version; extern P3D_set_super_mirror_func *P3D_set_super_mirror; extern P3D_new_instance_func *P3D_new_instance; extern P3D_instance_start_func *P3D_instance_start; diff --git a/direct/src/plugin/p3dInstance.cxx b/direct/src/plugin/p3dInstance.cxx index 3855e4158d..b77f9385cb 100644 --- a/direct/src/plugin/p3dInstance.cxx +++ b/direct/src/plugin/p3dInstance.cxx @@ -130,6 +130,25 @@ P3DInstance(P3D_request_ready_func *func, _panda_script_object->set_bool_property("downloadComplete", false); _panda_script_object->set_string_property("status", "initial"); + ostringstream stream; + stream << inst_mgr->get_plugin_major_version() << "." + << inst_mgr->get_plugin_minor_version() << "." + << inst_mgr->get_plugin_sequence_version(); + if (!inst_mgr->get_plugin_official_version()) { + stream << "c"; + } + _panda_script_object->set_string_property("pluginVersionString", stream.str()); + _panda_script_object->set_int_property("pluginMajorVersion", inst_mgr->get_plugin_major_version()); + _panda_script_object->set_int_property("pluginMinorVersion", inst_mgr->get_plugin_minor_version()); + _panda_script_object->set_int_property("pluginSequenceVersion", inst_mgr->get_plugin_sequence_version()); + _panda_script_object->set_bool_property("pluginOfficialVersion", inst_mgr->get_plugin_official_version()); + _panda_script_object->set_string_property("pluginDistributor", inst_mgr->get_plugin_distributor()); + _panda_script_object->set_string_property("coreapiHostUrl", inst_mgr->get_coreapi_host_url()); + time_t timestamp = inst_mgr->get_coreapi_timestamp(); + _panda_script_object->set_int_property("coreapiTimestamp", timestamp); + _panda_script_object->set_string_property("coreapiTimestampString", ctime(×tamp)); + + // We'll start off with the "download" image displayed in the splash // window (when it opens), until we get stuff downloaded. set_background_image(IT_download); diff --git a/direct/src/plugin/p3dInstanceManager.I b/direct/src/plugin/p3dInstanceManager.I index a295325d54..826270f20c 100644 --- a/direct/src/plugin/p3dInstanceManager.I +++ b/direct/src/plugin/p3dInstanceManager.I @@ -152,6 +152,86 @@ get_console_environment() const { return _console_environment; } +//////////////////////////////////////////////////////////////////// +// Function: P3DInstanceManager::get_plugin_major_version +// Access: Public +// Description: Returns the plugin's reported major version number. +//////////////////////////////////////////////////////////////////// +inline int P3DInstanceManager:: +get_plugin_major_version() const { + return _plugin_major_version; +} + +//////////////////////////////////////////////////////////////////// +// Function: P3DInstanceManager::get_plugin_minor_version +// Access: Public +// Description: Returns the plugin's reported minor version number. +//////////////////////////////////////////////////////////////////// +inline int P3DInstanceManager:: +get_plugin_minor_version() const { + return _plugin_minor_version; +} + +//////////////////////////////////////////////////////////////////// +// Function: P3DInstanceManager::get_plugin_sequence_version +// Access: Public +// Description: Returns the plugin's reported sequence version number. +//////////////////////////////////////////////////////////////////// +inline int P3DInstanceManager:: +get_plugin_sequence_version() const { + return _plugin_sequence_version; +} + +//////////////////////////////////////////////////////////////////// +// Function: P3DInstanceManager::get_plugin_official_version +// Access: Public +// Description: Returns true if the plugin claims to be from an +// "official" build, and the its version number is +// authoritative; or false if it makes no such claim +// (for instance, it was built by someone checking out +// from cvs). +//////////////////////////////////////////////////////////////////// +inline bool P3DInstanceManager:: +get_plugin_official_version() const { + return _plugin_official_version; +} + +//////////////////////////////////////////////////////////////////// +// Function: P3DInstanceManager::get_plugin_distributor +// Access: Public +// Description: Returns the "distributor" reported by the plugin. +// This should represent the entity that built and +// hosted the plugin. +//////////////////////////////////////////////////////////////////// +inline const string &P3DInstanceManager:: +get_plugin_distributor() const { + return _plugin_distributor; +} + +//////////////////////////////////////////////////////////////////// +// Function: P3DInstanceManager::get_coreapi_host_url +// Access: Public +// Description: Returns the host URL from which this Core API was +// downloaded (according to the plugin). +//////////////////////////////////////////////////////////////////// +inline const string &P3DInstanceManager:: +get_coreapi_host_url() const { + return _coreapi_host_url; +} + +//////////////////////////////////////////////////////////////////// +// Function: P3DInstanceManager::get_coreapi_timestamp +// Access: Public +// Description: Returns the timestamp associated with this Core API +// DLL (according to the plugin). This is the timestamp +// shown in the contents.xml for this host, and is +// usually the time at which the plugin was built. +//////////////////////////////////////////////////////////////////// +inline time_t P3DInstanceManager:: +get_coreapi_timestamp() const { + return _coreapi_timestamp; +} + //////////////////////////////////////////////////////////////////// // Function: P3DInstanceManager::get_super_mirror // Access: Public diff --git a/direct/src/plugin/p3dInstanceManager.cxx b/direct/src/plugin/p3dInstanceManager.cxx index 4777b6e054..1b6d82f4dc 100644 --- a/direct/src/plugin/p3dInstanceManager.cxx +++ b/direct/src/plugin/p3dInstanceManager.cxx @@ -57,6 +57,13 @@ P3DInstanceManager() { _next_temp_filename_counter = 1; _unique_id = 0; _trusted_environment = false; + _console_environment = false; + + _plugin_major_version = 0; + _plugin_minor_version = 0; + _plugin_sequence_version = 0; + _plugin_official_version = false; + _coreapi_timestamp = 0; _notify_thread_continue = false; _started_notify_thread = false; @@ -342,6 +349,26 @@ initialize(const string &contents_filename, const string &host_url, return true; } +//////////////////////////////////////////////////////////////////// +// Function: P3DInstanceManager::set_plugin_version +// Access: Public +// Description: Specifies the version of the calling plugin, for +// reporting to JavaScript and the like. +//////////////////////////////////////////////////////////////////// +void P3DInstanceManager:: +set_plugin_version(int major, int minor, int sequence, + bool official, const string &distributor, + const string &coreapi_host_url, + time_t coreapi_timestamp) { + _plugin_major_version = major; + _plugin_minor_version = minor; + _plugin_sequence_version = sequence; + _plugin_official_version = official; + _plugin_distributor = distributor; + _coreapi_host_url = coreapi_host_url; + _coreapi_timestamp = coreapi_timestamp; +} + //////////////////////////////////////////////////////////////////// // Function: P3DInstanceManager::set_super_mirror // Access: Public diff --git a/direct/src/plugin/p3dInstanceManager.h b/direct/src/plugin/p3dInstanceManager.h index 69acf1d944..f3ec327a8e 100644 --- a/direct/src/plugin/p3dInstanceManager.h +++ b/direct/src/plugin/p3dInstanceManager.h @@ -70,6 +70,18 @@ public: inline bool get_trusted_environment() const; inline bool get_console_environment() const; + void set_plugin_version(int major, int minor, int sequence, + bool official, const string &distributor, + const string &coreapi_host_url, + time_t coreapi_timestamp); + inline int get_plugin_major_version() const; + inline int get_plugin_minor_version() const; + inline int get_plugin_sequence_version() const; + inline bool get_plugin_official_version() const; + inline const string &get_plugin_distributor() const; + inline const string &get_coreapi_host_url() const; + inline time_t get_coreapi_timestamp() const; + void set_super_mirror(const string &super_mirror_url); inline const string &get_super_mirror() const; @@ -136,6 +148,13 @@ private: string _temp_directory; bool _trusted_environment; bool _console_environment; + int _plugin_major_version; + int _plugin_minor_version; + int _plugin_sequence_version; + bool _plugin_official_version; + string _plugin_distributor; + string _coreapi_host_url; + time_t _coreapi_timestamp; string _super_mirror_url; P3D_object *_undefined_object; diff --git a/direct/src/plugin/p3dMainObject.cxx b/direct/src/plugin/p3dMainObject.cxx index 545744cad4..2c5560f3fc 100644 --- a/direct/src/plugin/p3dMainObject.cxx +++ b/direct/src/plugin/p3dMainObject.cxx @@ -216,6 +216,8 @@ has_method(const string &method_name) { P3D_object *P3DMainObject:: call(const string &method_name, bool needs_response, P3D_object *params[], int num_params) { + P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr(); + if (method_name == "play") { return call_play(params, num_params); } else if (method_name == "read_game_log") { diff --git a/direct/src/plugin/p3d_plugin.cxx b/direct/src/plugin/p3d_plugin.cxx index 6195c55f34..9e34e4739b 100644 --- a/direct/src/plugin/p3d_plugin.cxx +++ b/direct/src/plugin/p3d_plugin.cxx @@ -84,6 +84,26 @@ P3D_finalize() { P3DInstanceManager::delete_global_ptr(); } +void +P3D_set_plugin_version(int major, int minor, int sequence, + bool official, const char *distributor, + const char *coreapi_host_url, + time_t coreapi_timestamp) { + assert(P3DInstanceManager::get_global_ptr()->is_initialized()); + if (distributor == NULL) { + distributor = ""; + } + if (coreapi_host_url == NULL) { + coreapi_host_url = ""; + } + + ACQUIRE_LOCK(_api_lock); + P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr(); + inst_mgr->set_plugin_version(major, minor, sequence, official, distributor, + coreapi_host_url, coreapi_timestamp); + RELEASE_LOCK(_api_lock); +} + void P3D_set_super_mirror(const char *super_mirror_url) { assert(P3DInstanceManager::get_global_ptr()->is_initialized()); diff --git a/direct/src/plugin/p3d_plugin.h b/direct/src/plugin/p3d_plugin.h index 2a0537de02..f573430abc 100644 --- a/direct/src/plugin/p3d_plugin.h +++ b/direct/src/plugin/p3d_plugin.h @@ -152,6 +152,14 @@ P3D_initialize_func(int api_version, const char *contents_filename, typedef void P3D_finalize_func(); +/* This function establishes the version of the calling plugin, for + reporting to JavaScript and the like. */ +typedef void +P3D_set_plugin_version_func(int major, int minor, int sequence, + bool official, const char *distributor, + const char *coreapi_host_url, + time_t coreapi_timestamp); + /* This function defines a "super mirror" URL: a special URL that is consulted first whenever downloading any package referenced by a p3d file. This setting is global, and affects all package @@ -877,6 +885,7 @@ P3D_instance_handle_event_func(P3D_instance *instance, P3D_event_data event); /* Define all of the actual prototypes for the above functions. */ EXPCL_P3D_PLUGIN P3D_initialize_func P3D_initialize; EXPCL_P3D_PLUGIN P3D_finalize_func P3D_finalize; +EXPCL_P3D_PLUGIN P3D_set_plugin_version_func P3D_set_plugin_version; EXPCL_P3D_PLUGIN P3D_set_super_mirror_func P3D_set_super_mirror; EXPCL_P3D_PLUGIN P3D_new_instance_func P3D_new_instance; diff --git a/direct/src/plugin_npapi/ppInstance.cxx b/direct/src/plugin_npapi/ppInstance.cxx index 1737894883..f122a43807 100644 --- a/direct/src/plugin_npapi/ppInstance.cxx +++ b/direct/src/plugin_npapi/ppInstance.cxx @@ -24,6 +24,7 @@ // 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 "pandaVersion.h" #include #include @@ -1133,6 +1134,17 @@ do_load_plugin() { nout << "Unable to launch core API in " << pathname << "\n"; return; } + +#ifdef PANDA_OFFICIAL_VERSION + static const bool official = true; +#else + static const bool official = false; +#endif + P3D_set_plugin_version(P3D_PLUGIN_MAJOR_VERSION, P3D_PLUGIN_MINOR_VERSION, + P3D_PLUGIN_SEQUENCE_VERSION, official, + PANDA_DISTRIBUTOR, + PANDA_PACKAGE_HOST_URL, _core_api_dll.get_timestamp()); + create_instance(); } diff --git a/direct/src/plugin_standalone/panda3d.cxx b/direct/src/plugin_standalone/panda3d.cxx index 22c1df9f42..4d6639b829 100644 --- a/direct/src/plugin_standalone/panda3d.cxx +++ b/direct/src/plugin_standalone/panda3d.cxx @@ -21,6 +21,7 @@ // 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 "pandaVersion.h" #include #include @@ -770,6 +771,16 @@ get_core_api(const Filename &contents_filename, TiXmlElement *xpackage) { } // Successfully loaded. +#ifdef PANDA_OFFICIAL_VERSION + static const bool official = true; +#else + static const bool official = false; +#endif + P3D_set_plugin_version(P3D_PLUGIN_MAJOR_VERSION, P3D_PLUGIN_MINOR_VERSION, + P3D_PLUGIN_SEQUENCE_VERSION, official, + PANDA_DISTRIBUTOR, + PANDA_PACKAGE_HOST_URL, _core_api_dll.get_timestamp()); + return true; } diff --git a/dtool/Package.pp b/dtool/Package.pp index cbbf77c300..478652ad5c 100644 --- a/dtool/Package.pp +++ b/dtool/Package.pp @@ -22,8 +22,12 @@ #defer PANDA_MAJOR_VERSION $[word 1,$[PANDA_VERSION]] #defer PANDA_MINOR_VERSION $[word 2,$[PANDA_VERSION]] #defer PANDA_SEQUENCE_VERSION $[word 3,$[PANDA_VERSION]] -#defer PANDA_VERSION_STR $[PANDA_MAJOR_VERSION].$[PANDA_MINOR_VERSION].$[PANDA_SEQUENCE_VERSION]$[if $[not $[OFFICIAL_VERSION]],c] -#defer PANDA_VERSION_SYMBOL panda_version_$[PANDA_MAJOR_VERSION]_$[PANDA_MINOR_VERSION]_$[PANDA_SEQUENCE_VERSION]$[if $[not $[OFFICIAL_VERSION]],c] +#defer PANDA_VERSION_STR $[PANDA_MAJOR_VERSION].$[PANDA_MINOR_VERSION].$[PANDA_SEQUENCE_VERSION]$[if $[not $[PANDA_OFFICIAL_VERSION]],c] +#defer PANDA_VERSION_SYMBOL panda_version_$[PANDA_MAJOR_VERSION]_$[PANDA_MINOR_VERSION]_$[PANDA_SEQUENCE_VERSION]$[if $[not $[PANDA_OFFICIAL_VERSION]],c] + +#defer P3D_PLUGIN_MAJOR_VERSION $[word 1,$[P3D_PLUGIN_VERSION]] +#defer P3D_PLUGIN_MINOR_VERSION $[word 2,$[P3D_PLUGIN_VERSION]] +#defer P3D_PLUGIN_SEQUENCE_VERSION $[word 3,$[P3D_PLUGIN_VERSION]] // What is the name of this source tree? #if $[eq $[PACKAGE],] diff --git a/dtool/PandaVersion.pp b/dtool/PandaVersion.pp index 393b24b818..b540b9d830 100644 --- a/dtool/PandaVersion.pp +++ b/dtool/PandaVersion.pp @@ -27,3 +27,11 @@ // build which you will be using to produce a distributable Panda3D // package, you should set this string appropriately. #define PANDA_PACKAGE_VERSION + +// We also define a version for the Panda3D plugin/runtime, +// i.e. nppanda3d.dll, p3dactivex.ocx, and panda3d.exe. This is an +// independent version number from PANDA_VERSION or +// PANDA_PACKAGE_VERSION, because it is anticipated that this plugin +// code, once settled, will need to be updated much less frequently +// than Panda itself. +#define P3D_PLUGIN_VERSION 0 9 0 diff --git a/dtool/src/dtoolutil/pandaVersion.h.pp b/dtool/src/dtoolutil/pandaVersion.h.pp index f49066f866..e19509216c 100644 --- a/dtool/src/dtoolutil/pandaVersion.h.pp +++ b/dtool/src/dtoolutil/pandaVersion.h.pp @@ -70,6 +70,13 @@ $[cdefine PANDA_OFFICIAL_VERSION] is no associated package. */ # define PANDA_PACKAGE_HOST_URL "$[PANDA_PACKAGE_HOST_URL]" +#if HAVE_P3D_PLUGIN +/* Similar definitions for the plugin versioning, if in use. */ +$[cdefine P3D_PLUGIN_MAJOR_VERSION] +$[cdefine P3D_PLUGIN_MINOR_VERSION] +$[cdefine P3D_PLUGIN_SEQUENCE_VERSION] +#endif + #end pandaVersion.h