plugin version

This commit is contained in:
David Rose 2009-10-09 23:54:45 +00:00
parent 7472fd8e5d
commit dcc5447688
17 changed files with 239 additions and 3 deletions

View File

@ -64,7 +64,7 @@ class FileSpec:
if self.size: if self.size:
xelement.SetAttribute('size', str(self.size)) xelement.SetAttribute('size', str(self.size))
if self.timestamp: if self.timestamp:
xelement.SetAttribute('timestamp', str(self.timestamp)) xelement.SetAttribute('timestamp', str(int(self.timestamp)))
if self.hash: if self.hash:
xelement.SetAttribute('hash', self.hash) xelement.SetAttribute('hash', self.hash)

View File

@ -56,6 +56,17 @@ get_size() const {
return _size; 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 // Function: FileSpec::get_actual_file
// Access: Public // Access: Public

View File

@ -39,6 +39,7 @@ public:
inline void set_filename(const string &filename); inline void set_filename(const string &filename);
inline string get_pathname(const string &package_dir) const; inline string get_pathname(const string &package_dir) const;
inline size_t get_size() const; inline size_t get_size() const;
inline time_t get_timestamp() const;
bool quick_verify(const string &package_dir); bool quick_verify(const string &package_dir);
bool quick_verify_pathname(const string &pathname); bool quick_verify_pathname(const string &pathname);

View File

@ -36,6 +36,7 @@ static const string default_plugin_filename = "p3d_plugin";
P3D_initialize_func *P3D_initialize; P3D_initialize_func *P3D_initialize;
P3D_finalize_func *P3D_finalize; P3D_finalize_func *P3D_finalize;
P3D_set_plugin_version_func *P3D_set_plugin_version;
P3D_set_super_mirror_func *P3D_set_super_mirror; P3D_set_super_mirror_func *P3D_set_super_mirror;
P3D_new_instance_func *P3D_new_instance; P3D_new_instance_func *P3D_new_instance;
P3D_instance_start_func *P3D_instance_start; 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. // Now get all of the function pointers.
P3D_initialize = (P3D_initialize_func *)get_func(module, "P3D_initialize"); P3D_initialize = (P3D_initialize_func *)get_func(module, "P3D_initialize");
P3D_finalize = (P3D_finalize_func *)get_func(module, "P3D_finalize"); 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_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_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"); 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. // Ensure that all of the function pointers have been found.
if (P3D_initialize == NULL || if (P3D_initialize == NULL ||
P3D_finalize == NULL || P3D_finalize == NULL ||
P3D_set_plugin_version == NULL ||
P3D_set_super_mirror == NULL || P3D_set_super_mirror == NULL ||
P3D_new_instance == NULL || P3D_new_instance == NULL ||
P3D_instance_start == NULL || P3D_instance_start == NULL ||
@ -268,6 +271,7 @@ load_plugin(const string &p3d_plugin_filename,
<< "Some function pointers not found:" << "Some function pointers not found:"
<< "\nP3D_initialize = " << P3D_initialize << "\nP3D_initialize = " << P3D_initialize
<< "\nP3D_finalize = " << P3D_finalize << "\nP3D_finalize = " << P3D_finalize
<< "\nP3D_set_plugin_version = " << P3D_set_plugin_version
<< "\nP3D_set_super_mirror = " << P3D_set_super_mirror << "\nP3D_set_super_mirror = " << P3D_set_super_mirror
<< "\nP3D_new_instance = " << P3D_new_instance << "\nP3D_new_instance = " << P3D_new_instance
<< "\nP3D_instance_start = " << P3D_instance_start << "\nP3D_instance_start = " << P3D_instance_start
@ -362,6 +366,7 @@ unload_dso() {
P3D_initialize = NULL; P3D_initialize = NULL;
P3D_finalize = NULL; P3D_finalize = NULL;
P3D_set_plugin_version = NULL;
P3D_set_super_mirror = NULL; P3D_set_super_mirror = NULL;
P3D_new_instance = NULL; P3D_new_instance = NULL;
P3D_instance_start = NULL; P3D_instance_start = NULL;

View File

@ -22,6 +22,7 @@ using namespace std;
extern P3D_initialize_func *P3D_initialize; extern P3D_initialize_func *P3D_initialize;
extern P3D_finalize_func *P3D_finalize; 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_set_super_mirror_func *P3D_set_super_mirror;
extern P3D_new_instance_func *P3D_new_instance; extern P3D_new_instance_func *P3D_new_instance;
extern P3D_instance_start_func *P3D_instance_start; extern P3D_instance_start_func *P3D_instance_start;

View File

@ -130,6 +130,25 @@ P3DInstance(P3D_request_ready_func *func,
_panda_script_object->set_bool_property("downloadComplete", false); _panda_script_object->set_bool_property("downloadComplete", false);
_panda_script_object->set_string_property("status", "initial"); _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(&timestamp));
// We'll start off with the "download" image displayed in the splash // We'll start off with the "download" image displayed in the splash
// window (when it opens), until we get stuff downloaded. // window (when it opens), until we get stuff downloaded.
set_background_image(IT_download); set_background_image(IT_download);

View File

@ -152,6 +152,86 @@ get_console_environment() const {
return _console_environment; 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 // Function: P3DInstanceManager::get_super_mirror
// Access: Public // Access: Public

View File

@ -57,6 +57,13 @@ P3DInstanceManager() {
_next_temp_filename_counter = 1; _next_temp_filename_counter = 1;
_unique_id = 0; _unique_id = 0;
_trusted_environment = false; _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; _notify_thread_continue = false;
_started_notify_thread = false; _started_notify_thread = false;
@ -342,6 +349,26 @@ initialize(const string &contents_filename, const string &host_url,
return true; 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 // Function: P3DInstanceManager::set_super_mirror
// Access: Public // Access: Public

View File

@ -70,6 +70,18 @@ public:
inline bool get_trusted_environment() const; inline bool get_trusted_environment() const;
inline bool get_console_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); void set_super_mirror(const string &super_mirror_url);
inline const string &get_super_mirror() const; inline const string &get_super_mirror() const;
@ -136,6 +148,13 @@ private:
string _temp_directory; string _temp_directory;
bool _trusted_environment; bool _trusted_environment;
bool _console_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; string _super_mirror_url;
P3D_object *_undefined_object; P3D_object *_undefined_object;

View File

@ -216,6 +216,8 @@ has_method(const string &method_name) {
P3D_object *P3DMainObject:: P3D_object *P3DMainObject::
call(const string &method_name, bool needs_response, call(const string &method_name, bool needs_response,
P3D_object *params[], int num_params) { P3D_object *params[], int num_params) {
P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr();
if (method_name == "play") { if (method_name == "play") {
return call_play(params, num_params); return call_play(params, num_params);
} else if (method_name == "read_game_log") { } else if (method_name == "read_game_log") {

View File

@ -84,6 +84,26 @@ P3D_finalize() {
P3DInstanceManager::delete_global_ptr(); 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 void
P3D_set_super_mirror(const char *super_mirror_url) { P3D_set_super_mirror(const char *super_mirror_url) {
assert(P3DInstanceManager::get_global_ptr()->is_initialized()); assert(P3DInstanceManager::get_global_ptr()->is_initialized());

View File

@ -152,6 +152,14 @@ P3D_initialize_func(int api_version, const char *contents_filename,
typedef void typedef void
P3D_finalize_func(); 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 /* This function defines a "super mirror" URL: a special URL that is
consulted first whenever downloading any package referenced by a consulted first whenever downloading any package referenced by a
p3d file. This setting is global, and affects all package 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. */ /* Define all of the actual prototypes for the above functions. */
EXPCL_P3D_PLUGIN P3D_initialize_func P3D_initialize; EXPCL_P3D_PLUGIN P3D_initialize_func P3D_initialize;
EXPCL_P3D_PLUGIN P3D_finalize_func P3D_finalize; 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_set_super_mirror_func P3D_set_super_mirror;
EXPCL_P3D_PLUGIN P3D_new_instance_func P3D_new_instance; EXPCL_P3D_PLUGIN P3D_new_instance_func P3D_new_instance;

View File

@ -24,6 +24,7 @@
// We can include this header file to get the DTOOL_PLATFORM // We can include this header file to get the DTOOL_PLATFORM
// definition, even though we don't link with dtool. // definition, even though we don't link with dtool.
#include "dtool_platform.h" #include "dtool_platform.h"
#include "pandaVersion.h"
#include <fstream> #include <fstream>
#include <algorithm> #include <algorithm>
@ -1133,6 +1134,17 @@ do_load_plugin() {
nout << "Unable to launch core API in " << pathname << "\n"; nout << "Unable to launch core API in " << pathname << "\n";
return; 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(); create_instance();
} }

View File

@ -21,6 +21,7 @@
// We can include this header file to get the DTOOL_PLATFORM // We can include this header file to get the DTOOL_PLATFORM
// definition, even though we don't link with dtool. // definition, even though we don't link with dtool.
#include "dtool_platform.h" #include "dtool_platform.h"
#include "pandaVersion.h"
#include <ctype.h> #include <ctype.h>
#include <sstream> #include <sstream>
@ -770,6 +771,16 @@ get_core_api(const Filename &contents_filename, TiXmlElement *xpackage) {
} }
// Successfully loaded. // 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; return true;
} }

View File

@ -22,8 +22,12 @@
#defer PANDA_MAJOR_VERSION $[word 1,$[PANDA_VERSION]] #defer PANDA_MAJOR_VERSION $[word 1,$[PANDA_VERSION]]
#defer PANDA_MINOR_VERSION $[word 2,$[PANDA_VERSION]] #defer PANDA_MINOR_VERSION $[word 2,$[PANDA_VERSION]]
#defer PANDA_SEQUENCE_VERSION $[word 3,$[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_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 $[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? // What is the name of this source tree?
#if $[eq $[PACKAGE],] #if $[eq $[PACKAGE],]

View File

@ -27,3 +27,11 @@
// build which you will be using to produce a distributable Panda3D // build which you will be using to produce a distributable Panda3D
// package, you should set this string appropriately. // package, you should set this string appropriately.
#define PANDA_PACKAGE_VERSION #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

View File

@ -70,6 +70,13 @@ $[cdefine PANDA_OFFICIAL_VERSION]
is no associated package. */ is no associated package. */
# define PANDA_PACKAGE_HOST_URL "$[PANDA_PACKAGE_HOST_URL]" # 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 #end pandaVersion.h