- Timestamp:
- Sep 24, 2014, 9:34:21 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/icedtea-web/plugin/icedteanp/IcedTeaPluginRequestProcessor.cc
r418 r429 48 48 */ 49 49 50 // Initialize static members used by the queue processing framework51 pthread_mutex_t message_queue_mutex = PTHREAD_MUTEX_INITIALIZER;52 pthread_mutex_t syn_write_mutex = PTHREAD_MUTEX_INITIALIZER;53 std::vector< std::vector<std::string*>* >* message_queue = new std::vector< std::vector<std::string*>* >();54 55 50 /** 56 51 * PluginRequestProcessor constructor. … … 61 56 PluginRequestProcessor::PluginRequestProcessor() 62 57 { 63 this-> pendingRequests = new std::map<pthread_t, uintmax_t>();58 this->message_queue = new std::vector< std::vector<std::string*>* >(); 64 59 65 60 internal_req_ref_counter = 0; 66 61 67 pthread_mutex_init(&message_queue_mutex, NULL); 68 pthread_mutex_init(&syn_write_mutex, NULL); 69 70 pthread_cond_init(&cond_message_available, NULL); 62 pthread_mutex_init(&this->message_queue_mutex, NULL); 63 pthread_mutex_init(&this->syn_write_mutex, NULL); 64 pthread_cond_init(&this->cond_message_available, NULL); 71 65 } 72 66 … … 81 75 PLUGIN_DEBUG("PluginRequestProcessor::~PluginRequestProcessor\n"); 82 76 83 if ( pendingRequests)84 delete pendingRequests;77 if (message_queue) 78 delete message_queue; 85 79 86 80 pthread_mutex_destroy(&message_queue_mutex); 87 81 pthread_mutex_destroy(&syn_write_mutex); 88 89 82 pthread_cond_destroy(&cond_message_available); 90 83 } … … 143 136 pthread_mutex_lock(&message_queue_mutex); 144 137 message_queue->push_back(message_parts); 138 pthread_cond_signal(&cond_message_available); 145 139 pthread_mutex_unlock(&message_queue_mutex); 146 140 147 // Broadcast that a message is now available148 pthread_cond_broadcast(&cond_message_available);149 141 150 142 return true; … … 414 406 propertyNameID = *(message_parts->at(6)); 415 407 416 if (*(message_parts->at(7)) == "literalreturn" )408 if (*(message_parts->at(7)) == "literalreturn" || *(message_parts->at(7)) == "jsobject" ) 417 409 { 418 410 value.append(*(message_parts->at(7))); … … 441 433 if (java_result->error_occurred) 442 434 { 443 printf("Unable to get member name for setMember. Error occurred: %s\n", java_result->error_msg->c_str());435 PLUGIN_ERROR("Unable to get member name for setMember. Error occurred: %s\n", java_result->error_msg->c_str()); 444 436 //goto cleanup; 445 437 } … … 472 464 * This is a static function, called in another thread. Since certain data 473 465 * can only be requested from the main thread in Mozilla, this function 474 * does whatever it can sep erately, and then makes an internal request that466 * does whatever it can separately, and then makes an internal request that 475 467 * causes _getMember to do the rest of the work. 476 468 * … … 522 514 if (java_result->error_occurred) 523 515 { 524 printf("Unable to process getMember request. Error occurred: %s\n", java_result->error_msg->c_str());516 PLUGIN_ERROR("Unable to process getMember request. Error occurred: %s\n", java_result->error_msg->c_str()); 525 517 //goto cleanup; 526 518 } … … 636 628 queue_cleanup(void* data) 637 629 { 638 639 pthread_mutex_destroy((pthread_mutex_t*) data);640 641 630 PLUGIN_DEBUG("Queue processing stopped.\n"); 631 } 632 633 static void 634 queue_wait_cleanup(void* data) 635 { 636 pthread_mutex_unlock((pthread_mutex_t*) data); 642 637 } 643 638 … … 651 646 PluginRequestProcessor* processor = (PluginRequestProcessor*) data; 652 647 #endif 648 processor->queueProcessorThread(); 649 return NULL; 650 } 651 652 void 653 PluginRequestProcessor::queueProcessorThread() 654 { 653 655 std::vector<std::string*>* message_parts = NULL; 654 656 std::string command; 655 pthread_mutex_t wait_mutex = PTHREAD_MUTEX_INITIALIZER;656 657 657 658 PLUGIN_DEBUG("Queue processor initialized. Queue = %p\n", message_queue); 658 659 pthread_mutex_init(&wait_mutex, NULL);660 659 661 660 #ifdef __OS2__ 662 661 queue_processor_data->stopRequested = false; 663 662 #else 664 pthread_cleanup_push(queue_cleanup, (void*) &wait_mutex);663 pthread_cleanup_push(queue_cleanup, NULL); 665 664 #endif 666 665 … … 681 680 if (command == "GetMember") 682 681 { 683 processor->sendMember(message_parts);682 sendMember(message_parts); 684 683 } else if (command == "ToString") 685 684 { 686 processor->sendString(message_parts);685 sendString(message_parts); 687 686 } else if (command == "SetMember") 688 687 { 689 688 // write methods are synchronized 690 689 pthread_mutex_lock(&syn_write_mutex); 691 processor->setMember(message_parts);690 setMember(message_parts); 692 691 pthread_mutex_unlock(&syn_write_mutex); 693 692 } else if (command == "Call") … … 695 694 // write methods are synchronized 696 695 pthread_mutex_lock(&syn_write_mutex); 697 processor->call(message_parts);696 call(message_parts); 698 697 pthread_mutex_unlock(&syn_write_mutex); 699 698 } else if (command == "Eval") … … 701 700 // write methods are synchronized 702 701 pthread_mutex_lock(&syn_write_mutex); 703 processor->eval(message_parts);702 eval(message_parts); 704 703 pthread_mutex_unlock(&syn_write_mutex); 705 704 } else if (command == "GetSlot") … … 707 706 // write methods are synchronized 708 707 pthread_mutex_lock(&syn_write_mutex); 709 processor->sendMember(message_parts);708 sendMember(message_parts); 710 709 pthread_mutex_unlock(&syn_write_mutex); 711 710 } else if (command == "SetSlot") … … 713 712 // write methods are synchronized 714 713 pthread_mutex_lock(&syn_write_mutex); 715 processor->setMember(message_parts);714 setMember(message_parts); 716 715 pthread_mutex_unlock(&syn_write_mutex); 717 716 } else if (command == "LoadURL") // For instance X url <url> <target> … … 719 718 // write methods are synchronized 720 719 pthread_mutex_lock(&syn_write_mutex); 721 processor->loadURL(message_parts);720 loadURL(message_parts); 722 721 pthread_mutex_unlock(&syn_write_mutex); 723 722 } else … … 732 731 } else 733 732 { 734 pthread_mutex_lock(&wait_mutex); 735 pthread_cond_wait(&cond_message_available, &wait_mutex); 736 pthread_mutex_unlock(&wait_mutex); 733 pthread_mutex_lock(&message_queue_mutex); 734 if (message_queue->size() == 0) 735 { 736 #ifndef __OS2__ 737 pthread_cleanup_push(queue_wait_cleanup, &message_queue_mutex); 738 #endif 739 pthread_cond_wait(&cond_message_available, &message_queue_mutex); 740 #ifndef __OS2__ 741 pthread_cleanup_pop(0); 742 #endif 743 } 744 pthread_mutex_unlock(&message_queue_mutex); 737 745 } 738 746 … … 748 756 749 757 #ifdef __OS2__ 750 queue_cleanup((void*) &wait_mutex); 758 queue_cleanup(NULL); 759 queue_wait_cleanup(&message_queue_mutex); 751 760 #else 752 761 pthread_cleanup_pop(1); … … 781 790 property_identifier = browser_functions.getstringidentifier(property_id->c_str()); 782 791 783 PLUGIN_DEBUG("Setting %s on instance %p, object %p to value %s\n", browser_functions.utf8fromidentifier(property_identifier), instance, member, value->c_str());792 PLUGIN_DEBUG("Setting %s on instance %p, object %p to value %s\n", IcedTeaPluginUtilities::NPIdentifierAsString(property_identifier).c_str(), instance, member, value->c_str()); 784 793 785 794 IcedTeaPluginUtilities::javaResultToNPVariant(instance, value, &value_variant); … … 801 810 802 811 instance = (NPP) parameters.at(0); 812 803 813 parent_ptr = (NPObject*) parameters.at(1); 804 814 std::string* member_id = (std::string*) parameters.at(2); … … 813 823 814 824 // Get the NPVariant corresponding to this member 815 PLUGIN_DEBUG("Looking for %p %p %p (%s)\n", instance, parent_ptr, member_identifier, browser_functions.utf8fromidentifier(member_identifier));825 PLUGIN_DEBUG("Looking for %p %p %p (%s)\n", instance, parent_ptr, member_identifier, IcedTeaPluginUtilities::NPIdentifierAsString(member_identifier).c_str()); 816 826 817 827 if (!browser_functions.hasproperty(instance, parent_ptr, member_identifier)) 818 828 { 819 printf("%s not found!\n", browser_functions.utf8fromidentifier(member_identifier));829 PLUGIN_ERROR("%s not found!\n", IcedTeaPluginUtilities::NPIdentifierAsString(member_identifier).c_str()); 820 830 } 821 831 ((AsyncCallThreadData*) data)->call_successful = browser_functions.getproperty(instance, parent_ptr, member_identifier, member_ptr); … … 827 837 createJavaObjectFromVariant(instance, *member_ptr, &member_ptr_str); 828 838 ((AsyncCallThreadData*) data)->result.append(member_ptr_str); 829 839 } else 840 { 841 ((AsyncCallThreadData*) data)->result.append("null"); 830 842 } 831 843 ((AsyncCallThreadData*) data)->result_ready = true; … … 856 868 script_str = (std::string*) call_data->at(2); 857 869 858 #if MOZILLA_VERSION_COLLAPSED < 1090200859 script.utf8characters = script_str->c_str();860 script.utf8length = script_str->size();861 862 PLUGIN_DEBUG("Evaluating: %s\n", script_str->c_str());863 #else864 870 script.UTF8Characters = script_str->c_str(); 865 871 script.UTF8Length = script_str->size(); 866 872 867 873 PLUGIN_DEBUG("Evaluating: %s\n", script_str->c_str()); 868 #endif869 874 870 875 ((AsyncCallThreadData*) data)->call_successful = browser_functions.evaluate(instance, window_ptr, &script, eval_variant); … … 980 985 { 981 986 createJavaObjectFromVariant(instance, tostring_result, &(((AsyncCallThreadData*) data)->result)); 987 } else 988 { 989 ((AsyncCallThreadData*) data)->result.append("null"); 982 990 } 983 991 ((AsyncCallThreadData*) data)->result_ready = true;
Note:
See TracChangeset
for help on using the changeset viewer.