void mt::ThreadGroup::joinAll() { bool failed = false; // Keep track of which threads we've already joined. for (; mLastJoined < mThreads.size(); mLastJoined++) { try { mThreads[mLastJoined]->join(); } catch (...) { failed = true; } } if (!mExceptions.empty()) { std::string messageString("Exceptions thrown from ThreadGroup in the following order:\n"); for (size_t ii=0; ii<mExceptions.size(); ++ii) { messageString += mExceptions.at(ii).toString(); } throw except::Exception(Ctxt(messageString)); } if (failed) throw except::Error(Ctxt("ThreadGroup could not be joined")); }
static bool regexOk(const AndroidLogEntry& entry) { if (!g_regex) { return true; } std::string messageString(entry.message, entry.messageLen); return g_regex->PartialMatch(messageString); }
/* ******************************************************************* * Function: TeamRegister * * Description: * Registers for a team - calls the register command and then * resolves a team and sends a message to each player in the team * * Parameters: * CGBLTeamID teamID - the ID of the team to register * TGBLLOMeasuredObjectiveCallback *callbackFunction - the callback function * to register (if any) * * Returns: * int - the registration ID * ******************************************************************* */ int CGBLLOMeasuredObjective::TeamRegister(CGBLTeamID theTeamID, TGBLLOMeasuredObjectiveCallback *callbackFunction) { // first, check if the team ID has already been set for this MO if (0 == teamID) { teamID = theTeamID; } int returnRegID = 0; // Check the team ID is the same if ((int)teamID == (int)theTeamID) { // register the measurement with the standard registration returnRegID = Register(callbackFunction, true); // Create a CKDataArray from the context CKDataArray *theArray = (CKDataArray *)theContext->CreateObject(CKCID_DATAARRAY, "Team Array"); CGBLCOError theError = theProfileManager->GetTeamPlayers(theArray, teamID); // Now iterate through the CKDataArray int counter = 0; while (counter < theArray->GetRowCount()) { CGBLLOMessagePacket messagePacket; int tempUserID = (int)*(theArray->GetElement(0, counter)); userArray.PushBack((CGBLUserID)tempUserID); // Now fill the messagePacket messagePacket.destination = tempUserID; messagePacket.source = myUserID; messagePacket.messageID = theArrayHandler->GetMesssageID(); XString messageString("Register,MO,"); messageString += theMOData->GetName(); messagePacket.messageType = eRegistration; messagePacket.messageSize = sizeof(messageString); messagePacket.theMessage = messageString; // Send the message to the Array Handler theArrayHandler->AddToSendArray(messagePacket); // Ignore the error - nothing we can do here counter++; } } return returnRegID; }
/* ******************************************************************* * Function: AddPlayerToTeam * * Description: * * Parameters: * * Returns: * ******************************************************************* */ CGBLCOError CGBLLOMeasuredObjective::AddPlayerToTeam(CGBLUserID theUser, CGBLTeamID theTeam) { CGBLCOError errorType(CGBLCOError::EGBLCOErrorType::GBLCO_OK); // double check that this is the right team if ((int)teamID == (int)theTeam) { // Send the message to the new player for the MO CGBLLOMessagePacket messagePacket; // add a player to the team list userArray.PushBack((int)theUser); // Now send the message to register for this measurement messagePacket.destination = theUser; messagePacket.source = myUserID; messagePacket.messageID = theArrayHandler->GetMesssageID(); XString messageString("Register,MO,"); messageString += theMOData->GetName(); messagePacket.messageType = eRegistration; messagePacket.messageSize = sizeof(messageString); messagePacket.theMessage = messageString; // Send the message to the Array Handler errorType = theArrayHandler->AddToSendArray(messagePacket); // Now, iterate through the measurements and call Add player on them int counter = 0; while (counter < measurementList.Size()) { errorType = measurementList[counter]->AddPlayerToTeam(theTeam, theUser); counter++; } } else { errorType = CGBLCOError(CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL, GBLLO_ERROR_INCORRECTTEAM_DESC, GBLLO_ERROR_INCORRECTTEAM); } return errorType; }
// Actual logging is done in this routine void log(Logger::LogFileType logFileType, const String& systemId, Uint32 logLevel, const String localizedMsg) { // Prepend the systemId to the incoming message String messageString(systemId); messageString.append(": "); messageString.append(localizedMsg); // l10n // Get the logLevel String // This converts bitmap to string based on highest order // bit set // ATTN: KS Fix this more efficiently. const char* tmp = ""; if (logLevel & Logger::TRACE) tmp = "TRACE "; if (logLevel & Logger::INFORMATION) tmp = "INFO "; if (logLevel & Logger::WARNING) tmp = "WARNING "; if (logLevel & Logger::SEVERE) tmp = "SEVERE "; if (logLevel & Logger::FATAL) tmp = "FATAL "; # ifndef PEGASUS_OS_VMS // Acquire AutoMutex (for thread sync) // and AutoFileLock (for Process Sync). AutoMutex am(_mutex); AutoFileLock fileLock(_loggerLockFileName); Uint32 logFileSize = 0; // Read logFileSize to check if the logfile needs to be pruned. FileSystem::getFileSize(String(_logFileNames[logFileType]), logFileSize); // Check if the size of the logfile is exceeding _maxLogFileSizeBytes. if ( logFileSize > _maxLogFileSizeBytes) { // Prepare appropriate file name based on the logFileType. // Eg: if Logfile name is PegasusStandard.log, pruned logfile name // will be PegasusStandard-062607-122302.log,where 062607-122302 // is the time stamp. String prunedLogfile(_logFileNames[logFileType], (Uint32)strlen(_logFileNames[logFileType]) - 4); prunedLogfile.append('-'); // Get timestamp,remove illegal chars in file name'/' and ':' // (: is illegal Open VMS) from the time stamp. Append the time // info to the file name. String timeStamp = System::getCurrentASCIITime(); for (unsigned int i=0; i<=timeStamp.size(); i++) { if(timeStamp[i] == '/' || timeStamp[i] == ':') { timeStamp.remove(i, 1); } } prunedLogfile.append(timeStamp); // Append '.log' to the file prunedLogfile.append( ".log"); // Rename the logfile FileSystem::renameFile(String(_logFileNames[logFileType]), prunedLogfile); } // Check if the logfile needs to be pruned. # endif // ifndef PEGASUS_OS_VMS // Open Logfile. Based on the value of logFileType, one of the five // Logfiles will be opened. ofstream logFileStream; logFileStream.open(_logFileNames[logFileType], ios::app); logFileStream << System::getCurrentASCIITime() << " " << tmp << (const char *)messageString.getCString() << endl; logFileStream.close(); }
static void testWebContextSecurityFileXHR(WebViewTest* test, gconstpointer) { GUniquePtr<char> fileURL(g_strdup_printf("file://%s/simple.html", Test::getResourcesDir(Test::WebKit2Resources).data())); test->loadURI(fileURL.get()); test->waitUntilLoadFinished(); GUniquePtr<char> jsonURL(g_strdup_printf("file://%s/simple.json", Test::getResourcesDir().data())); GUniquePtr<char> xhr(g_strdup_printf("var xhr = new XMLHttpRequest; xhr.open(\"GET\", \"%s\"); xhr.send();", jsonURL.get())); WebKitJavascriptResult* consoleMessage = nullptr; webkit_user_content_manager_register_script_message_handler(test->m_userContentManager.get(), "console"); g_signal_connect(test->m_userContentManager.get(), "script-message-received::console", G_CALLBACK(consoleMessageReceivedCallback), &consoleMessage); // By default file access is not allowed, this will show a console message with a cross-origin error. GUniqueOutPtr<GError> error; WebKitJavascriptResult* javascriptResult = test->runJavaScriptAndWaitUntilFinished(xhr.get(), &error.outPtr()); g_assert(javascriptResult); g_assert(!error); g_assert(consoleMessage); GUniquePtr<char> messageString(WebViewTest::javascriptResultToCString(consoleMessage)); GRefPtr<GVariant> variant = g_variant_parse(G_VARIANT_TYPE("(uusus)"), messageString.get(), nullptr, nullptr, nullptr); g_assert(variant.get()); unsigned level; const char* messageText; g_variant_get(variant.get(), "(uu&su&s)", nullptr, &level, &messageText, nullptr, nullptr); g_assert_cmpuint(level, ==, 3); // Console error message. GUniquePtr<char> expectedErrorMessage(g_strdup_printf("XMLHttpRequest cannot load %s. Cross origin requests are only supported for HTTP.", jsonURL.get())); g_assert_cmpstr(messageText, ==, expectedErrorMessage.get()); webkit_javascript_result_unref(consoleMessage); consoleMessage = nullptr; level = 0; messageText = nullptr; variant = nullptr; // Allow file access from file URLs. webkit_settings_set_allow_file_access_from_file_urls(webkit_web_view_get_settings(test->m_webView), TRUE); test->loadURI(fileURL.get()); test->waitUntilLoadFinished(); javascriptResult = test->runJavaScriptAndWaitUntilFinished(xhr.get(), &error.outPtr()); g_assert(javascriptResult); g_assert(!error); // It isn't still possible to load file from an HTTP URL. test->loadURI(kServer->getURIForPath("/").data()); test->waitUntilLoadFinished(); javascriptResult = test->runJavaScriptAndWaitUntilFinished(xhr.get(), &error.outPtr()); g_assert(javascriptResult); g_assert(!error); g_assert(consoleMessage); variant = g_variant_parse(G_VARIANT_TYPE("(uusus)"), messageString.get(), nullptr, nullptr, nullptr); g_assert(variant.get()); g_variant_get(variant.get(), "(uu&su&s)", nullptr, &level, &messageText, nullptr, nullptr); g_assert_cmpuint(level, ==, 3); // Console error message. g_assert_cmpstr(messageText, ==, expectedErrorMessage.get()); webkit_javascript_result_unref(consoleMessage); g_signal_handlers_disconnect_matched(test->m_userContentManager.get(), G_SIGNAL_MATCH_DATA, 0, 0, nullptr, nullptr, &consoleMessage); webkit_user_content_manager_unregister_script_message_handler(test->m_userContentManager.get(), "console"); webkit_settings_set_allow_file_access_from_file_urls(webkit_web_view_get_settings(test->m_webView), FALSE); }
/* ******************************************************************* * Function: DeRegister * * Description: * * Parameters: * * Returns: * ******************************************************************* */ CGBLCOError CGBLLOMeasuredObjective::DeRegister(int regID) { CGBLCOError errorType(CGBLCOError::EGBLCOErrorType::GBLCO_OK); // find the registration - iterate through the registrations until the reg is found int counter = 0; while ( (counter < registrationIDArray.Size()) && (regID != registrationIDArray[counter]->registrationID) ) { counter++; } // Has the registration been found? if (counter < registrationIDArray.Size()) { MORegHelperClass *toDelete = registrationIDArray[counter]; // check to see if the registration was a team registration if (teamID != 0) { // De register the team stuff int counter2 = 0; int size = userArray.Size(); while (counter2 < size) { CGBLLOMessagePacket messagePacket; int userID = userArray[counter2]; // Remove the player from the team userArray.RemoveAt(counter2); // Deregister the MO with the player messagePacket.destination = userID; messagePacket.source = myUserID; messagePacket.messageID = theArrayHandler->GetMesssageID(); XString messageString("Deregister,MO,"); messageString += theMOData->GetName(); messagePacket.messageType = eRegistration; messagePacket.messageSize = sizeof(messageString); messagePacket.theMessage = messageString; // Send the message to the Array Handler errorType = theArrayHandler->AddToSendArray(messagePacket); counter2++; } } registrationIDArray.Remove(toDelete); delete toDelete; } else { errorType = CGBLCOError(CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL, GBLLO_ERROR_REGISTRATIONNOTFOUND_DESC, GBLLO_ERROR_REGISTRATIONNOTFOUND); } // Check to see if it's the last registration. If it is, mark the class for deletion if (0 == registrationIDArray.Size()) { errorType = CGBLCOError(CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL, GBLLO_ERROR_EMPTYREGARRAY_DESC, GBLLO_ERROR_EMPTYREGARRAY); } return errorType; }
/* ******************************************************************* * Function: RemovePlayerFromTeam * * Description: * * Parameters: * * Returns: * ******************************************************************* */ CGBLCOError CGBLLOMeasuredObjective::RemovePlayerFromTeam(CGBLUserID theUser, CGBLTeamID theTeam) { CGBLCOError errorType(CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL); CGBLLOMessagePacket messagePacket; // double check that this is the right team if ((int)teamID == (int)theTeam) { // Find the player in the array int counter=0; int size = userArray.Size(); bool found = false; while ( (counter < size) && !found ) { if ((int)userArray[counter] == (int)theUser) { found = true; } else { counter++; } } if (found) { // Remove the player from the team userArray.RemoveAt(counter); // Deregister the measurement with the player messagePacket.destination = theUser; messagePacket.source = myUserID; messagePacket.messageID = theArrayHandler->GetMesssageID(); XString messageString("Deregister,MO,"); messageString += theMOData->GetName(); messagePacket.messageType = eRegistration; messagePacket.messageSize = sizeof(messageString); messagePacket.theMessage = messageString; // Send the message to the Array Handler errorType = theArrayHandler->AddToSendArray(messagePacket); // Now iterate through all the measurements and call the Remove player int counter = 0; while (counter < measurementList.Size()) { errorType = measurementList[counter]->RemovePlayerFromTeam(theTeam, theUser); counter++; } } else { errorType = CGBLCOError(CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL, GBLLO_ERROR_USERNOTFOUND_DESC, GBLLO_ERROR_USERNOTFOUND); } } else { errorType = CGBLCOError(CGBLCOError::EGBLCOErrorType::GBLCO_LOCAL, GBLLO_ERROR_INCORRECTTEAM_DESC, GBLLO_ERROR_INCORRECTTEAM); } return errorType; }