diff --git a/direct/src/plugin/Sources.pp b/direct/src/plugin/Sources.pp index 84f3f72617..1c92dba9a8 100644 --- a/direct/src/plugin/Sources.pp +++ b/direct/src/plugin/Sources.pp @@ -20,41 +20,41 @@ p3d_lock.h p3d_plugin.h \ p3d_plugin_config.h \ p3d_plugin_common.h \ - p3dBoolValue.h \ + p3dBoolObject.h \ p3dDownload.h p3dDownload.I \ p3dFileDownload.h p3dFileDownload.I \ p3dFileParams.h p3dFileParams.I \ - p3dFloatValue.h \ + p3dFloatObject.h \ p3dInstance.h p3dInstance.I \ p3dInstanceManager.h p3dInstanceManager.I \ - p3dIntValue.h \ - p3dListValue.h \ + p3dIntObject.h \ + p3dListObject.h \ p3dMultifileReader.h p3dMultifileReader.I \ p3dPackage.h p3dPackage.I \ p3dSession.h p3dSession.I \ p3dSplashWindow.h p3dSplashWindow.I \ - p3dStringValue.h \ - p3dValue.h p3dValue.I \ + p3dStringObject.h \ + p3dObject.h p3dObject.I \ p3dWinSplashWindow.h p3dWinSplashWindow.I \ p3dWindowParams.h p3dWindowParams.I #define INCLUDED_SOURCES \ p3d_plugin.cxx \ - p3dBoolValue.cxx \ + p3dBoolObject.cxx \ p3dDownload.cxx \ p3dFileDownload.cxx \ p3dFileParams.cxx \ - p3dFloatValue.cxx \ + p3dFloatObject.cxx \ p3dInstance.cxx \ p3dInstanceManager.cxx \ - p3dIntValue.cxx \ - p3dListValue.cxx \ + p3dIntObject.cxx \ + p3dListObject.cxx \ p3dMultifileReader.cxx \ p3dPackage.cxx \ p3dSession.cxx \ p3dSplashWindow.cxx \ - p3dStringValue.cxx \ - p3dValue.cxx \ + p3dStringObject.cxx \ + p3dObject.cxx \ p3dWinSplashWindow.cxx \ p3dWindowParams.cxx diff --git a/direct/src/plugin/load_plugin.cxx b/direct/src/plugin/load_plugin.cxx index 8e28b3546b..9ef36bb23f 100755 --- a/direct/src/plugin/load_plugin.cxx +++ b/direct/src/plugin/load_plugin.cxx @@ -17,6 +17,8 @@ #include "assert.h" +#include + #ifndef _WIN32 #include #endif @@ -32,36 +34,26 @@ static const string dll_ext = ".so"; static const string default_plugin_filename = "p3d_plugin"; P3D_initialize_func *P3D_initialize; +P3D_finalize_func *P3D_finalize; P3D_new_instance_func *P3D_new_instance; P3D_instance_start_func *P3D_instance_start; P3D_instance_finish_func *P3D_instance_finish; P3D_instance_setup_window_func *P3D_instance_setup_window; -P3D_value_finish_func *P3D_value_finish; -P3D_value_copy_func *P3D_value_copy; -P3D_new_none_value_func *P3D_new_none_value; -P3D_new_bool_value_func *P3D_new_bool_value; -P3D_value_get_bool_func *P3D_value_get_bool; -P3D_new_int_value_func *P3D_new_int_value; -P3D_value_get_int_func *P3D_value_get_int; -P3D_new_float_value_func *P3D_new_float_value; -P3D_value_get_float_func *P3D_value_get_float; -P3D_new_string_value_func *P3D_new_string_value; -P3D_value_get_string_length_func *P3D_value_get_string_length; -P3D_value_extract_string_func *P3D_value_extract_string; -P3D_new_list_value_func *P3D_new_list_value; -P3D_value_get_list_length_func *P3D_value_get_list_length; -P3D_value_get_list_item_func *P3D_value_get_list_item; -P3D_instance_get_property_func *P3D_instance_get_property; -P3D_instance_get_property_list_func *P3D_instance_get_property_list; -P3D_instance_set_property_func *P3D_instance_set_property; -P3D_instance_call_func *P3D_instance_call; +P3D_make_class_definition_func *P3D_make_class_definition; +P3D_new_none_object_func *P3D_new_none_object; +P3D_new_bool_object_func *P3D_new_bool_object; +P3D_new_int_object_func *P3D_new_int_object; +P3D_new_float_object_func *P3D_new_float_object; +P3D_new_string_object_func *P3D_new_string_object; +P3D_new_list_object_func *P3D_new_list_object; +P3D_instance_get_script_object_func *P3D_instance_get_script_object; +P3D_instance_set_script_object_func *P3D_instance_set_script_object; P3D_instance_get_request_func *P3D_instance_get_request; P3D_check_request_func *P3D_check_request; P3D_request_finish_func *P3D_request_finish; P3D_instance_feed_url_stream_func *P3D_instance_feed_url_stream; -P3D_instance_feed_value_func *P3D_instance_feed_value; #ifdef _WIN32 static HMODULE module = NULL; @@ -157,6 +149,7 @@ load_plugin(const string &p3d_plugin_filename) { filename += "."; } + SetErrorMode(0); module = LoadLibrary(filename.c_str()); if (module == NULL) { // Couldn't load the DLL. @@ -178,73 +171,80 @@ load_plugin(const string &p3d_plugin_filename) { #endif // _WIN32 + cerr << "Got module = " << module << "\n"; + // 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_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_finish = (P3D_instance_finish_func *)get_func(module, "P3D_instance_finish"); P3D_instance_setup_window = (P3D_instance_setup_window_func *)get_func(module, "P3D_instance_setup_window"); - P3D_value_finish = (P3D_value_finish_func *)get_func(module, "P3D_value_finish"); - P3D_value_copy = (P3D_value_copy_func *)get_func(module, "P3D_value_copy"); - P3D_new_none_value = (P3D_new_none_value_func *)get_func(module, "P3D_new_none_value"); - P3D_new_bool_value = (P3D_new_bool_value_func *)get_func(module, "P3D_new_bool_value"); - P3D_value_get_bool = (P3D_value_get_bool_func *)get_func(module, "P3D_value_get_bool"); - P3D_new_int_value = (P3D_new_int_value_func *)get_func(module, "P3D_new_int_value"); - P3D_value_get_int = (P3D_value_get_int_func *)get_func(module, "P3D_value_get_int"); - P3D_new_float_value = (P3D_new_float_value_func *)get_func(module, "P3D_new_float_value"); - P3D_value_get_float = (P3D_value_get_float_func *)get_func(module, "P3D_value_get_float"); - P3D_new_string_value = (P3D_new_string_value_func *)get_func(module, "P3D_new_string_value"); - P3D_value_get_string_length = (P3D_value_get_string_length_func *)get_func(module, "P3D_value_get_string_length"); - P3D_value_extract_string = (P3D_value_extract_string_func *)get_func(module, "P3D_value_extract_string"); - P3D_new_list_value = (P3D_new_list_value_func *)get_func(module, "P3D_new_list_value"); - P3D_value_get_list_length = (P3D_value_get_list_length_func *)get_func(module, "P3D_value_get_list_length"); - P3D_value_get_list_item = (P3D_value_get_list_item_func *)get_func(module, "P3D_value_get_list_item"); - P3D_instance_get_property = (P3D_instance_get_property_func *)get_func(module, "P3D_instance_get_property"); - P3D_instance_get_property_list = (P3D_instance_get_property_list_func *)get_func(module, "P3D_instance_get_property_list"); - P3D_instance_set_property = (P3D_instance_set_property_func *)get_func(module, "P3D_instance_set_property"); - P3D_instance_call = (P3D_instance_call_func *)get_func(module, "P3D_instance_call"); + P3D_make_class_definition = (P3D_make_class_definition_func *)get_func(module, "P3D_make_class_definition"); + P3D_new_none_object = (P3D_new_none_object_func *)get_func(module, "P3D_new_none_object"); + P3D_new_bool_object = (P3D_new_bool_object_func *)get_func(module, "P3D_new_bool_object"); + P3D_new_int_object = (P3D_new_int_object_func *)get_func(module, "P3D_new_int_object"); + P3D_new_float_object = (P3D_new_float_object_func *)get_func(module, "P3D_new_float_object"); + P3D_new_string_object = (P3D_new_string_object_func *)get_func(module, "P3D_new_string_object"); + P3D_new_list_object = (P3D_new_list_object_func *)get_func(module, "P3D_new_list_object"); + P3D_instance_get_script_object = (P3D_instance_get_script_object_func *)get_func(module, "P3D_instance_get_script_object"); + P3D_instance_set_script_object = (P3D_instance_set_script_object_func *)get_func(module, "P3D_instance_set_script_object"); P3D_instance_get_request = (P3D_instance_get_request_func *)get_func(module, "P3D_instance_get_request"); P3D_check_request = (P3D_check_request_func *)get_func(module, "P3D_check_request"); P3D_request_finish = (P3D_request_finish_func *)get_func(module, "P3D_request_finish"); P3D_instance_feed_url_stream = (P3D_instance_feed_url_stream_func *)get_func(module, "P3D_instance_feed_url_stream"); - P3D_instance_feed_value = (P3D_instance_feed_value_func *)get_func(module, "P3D_instance_feed_value"); #undef get_func // Ensure that all of the function pointers have been found. if (P3D_initialize == NULL || + P3D_finalize == NULL || P3D_new_instance == NULL || P3D_instance_start == NULL || P3D_instance_finish == NULL || P3D_instance_setup_window == NULL || - P3D_value_finish == NULL || - P3D_value_copy == NULL || - P3D_new_none_value == NULL || - P3D_new_bool_value == NULL || - P3D_value_get_bool == NULL || - P3D_new_int_value == NULL || - P3D_value_get_int == NULL || - P3D_new_float_value == NULL || - P3D_value_get_float == NULL || - P3D_new_string_value == NULL || - P3D_value_get_string_length == NULL || - P3D_value_extract_string == NULL || - P3D_new_list_value == NULL || - P3D_value_get_list_length == NULL || - P3D_value_get_list_item == NULL || - P3D_instance_get_property == NULL || - P3D_instance_get_property_list == NULL || - P3D_instance_set_property == NULL || - P3D_instance_call == NULL || + P3D_make_class_definition == NULL || + P3D_new_none_object == NULL || + P3D_new_bool_object == NULL || + P3D_new_int_object == NULL || + P3D_new_float_object == NULL || + P3D_new_string_object == NULL || + P3D_new_list_object == NULL || + P3D_instance_get_script_object == NULL || + P3D_instance_set_script_object == NULL || P3D_instance_get_request == NULL || P3D_check_request == NULL || P3D_request_finish == NULL || - P3D_instance_feed_url_stream == NULL || - P3D_instance_feed_value == NULL) { + P3D_instance_feed_url_stream == NULL) { + + cerr + << "Some function pointers not found:" + << "\nP3D_initialize = " << P3D_initialize + << "\nP3D_finalize = " << P3D_finalize + << "\nP3D_new_instance = " << P3D_new_instance + << "\nP3D_instance_start = " << P3D_instance_start + << "\nP3D_instance_finish = " << P3D_instance_finish + << "\nP3D_instance_setup_window = " << P3D_instance_setup_window + + << "\nP3D_make_class_definition = " << P3D_make_class_definition + << "\nP3D_new_none_object = " << P3D_new_none_object + << "\nP3D_new_bool_object = " << P3D_new_bool_object + << "\nP3D_new_int_object = " << P3D_new_int_object + << "\nP3D_new_float_object = " << P3D_new_float_object + << "\nP3D_new_string_object = " << P3D_new_string_object + << "\nP3D_new_list_object = " << P3D_new_list_object + << "\nP3D_instance_get_script_object = " << P3D_instance_get_script_object + << "\nP3D_instance_set_script_object = " << P3D_instance_set_script_object + + << "\nP3D_instance_get_request = " << P3D_instance_get_request + << "\nP3D_check_request = " << P3D_check_request + << "\nP3D_request_finish = " << P3D_request_finish + << "\nP3D_instance_feed_url_stream = " << P3D_instance_feed_url_stream + << "\n"; return false; } @@ -255,6 +255,7 @@ load_plugin(const string &p3d_plugin_filename) { if (!P3D_initialize(P3D_API_VERSION, logfilename.c_str())) { // Oops, failure to initialize. + cerr << "Failed to initialize plugin (wrong API version?)\n"; unload_plugin(); return false; } @@ -273,6 +274,8 @@ unload_plugin() { return; } + P3D_finalize(); + #ifdef _WIN32 assert(module != NULL); FreeLibrary(module); @@ -284,36 +287,26 @@ unload_plugin() { #endif P3D_initialize = NULL; + P3D_finalize = NULL; P3D_new_instance = NULL; P3D_instance_start = NULL; P3D_instance_finish = NULL; P3D_instance_setup_window = NULL; - P3D_value_finish = NULL; - P3D_value_copy = NULL; - P3D_new_none_value = NULL; - P3D_new_bool_value = NULL; - P3D_value_get_bool = NULL; - P3D_new_int_value = NULL; - P3D_value_get_int = NULL; - P3D_new_float_value = NULL; - P3D_value_get_float = NULL; - P3D_new_string_value = NULL; - P3D_value_get_string_length = NULL; - P3D_value_extract_string = NULL; - P3D_new_list_value = NULL; - P3D_value_get_list_length = NULL; - P3D_value_get_list_item = NULL; - P3D_instance_get_property = NULL; - P3D_instance_get_property_list = NULL; - P3D_instance_set_property = NULL; - P3D_instance_call = NULL; + P3D_make_class_definition = NULL; + P3D_new_none_object = NULL; + P3D_new_bool_object = NULL; + P3D_new_int_object = NULL; + P3D_new_float_object = NULL; + P3D_new_string_object = NULL; + P3D_new_list_object = NULL; + P3D_instance_get_script_object = NULL; + P3D_instance_set_script_object = NULL; P3D_instance_get_request = NULL; P3D_check_request = NULL; P3D_request_finish = NULL; P3D_instance_feed_url_stream = NULL; - P3D_instance_feed_value = NULL; plugin_loaded = false; } diff --git a/direct/src/plugin/load_plugin.h b/direct/src/plugin/load_plugin.h index 3bda3ce9ba..0fb216c269 100755 --- a/direct/src/plugin/load_plugin.h +++ b/direct/src/plugin/load_plugin.h @@ -21,36 +21,26 @@ using namespace std; extern P3D_initialize_func *P3D_initialize; +extern P3D_finalize_func *P3D_finalize; extern P3D_new_instance_func *P3D_new_instance; extern P3D_instance_start_func *P3D_instance_start; extern P3D_instance_finish_func *P3D_instance_finish; extern P3D_instance_setup_window_func *P3D_instance_setup_window; -extern P3D_value_finish_func *P3D_value_finish; -extern P3D_value_copy_func *P3D_value_copy; -extern P3D_new_none_value_func *P3D_new_none_value; -extern P3D_new_bool_value_func *P3D_new_bool_value; -extern P3D_value_get_bool_func *P3D_value_get_bool; -extern P3D_new_int_value_func *P3D_new_int_value; -extern P3D_value_get_int_func *P3D_value_get_int; -extern P3D_new_float_value_func *P3D_new_float_value; -extern P3D_value_get_float_func *P3D_value_get_float; -extern P3D_new_string_value_func *P3D_new_string_value; -extern P3D_value_get_string_length_func *P3D_value_get_string_length; -extern P3D_value_extract_string_func *P3D_value_extract_string; -extern P3D_new_list_value_func *P3D_new_list_value; -extern P3D_value_get_list_length_func *P3D_value_get_list_length; -extern P3D_value_get_list_item_func *P3D_value_get_list_item; -extern P3D_instance_get_property_func *P3D_instance_get_property; -extern P3D_instance_get_property_list_func *P3D_instance_get_property_list; -extern P3D_instance_set_property_func *P3D_instance_set_property; -extern P3D_instance_call_func *P3D_instance_call; +extern P3D_make_class_definition_func *P3D_make_class_definition; +extern P3D_new_none_object_func *P3D_new_none_object; +extern P3D_new_bool_object_func *P3D_new_bool_object; +extern P3D_new_int_object_func *P3D_new_int_object; +extern P3D_new_float_object_func *P3D_new_float_object; +extern P3D_new_string_object_func *P3D_new_string_object; +extern P3D_new_list_object_func *P3D_new_list_object; +extern P3D_instance_get_script_object_func *P3D_instance_get_script_object; +extern P3D_instance_set_script_object_func *P3D_instance_set_script_object; extern P3D_instance_get_request_func *P3D_instance_get_request; extern P3D_check_request_func *P3D_check_request; extern P3D_request_finish_func *P3D_request_finish; extern P3D_instance_feed_url_stream_func *P3D_instance_feed_url_stream; -extern P3D_instance_feed_value_func *P3D_instance_feed_value; string get_plugin_basename(); bool load_plugin(const string &p3d_plugin_filename); diff --git a/direct/src/plugin/p3dBoolValue.cxx b/direct/src/plugin/p3dBoolObject.cxx similarity index 74% rename from direct/src/plugin/p3dBoolValue.cxx rename to direct/src/plugin/p3dBoolObject.cxx index ce73c9db43..9c6dbb6d3b 100644 --- a/direct/src/plugin/p3dBoolValue.cxx +++ b/direct/src/plugin/p3dBoolObject.cxx @@ -1,4 +1,4 @@ -// Filename: p3dBoolValue.cxx +// Filename: p3dBoolObject.cxx // Created by: drose (30Jun09) // //////////////////////////////////////////////////////////////////// @@ -12,71 +12,71 @@ // //////////////////////////////////////////////////////////////////// -#include "p3dBoolValue.h" +#include "p3dBoolObject.h" //////////////////////////////////////////////////////////////////// -// Function: P3DBoolValue::Constructor +// Function: P3DBoolObject::Constructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// -P3DBoolValue:: -P3DBoolValue(bool value) : - P3DValue(P3D_VT_bool), +P3DBoolObject:: +P3DBoolObject(bool value) : + P3DObject(P3D_OT_bool), _value(value) { } //////////////////////////////////////////////////////////////////// -// Function: P3DBoolValue::Copy Constructor +// Function: P3DBoolObject::Copy Constructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// -P3DBoolValue:: -P3DBoolValue(const P3DBoolValue ©) : - P3DValue(copy), +P3DBoolObject:: +P3DBoolObject(const P3DBoolObject ©) : + P3DObject(copy), _value(copy._value) { } //////////////////////////////////////////////////////////////////// -// Function: P3DBoolValue::make_copy +// Function: P3DBoolObject::make_copy // Access: Public, Virtual // Description: //////////////////////////////////////////////////////////////////// -P3DValue *P3DBoolValue:: -make_copy() { - return new P3DBoolValue(*this); +P3DObject *P3DBoolObject:: +make_copy() const { + return new P3DBoolObject(*this); } //////////////////////////////////////////////////////////////////// -// Function: P3DBoolValue::get_bool +// Function: P3DBoolObject::get_bool // Access: Public, Virtual -// Description: Returns the value value coerced to a boolean, if +// Description: Returns the object value coerced to a boolean, if // possible. //////////////////////////////////////////////////////////////////// -bool P3DBoolValue:: +bool P3DBoolObject:: get_bool() const { return _value; } //////////////////////////////////////////////////////////////////// -// Function: P3DBoolValue::get_int +// Function: P3DBoolObject::get_int // Access: Public, Virtual -// Description: Returns the value value coerced to an integer, if +// Description: Returns the object value coerced to an integer, if // possible. //////////////////////////////////////////////////////////////////// -int P3DBoolValue:: +int P3DBoolObject:: get_int() const { return _value; } //////////////////////////////////////////////////////////////////// -// Function: P3DBoolValue::make_string +// Function: P3DBoolObject::make_string // Access: Public, Virtual // Description: Fills the indicated C++ string object with the value // of this object coerced to a string. //////////////////////////////////////////////////////////////////// -void P3DBoolValue:: +void P3DBoolObject:: make_string(string &value) const { if (_value) { value = "True"; @@ -86,12 +86,12 @@ make_string(string &value) const { } //////////////////////////////////////////////////////////////////// -// Function: P3DBoolValue::make_xml +// Function: P3DBoolObject::make_xml // Access: Public, Virtual // Description: Allocates and returns a new XML structure // corresponding to this value. //////////////////////////////////////////////////////////////////// -TiXmlElement *P3DBoolValue:: +TiXmlElement *P3DBoolObject:: make_xml() const { TiXmlElement *xvalue = new TiXmlElement("value"); xvalue->SetAttribute("type", "bool"); diff --git a/direct/src/plugin/p3dBoolValue.h b/direct/src/plugin/p3dBoolObject.h similarity index 70% rename from direct/src/plugin/p3dBoolValue.h rename to direct/src/plugin/p3dBoolObject.h index 3ea47ca529..0c332d6904 100644 --- a/direct/src/plugin/p3dBoolValue.h +++ b/direct/src/plugin/p3dBoolObject.h @@ -1,4 +1,4 @@ -// Filename: p3dBoolValue.h +// Filename: p3dBoolObject.h // Created by: drose (30Jun09) // //////////////////////////////////////////////////////////////////// @@ -12,23 +12,23 @@ // //////////////////////////////////////////////////////////////////// -#ifndef P3DBOOLVALUE_H -#define P3DBOOLVALUE_H +#ifndef P3DBOOLOBJECT_H +#define P3DBOOLOBJECT_H #include "p3d_plugin_common.h" -#include "p3dValue.h" +#include "p3dObject.h" //////////////////////////////////////////////////////////////////// -// Class : P3DBoolValue -// Description : A value type that contains a boolean value. +// Class : P3DBoolObject +// Description : An object type that contains a boolean value. //////////////////////////////////////////////////////////////////// -class P3DBoolValue : public P3DValue { +class P3DBoolObject : public P3DObject { public: - P3DBoolValue(bool value); - P3DBoolValue(const P3DBoolValue ©); + P3DBoolObject(bool value); + P3DBoolObject(const P3DBoolObject ©); public: - virtual P3DValue *make_copy(); + virtual P3DObject *make_copy() const; virtual bool get_bool() const; virtual int get_int() const; virtual void make_string(string &value) const; diff --git a/direct/src/plugin/p3dFloatValue.cxx b/direct/src/plugin/p3dFloatObject.cxx similarity index 73% rename from direct/src/plugin/p3dFloatValue.cxx rename to direct/src/plugin/p3dFloatObject.cxx index dc1da706fd..f6c4e4d47e 100644 --- a/direct/src/plugin/p3dFloatValue.cxx +++ b/direct/src/plugin/p3dFloatObject.cxx @@ -1,4 +1,4 @@ -// Filename: p3dFloatValue.cxx +// Filename: p3dFloatObject.cxx // Created by: drose (30Jun09) // //////////////////////////////////////////////////////////////////// @@ -12,82 +12,82 @@ // //////////////////////////////////////////////////////////////////// -#include "p3dFloatValue.h" +#include "p3dFloatObject.h" //////////////////////////////////////////////////////////////////// -// Function: P3DFloatValue::Constructor +// Function: P3DFloatObject::Constructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// -P3DFloatValue:: -P3DFloatValue(double value) : - P3DValue(P3D_VT_float), +P3DFloatObject:: +P3DFloatObject(double value) : + P3DObject(P3D_OT_float), _value(value) { } //////////////////////////////////////////////////////////////////// -// Function: P3DFloatValue::Copy Constructor +// Function: P3DFloatObject::Copy Constructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// -P3DFloatValue:: -P3DFloatValue(const P3DFloatValue ©) : - P3DValue(copy), +P3DFloatObject:: +P3DFloatObject(const P3DFloatObject ©) : + P3DObject(copy), _value(copy._value) { } //////////////////////////////////////////////////////////////////// -// Function: P3DFloatValue::make_copy +// Function: P3DFloatObject::make_copy // Access: Public, Virtual // Description: //////////////////////////////////////////////////////////////////// -P3DValue *P3DFloatValue:: -make_copy() { - return new P3DFloatValue(*this); +P3DObject *P3DFloatObject:: +make_copy() const { + return new P3DFloatObject(*this); } //////////////////////////////////////////////////////////////////// -// Function: P3DFloatValue::get_bool +// Function: P3DFloatObject::get_bool // Access: Public, Virtual -// Description: Returns the value value coerced to a boolean, if +// Description: Returns the object value coerced to a boolean, if // possible. //////////////////////////////////////////////////////////////////// -bool P3DFloatValue:: +bool P3DFloatObject:: get_bool() const { return (_value != 0.0); } //////////////////////////////////////////////////////////////////// -// Function: P3DFloatValue::get_int +// Function: P3DFloatObject::get_int // Access: Public, Virtual -// Description: Returns the value value coerced to an integer, if +// Description: Returns the object value coerced to an integer, if // possible. //////////////////////////////////////////////////////////////////// -int P3DFloatValue:: +int P3DFloatObject:: get_int() const { return (int)_value; } //////////////////////////////////////////////////////////////////// -// Function: P3DFloatValue::get_float +// Function: P3DFloatObject::get_float // Access: Public, Virtual -// Description: Returns the value value coerced to a floating-point +// Description: Returns the object value coerced to a floating-point // value, if possible. //////////////////////////////////////////////////////////////////// -double P3DFloatValue:: +double P3DFloatObject:: get_float() const { return _value; } //////////////////////////////////////////////////////////////////// -// Function: P3DFloatValue::make_string +// Function: P3DFloatObject::make_string // Access: Public, Virtual // Description: Fills the indicated C++ string object with the value // of this object coerced to a string. //////////////////////////////////////////////////////////////////// -void P3DFloatValue:: +void P3DFloatObject:: make_string(string &value) const { ostringstream strm; strm << _value; @@ -96,12 +96,12 @@ make_string(string &value) const { //////////////////////////////////////////////////////////////////// -// Function: P3DFloatValue::make_xml +// Function: P3DFloatObject::make_xml // Access: Public, Virtual // Description: Allocates and returns a new XML structure // corresponding to this value. //////////////////////////////////////////////////////////////////// -TiXmlElement *P3DFloatValue:: +TiXmlElement *P3DFloatObject:: make_xml() const { TiXmlElement *xvalue = new TiXmlElement("value"); xvalue->SetAttribute("type", "float"); diff --git a/direct/src/plugin/p3dFloatValue.h b/direct/src/plugin/p3dFloatObject.h similarity index 70% rename from direct/src/plugin/p3dFloatValue.h rename to direct/src/plugin/p3dFloatObject.h index 68e1d38988..a38716b4b9 100644 --- a/direct/src/plugin/p3dFloatValue.h +++ b/direct/src/plugin/p3dFloatObject.h @@ -1,4 +1,4 @@ -// Filename: p3dFloatValue.h +// Filename: p3dFloatObject.h // Created by: drose (30Jun09) // //////////////////////////////////////////////////////////////////// @@ -12,23 +12,23 @@ // //////////////////////////////////////////////////////////////////// -#ifndef P3DFLOATVALUE_H -#define P3DFLOATVALUE_H +#ifndef P3DFLOATOBJECT_H +#define P3DFLOATOBJECT_H #include "p3d_plugin_common.h" -#include "p3dValue.h" +#include "p3dObject.h" //////////////////////////////////////////////////////////////////// -// Class : P3DFloatValue -// Description : A value type that contains a floating-point value. +// Class : P3DFloatObject +// Description : An object type that contains a floating-point value. //////////////////////////////////////////////////////////////////// -class P3DFloatValue : public P3DValue { +class P3DFloatObject : public P3DObject { public: - P3DFloatValue(double value); - P3DFloatValue(const P3DFloatValue ©); + P3DFloatObject(double value); + P3DFloatObject(const P3DFloatObject ©); public: - virtual P3DValue *make_copy(); + virtual P3DObject *make_copy() const; virtual bool get_bool() const; virtual int get_int() const; virtual double get_float() const; diff --git a/direct/src/plugin/p3dInstance.cxx b/direct/src/plugin/p3dInstance.cxx index fc0b30e85d..29e35c1487 100644 --- a/direct/src/plugin/p3dInstance.cxx +++ b/direct/src/plugin/p3dInstance.cxx @@ -19,8 +19,8 @@ #include "p3dPackage.h" #include "p3dSplashWindow.h" #include "p3dWinSplashWindow.h" -#include "p3dValue.h" -#include "p3dNoneValue.h" +#include "p3dObject.h" +#include "p3dNoneObject.h" #include #include @@ -169,7 +169,7 @@ set_wparams(const P3DWindowParams &wparams) { // Panda application, and the Javascript on the // containing web page). //////////////////////////////////////////////////////////////////// -P3DValue *P3DInstance:: +P3DObject *P3DInstance:: get_property(const string &property_name) const { return NULL; } @@ -180,7 +180,7 @@ get_property(const string &property_name) const { // Description: Returns a list of subordinate properties below the // named property. //////////////////////////////////////////////////////////////////// -P3DValue *P3DInstance:: +P3DObject *P3DInstance:: get_property_list(const string &property_name) const { return NULL; } @@ -194,7 +194,7 @@ get_property_list(const string &property_name) const { // false on failure. //////////////////////////////////////////////////////////////////// bool P3DInstance:: -set_property(const string &property_name, const P3DValue *value) { +set_property(const string &property_name, const P3DObject *value) { return false; } @@ -204,9 +204,9 @@ set_property(const string &property_name, const P3DValue *value) { // Description: Calls the named property as a method, supplying the // indicated parameters. //////////////////////////////////////////////////////////////////// -P3DValue *P3DInstance:: -call(const string &property_name, const P3DValue *params) { - return new P3DNoneValue; +P3DObject *P3DInstance:: +call(const string &property_name, const P3DObject *params) { + return new P3DNoneObject; } @@ -353,7 +353,7 @@ feed_url_stream(int unique_id, // freshly allocated; it will be deleted by this method. //////////////////////////////////////////////////////////////////// void P3DInstance:: -feed_value(int unique_id, P3DValue *value) { +feed_value(int unique_id, P3DObject *value) { if (_session != NULL) { TiXmlDocument *doc = new TiXmlDocument; TiXmlDeclaration *decl = new TiXmlDeclaration("1.0", "utf-8", ""); diff --git a/direct/src/plugin/p3dInstance.h b/direct/src/plugin/p3dInstance.h index 06daa1c2e5..85c67bec9b 100644 --- a/direct/src/plugin/p3dInstance.h +++ b/direct/src/plugin/p3dInstance.h @@ -28,7 +28,7 @@ class P3DSession; class P3DSplashWindow; class P3DDownload; class P3DPackage; -class P3DValue; +class P3DObject; //////////////////////////////////////////////////////////////////// // Class : P3DInstance @@ -46,11 +46,11 @@ public: void set_wparams(const P3DWindowParams &wparams); inline const P3DWindowParams &get_wparams() const; - P3DValue *get_property(const string &property_name) const; - P3DValue *get_property_list(const string &property_name) const; + P3DObject *get_property(const string &property_name) const; + P3DObject *get_property_list(const string &property_name) const; bool set_property(const string &property_name, - const P3DValue *value); - P3DValue *call(const string &property_name, const P3DValue *params); + const P3DObject *value); + P3DObject *call(const string &property_name, const P3DObject *params); bool has_request(); P3D_request *get_request(); @@ -63,7 +63,7 @@ public: size_t total_expected_data, const unsigned char *this_data, size_t this_data_size); - void feed_value(int unique_id, P3DValue *value); + void feed_value(int unique_id, P3DObject *value); inline int get_instance_id() const; inline const string &get_session_key() const; diff --git a/direct/src/plugin/p3dInstanceManager.cxx b/direct/src/plugin/p3dInstanceManager.cxx index 3fc32dc12c..5525e905b9 100644 --- a/direct/src/plugin/p3dInstanceManager.cxx +++ b/direct/src/plugin/p3dInstanceManager.cxx @@ -294,6 +294,17 @@ signal_request_ready() { #endif } +//////////////////////////////////////////////////////////////////// +// Function: P3DInstanceManager::make_class_definition +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +P3D_class_definition *P3DInstanceManager:: +make_class_definition() const { + // TODO. + return NULL; +} + //////////////////////////////////////////////////////////////////// // Function: P3DInstanceManager::get_global_ptr // Access: Public, Static diff --git a/direct/src/plugin/p3dInstanceManager.h b/direct/src/plugin/p3dInstanceManager.h index fd1d753667..6813685883 100644 --- a/direct/src/plugin/p3dInstanceManager.h +++ b/direct/src/plugin/p3dInstanceManager.h @@ -62,6 +62,8 @@ public: int get_unique_session_index(); void signal_request_ready(); + P3D_class_definition *make_class_definition() const; + static P3DInstanceManager *get_global_ptr(); private: diff --git a/direct/src/plugin/p3dIntValue.cxx b/direct/src/plugin/p3dIntObject.cxx similarity index 75% rename from direct/src/plugin/p3dIntValue.cxx rename to direct/src/plugin/p3dIntObject.cxx index c0d6146fe3..dcbe1bfeda 100644 --- a/direct/src/plugin/p3dIntValue.cxx +++ b/direct/src/plugin/p3dIntObject.cxx @@ -1,4 +1,4 @@ -// Filename: p3dIntValue.cxx +// Filename: p3dIntObject.cxx // Created by: drose (30Jun09) // //////////////////////////////////////////////////////////////////// @@ -12,71 +12,71 @@ // //////////////////////////////////////////////////////////////////// -#include "p3dIntValue.h" +#include "p3dIntObject.h" //////////////////////////////////////////////////////////////////// -// Function: P3DIntValue::Constructor +// Function: P3DIntObject::Constructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// -P3DIntValue:: -P3DIntValue(int value) : - P3DValue(P3D_VT_int), +P3DIntObject:: +P3DIntObject(int value) : + P3DObject(P3D_OT_int), _value(value) { } //////////////////////////////////////////////////////////////////// -// Function: P3DIntValue::Copy Constructor +// Function: P3DIntObject::Copy Constructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// -P3DIntValue:: -P3DIntValue(const P3DIntValue ©) : - P3DValue(copy), +P3DIntObject:: +P3DIntObject(const P3DIntObject ©) : + P3DObject(copy), _value(copy._value) { } //////////////////////////////////////////////////////////////////// -// Function: P3DIntValue::make_copy +// Function: P3DIntObject::make_copy // Access: Public, Virtual // Description: //////////////////////////////////////////////////////////////////// -P3DValue *P3DIntValue:: -make_copy() { - return new P3DIntValue(*this); +P3DObject *P3DIntObject:: +make_copy() const { + return new P3DIntObject(*this); } //////////////////////////////////////////////////////////////////// -// Function: P3DIntValue::get_bool +// Function: P3DIntObject::get_bool // Access: Public, Virtual -// Description: Returns the value value coerced to a boolean, if +// Description: Returns the object value coerced to a boolean, if // possible. //////////////////////////////////////////////////////////////////// -bool P3DIntValue:: +bool P3DIntObject:: get_bool() const { return (_value != 0); } //////////////////////////////////////////////////////////////////// -// Function: P3DIntValue::get_int +// Function: P3DIntObject::get_int // Access: Public, Virtual -// Description: Returns the value value coerced to an integer, if +// Description: Returns the object value coerced to an integer, if // possible. //////////////////////////////////////////////////////////////////// -int P3DIntValue:: +int P3DIntObject:: get_int() const { return _value; } //////////////////////////////////////////////////////////////////// -// Function: P3DIntValue::make_string +// Function: P3DIntObject::make_string // Access: Public, Virtual // Description: Fills the indicated C++ string object with the value // of this object coerced to a string. //////////////////////////////////////////////////////////////////// -void P3DIntValue:: +void P3DIntObject:: make_string(string &value) const { ostringstream strm; strm << _value; @@ -85,12 +85,12 @@ make_string(string &value) const { //////////////////////////////////////////////////////////////////// -// Function: P3DIntValue::make_xml +// Function: P3DIntObject::make_xml // Access: Public, Virtual // Description: Allocates and returns a new XML structure // corresponding to this value. //////////////////////////////////////////////////////////////////// -TiXmlElement *P3DIntValue:: +TiXmlElement *P3DIntObject:: make_xml() const { TiXmlElement *xvalue = new TiXmlElement("value"); xvalue->SetAttribute("type", "int"); diff --git a/direct/src/plugin/p3dIntValue.h b/direct/src/plugin/p3dIntObject.h similarity index 71% rename from direct/src/plugin/p3dIntValue.h rename to direct/src/plugin/p3dIntObject.h index b1542bf9ac..a9151584db 100644 --- a/direct/src/plugin/p3dIntValue.h +++ b/direct/src/plugin/p3dIntObject.h @@ -1,4 +1,4 @@ -// Filename: p3dIntValue.h +// Filename: p3dIntObject.h // Created by: drose (30Jun09) // //////////////////////////////////////////////////////////////////// @@ -12,23 +12,23 @@ // //////////////////////////////////////////////////////////////////// -#ifndef P3DINTVALUE_H -#define P3DINTVALUE_H +#ifndef P3DINTOBJECT_H +#define P3DINTOBJECT_H #include "p3d_plugin_common.h" -#include "p3dValue.h" +#include "p3dObject.h" //////////////////////////////////////////////////////////////////// -// Class : P3DIntValue -// Description : A value type that contains an integer value. +// Class : P3DIntObject +// Description : An object type that contains an integer value. //////////////////////////////////////////////////////////////////// -class P3DIntValue : public P3DValue { +class P3DIntObject : public P3DObject { public: - P3DIntValue(int value); - P3DIntValue(const P3DIntValue ©); + P3DIntObject(int value); + P3DIntObject(const P3DIntObject ©); public: - virtual P3DValue *make_copy(); + virtual P3DObject *make_copy() const; virtual bool get_bool() const; virtual int get_int() const; virtual void make_string(string &value) const; diff --git a/direct/src/plugin/p3dListValue.cxx b/direct/src/plugin/p3dListObject.cxx similarity index 63% rename from direct/src/plugin/p3dListValue.cxx rename to direct/src/plugin/p3dListObject.cxx index 34e5e4617c..2aa595b360 100644 --- a/direct/src/plugin/p3dListValue.cxx +++ b/direct/src/plugin/p3dListObject.cxx @@ -1,4 +1,4 @@ -// Filename: p3dListValue.cxx +// Filename: p3dListObject.cxx // Created by: drose (30Jun09) // //////////////////////////////////////////////////////////////////// @@ -12,92 +12,75 @@ // //////////////////////////////////////////////////////////////////// -#include "p3dListValue.h" +#include "p3dListObject.h" //////////////////////////////////////////////////////////////////// -// Function: P3DListValue::Default Constructor +// Function: P3DListObject::Default Constructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// -P3DListValue:: -P3DListValue() : P3DValue(P3D_VT_list) { +P3DListObject:: +P3DListObject() : P3DObject(P3D_OT_list) { } //////////////////////////////////////////////////////////////////// -// Function: P3DListValue::Constructor -// Access: Public -// Description: Note that the ownership of the elements in the array -// (but not the array itself) is transferred to the -// list. -//////////////////////////////////////////////////////////////////// -P3DListValue:: -P3DListValue(P3DValue * const elements[], int num_elements) : - P3DValue(P3D_VT_list) -{ - _elements.reserve(num_elements); - for (int i = 0; i < num_elements; ++i) { - _elements.push_back(elements[i]); - } -} - -//////////////////////////////////////////////////////////////////// -// Function: P3DListValue::Copy Constructor +// Function: P3DListObject::Copy Constructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// -P3DListValue:: -P3DListValue(const P3DListValue ©) : - P3DValue(copy) +P3DListObject:: +P3DListObject(const P3DListObject ©) : + P3DObject(copy) { _elements.reserve(copy._elements.size()); Elements::const_iterator ei; for (ei = copy._elements.begin(); ei != copy._elements.end(); ++ei) { - _elements.push_back((*ei)->make_copy()); + _elements.push_back(P3D_OBJECT_COPY(*ei)); } } //////////////////////////////////////////////////////////////////// -// Function: P3DListValue::Destructor +// Function: P3DListObject::Destructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// -P3DListValue:: -~P3DListValue() { +P3DListObject:: +~P3DListObject() { Elements::iterator ei; for (ei = _elements.begin(); ei != _elements.end(); ++ei) { - delete (*ei); + P3D_OBJECT_FINISH(*ei); } } //////////////////////////////////////////////////////////////////// -// Function: P3DListValue::make_copy +// Function: P3DListObject::make_copy // Access: Public, Virtual // Description: //////////////////////////////////////////////////////////////////// -P3DValue *P3DListValue:: -make_copy() { - return new P3DListValue(*this); +P3DObject *P3DListObject:: +make_copy() const { + return new P3DListObject(*this); } //////////////////////////////////////////////////////////////////// -// Function: P3DListValue::get_bool +// Function: P3DListObject::get_bool // Access: Public, Virtual -// Description: Returns the value value coerced to a boolean, if +// Description: Returns the object value coerced to a boolean, if // possible. //////////////////////////////////////////////////////////////////// -bool P3DListValue:: +bool P3DListObject:: get_bool() const { return !_elements.empty(); } //////////////////////////////////////////////////////////////////// -// Function: P3DListValue::make_string +// Function: P3DListObject::make_string // Access: Public, Virtual // Description: Fills the indicated C++ string object with the value // of this object coerced to a string. //////////////////////////////////////////////////////////////////// -void P3DListValue:: +void P3DListObject:: make_string(string &value) const { ostringstream strm; strm << "["; @@ -113,55 +96,78 @@ make_string(string &value) const { } //////////////////////////////////////////////////////////////////// -// Function: P3DListValue::get_list_length +// Function: P3DListObject::get_list_length // Access: Public, Virtual -// Description: Returns the length of the value value as a list. +// Description: Returns the length of the object as a list. //////////////////////////////////////////////////////////////////// -int P3DListValue:: +int P3DListObject:: get_list_length() const { return _elements.size(); } //////////////////////////////////////////////////////////////////// -// Function: P3DListValue::get_list_item +// Function: P3DListObject::get_element // Access: Public, Virtual // Description: Returns the nth item in the value as a list. The -// return value is a freshly-allocated P3DValue object +// return value is a freshly-allocated P3DObject object // that must be deleted by the caller, or NULL on error. //////////////////////////////////////////////////////////////////// -P3DValue *P3DListValue:: -get_list_item(int n) const { +P3D_object *P3DListObject:: +get_element(int n) const { if (n >= 0 && n < (int)_elements.size()) { - return _elements[n]->make_copy(); + return P3D_OBJECT_COPY(_elements[n]); } return NULL; } //////////////////////////////////////////////////////////////////// -// Function: P3DListValue::append_item +// Function: P3DListObject::set_element // Access: Public, Virtual -// Description: Appends a new item to the end of the list. Ownership -// of the item is transferred to the list. +// Description: Modifies (or deletes, if value is NULL) the nth item +// in the value as a list. Returns true on success, +// false on failure. //////////////////////////////////////////////////////////////////// -void P3DListValue:: -append_item(P3DValue *item) { - _elements.push_back(item); +bool P3DListObject:: +set_element(int n, P3D_object *value) { + if (n < 0 || n > (int)_elements.size()) { + // Invalid index. + return false; + } + + if (n == _elements.size()) { + // Append one. + _elements.push_back(NULL); + } + if (_elements[n] != NULL) { + // Delete prior. + P3D_OBJECT_FINISH(_elements[n]); + } + _elements[n] = value; + + // Delete NULL elements on the end. + while (!_elements.empty() && _elements.back() == NULL) { + _elements.pop_back(); + } + + return true; } //////////////////////////////////////////////////////////////////// -// Function: P3DListValue::make_xml +// Function: P3DListObject::make_xml // Access: Public, Virtual // Description: Allocates and returns a new XML structure // corresponding to this value. //////////////////////////////////////////////////////////////////// -TiXmlElement *P3DListValue:: +TiXmlElement *P3DListObject:: make_xml() const { TiXmlElement *xvalue = new TiXmlElement("value"); xvalue->SetAttribute("type", "list"); Elements::const_iterator ei; for (ei = _elements.begin(); ei != _elements.end(); ++ei) { - TiXmlElement *xchild = (*ei)->make_xml(); + P3D_object *child = (*ei); + assert(child->_class == &P3DObject::_object_class); + TiXmlElement *xchild = ((P3DObject *)child)->make_xml(); xvalue->LinkEndChild(xchild); } diff --git a/direct/src/plugin/p3dListValue.h b/direct/src/plugin/p3dListObject.h similarity index 61% rename from direct/src/plugin/p3dListValue.h rename to direct/src/plugin/p3dListObject.h index a7f38dbb49..5ef0825739 100644 --- a/direct/src/plugin/p3dListValue.h +++ b/direct/src/plugin/p3dListObject.h @@ -1,4 +1,4 @@ -// Filename: p3dListValue.h +// Filename: p3dListObject.h // Created by: drose (30Jun09) // //////////////////////////////////////////////////////////////////// @@ -12,37 +12,35 @@ // //////////////////////////////////////////////////////////////////// -#ifndef P3DLISTVALUE_H -#define P3DLISTVALUE_H +#ifndef P3DLISTOBJECT_H +#define P3DLISTOBJECT_H #include "p3d_plugin_common.h" -#include "p3dValue.h" +#include "p3dObject.h" //////////////////////////////////////////////////////////////////// -// Class : P3DListValue -// Description : A value type that contains a list of other values. +// Class : P3DListObject +// Description : An object type that contains a list of objects. //////////////////////////////////////////////////////////////////// -class P3DListValue : public P3DValue { +class P3DListObject : public P3DObject { public: - P3DListValue(); - P3DListValue(P3DValue * const elements[], int num_elements); - P3DListValue(const P3DListValue ©); + P3DListObject(); + P3DListObject(const P3DListObject ©); public: - virtual ~P3DListValue(); + virtual ~P3DListObject(); - virtual P3DValue *make_copy(); + virtual P3DObject *make_copy() const; virtual bool get_bool() const; virtual void make_string(string &value) const; virtual int get_list_length() const; - virtual P3DValue *get_list_item(int n) const; - - void append_item(P3DValue *item); + virtual P3D_object *get_element(int n) const; + virtual bool set_element(int n, P3D_object *value); virtual TiXmlElement *make_xml() const; private: - typedef vector Elements; + typedef vector Elements; Elements _elements; }; diff --git a/direct/src/plugin/p3dNoneValue.cxx b/direct/src/plugin/p3dNoneObject.cxx similarity index 76% rename from direct/src/plugin/p3dNoneValue.cxx rename to direct/src/plugin/p3dNoneObject.cxx index 01d178dca1..3fa91a70d6 100644 --- a/direct/src/plugin/p3dNoneValue.cxx +++ b/direct/src/plugin/p3dNoneObject.cxx @@ -1,4 +1,4 @@ -// Filename: p3dNoneValue.cxx +// Filename: p3dNoneObject.cxx // Created by: drose (30Jun09) // //////////////////////////////////////////////////////////////////// @@ -12,56 +12,56 @@ // //////////////////////////////////////////////////////////////////// -#include "p3dNoneValue.h" +#include "p3dNoneObject.h" //////////////////////////////////////////////////////////////////// -// Function: P3DNoneValue::Constructor +// Function: P3DNoneObject::Constructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// -P3DNoneValue:: -P3DNoneValue() : P3DValue(P3D_VT_none) { +P3DNoneObject:: +P3DNoneObject() : P3DObject(P3D_OT_none) { } //////////////////////////////////////////////////////////////////// -// Function: P3DNoneValue::make_copy +// Function: P3DNoneObject::make_copy // Access: Public, Virtual // Description: //////////////////////////////////////////////////////////////////// -P3DValue *P3DNoneValue:: -make_copy() { - return new P3DNoneValue(*this); +P3DObject *P3DNoneObject:: +make_copy() const { + return new P3DNoneObject(*this); } //////////////////////////////////////////////////////////////////// -// Function: P3DNoneValue::get_bool +// Function: P3DNoneObject::get_bool // Access: Public, Virtual -// Description: Returns the value value coerced to a boolean, if +// Description: Returns the object value coerced to a boolean, if // possible. //////////////////////////////////////////////////////////////////// -bool P3DNoneValue:: +bool P3DNoneObject:: get_bool() const { return false; } //////////////////////////////////////////////////////////////////// -// Function: P3DNoneValue::make_string +// Function: P3DNoneObject::make_string // Access: Public, Virtual // Description: Fills the indicated C++ string object with the value // of this object coerced to a string. //////////////////////////////////////////////////////////////////// -void P3DNoneValue:: +void P3DNoneObject:: make_string(string &value) const { value = "None"; } //////////////////////////////////////////////////////////////////// -// Function: P3DNoneValue::make_xml +// Function: P3DNoneObject::make_xml // Access: Public, Virtual // Description: Allocates and returns a new XML structure // corresponding to this value. //////////////////////////////////////////////////////////////////// -TiXmlElement *P3DNoneValue:: +TiXmlElement *P3DNoneObject:: make_xml() const { TiXmlElement *xvalue = new TiXmlElement("value"); xvalue->SetAttribute("type", "none"); diff --git a/direct/src/plugin/p3dNoneValue.h b/direct/src/plugin/p3dNoneObject.h similarity index 73% rename from direct/src/plugin/p3dNoneValue.h rename to direct/src/plugin/p3dNoneObject.h index 719bc01f46..0c9d3a02bb 100644 --- a/direct/src/plugin/p3dNoneValue.h +++ b/direct/src/plugin/p3dNoneObject.h @@ -1,4 +1,4 @@ -// Filename: p3dNoneValue.h +// Filename: p3dNoneObject.h // Created by: drose (30Jun09) // //////////////////////////////////////////////////////////////////// @@ -12,23 +12,23 @@ // //////////////////////////////////////////////////////////////////// -#ifndef P3DNONEVALUE_H -#define P3DNONEVALUE_H +#ifndef P3DNONEOBJECT_H +#define P3DNONEOBJECT_H #include "p3d_plugin_common.h" -#include "p3dValue.h" +#include "p3dObject.h" //////////////////////////////////////////////////////////////////// -// Class : P3DNoneValue -// Description : A value type that contains no value, similar to +// Class : P3DNoneObject +// Description : An object type that contains no value, similar to // Python's None type. //////////////////////////////////////////////////////////////////// -class P3DNoneValue : public P3DValue { +class P3DNoneObject : public P3DObject { public: - P3DNoneValue(); + P3DNoneObject(); public: - virtual P3DValue *make_copy(); + virtual P3DObject *make_copy() const; virtual bool get_bool() const; virtual void make_string(string &value) const; diff --git a/direct/src/plugin/p3dValue.I b/direct/src/plugin/p3dObject.I similarity index 59% rename from direct/src/plugin/p3dValue.I rename to direct/src/plugin/p3dObject.I index 4055b267f3..d531b8fa3e 100644 --- a/direct/src/plugin/p3dValue.I +++ b/direct/src/plugin/p3dObject.I @@ -1,4 +1,4 @@ -// Filename: p3dValue.I +// Filename: p3dObject.I // Created by: drose (30Jun09) // //////////////////////////////////////////////////////////////////// @@ -14,21 +14,32 @@ //////////////////////////////////////////////////////////////////// -// Function: P3DValue::Constructor +// Function: P3DObject::Constructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// -inline P3DValue:: -P3DValue(P3D_value_type type) { +inline P3DObject:: +P3DObject(P3D_object_type type) { + _class = &_object_class; _type = type; } //////////////////////////////////////////////////////////////////// -// Function: P3DValue::Copy Constructor +// Function: P3DObject::Copy Constructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// -inline P3DValue:: -P3DValue(const P3DValue ©) { +inline P3DObject:: +P3DObject(const P3DObject ©) { _type = copy._type; } + +//////////////////////////////////////////////////////////////////// +// Function: P3DObject::get_type +// Access: Public +// Description: Returns the fundamental type of this kind of object. +//////////////////////////////////////////////////////////////////// +inline P3D_object_type P3DObject:: +get_type() const { + return _type; +} diff --git a/direct/src/plugin/p3dObject.cxx b/direct/src/plugin/p3dObject.cxx new file mode 100644 index 0000000000..6d0bb792de --- /dev/null +++ b/direct/src/plugin/p3dObject.cxx @@ -0,0 +1,284 @@ +// Filename: p3dObject.cxx +// Created by: drose (30Jun09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "p3dObject.h" +#include // strncpy + +// The following functions are C-style wrappers around the above +// P3DObject virtual methods; they are defined to allow us to create +// the C-style P3D_class_definition method table to store in the +// P3D_object structure. +static void +object_finish(P3D_object *object) { + delete ((P3DObject *)object); +} + +static P3D_object * +object_copy(const P3D_object *object) { + return ((const P3DObject *)object)->make_copy(); +} + +static P3D_object_type +object_get_type(const P3D_object *object) { + return ((const P3DObject *)object)->get_type(); +} + +static bool +object_get_bool(const P3D_object *object) { + return ((const P3DObject *)object)->get_bool(); +} + +static int +object_get_int(const P3D_object *object) { + return ((const P3DObject *)object)->get_int(); +} + +static double +object_get_float(const P3D_object *object) { + return ((const P3DObject *)object)->get_float(); +} + +static int +object_get_string(const P3D_object *object, char *buffer, int buffer_length) { + return ((const P3DObject *)object)->get_string(buffer, buffer_length); +} + +static int +object_get_repr(const P3D_object *object, char *buffer, int buffer_length) { + return ((const P3DObject *)object)->get_repr(buffer, buffer_length); +} + +static P3D_object * +object_get_property(const P3D_object *object, const char *property) { + return ((const P3DObject *)object)->get_property(property); +} + +static bool +object_set_property(P3D_object *object, const char *property, + P3D_object *value) { + return ((P3DObject *)object)->set_property(property, value); +} + +static P3D_object * +object_get_element(const P3D_object *object, int n) { + return ((const P3DObject *)object)->get_element(n); +} + +static bool +object_set_element(P3D_object *object, int n, P3D_object *value) { + return ((P3DObject *)object)->set_element(n, value); +} + +static int object_get_list_length(const P3D_object *object) { + return ((const P3DObject *)object)->get_list_length(); +} + +static P3D_object * +object_call(const P3D_object *object, P3D_object *params) { + return ((const P3DObject *)object)->call(params); +} + +static P3D_object * +object_evaluate(const P3D_object *object, const char *expression) { + return ((const P3DObject *)object)->evaluate(expression); +} + +P3D_class_definition P3DObject::_object_class = { + &object_finish, + &object_copy, + &object_get_type, + &object_get_bool, + &object_get_int, + &object_get_float, + &object_get_string, + &object_get_repr, + &object_get_property, + &object_set_property, + &object_get_element, + &object_set_element, + &object_get_list_length, + &object_call, + &object_evaluate, +}; + +//////////////////////////////////////////////////////////////////// +// Function: P3DObject::Destructor +// Access: Public, Virtual +// Description: +//////////////////////////////////////////////////////////////////// +P3DObject:: +~P3DObject() { + _type = P3D_OT_none; +} + +//////////////////////////////////////////////////////////////////// +// Function: P3DObject::get_int +// Access: Public, Virtual +// Description: Returns the object value coerced to an integer, if +// possible. +//////////////////////////////////////////////////////////////////// +int P3DObject:: +get_int() const { + return 0; +} + +//////////////////////////////////////////////////////////////////// +// Function: P3DObject::get_float +// Access: Public, Virtual +// Description: Returns the object value coerced to a floating-point +// value, if possible. +//////////////////////////////////////////////////////////////////// +double P3DObject:: +get_float() const { + return get_int(); +} + +//////////////////////////////////////////////////////////////////// +// Function: P3DObject::get_string +// Access: Public +// Description: Stores a string that represents the object value in +// the indicated buffer; a null character is included if +// there is space. Returns the number of characters +// needed in the output (which might be more than the +// actual number of characters stored if buffer_length +// was too small). +//////////////////////////////////////////////////////////////////// +int P3DObject:: +get_string(char *buffer, int buffer_length) const { + string result; + make_string(result); + strncpy(buffer, result.c_str(), buffer_length); + return (int)result.size(); +} + +//////////////////////////////////////////////////////////////////// +// Function: P3DObject::get_repr +// Access: Public +// Description: Returns a user-friendly representation of the object, +// similar to get_string(), above. +//////////////////////////////////////////////////////////////////// +int P3DObject:: +get_repr(char *buffer, int buffer_length) const { + ostringstream strm; + output(strm); + string result = strm.str(); + strncpy(buffer, result.c_str(), buffer_length); + return (int)result.size(); +} + +//////////////////////////////////////////////////////////////////// +// Function: P3DObject::get_property +// Access: Public, Virtual +// Description: Returns the named property element in the object. The +// return value is a freshly-allocated P3DObject object +// that must be deleted by the caller, or NULL on error. +//////////////////////////////////////////////////////////////////// +P3D_object *P3DObject:: +get_property(const string &property) const { + return NULL; +} + +//////////////////////////////////////////////////////////////////// +// Function: P3DObject::set_property +// Access: Public, Virtual +// Description: Modifies (or deletes, if value is NULL) the named +// property element in the object. Returns true on +// success, false on failure. +//////////////////////////////////////////////////////////////////// +bool P3DObject:: +set_property(const string &property, P3D_object *value) { + if (value != NULL) { + P3D_OBJECT_FINISH(value); + } + return false; +} + +//////////////////////////////////////////////////////////////////// +// Function: P3DObject::get_list_length +// Access: Public, Virtual +// Description: Returns the length of the object as a list. +//////////////////////////////////////////////////////////////////// +int P3DObject:: +get_list_length() const { + return 0; +} + +//////////////////////////////////////////////////////////////////// +// Function: P3DObject::get_element +// Access: Public, Virtual +// Description: Returns the nth item in the value as a list. The +// return value is a freshly-allocated P3DObject object +// that must be deleted by the caller, or NULL on error. +//////////////////////////////////////////////////////////////////// +P3D_object *P3DObject:: +get_element(int n) const { + return NULL; +} + +//////////////////////////////////////////////////////////////////// +// Function: P3DObject::set_element +// Access: Public, Virtual +// Description: Modifies (or deletes, if value is NULL) the nth item +// in the value as a list. Returns true on success, +// false on failure. +//////////////////////////////////////////////////////////////////// +bool P3DObject:: +set_element(int n, P3D_object *value) { + if (value != NULL) { + P3D_OBJECT_FINISH(value); + } + return false; +} + +//////////////////////////////////////////////////////////////////// +// Function: P3DObject::call +// Access: Public, Virtual +// Description: Invokes the object as a method, passing the indicated +// parameters. Returns the return value on success, +// NULL on error. +//////////////////////////////////////////////////////////////////// +P3D_object *P3DObject:: +call(P3D_object *params) const { + if (params != NULL) { + P3D_OBJECT_FINISH(params); + } + return NULL; +} + +//////////////////////////////////////////////////////////////////// +// Function: P3DObject::evaluate +// Access: Public, Virtual +// Description: Evaluates an arbitrary script expression within the +// context of this object. Returns the return value on +// success, NULL on error. +//////////////////////////////////////////////////////////////////// +P3D_object *P3DObject:: +evaluate(const string &expression) const { + return NULL; +} + +//////////////////////////////////////////////////////////////////// +// Function: P3DObject::output +// Access: Public, Virtual +// Description: Writes a formatted representation of the value to the +// indicated string. This is intended for developer +// assistance. +//////////////////////////////////////////////////////////////////// +void P3DObject:: +output(ostream &out) const { + string value; + make_string(value); + out << value; +} + diff --git a/direct/src/plugin/p3dObject.h b/direct/src/plugin/p3dObject.h new file mode 100644 index 0000000000..a7b252eb36 --- /dev/null +++ b/direct/src/plugin/p3dObject.h @@ -0,0 +1,89 @@ +// Filename: p3dObject.h +// Created by: drose (30Jun09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef P3DOBJECT_H +#define P3DOBJECT_H + +#include "p3d_plugin_common.h" + +//////////////////////////////////////////////////////////////////// +// Class : P3DObject +// Description : The C++ implementation of P3D_value, corresponding +// to a single atomic value that is passed around +// between scripting languages. This is an abstract +// base class; the actual implementations are provided +// by the various specialized classes. +//////////////////////////////////////////////////////////////////// +class P3DObject : public P3D_object { +protected: + inline P3DObject(P3D_object_type type); + inline P3DObject(const P3DObject ©); + +public: + virtual ~P3DObject(); + + virtual P3DObject *make_copy() const=0; + inline P3D_object_type get_type() const; + virtual bool get_bool() const=0; + virtual int get_int() const; + virtual double get_float() const; + + int get_string(char *buffer, int buffer_length) const; + int get_repr(char *buffer, int buffer_length) const; + virtual void make_string(string &value) const=0; + + virtual P3D_object *get_property(const string &property) const; + virtual bool set_property(const string &property, P3D_object *value); + + virtual int get_list_length() const; + virtual P3D_object *get_element(int n) const; + virtual bool set_element(int n, P3D_object *value); + + virtual P3D_object *call(P3D_object *params) const; + virtual P3D_object *evaluate(const string &expression) const; + + virtual TiXmlElement *make_xml() const=0; + + virtual void output(ostream &out) const; + +protected: + P3D_object_type _type; + +public: + static P3D_class_definition _object_class; +}; + +#include "p3dObject.I" + +// For classes that inherit from P3DObject, above, we can use the +// virtual method to write the output simply. +inline ostream &operator << (ostream &out, const P3DObject &value) { + value.output(out); + return out; +} + +// For classes that inherit only from P3D_object, we have to use the +// generic C method, a little clumsier. +inline ostream &operator << (ostream &out, const P3D_object &value) { + int size = P3D_OBJECT_GET_REPR(&value, NULL, 0); + char *buffer = new char[size]; + P3D_OBJECT_GET_REPR(&value, buffer, size); + out.write(buffer, size); + delete[] buffer; + + return out; +} + +#endif + diff --git a/direct/src/plugin/p3dSession.cxx b/direct/src/plugin/p3dSession.cxx index 414cfb84fc..414839289f 100644 --- a/direct/src/plugin/p3dSession.cxx +++ b/direct/src/plugin/p3dSession.cxx @@ -450,16 +450,6 @@ rt_make_p3d_request(TiXmlElement *xrequest) { request->_request._notify._message = strdup(message); } - } else if (strcmp(rtype, "evaluate") == 0) { - const char *expression = xrequest->Attribute("expression"); - int unique_id; - if (expression != NULL && xrequest->QueryIntAttribute("unique_id", &unique_id) == TIXML_SUCCESS) { - request = new P3D_request; - request->_request_type = P3D_RT_evaluate; - request->_request._evaluate._expression = strdup(expression); - request->_request._evaluate._unique_id = unique_id; - } - } else { nout << "ignoring request of type " << rtype << "\n"; } @@ -472,31 +462,31 @@ rt_make_p3d_request(TiXmlElement *xrequest) { // Function: P3DSession::rt_from_xml_value // Access: Private // Description: Converts the XML representation of the particular -// value value into a corresponding P3DValue object. +// value value into a corresponding P3DObject object. // Returns the newly-allocated object. //////////////////////////////////////////////////////////////////// -P3DValue *P3DSession:: +P3DObject *P3DSession:: rt_from_xml_value(TiXmlElement *xvalue) { const char *type = xvalue->Attribute("type"); if (strcmp(type, "none") == 0) { - return new P3DNoneValue; + return new P3DNoneObject; } else if (strcmp(type, "bool") == 0) { int value; if (xvalue->QueryIntAttribute("value", &value) == TIXML_SUCCESS) { - return new P3DBoolValue(value != 0); + return new P3DBoolObject(value != 0); } } else if (strcmp(type, "int") == 0) { int value; if (xvalue->QueryIntAttribute("value", &value) == TIXML_SUCCESS) { - return new P3DIntValue(value); + return new P3DIntObject(value); } } else if (strcmp(type, "float") == 0) { double value; if (xvalue->QueryDoubleAttribute("value", &value) == TIXML_SUCCESS) { - return new P3DFloatValue(value); + return new P3DFloatObject(value); } } else if (strcmp(type, "string") == 0) { @@ -504,22 +494,22 @@ rt_from_xml_value(TiXmlElement *xvalue) { // don't get tripped up on embedded null characters. const string *value = xvalue->Attribute(string("value")); if (value != NULL) { - return new P3DStringValue(*value); + return new P3DStringObject(*value); } } else if (strcmp(type, "list") == 0) { - P3DListValue *list = new P3DListValue; + P3DListObject *list = new P3DListObject; TiXmlElement *xchild = xvalue->FirstChildElement("value"); while (xchild != NULL) { - list->append_item(rt_from_xml_value(xchild)); + list->set_element(list->get_list_length(), rt_from_xml_value(xchild)); xchild = xchild->NextSiblingElement("value"); } return list; } // Something went wrong in decoding. - return new P3DNoneValue; + return new P3DNoneObject; } //////////////////////////////////////////////////////////////////// diff --git a/direct/src/plugin/p3dSession.h b/direct/src/plugin/p3dSession.h index 7b9e50e5aa..aeea1202fa 100644 --- a/direct/src/plugin/p3dSession.h +++ b/direct/src/plugin/p3dSession.h @@ -61,7 +61,7 @@ private: void rt_terminate(); void rt_handle_request(TiXmlDocument *doc); P3D_request *rt_make_p3d_request(TiXmlElement *xrequest); - P3DValue *rt_from_xml_value(TiXmlElement *xvalue); + P3DObject *rt_from_xml_value(TiXmlElement *xvalue); #ifdef _WIN32 static DWORD WINAPI win_rt_thread_run(LPVOID data); diff --git a/direct/src/plugin/p3dStringValue.cxx b/direct/src/plugin/p3dStringObject.cxx similarity index 78% rename from direct/src/plugin/p3dStringValue.cxx rename to direct/src/plugin/p3dStringObject.cxx index 668ad9b89e..986f4b892e 100644 --- a/direct/src/plugin/p3dStringValue.cxx +++ b/direct/src/plugin/p3dStringObject.cxx @@ -1,4 +1,4 @@ -// Filename: p3dStringValue.cxx +// Filename: p3dStringObject.cxx // Created by: drose (30Jun09) // //////////////////////////////////////////////////////////////////// @@ -12,80 +12,80 @@ // //////////////////////////////////////////////////////////////////// -#include "p3dStringValue.h" +#include "p3dStringObject.h" //////////////////////////////////////////////////////////////////// -// Function: P3DStringValue::Constructor +// Function: P3DStringObject::Constructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// -P3DStringValue:: -P3DStringValue(const string &value) : - P3DValue(P3D_VT_string), +P3DStringObject:: +P3DStringObject(const string &value) : + P3DObject(P3D_OT_string), _value(value) { } //////////////////////////////////////////////////////////////////// -// Function: P3DStringValue::Copy Constructor +// Function: P3DStringObject::Copy Constructor // Access: Public // Description: //////////////////////////////////////////////////////////////////// -P3DStringValue:: -P3DStringValue(const P3DStringValue ©) : - P3DValue(copy), +P3DStringObject:: +P3DStringObject(const P3DStringObject ©) : + P3DObject(copy), _value(copy._value) { } //////////////////////////////////////////////////////////////////// -// Function: P3DStringValue::Destructor +// Function: P3DStringObject::Destructor // Access: Public, Virtual // Description: //////////////////////////////////////////////////////////////////// -P3DStringValue:: -~P3DStringValue() { +P3DStringObject:: +~P3DStringObject() { } //////////////////////////////////////////////////////////////////// -// Function: P3DStringValue::make_copy +// Function: P3DStringObject::make_copy // Access: Public, Virtual // Description: //////////////////////////////////////////////////////////////////// -P3DValue *P3DStringValue:: -make_copy() { - return new P3DStringValue(*this); +P3DObject *P3DStringObject:: +make_copy() const { + return new P3DStringObject(*this); } //////////////////////////////////////////////////////////////////// -// Function: P3DStringValue::get_bool +// Function: P3DStringObject::get_bool // Access: Public, Virtual -// Description: Returns the value value coerced to a boolean, if +// Description: Returns the object value coerced to a boolean, if // possible. //////////////////////////////////////////////////////////////////// -bool P3DStringValue:: +bool P3DStringObject:: get_bool() const { return !_value.empty(); } //////////////////////////////////////////////////////////////////// -// Function: P3DStringValue::make_string +// Function: P3DStringObject::make_string // Access: Public, Virtual // Description: Fills the indicated C++ string object with the value // of this object coerced to a string. //////////////////////////////////////////////////////////////////// -void P3DStringValue:: +void P3DStringObject:: make_string(string &value) const { value = _value; } //////////////////////////////////////////////////////////////////// -// Function: P3DStringValue::make_xml +// Function: P3DStringObject::make_xml // Access: Public, Virtual // Description: Allocates and returns a new XML structure // corresponding to this value. //////////////////////////////////////////////////////////////////// -TiXmlElement *P3DStringValue:: +TiXmlElement *P3DStringObject:: make_xml() const { TiXmlElement *xvalue = new TiXmlElement("value"); xvalue->SetAttribute("type", "string"); @@ -94,13 +94,13 @@ make_xml() const { } //////////////////////////////////////////////////////////////////// -// Function: P3DStringValue::output +// Function: P3DStringObject::output // Access: Public, Virtual // Description: Writes a formatted representation of the value to the // indicated string. This is intended for developer // assistance. //////////////////////////////////////////////////////////////////// -void P3DStringValue:: +void P3DStringObject:: output(ostream &out) const { out << '"'; for (string::const_iterator si = _value.begin(); si != _value.end(); ++si) { diff --git a/direct/src/plugin/p3dStringValue.h b/direct/src/plugin/p3dStringObject.h similarity index 68% rename from direct/src/plugin/p3dStringValue.h rename to direct/src/plugin/p3dStringObject.h index 037286a3f9..498ff73aa6 100644 --- a/direct/src/plugin/p3dStringValue.h +++ b/direct/src/plugin/p3dStringObject.h @@ -1,4 +1,4 @@ -// Filename: p3dStringValue.h +// Filename: p3dStringObject.h // Created by: drose (30Jun09) // //////////////////////////////////////////////////////////////////// @@ -12,25 +12,25 @@ // //////////////////////////////////////////////////////////////////// -#ifndef P3DSTRINGVALUE_H -#define P3DSTRINGVALUE_H +#ifndef P3DSTRINGOBJECT_H +#define P3DSTRINGOBJECT_H #include "p3d_plugin_common.h" -#include "p3dValue.h" +#include "p3dObject.h" //////////////////////////////////////////////////////////////////// -// Class : P3DStringValue -// Description : A value type that contains a string value. +// Class : P3DStringObject +// Description : An object type that contains a string value. //////////////////////////////////////////////////////////////////// -class P3DStringValue : public P3DValue { +class P3DStringObject : public P3DObject { public: - P3DStringValue(const string &value); - P3DStringValue(const P3DStringValue ©); + P3DStringObject(const string &value); + P3DStringObject(const P3DStringObject ©); public: - virtual ~P3DStringValue(); + virtual ~P3DStringObject(); - virtual P3DValue *make_copy(); + virtual P3DObject *make_copy() const; virtual bool get_bool() const; virtual void make_string(string &value) const; diff --git a/direct/src/plugin/p3dValue.cxx b/direct/src/plugin/p3dValue.cxx deleted file mode 100644 index fa61965b71..0000000000 --- a/direct/src/plugin/p3dValue.cxx +++ /dev/null @@ -1,116 +0,0 @@ -// Filename: p3dValue.cxx -// Created by: drose (30Jun09) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) Carnegie Mellon University. All rights reserved. -// -// All use of this software is subject to the terms of the revised BSD -// license. You should have received a copy of this license along -// with this source code in a file named "LICENSE." -// -//////////////////////////////////////////////////////////////////// - -#include "p3dValue.h" -#include // memcpy - -//////////////////////////////////////////////////////////////////// -// Function: P3DValue::Destructor -// Access: Public, Virtual -// Description: -//////////////////////////////////////////////////////////////////// -P3DValue:: -~P3DValue() { - _type = P3D_VT_none; -} - -//////////////////////////////////////////////////////////////////// -// Function: P3DValue::get_int -// Access: Public, Virtual -// Description: Returns the value value coerced to an integer, if -// possible. -//////////////////////////////////////////////////////////////////// -int P3DValue:: -get_int() const { - return 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: P3DValue::get_float -// Access: Public, Virtual -// Description: Returns the value value coerced to a floating-point -// value, if possible. -//////////////////////////////////////////////////////////////////// -double P3DValue:: -get_float() const { - return get_int(); -} - -//////////////////////////////////////////////////////////////////// -// Function: P3DValue::get_string_length -// Access: Public, Virtual -// Description: Returns the length of the string that represents the -// value value, not counting any null termination -// characters. -//////////////////////////////////////////////////////////////////// -int P3DValue:: -get_string_length() const { - string result; - make_string(result); - return result.length(); -} - -//////////////////////////////////////////////////////////////////// -// Function: P3DValue::extract_string -// Access: Public, Virtual -// Description: Stores a string that represents the value value in -// the indicated buffer; a null character is included if -// there is space. Returns the number of characters -// needed in the output (which might be more than the -// actual number of characters stored if buffer_length -// was too small). -//////////////////////////////////////////////////////////////////// -int P3DValue:: -extract_string(char *buffer, int buffer_length) const { - string result; - make_string(result); - memcpy(buffer, result.c_str(), min(buffer_length, (int)result.size() + 1)); - return (int)result.size(); -} - -//////////////////////////////////////////////////////////////////// -// Function: P3DValue::get_list_length -// Access: Public, Virtual -// Description: Returns the length of the value value as a list. -//////////////////////////////////////////////////////////////////// -int P3DValue:: -get_list_length() const { - return 0; -} - -//////////////////////////////////////////////////////////////////// -// Function: P3DValue::get_list_item -// Access: Public, Virtual -// Description: Returns the nth item in the value as a list. The -// return value is a freshly-allocated P3DValue object -// that must be deleted by the caller, or NULL on error. -//////////////////////////////////////////////////////////////////// -P3DValue *P3DValue:: -get_list_item(int n) const { - return NULL; -} - -//////////////////////////////////////////////////////////////////// -// Function: P3DValue::output -// Access: Public, Virtual -// Description: Writes a formatted representation of the value to the -// indicated string. This is intended for developer -// assistance. -//////////////////////////////////////////////////////////////////// -void P3DValue:: -output(ostream &out) const { - string value; - make_string(value); - out << value; -} diff --git a/direct/src/plugin/p3dValue.h b/direct/src/plugin/p3dValue.h deleted file mode 100644 index bb3bbfcc3f..0000000000 --- a/direct/src/plugin/p3dValue.h +++ /dev/null @@ -1,61 +0,0 @@ -// Filename: p3dValue.h -// Created by: drose (30Jun09) -// -//////////////////////////////////////////////////////////////////// -// -// PANDA 3D SOFTWARE -// Copyright (c) Carnegie Mellon University. All rights reserved. -// -// All use of this software is subject to the terms of the revised BSD -// license. You should have received a copy of this license along -// with this source code in a file named "LICENSE." -// -//////////////////////////////////////////////////////////////////// - -#ifndef P3DVALUE_H -#define P3DVALUE_H - -#include "p3d_plugin_common.h" - -//////////////////////////////////////////////////////////////////// -// Class : P3DValue -// Description : The C++ implementation of P3D_value, corresponding -// to a single atomic value that is passed around -// between scripting languages. This is an abstract -// base class; the actual implementations are provided -// by the various specialized classes, below. -//////////////////////////////////////////////////////////////////// -class P3DValue : public P3D_value { -protected: - inline P3DValue(P3D_value_type type); - inline P3DValue(const P3DValue ©); - -public: - virtual ~P3DValue(); - - virtual P3DValue *make_copy()=0; - virtual bool get_bool() const=0; - virtual int get_int() const; - virtual double get_float() const; - - int get_string_length() const; - int extract_string(char *buffer, int buffer_length) const; - virtual void make_string(string &value) const=0; - - virtual int get_list_length() const; - virtual P3DValue *get_list_item(int n) const; - - virtual TiXmlElement *make_xml() const=0; - - virtual void output(ostream &out) const; -}; - -#include "p3dValue.I" - -inline ostream &operator << (ostream &out, const P3DValue &value) { - value.output(out); - return out; -} - -#endif - diff --git a/direct/src/plugin/p3d_plugin.cxx b/direct/src/plugin/p3d_plugin.cxx index 77982d9add..8c55d8e82c 100644 --- a/direct/src/plugin/p3d_plugin.cxx +++ b/direct/src/plugin/p3d_plugin.cxx @@ -16,12 +16,12 @@ #include "p3dInstanceManager.h" #include "p3dInstance.h" #include "p3dWindowParams.h" -#include "p3dNoneValue.h" -#include "p3dBoolValue.h" -#include "p3dIntValue.h" -#include "p3dFloatValue.h" -#include "p3dStringValue.h" -#include "p3dListValue.h" +#include "p3dNoneObject.h" +#include "p3dBoolObject.h" +#include "p3dIntObject.h" +#include "p3dFloatObject.h" +#include "p3dStringObject.h" +#include "p3dListObject.h" #include @@ -67,6 +67,10 @@ P3D_initialize(int api_version, const char *output_filename) { return result; } +void +P3D_finalize() { +} + P3D_instance * P3D_new_instance(P3D_request_ready_func *func, void *user_data) { assert(P3DInstanceManager::get_global_ptr()->is_initialized()); @@ -116,184 +120,105 @@ P3D_instance_setup_window(P3D_instance *instance, RELEASE_LOCK(_lock); } -void -P3D_value_finish(P3D_value *value) { +P3D_class_definition * +P3D_make_class_definition() { assert(P3DInstanceManager::get_global_ptr()->is_initialized()); ACQUIRE_LOCK(_lock); - if (value != NULL) { - delete (P3DValue *)value; - } - RELEASE_LOCK(_lock); -} -P3D_value * -P3D_value_copy(const P3D_value *value) { - assert(P3DInstanceManager::get_global_ptr()->is_initialized()); - ACQUIRE_LOCK(_lock); - P3D_value *result = ((P3DValue *)value)->make_copy(); + P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr(); + P3D_class_definition *result = inst_mgr->make_class_definition(); + RELEASE_LOCK(_lock); return result; } -P3D_value * -P3D_new_none_value() { +P3D_object * +P3D_new_none_object() { assert(P3DInstanceManager::get_global_ptr()->is_initialized()); ACQUIRE_LOCK(_lock); - P3D_value *result = new P3DNoneValue(); + + P3D_object *result = new P3DNoneObject(); + RELEASE_LOCK(_lock); return result; } -P3D_value * -P3D_new_bool_value(bool value) { +P3D_object * +P3D_new_bool_object(bool value) { assert(P3DInstanceManager::get_global_ptr()->is_initialized()); ACQUIRE_LOCK(_lock); - P3D_value *result = new P3DBoolValue(value); + + P3D_object *result = new P3DBoolObject(value); + RELEASE_LOCK(_lock); return result; } -bool -P3D_value_get_bool(const P3D_value *value) { +P3D_object * +P3D_new_int_object(int value) { assert(P3DInstanceManager::get_global_ptr()->is_initialized()); ACQUIRE_LOCK(_lock); - bool result = ((const P3DValue *)value)->get_bool(); + + P3D_object *result = new P3DIntObject(value); + RELEASE_LOCK(_lock); return result; } -P3D_value * -P3D_new_int_value(int value) { +P3D_object * +P3D_new_float_object(double value) { assert(P3DInstanceManager::get_global_ptr()->is_initialized()); ACQUIRE_LOCK(_lock); - P3D_value *result = new P3DIntValue(value); + + P3D_object *result = new P3DFloatObject(value); + RELEASE_LOCK(_lock); return result; } -int -P3D_value_get_int(const P3D_value *value) { +P3D_object * +P3D_new_string_object(const char *str, int length) { assert(P3DInstanceManager::get_global_ptr()->is_initialized()); ACQUIRE_LOCK(_lock); - int result = ((const P3DValue *)value)->get_int(); + + P3D_object *result = new P3DStringObject(string(str, length)); + RELEASE_LOCK(_lock); return result; } -P3D_value * -P3D_new_float_value(double value) { +P3D_object * +P3D_new_list_object() { assert(P3DInstanceManager::get_global_ptr()->is_initialized()); ACQUIRE_LOCK(_lock); - P3D_value *result = new P3DFloatValue(value); + + P3D_object *result = new P3DListObject; + RELEASE_LOCK(_lock); return result; } -double -P3D_value_get_float(const P3D_value *value) { +P3D_object * +P3D_instance_get_script_object(P3D_instance *instance) { assert(P3DInstanceManager::get_global_ptr()->is_initialized()); ACQUIRE_LOCK(_lock); - double result = ((const P3DValue *)value)->get_float(); + + // TODO. + P3D_object *result = NULL; + RELEASE_LOCK(_lock); return result; } -P3D_value * -P3D_new_string_value(const char *value, int length) { +void +P3D_instance_set_script_object(P3D_instance *instance, + P3D_object *object) { assert(P3DInstanceManager::get_global_ptr()->is_initialized()); ACQUIRE_LOCK(_lock); - P3D_value *result = new P3DStringValue(string(value, length)); - RELEASE_LOCK(_lock); - return result; -} -int -P3D_value_get_string_length(const P3D_value *value) { - assert(P3DInstanceManager::get_global_ptr()->is_initialized()); - ACQUIRE_LOCK(_lock); - int result = ((const P3DValue *)value)->get_string_length(); + // TODO. + RELEASE_LOCK(_lock); - return result; -} - -int -P3D_value_extract_string(const P3D_value *value, char *buffer, - int buffer_length) { - assert(P3DInstanceManager::get_global_ptr()->is_initialized()); - ACQUIRE_LOCK(_lock); - int result = - ((const P3DValue *)value)->extract_string(buffer, buffer_length); - RELEASE_LOCK(_lock); - return result; -} - -P3D_value * -P3D_new_list_value(P3D_value * const elements[], int num_elements) { - assert(P3DInstanceManager::get_global_ptr()->is_initialized()); - ACQUIRE_LOCK(_lock); - P3D_value *result = new P3DListValue((P3DValue * const *)elements, num_elements); - RELEASE_LOCK(_lock); - return result; -} - -int -P3D_value_get_list_length(const P3D_value *value) { - assert(P3DInstanceManager::get_global_ptr()->is_initialized()); - ACQUIRE_LOCK(_lock); - int result = ((const P3DValue *)value)->get_list_length(); - RELEASE_LOCK(_lock); - return result; -} - -P3D_value * -P3D_value_get_list_item(const P3D_value *value, int n) { - assert(P3DInstanceManager::get_global_ptr()->is_initialized()); - ACQUIRE_LOCK(_lock); - P3D_value *result = ((const P3DValue *)value)->get_list_item(n); - RELEASE_LOCK(_lock); - return result; -} - -P3D_value * -P3D_instance_get_property(const P3D_instance *instance, - const char *property_name) { - assert(P3DInstanceManager::get_global_ptr()->is_initialized()); - ACQUIRE_LOCK(_lock); - P3D_value *result = ((const P3DInstance *)instance)->get_property(property_name); - RELEASE_LOCK(_lock); - return result; -} - -P3D_value * -P3D_instance_get_property_list(const P3D_instance *instance, - const char *property_name) { - assert(P3DInstanceManager::get_global_ptr()->is_initialized()); - ACQUIRE_LOCK(_lock); - P3D_value *result = ((const P3DInstance *)instance)->get_property_list(property_name); - RELEASE_LOCK(_lock); - return result; -} - -bool -P3D_instance_set_property(P3D_instance *instance, const char *property_name, - const P3D_value *value) { - assert(P3DInstanceManager::get_global_ptr()->is_initialized()); - ACQUIRE_LOCK(_lock); - bool result = - ((P3DInstance *)instance)->set_property(property_name, (const P3DValue *)value); - RELEASE_LOCK(_lock); - return result; -} - -P3D_value * -P3D_instance_call(P3D_instance *instance, const char *property_name, - const P3D_value *params) { - assert(P3DInstanceManager::get_global_ptr()->is_initialized()); - ACQUIRE_LOCK(_lock); - P3D_value *result = - ((P3DInstance *)instance)->call(property_name, (P3DValue *)params); - RELEASE_LOCK(_lock); - return result; } @@ -356,12 +281,3 @@ P3D_instance_feed_url_stream(P3D_instance *instance, int unique_id, RELEASE_LOCK(_lock); return result; } - -void -P3D_instance_feed_value(P3D_instance *instance, int unique_id, - P3D_value *value) { - assert(P3DInstanceManager::get_global_ptr()->is_initialized()); - ACQUIRE_LOCK(_lock); - ((P3DInstance *)instance)->feed_value(unique_id, (P3DValue *)value); - RELEASE_LOCK(_lock); -} diff --git a/direct/src/plugin/p3d_plugin.h b/direct/src/plugin/p3d_plugin.h index 038b6caa5b..5765d54a57 100644 --- a/direct/src/plugin/p3d_plugin.h +++ b/direct/src/plugin/p3d_plugin.h @@ -97,6 +97,12 @@ the interface specifications defined in this header file. */ typedef bool P3D_initialize_func(int api_version, const char *output_filename); +/* This function should be called to unload the plugin. It will + release all internally-allocated memory and return the plugin to + its initial state. */ +typedef void +P3D_finalize_func(); + /********************** INSTANCE MANAGEMENT **************************/ /* The following interfaces define the API to manage individual @@ -263,162 +269,276 @@ P3D_instance_setup_window_func(P3D_instance *instance, /* The following interfaces are provided to support controlling the plugin via JavaScript or related interfaces on the browser. */ -/* This enumeration indicates which fundamental type is represented by - a particular P3D_value object, below. */ -typedef enum { - P3D_VT_none, - P3D_VT_bool, - P3D_VT_int, - P3D_VT_float, - P3D_VT_string, - P3D_VT_list -} P3D_value_type; +/* We require an "object" that contains some number of possible + different interfaces. An "object" might be a simple primitive like + an int, float, or string; or it might be a class object with + methods and properties. Instances of P3D_object are passed around + as parameters into and return values from functions. + + To implement a P3D_object, we need to first define a class + definition, which is a table of methods. Most classes are defined + internally by the plugin, but the host must define at least one + class type as well, which provides callbacks into host-provided + objects. -/* This structure represents a concrete value of some arbitrary type. - Instances of this structure may be assigned to property names, or - passed into or returned from function calls. */ -typedef struct { - P3D_value_type _type; + These function types define the methods available on a class. + These are function type declarations only; they do not correspond + to named functions within the plugin DLL. Instead, the function + pointers themselves are stored within the P3D_class_definition + structure, below. */ + +/* A forward declaration of P3D_object. */ +typedef struct _P3D_object P3D_object; + +/* A list of fundamental object types. */ +typedef enum { + P3D_OT_none, + P3D_OT_bool, + P3D_OT_int, + P3D_OT_float, + P3D_OT_string, + P3D_OT_list, + P3D_OT_object, +} P3D_object_type; + +/* This method is called to deallocate the object and all of its + internal structures. */ +typedef void +P3D_object_finish_method(P3D_object *object); + +/* Returns a new copy of the object. The caller receives ownership of + the new object and must eventually pass its pointer to + P3D_OBJECT_FINISH() to delete it, or into some other call that + transfers ownership. */ +typedef P3D_object * +P3D_object_copy_method(const P3D_object *object); + +/* Returns the fundamental type of the object. This should be treated + as a hint to suggest how the object can most accurately be + represented; it does not limit the actual interfaces available to + an object. For instance, you may call P3D_OBJECT_GET_PROPERTY() + even if the object's type is not "object". */ +typedef P3D_object_type +P3D_object_get_type_method(const P3D_object *object); + +/* Each of the following methods returns the object's value expressed + as the corresponding type. If the object is not precisely that + type, a coercion is performed. */ + +/* Return the object as a bool. */ +typedef bool +P3D_object_get_bool_method(const P3D_object *object); + +/* Return the object as an integer. */ +typedef int +P3D_object_get_int_method(const P3D_object *object); + +/* Return the object as a floating-point number. */ +typedef double +P3D_object_get_float_method(const P3D_object *object); + +/* Get the object as a string. This method copies the string into the + provided buffer, and returns the actual length of the internal + string (not counting any terminating null character). If the + return value is larger than buffer_length, the string has been + truncated. If it is equal, there is no null character written to + the buffer (like strncpy). */ +typedef int +P3D_object_get_string_method(const P3D_object *object, + char *buffer, int buffer_length); + +/* As above, but instead of the literal object data, returns a + user-friendly reprensentation of the object as a string. For + instance, a string object returns the string itself to + P3D_OBJECT_GET_STRING(), but returns the string with quotation + marks and escape characters from P3D_OBJECT_GET_REPR(). + Mechanically, this function works the same way as get_string(). */ +typedef int +P3D_object_get_repr_method(const P3D_object *object, + char *buffer, int buffer_length); + +/* Looks up a property on the object by name, i.e. a data member or a + method. The return value is a newly-allocated P3D_object if the + property exists, or NULL if it does not. If it is not NULL, + ownership of the return value is transferred to the caller, who + will be responsible for deleting it later. */ +typedef P3D_object * +P3D_object_get_property_method(const P3D_object *object, const char *property); + +/* Changes the value at the indicated property. Any existing object + already at the corresponding property is deleted. If the value + object pointer is NULL, the property is deleted. Returns true on + success, false on failure. The caller must have ownership of the + value object before the call; after the call, ownership of the + value object is transferred to this object. */ +typedef bool +P3D_object_set_property_method(P3D_object *object, const char *property, + P3D_object *value); + +/* These methods are similar to the above, but for integer properties, + e.g. for elements of an array. */ +typedef P3D_object * +P3D_object_get_element_method(const P3D_object *object, int n); +typedef bool +P3D_object_set_element_method(P3D_object *object, int n, P3D_object *value); + +/* For objects that implement an array or list with a specific size + and all elements below that index filled in, this method will + return the size of the list. */ +typedef int +P3D_object_get_list_length_method(const P3D_object *object); + +/* Invokes the object as a function. The params object should be a + list object containing the individual parameters; ownership of this + list object is transferred in this call, and it will automatically + be deleted. The return value is a newly-allocated P3D_object on + success, or NULL on failure. Ownership of the return value is + transferred to the caller. */ +typedef P3D_object * +P3D_object_call_method(const P3D_object *object, P3D_object *params); + +/* Evaluates an arbitrary script expression, if possible, within the + context of the object. The return value is the return value of the + expression, or NULL on error. As above, ownership of the return + value is transferred to the caller. */ +typedef P3D_object * +P3D_object_evaluate_method(const P3D_object *object, const char *expression); + +/* This defines the class structure that implements all of the above + methods. */ +typedef struct _P3D_class_definition { + P3D_object_finish_method *_finish; + P3D_object_copy_method *_copy; + + P3D_object_get_type_method *_get_type; + P3D_object_get_bool_method *_get_bool; + P3D_object_get_int_method *_get_int; + P3D_object_get_float_method *_get_float; + P3D_object_get_string_method *_get_string; + P3D_object_get_repr_method *_get_repr; + + P3D_object_get_property_method *_get_property; + P3D_object_set_property_method *_set_property; + P3D_object_get_element_method *_get_element; + P3D_object_set_element_method *_set_element; + P3D_object_get_list_length_method *_get_list_length; + + P3D_object_call_method *_call; + P3D_object_evaluate_method *_evaluate; + +} P3D_class_definition; + +/* And this structure defines the actual instances of P3D_object. */ +struct _P3D_object { + const P3D_class_definition *_class; /* Additional opaque data may be stored here. */ -} P3D_value; +}; -/* Deallocates a P3D_value previously allocated with one of the - below calls, or returned from a function such as - P3D_value_get_property(). After this has been called, the - value's pointer must no longer be used. */ -typedef void -P3D_value_finish_func(P3D_value *value); +/* These macros are defined for the convenience of invoking any of the + above method functions on an object. */ -/* Returns a duplicate copy of the indicated value. The return - value should be eventually passed to P3D_value_finish(), - above. */ -typedef P3D_value * -P3D_value_copy_func(const P3D_value *value); +#define P3D_OBJECT_FINISH(object) ((object)->_class->_finish((object))) +#define P3D_OBJECT_COPY(object) ((object)->_class->_copy((object))) -/* Allocates a new P3D_value of type none. This value has no +#define P3D_OBJECT_GET_TYPE(object) ((object)->_class->_get_type((object))) +#define P3D_OBJECT_GET_BOOL(object) ((object)->_class->_get_bool((object))) +#define P3D_OBJECT_GET_INT(object) ((object)->_class->_get_int((object))) +#define P3D_OBJECT_GET_FLOAT(object) ((object)->_class->_get_float((object))) +#define P3D_OBJECT_GET_STRING(object, buffer, buffer_size) ((object)->_class->_get_string((object), (buffer), (buffer_size))) +#define P3D_OBJECT_GET_REPR(object, buffer, buffer_size) ((object)->_class->_get_repr((object), (buffer), (buffer_size))) + +#define P3D_OBJECT_GET_PROPERTY(object, property) ((object)->_class->_get_property((object), (property))) +#define P3D_OBJECT_SET_PROPERTY(object, property, value) ((object)->_class->_set_property((object), (property), (value))) + +#define P3D_OBJECT_GET_ELEMENT(object, n) ((object)->_class->_get_element((object), (n))) +#define P3D_OBJECT_SET_ELEMENT(object, n, value) ((object)->_class->_set_element((object), (n), (value))) +#define P3D_OBJECT_GET_LIST_LENGTH(object, n, value) ((object)->_class->_get_list_length((object), (n), (value))) + +#define P3D_OBJECT_CALL(object, params) ((object)->_class->_call((object), (params))) +#define P3D_OBJECT_EVALUATE(object, expression) ((object)->_class->_evaluate((object), (expression))) + + +/* The following function types are once again meant to define + actual function pointers to be found within the plugin DLL. */ + +/* Returns a newly-allocated P3D_class_definition object, filled with + generic function pointers that have reasonable default behavior for + all methods. The host should use this function to get a clean + P3D_class_definition object before calling + P3D_instance_set_script_object() (see below). Note that this + pointer will automatically be freed when P3D_finalize() is + called. */ +typedef P3D_class_definition * +P3D_make_class_definition_func(); + +/* Allocates a new P3D_object of type none. This value has no particular value and corresponds to Python's None type or C's void type. */ -typedef P3D_value * -P3D_new_none_value_func(); +typedef P3D_object * +P3D_new_none_object_func(); -/* Allocates a new P3D_value of type bool. */ -typedef P3D_value * -P3D_new_bool_value_func(bool value); +/* Allocates a new P3D_object of type bool. */ +typedef P3D_object * +P3D_new_bool_object_func(bool value); -/* Retrieves the boolean value associated with this type. If the - value's type is not P3D_VT_bool, this implicitly coerces the - value to a boolean value. */ -typedef bool -P3D_value_get_bool_func(const P3D_value *value); +/* Allocates a new P3D_object of type int. */ +typedef P3D_object * +P3D_new_int_object_func(int value); -/* Allocates a new P3D_value of type int. */ -typedef P3D_value * -P3D_new_int_value_func(int value); +/* Allocates a new P3D_object of type float. */ +typedef P3D_object * +P3D_new_float_object_func(double value); -/* Retrieves the integer value associated with this type. If the - value's type is not P3D_VT_int, this implicitly coerces the value - to an integer value. */ -typedef int -P3D_value_get_int_func(const P3D_value *value); +/* Allocates a new P3D_object of type string. The supplied string is + copied into the object and stored internally. */ +typedef P3D_object * +P3D_new_string_object_func(const char *string, int length); -/* Allocates a new P3D_value of type float. */ -typedef P3D_value * -P3D_new_float_value_func(double value); +/* Allocates a new P3D_object of type list. The new list is empty; + use repeated calls to P3D_OBJECT_SET_ELEMENT() to populate it. */ +typedef P3D_object * +P3D_new_list_object_func(); -/* Retrieves the floating-point value associated with this type. If - the value's type is not P3D_VT_float, this implicitly coerces the - value to a floating-point value. */ -typedef double -P3D_value_get_float_func(const P3D_value *value); +/* Returns a pointer to the top-level scriptable object of the + instance. Scripts running on the host may use this object to + communicate with the instance, by using the above methods to set or + query properties, and/or call methods, on the instance. -/* Allocates a new P3D_value of type string. */ -typedef P3D_value * -P3D_new_string_value_func(const char *value, int length); + The return value from this function is a newly-allocated object; + ownership of the object is passed to the caller, who should be + responsible for deleting it eventually. */ +typedef P3D_object * +P3D_instance_get_script_object_func(P3D_instance *instance); -/* Retrieves the length of the string value associated with this type. - This is the number of bytes that must be allocated to hold the - results of P3D_value_extract_string(), not including any - terminating null byte. */ -typedef int -P3D_value_get_string_length_func(const P3D_value *value); +/* The inverse functionality: this supplies an object pointer to the + instance to allow the plugin to control the browser. In order to + enable browser scriptability, the host must call this method + shortly after creating the instance, preferably before calling + P3D_instance_start(). -/* Stores the string value associated with this type in the indicated - buffer, which has the specified length. The return value is the - number of characters required for complete representation of the - string (which may or may not represent the number of characters - actually written). A terminating null byte is written to the - buffer if there is space. If the variable's type is not - P3D_VT_string, this implicitly coerces the value to a string - value. */ -typedef int -P3D_value_extract_string_func(const P3D_value *value, char *buffer, - int buffer_length); + The object parameter must have been created by the host. It will + have a custom P3D_class_definition pointer, which also must have + been created by the host. The best way to create an appropriate + class definition is call P3D_make_class_definition(), and then + replace the function pointers for at least _finish, _get_property, + _set_property, and _call. Set these pointers to the host's own + functions that make the appropriate changes in the DOM, or invoke + the appropriate JavaScript functions. -/* Allocates a new P3D_value of type list. This is a list of an - arbitrary number of P3D_value objects. The indicated P3D_value - objects are stored directly within the list; ownership of the - objects in this array (but not the array pointer itself) is passed - to the list. The caller must no longer call P3D_value_finish() - on any objects added to the list (but should still call - P3D_value_finish() on the list itself). */ -typedef P3D_value * -P3D_new_list_value_func(P3D_value * const elements[], int num_elements); + If this function is never called, the instance will not be able to + make outcalls to the DOM or to JavaScript, but scripts may still be + able to control the instance via P3D_instance_get_script_object(), + above. -/* Returns the number of items in the list, if the value's type is - of P3D_VT_list. */ -typedef int -P3D_value_get_list_length_func(const P3D_value *value); + Ownership of the object is passed into the instance. The caller + must have freshly allocated the object, and should no longer store + or delete it. The instance will eventually delete it by calling + its _finish method. */ +typedef void +P3D_instance_set_script_object_func(P3D_instance *instance, + P3D_object *object); -/* Returns the nth item in the list. The caller inherits ownership of - this object, and should call P3D_value_finish() on it. */ -typedef P3D_value * -P3D_value_get_list_item_func(const P3D_value *value, int n); - -/* Retrieves the named property from the instance, if any. The - property name may be a dot-delimited sequence to reference nested - properties. Returns NULL if the instance does not have the named - property. If not NULL, you should pass the return value to - P3D_value_finish(). */ -typedef P3D_value * -P3D_instance_get_property_func(const P3D_instance *instance, - const char *property_name); - -/* Returns a list of properties on the instance below the named - property. The property name may be a dot-delimited sequence to - reference nested properties. Returns NULL if the instance does not - have the named property; otherwise, returns a list value that - contains a list of string values, one for each property stored on - the named property. If not NULL, you should pass the return value - to P3D_value_finish(). */ -typedef P3D_value * -P3D_instance_get_property_list_func(const P3D_instance *instance, - const char *property_name); - -/* Changes or sets the named property on the instance. The property - name may be a dot-delimited sequence; if so, all of the properties - except the last one must already exist. Returns true on success, - false on failure (for instance, because a parent property does not - exist). Pass NULL for the value to delete the last property. The - caller retains ownership of the value object, and should eventually - delete with P3D_value_finish(). */ -typedef bool -P3D_instance_set_property_func(P3D_instance *instance, const char *property_name, - const P3D_value *value); - -/* Calls the named property as a function. The property name may be a - dot-delimited sequence. The params value is an object of type - P3D_VT_list, which contains the list of parameters to the function. - The caller retains ownership of the params object. The return - value is NULL on error, or a newly-allocated value on success; if - not NULL, you should pass the return value to - P3D_value_finish(). */ -typedef P3D_value * -P3D_instance_call_func(P3D_instance *instance, const char *property_name, - const P3D_value *params); - -/* Some scriptable properties on the host may be queried or modified - via requests, below. */ /********************** REQUEST HANDLING **************************/ @@ -451,7 +571,6 @@ typedef enum { P3D_RT_get_url, P3D_RT_post_url, P3D_RT_notify, - P3D_RT_evaluate, } P3D_request_type; /* Structures corresponding to the request types in the above enum. */ @@ -495,19 +614,6 @@ typedef struct { const char *_message; } P3D_request_notify; -/* A request to evaluate a Javascript expression or statement. The - expression will be evaluated in the context of the parent window. - It is particularly useful for querying document state, such as - "document.form.username.value", or for changing this state, such as - "document.form.choose.red.select = 1". After evaluating the - expression, the host should return the response to this request by - calling P3D_instance_feed_value() with the given unique_id and the - result value, or NULL if there was an error with the expression. */ -typedef struct { - const char *_expression; - int _unique_id; -} P3D_request_evaluate; - /* This is the overall structure that represents a single request. It is returned by P3D_instance_get_request(). */ typedef struct { @@ -518,7 +624,6 @@ typedef struct { P3D_request_get_url _get_url; P3D_request_post_url _post_url; P3D_request_notify _notify; - P3D_request_evaluate _evaluate; } _request; } P3D_request; @@ -620,52 +725,31 @@ P3D_instance_feed_url_stream_func(P3D_instance *instance, int unique_id, const void *this_data, size_t this_data_size); -/* This function is called by the host in response to an evaulate - request. The instance and unique_id parameters are from the - original request; the value should be a freshly-allocated P3D_value - that represents the value of the evaluated expression, or NULL on - error. Ownership of the value value is passed into the plugin; the - host should *not* call P3D_value_finish() on this pointer. */ -typedef void -P3D_instance_feed_value_func(P3D_instance *instance, int unique_id, - P3D_value *value); - - #ifdef P3D_FUNCTION_PROTOTYPES /* 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_new_instance_func P3D_new_instance; EXPCL_P3D_PLUGIN P3D_instance_start_func P3D_instance_start; EXPCL_P3D_PLUGIN P3D_instance_finish_func P3D_instance_finish; EXPCL_P3D_PLUGIN P3D_instance_setup_window_func P3D_instance_setup_window; -EXPCL_P3D_PLUGIN P3D_value_finish_func P3D_value_finish; -EXPCL_P3D_PLUGIN P3D_value_copy_func P3D_value_copy; -EXPCL_P3D_PLUGIN P3D_new_none_value_func P3D_new_none_value; -EXPCL_P3D_PLUGIN P3D_new_bool_value_func P3D_new_bool_value; -EXPCL_P3D_PLUGIN P3D_value_get_bool_func P3D_value_get_bool; -EXPCL_P3D_PLUGIN P3D_new_int_value_func P3D_new_int_value; -EXPCL_P3D_PLUGIN P3D_value_get_int_func P3D_value_get_int; -EXPCL_P3D_PLUGIN P3D_new_float_value_func P3D_new_float_value; -EXPCL_P3D_PLUGIN P3D_value_get_float_func P3D_value_get_float; -EXPCL_P3D_PLUGIN P3D_new_string_value_func P3D_new_string_value; -EXPCL_P3D_PLUGIN P3D_value_get_string_length_func P3D_value_get_string_length; -EXPCL_P3D_PLUGIN P3D_value_extract_string_func P3D_value_extract_string; -EXPCL_P3D_PLUGIN P3D_new_list_value_func P3D_new_list_value; -EXPCL_P3D_PLUGIN P3D_value_get_list_length_func P3D_value_get_list_length; -EXPCL_P3D_PLUGIN P3D_value_get_list_item_func P3D_value_get_list_item; -EXPCL_P3D_PLUGIN P3D_instance_get_property_func P3D_instance_get_property; -EXPCL_P3D_PLUGIN P3D_instance_get_property_list_func P3D_instance_get_property_list; -EXPCL_P3D_PLUGIN P3D_instance_set_property_func P3D_instance_set_property; -EXPCL_P3D_PLUGIN P3D_instance_call_func P3D_instance_call; +EXPCL_P3D_PLUGIN P3D_make_class_definition_func P3D_make_class_definition; +EXPCL_P3D_PLUGIN P3D_new_none_object_func P3D_new_none_object; +EXPCL_P3D_PLUGIN P3D_new_bool_object_func P3D_new_bool_object; +EXPCL_P3D_PLUGIN P3D_new_int_object_func P3D_new_int_object; +EXPCL_P3D_PLUGIN P3D_new_float_object_func P3D_new_float_object; +EXPCL_P3D_PLUGIN P3D_new_string_object_func P3D_new_string_object; +EXPCL_P3D_PLUGIN P3D_new_list_object_func P3D_new_list_object; +EXPCL_P3D_PLUGIN P3D_instance_get_script_object_func P3D_instance_get_script_object; +EXPCL_P3D_PLUGIN P3D_instance_set_script_object_func P3D_instance_set_script_object; EXPCL_P3D_PLUGIN P3D_instance_get_request_func P3D_instance_get_request; EXPCL_P3D_PLUGIN P3D_check_request_func P3D_check_request; EXPCL_P3D_PLUGIN P3D_request_finish_func P3D_request_finish; EXPCL_P3D_PLUGIN P3D_instance_feed_url_stream_func P3D_instance_feed_url_stream; -EXPCL_P3D_PLUGIN P3D_instance_feed_value_func P3D_instance_feed_value; #endif /* P3D_FUNCTION_PROTOTYPES */ diff --git a/direct/src/plugin/p3d_plugin_composite1.cxx b/direct/src/plugin/p3d_plugin_composite1.cxx index 67127af151..47abe17c3a 100644 --- a/direct/src/plugin/p3d_plugin_composite1.cxx +++ b/direct/src/plugin/p3d_plugin_composite1.cxx @@ -5,16 +5,16 @@ #include "p3dInstance.cxx" #include "p3dInstanceManager.cxx" #include "p3dMultifileReader.cxx" -#include "p3dNoneValue.cxx" +#include "p3dNoneObject.cxx" #include "p3dPackage.cxx" #include "p3dSplashWindow.cxx" #include "p3dSession.cxx" #include "p3dWindowParams.cxx" #include "p3dWinSplashWindow.cxx" -#include "p3dValue.cxx" -#include "p3dBoolValue.cxx" -#include "p3dIntValue.cxx" -#include "p3dFloatValue.cxx" -#include "p3dListValue.cxx" -#include "p3dStringValue.cxx" +#include "p3dObject.cxx" +#include "p3dBoolObject.cxx" +#include "p3dIntObject.cxx" +#include "p3dFloatObject.cxx" +#include "p3dListObject.cxx" +#include "p3dStringObject.cxx" diff --git a/direct/src/plugin_npapi/ppInstance.cxx b/direct/src/plugin_npapi/ppInstance.cxx index c2ff2438dc..18ac802bc5 100644 --- a/direct/src/plugin_npapi/ppInstance.cxx +++ b/direct/src/plugin_npapi/ppInstance.cxx @@ -384,17 +384,6 @@ handle_request(P3D_request *request) { } break; - case P3D_RT_evaluate: - { - logfile << "Got P3D_RT_evaluate: " - << request->_request._evaluate._expression << "\n" - << flush; - const string &expression = request->_request._evaluate._expression; - int unique_id = request->_request._evaluate._unique_id; - handle_evaluate(expression, unique_id); - } - break; - default: // Some request types are not handled. logfile << "Unhandled request: " << request->_request_type << "\n"; @@ -621,44 +610,6 @@ send_window() { parent_window); } -//////////////////////////////////////////////////////////////////// -// Function: PPInstance::handle_evaluate -// Access: Private -// Description: Evaluates the script within the window, as requested -// by the Panda code. -//////////////////////////////////////////////////////////////////// -void PPInstance:: -handle_evaluate(const string &expression, int unique_id) { - NPObject *window = NULL; - if (browser->getvalue(_npp_instance, NPNVWindowNPObject, &window) == NPERR_NO_ERROR) { - logfile << "Got object for NPNVWindowNPObject: " << window << "\n"; - - NPString script; - script.utf8characters = expression.c_str(); - script.utf8length = expression.length(); - NPVariant result; - if (browser->evaluate(_npp_instance, window, &script, &result)) { - logfile << "Evaluated, result = "; - show_np_variant(result); - logfile << "\n" << flush; - - P3D_value *value = np_variant_to_value(result); - browser->releasevariantvalue(&result); - - P3D_instance_feed_value(_p3d_inst, unique_id, value); - - } else { - logfile << "Couldn't evaluate\n"; - P3D_instance_feed_value(_p3d_inst, unique_id, NULL); - } - - } else { - logfile << "Couldn't get object for NPNVWindowNPObject: " << window - << "\n"; - P3D_instance_feed_value(_p3d_inst, unique_id, NULL); - } -} - //////////////////////////////////////////////////////////////////// // Function: PPInstance::show_np_variant // Access: Private @@ -686,29 +637,29 @@ show_np_variant(const NPVariant &result) { } //////////////////////////////////////////////////////////////////// -// Function: PPInstance::np_variant_to_value +// Function: PPInstance::np_variant_to_object // Access: Private -// Description: Returns a fresly-allocated P3D_value object -// corresponding to the indicated NPVariant. +// Description: Returns a freshly-allocated P3D_object corresponding +// to the indicated NPVariant. //////////////////////////////////////////////////////////////////// -P3D_value *PPInstance:: -np_variant_to_value(const NPVariant &result) { +P3D_object *PPInstance:: +np_variant_to_object(const NPVariant &result) { if (NPVARIANT_IS_NULL(result)) { return NULL; } else if (NPVARIANT_IS_VOID(result)) { - return P3D_new_none_value(); + return P3D_new_none_object(); } else if (NPVARIANT_IS_BOOLEAN(result)) { - return P3D_new_bool_value(NPVARIANT_TO_BOOLEAN(result)); + return P3D_new_bool_object(NPVARIANT_TO_BOOLEAN(result)); } else if (NPVARIANT_IS_INT32(result)) { - return P3D_new_int_value(NPVARIANT_TO_INT32(result)); + return P3D_new_int_object(NPVARIANT_TO_INT32(result)); } else if (NPVARIANT_IS_DOUBLE(result)) { - return P3D_new_float_value(NPVARIANT_TO_DOUBLE(result)); + return P3D_new_float_object(NPVARIANT_TO_DOUBLE(result)); } else if (NPVARIANT_IS_STRING(result)) { NPString str = NPVARIANT_TO_STRING(result); - return P3D_new_string_value(str.utf8characters, str.utf8length); + return P3D_new_string_object(str.utf8characters, str.utf8length); } else if (NPVARIANT_IS_OBJECT(result)) { // TODO? - return P3D_new_none_value(); + return P3D_new_none_object(); // NPVARIANT_TO_OBJECT(result); } diff --git a/direct/src/plugin_npapi/ppInstance.h b/direct/src/plugin_npapi/ppInstance.h index e996c42e79..3520f26021 100644 --- a/direct/src/plugin_npapi/ppInstance.h +++ b/direct/src/plugin_npapi/ppInstance.h @@ -53,9 +53,8 @@ private: void create_instance(); void send_window(); - void handle_evaluate(const string &expression, int unique_id); void show_np_variant(const NPVariant &result); - P3D_value *np_variant_to_value(const NPVariant &result); + P3D_object *np_variant_to_object(const NPVariant &result); private: NPP _npp_instance; diff --git a/direct/src/plugin_standalone/panda3d.cxx b/direct/src/plugin_standalone/panda3d.cxx index 2f027fc191..8d1a362959 100644 --- a/direct/src/plugin_standalone/panda3d.cxx +++ b/direct/src/plugin_standalone/panda3d.cxx @@ -406,22 +406,6 @@ handle_request(P3D_request *request) { // Ignore notifications. break; - case P3D_RT_evaluate: - cerr << "Got P3D_RT_evaluate: " - << request->_request._evaluate._expression << "\n"; - { - // In this standalone executable, every expression evaluates to - // itself as a string. We do this just to help debug the - // expression passing to and from the low-level Python code. - const string &expression = request->_request._evaluate._expression; - P3D_value *value = P3D_new_string_value(expression.data(), expression.length()); - P3D_instance_feed_value(request->_instance, - request->_request._evaluate._unique_id, - value); - handled = true; - } - break; - default: // Some request types are not handled. cerr << "Unhandled request: " << request->_request_type << "\n"; diff --git a/direct/src/showutil/runp3d.py b/direct/src/showutil/runp3d.py index e5eef215bc..14d2eb138c 100755 --- a/direct/src/showutil/runp3d.py +++ b/direct/src/showutil/runp3d.py @@ -234,12 +234,6 @@ class AppRunner(DirectObject): def sendRequest(self, request, *args): self.requestFunc(self.instanceId, request, args) - def feedValue(self, uniqueId, value, success): - """ Called by the host in response to an 'evaluate' - request. """ - - print "feedValue(%s, %s, %s)" % (uniqueId, value, success) - def windowEvent(self, win): print "Got window event in runp3d"