Ignore:
Timestamp:
Sep 24, 2014, 9:34:21 PM (11 years ago)
Author:
dmik
Message:

icedtea-web: Merge version 1.5.1 from vendor to trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/icedtea-web/plugin/icedteanp/IcedTeaPluginRequestProcessor.cc

    r418 r429  
    4848 */
    4949
    50 // Initialize static members used by the queue processing framework
    51 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 
    5550/**
    5651 * PluginRequestProcessor constructor.
     
    6156PluginRequestProcessor::PluginRequestProcessor()
    6257{
    63     this->pendingRequests = new std::map<pthread_t, uintmax_t>();
     58    this->message_queue = new std::vector< std::vector<std::string*>* >();
    6459
    6560    internal_req_ref_counter = 0;
    6661
    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);
    7165}
    7266
     
    8175    PLUGIN_DEBUG("PluginRequestProcessor::~PluginRequestProcessor\n");
    8276
    83     if (pendingRequests)
    84         delete pendingRequests;
     77    if (message_queue)
     78        delete message_queue;
    8579
    8680    pthread_mutex_destroy(&message_queue_mutex);
    8781    pthread_mutex_destroy(&syn_write_mutex);
    88 
    8982    pthread_cond_destroy(&cond_message_available);
    9083}
     
    143136            pthread_mutex_lock(&message_queue_mutex);
    144137            message_queue->push_back(message_parts);
     138            pthread_cond_signal(&cond_message_available);
    145139            pthread_mutex_unlock(&message_queue_mutex);
    146140
    147             // Broadcast that a message is now available
    148             pthread_cond_broadcast(&cond_message_available);
    149141
    150142            return true;
     
    414406    propertyNameID = *(message_parts->at(6));
    415407
    416     if (*(message_parts->at(7)) == "literalreturn")
     408    if (*(message_parts->at(7)) == "literalreturn" || *(message_parts->at(7)) == "jsobject" )
    417409    {
    418410        value.append(*(message_parts->at(7)));
     
    441433        if (java_result->error_occurred)
    442434        {
    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());
    444436            //goto cleanup;
    445437        }
     
    472464 * This is a static function, called in another thread. Since certain data
    473465 * can only be requested from the main thread in Mozilla, this function
    474  * does whatever it can seperately, and then makes an internal request that
     466 * does whatever it can separately, and then makes an internal request that
    475467 * causes _getMember to do the rest of the work.
    476468 *
     
    522514        if (java_result->error_occurred)
    523515        {
    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());
    525517            //goto cleanup;
    526518        }
     
    636628queue_cleanup(void* data)
    637629{
    638 
    639     pthread_mutex_destroy((pthread_mutex_t*) data);
    640 
    641630    PLUGIN_DEBUG("Queue processing stopped.\n");
     631}
     632
     633static void
     634queue_wait_cleanup(void* data)
     635{
     636    pthread_mutex_unlock((pthread_mutex_t*) data);
    642637}
    643638
     
    651646    PluginRequestProcessor* processor = (PluginRequestProcessor*) data;
    652647#endif
     648    processor->queueProcessorThread();
     649    return NULL;
     650}
     651
     652void
     653PluginRequestProcessor::queueProcessorThread()
     654{
    653655    std::vector<std::string*>* message_parts = NULL;
    654656    std::string command;
    655     pthread_mutex_t wait_mutex = PTHREAD_MUTEX_INITIALIZER;
    656657
    657658    PLUGIN_DEBUG("Queue processor initialized. Queue = %p\n", message_queue);
    658 
    659     pthread_mutex_init(&wait_mutex, NULL);
    660659
    661660#ifdef __OS2__
    662661    queue_processor_data->stopRequested = false;
    663662#else
    664     pthread_cleanup_push(queue_cleanup, (void*) &wait_mutex);
     663    pthread_cleanup_push(queue_cleanup, NULL);
    665664#endif
    666665
     
    681680            if (command == "GetMember")
    682681            {
    683                 processor->sendMember(message_parts);
     682                sendMember(message_parts);
    684683            } else if (command == "ToString")
    685684            {
    686                 processor->sendString(message_parts);
     685                sendString(message_parts);
    687686            } else if (command == "SetMember")
    688687            {
    689688                // write methods are synchronized
    690689                pthread_mutex_lock(&syn_write_mutex);
    691                 processor->setMember(message_parts);
     690                setMember(message_parts);
    692691                pthread_mutex_unlock(&syn_write_mutex);
    693692            } else if (command == "Call")
     
    695694                // write methods are synchronized
    696695                pthread_mutex_lock(&syn_write_mutex);
    697                 processor->call(message_parts);
     696                call(message_parts);
    698697                pthread_mutex_unlock(&syn_write_mutex);
    699698            } else if (command == "Eval")
     
    701700                // write methods are synchronized
    702701                pthread_mutex_lock(&syn_write_mutex);
    703                 processor->eval(message_parts);
     702                eval(message_parts);
    704703                pthread_mutex_unlock(&syn_write_mutex);
    705704            } else if (command == "GetSlot")
     
    707706                // write methods are synchronized
    708707                pthread_mutex_lock(&syn_write_mutex);
    709                 processor->sendMember(message_parts);
     708                sendMember(message_parts);
    710709                pthread_mutex_unlock(&syn_write_mutex);
    711710            } else if (command == "SetSlot")
     
    713712                // write methods are synchronized
    714713                pthread_mutex_lock(&syn_write_mutex);
    715                 processor->setMember(message_parts);
     714                setMember(message_parts);
    716715                pthread_mutex_unlock(&syn_write_mutex);
    717716            } else if (command == "LoadURL") // For instance X url <url> <target>
     
    719718                // write methods are synchronized
    720719                pthread_mutex_lock(&syn_write_mutex);
    721                 processor->loadURL(message_parts);
     720                loadURL(message_parts);
    722721                pthread_mutex_unlock(&syn_write_mutex);
    723722            } else
     
    732731        } else
    733732        {
    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);
    737745        }
    738746
     
    748756
    749757#ifdef __OS2__
    750     queue_cleanup((void*) &wait_mutex);
     758    queue_cleanup(NULL);
     759    queue_wait_cleanup(&message_queue_mutex);
    751760#else
    752761    pthread_cleanup_pop(1);
     
    781790        property_identifier = browser_functions.getstringidentifier(property_id->c_str());
    782791
    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());
    784793
    785794    IcedTeaPluginUtilities::javaResultToNPVariant(instance, value, &value_variant);
     
    801810
    802811    instance = (NPP) parameters.at(0);
     812
    803813    parent_ptr = (NPObject*) parameters.at(1);
    804814    std::string*  member_id = (std::string*) parameters.at(2);
     
    813823
    814824    // 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());
    816826
    817827    if (!browser_functions.hasproperty(instance, parent_ptr, member_identifier))
    818828    {
    819         printf("%s not found!\n", browser_functions.utf8fromidentifier(member_identifier));
     829        PLUGIN_ERROR("%s not found!\n", IcedTeaPluginUtilities::NPIdentifierAsString(member_identifier).c_str());
    820830    }
    821831    ((AsyncCallThreadData*) data)->call_successful = browser_functions.getproperty(instance, parent_ptr, member_identifier, member_ptr);
     
    827837        createJavaObjectFromVariant(instance, *member_ptr, &member_ptr_str);
    828838        ((AsyncCallThreadData*) data)->result.append(member_ptr_str);
    829 
     839    } else
     840    {
     841        ((AsyncCallThreadData*) data)->result.append("null");
    830842    }
    831843    ((AsyncCallThreadData*) data)->result_ready = true;
     
    856868    script_str = (std::string*) call_data->at(2);
    857869
    858 #if MOZILLA_VERSION_COLLAPSED < 1090200
    859     script.utf8characters = script_str->c_str();
    860     script.utf8length = script_str->size();
    861 
    862     PLUGIN_DEBUG("Evaluating: %s\n", script_str->c_str());
    863 #else
    864870    script.UTF8Characters = script_str->c_str();
    865871    script.UTF8Length = script_str->size();
    866872
    867873    PLUGIN_DEBUG("Evaluating: %s\n", script_str->c_str());
    868 #endif
    869874
    870875    ((AsyncCallThreadData*) data)->call_successful = browser_functions.evaluate(instance, window_ptr, &script, eval_variant);
     
    980985    {
    981986        createJavaObjectFromVariant(instance, tostring_result, &(((AsyncCallThreadData*) data)->result));
     987    } else
     988    {
     989        ((AsyncCallThreadData*) data)->result.append("null");
    982990    }
    983991    ((AsyncCallThreadData*) data)->result_ready = true;
Note: See TracChangeset for help on using the changeset viewer.