From 0782c4c2e91f1706cbc4080bb8e7c8f8e0de97f1 Mon Sep 17 00:00:00 2001 From: David Rose Date: Fri, 4 Dec 2009 22:40:04 +0000 Subject: [PATCH] query game log even after application shuts down --- direct/src/plugin/p3dInstance.cxx | 20 ++++++++++++++ direct/src/plugin/p3dInstance.h | 2 ++ direct/src/plugin/p3dMainObject.cxx | 43 ++++++++++++++++------------- direct/src/plugin/p3dMainObject.h | 1 + direct/src/plugin/p3dSession.cxx | 2 ++ 5 files changed, 49 insertions(+), 19 deletions(-) diff --git a/direct/src/plugin/p3dInstance.cxx b/direct/src/plugin/p3dInstance.cxx index 4b7bc87e8b..41c089b136 100644 --- a/direct/src/plugin/p3dInstance.cxx +++ b/direct/src/plugin/p3dInstance.cxx @@ -890,6 +890,26 @@ handle_event(const P3D_event_data &event) { return retval; } +//////////////////////////////////////////////////////////////////// +// Function: P3DInstance::get_log_pathname +// Access: Public +// Description: Returns the log filename for this particular session, +// if the session was started and if it has a log file. +// Returns empty string if the session never started or +// if it lacks a log file. +// +// This is the same value returned by +// P3DSession::get_log_pathname(), except that it +// remains valid even after the session has closed. +//////////////////////////////////////////////////////////////////// +const string &P3DInstance:: +get_log_pathname() const { + if (_session != NULL) { + return _session->_log_pathname; + } + return _log_pathname; +} + //////////////////////////////////////////////////////////////////// // Function: P3DInstance::add_package // Access: Public diff --git a/direct/src/plugin/p3dInstance.h b/direct/src/plugin/p3dInstance.h index e0f37f3667..e710172349 100644 --- a/direct/src/plugin/p3dInstance.h +++ b/direct/src/plugin/p3dInstance.h @@ -86,6 +86,7 @@ public: inline int get_instance_id() const; inline const string &get_session_key() const; + const string &get_log_pathname() const; inline P3DSession *get_session() const; @@ -265,6 +266,7 @@ private: P3DSession *_session; P3DAuthSession *_auth_session; + string _log_pathname; #ifdef __APPLE__ // On OSX, we have to get a copy of the framebuffer data back from diff --git a/direct/src/plugin/p3dMainObject.cxx b/direct/src/plugin/p3dMainObject.cxx index efc2532be8..1ce9bf9353 100644 --- a/direct/src/plugin/p3dMainObject.cxx +++ b/direct/src/plugin/p3dMainObject.cxx @@ -25,9 +25,10 @@ //////////////////////////////////////////////////////////////////// P3DMainObject:: P3DMainObject() : - _pyobj(NULL) + _pyobj(NULL), + _inst(NULL), + _unauth_play(false) { - _unauth_play = false; } //////////////////////////////////////////////////////////////////// @@ -297,6 +298,12 @@ get_pyobj() const { //////////////////////////////////////////////////////////////////// void P3DMainObject:: set_instance(P3DInstance *inst) { + if (_inst != NULL) { + // Save the game log filename of the instance just before it goes + // away, in case JavaScript asks for it later. + _game_log_pathname = _inst->get_log_pathname(); + } + _inst = inst; } @@ -350,24 +357,22 @@ call_play(P3D_object *params[], int num_params) { //////////////////////////////////////////////////////////////////// P3D_object *P3DMainObject:: call_read_game_log(P3D_object *params[], int num_params) { + if (_inst != NULL) { + nout << "querying " << _inst << "->_log_pathname\n"; + string log_pathname = _inst->get_log_pathname(); + nout << "result is " << log_pathname << "\n"; + return read_log(log_pathname, params, num_params); + } + + if (!_game_log_pathname.empty()) { + // The instance has already finished, but we saved its log + // filename. + return read_log(_game_log_pathname, params, num_params); + } + + // No log available for us. P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr(); - if (_inst == NULL) { - return inst_mgr->new_undefined_object(); - } - - if (!_inst->get_matches_script_origin()) { - // If you're not allowed to be scripting us, you can't query the - // game log either. (But you can query the system log.) - return inst_mgr->new_undefined_object(); - } - - P3DSession *session = _inst->get_session(); - if (session == NULL) { - return inst_mgr->new_undefined_object(); - } - - string log_pathname = session->get_log_pathname(); - return read_log(log_pathname, params, num_params); + return inst_mgr->new_undefined_object(); } //////////////////////////////////////////////////////////////////// diff --git a/direct/src/plugin/p3dMainObject.h b/direct/src/plugin/p3dMainObject.h index 9d9cc1e8af..a04af29e5a 100644 --- a/direct/src/plugin/p3dMainObject.h +++ b/direct/src/plugin/p3dMainObject.h @@ -79,6 +79,7 @@ private: P3DInstance *_inst; bool _unauth_play; + string _game_log_pathname; // This map is used to store properties and retrieve until // set_pyobj() is called for the firs ttime. At that point, the diff --git a/direct/src/plugin/p3dSession.cxx b/direct/src/plugin/p3dSession.cxx index 5e87ed8952..77b352c50f 100644 --- a/direct/src/plugin/p3dSession.cxx +++ b/direct/src/plugin/p3dSession.cxx @@ -273,6 +273,8 @@ terminate_instance(P3DInstance *inst) { ACQUIRE_LOCK(_instances_lock); if (inst->_session == this) { + nout << "Assigning " << inst << "->log_pathname = " << _log_pathname << "\n"; + inst->_log_pathname = _log_pathname; inst->_session = NULL; _instances.erase(inst->get_instance_id()); }