void WriterThread::run() { ... lock.lockForWrite(); write_file(); lock.unlock(); ... }
UtlBoolean SipSubscribeServer::enableEventType(const char* eventTypeToken, SipUserAgent* userAgent, SipPublishContentMgr* contentMgr, SipSubscribeServerEventHandler* eventHandler, SipSubscriptionMgr* subscriptionMgr) { UtlBoolean addedEvent = FALSE; UtlString eventName(eventTypeToken ? eventTypeToken : ""); lockForWrite(); // Only add the event support if it does not already exist; SubscribeServerEventData* eventData = (SubscribeServerEventData*) mEventDefinitions.find(&eventName); if(!eventData) { addedEvent = TRUE; eventData = new SubscribeServerEventData(); *((UtlString*)eventData) = eventName; eventData->mpEventSpecificUserAgent = userAgent ? userAgent : mpDefaultUserAgent; eventData->mpEventSpecificContentMgr = contentMgr ? contentMgr : mpDefaultContentMgr; eventData->mpEventSpecificHandler = eventHandler ? eventHandler : mpDefaultEventHandler; eventData->mpEventSpecificSubscriptionMgr = subscriptionMgr ? subscriptionMgr : mpDefaultSubscriptionMgr; mEventDefinitions.insert(eventData); // Register an interest in SUBSCRIBE requests and NOTIFY responses // for this event type eventData->mpEventSpecificUserAgent->addMessageObserver(*(getMessageQueue()), SIP_SUBSCRIBE_METHOD, TRUE, // requests FALSE, // not reponses TRUE, // incoming FALSE, // no outgoing eventName, NULL, NULL); eventData->mpEventSpecificUserAgent->addMessageObserver(*(getMessageQueue()), SIP_NOTIFY_METHOD, FALSE, // no requests TRUE, // reponses TRUE, // incoming FALSE, // no outgoing eventName, NULL, NULL); // Register the callback for changes that occur in the // publish content manager eventData->mpEventSpecificContentMgr->setContentChangeObserver(eventName, this, contentChangeCallback); } unlockForWrite(); return(addedEvent); }
bool ObjectActionSpring::updateArguments(QVariantMap arguments) { // targets are required, spring-constants are optional bool ok = true; glm::vec3 positionalTarget = EntityActionInterface::extractVec3Argument("spring action", arguments, "targetPosition", ok, false); if (!ok) { positionalTarget = _positionalTarget; } ok = true; float linearTimeScale = EntityActionInterface::extractFloatArgument("spring action", arguments, "linearTimeScale", ok, false); if (!ok || linearTimeScale <= 0.0f) { linearTimeScale = _linearTimeScale; } ok = true; glm::quat rotationalTarget = EntityActionInterface::extractQuatArgument("spring action", arguments, "targetRotation", ok, false); if (!ok) { rotationalTarget = _rotationalTarget; } ok = true; float angularTimeScale = EntityActionInterface::extractFloatArgument("spring action", arguments, "angularTimeScale", ok, false); if (!ok) { angularTimeScale = _angularTimeScale; } if (positionalTarget != _positionalTarget || linearTimeScale != _linearTimeScale || rotationalTarget != _rotationalTarget || angularTimeScale != _angularTimeScale) { // something changed lockForWrite(); _positionalTarget = positionalTarget; _linearTimeScale = glm::max(MIN_TIMESCALE, glm::abs(linearTimeScale)); _rotationalTarget = rotationalTarget; _angularTimeScale = glm::max(MIN_TIMESCALE, glm::abs(angularTimeScale)); _active = true; activateBody(); unlock(); } return true; }
UtlBoolean SipSubscribeServer::disableEventType(const char* eventTypeToken, SipUserAgent*& userAgent, SipPublishContentMgr*& contentMgr, SipSubscribeServerEventHandler*& eventHandler, SipSubscriptionMgr*& subscriptionMgr) { UtlBoolean removedEvent = FALSE; UtlString eventName(eventTypeToken ? eventTypeToken : ""); lockForWrite(); // Only add the event support if it does not already exist; SubscribeServerEventData* eventData = (SubscribeServerEventData*) mEventDefinitions.remove(&eventName); if(eventData) { removedEvent = TRUE; userAgent = eventData->mpEventSpecificUserAgent == mpDefaultUserAgent ? NULL : eventData->mpEventSpecificUserAgent; contentMgr = eventData->mpEventSpecificContentMgr == mpDefaultContentMgr ? NULL : eventData->mpEventSpecificContentMgr; eventHandler = eventData->mpEventSpecificHandler == mpDefaultEventHandler ? NULL : eventData->mpEventSpecificHandler; subscriptionMgr = eventData->mpEventSpecificSubscriptionMgr == mpDefaultSubscriptionMgr ? NULL : eventData->mpEventSpecificSubscriptionMgr; // Unregister interest in SUBSCRIBE requests and NOTIFY // responses for this event type eventData->mpEventSpecificUserAgent->removeMessageObserver(*(getMessageQueue())); delete eventData; eventData = NULL; } else { userAgent = NULL; contentMgr = NULL; eventHandler = NULL; subscriptionMgr = NULL; } unlockForWrite(); return(removedEvent); }
UtlBoolean SipPublishServer::disableEventType(const char* eventType) { UtlString eventName(eventType); lockForWrite(); PublishServerEventData* eventData = dynamic_cast <PublishServerEventData*> (mEventDefinitions.remove(&eventName)); if (eventData) { // Unregister interest in PUBLISH requests for this event type eventData->mpEventSpecificUserAgent->removeMessageObserver(*(getMessageQueue())); delete eventData; } unlockForWrite(); return eventData != NULL; }
UtlBoolean SipSubscribeServer::disableEventType(const char* eventType) { // :TODO: We should terminate all subscriptions for this event type. UtlString eventName(eventType); lockForWrite(); SubscribeServerEventData* eventData = dynamic_cast <SubscribeServerEventData*> (mEventDefinitions.remove(&eventName)); if (eventData) { // Unregister interest in SUBSCRIBE requests and NOTIFY // responses for this event type eventData->mpEventSpecificUserAgent->removeMessageObserver(*(getMessageQueue())); delete eventData; } unlockForWrite(); return eventData != NULL; }
UtlBoolean SipPublishServer::disableEventType(const char* eventTypeToken, SipUserAgent*& userAgent, SipPublishServerEventStateMgr*& eventStateMgr, SipPublishServerEventStateCompositor*& eventStateCompositor) { UtlBoolean removedEvent = FALSE; UtlString eventName(eventTypeToken ? eventTypeToken : ""); lockForWrite(); // Only add the event support if it does not already exist; PublishServerEventData* eventData = (PublishServerEventData*) mEventDefinitions.remove(&eventName); if(eventData) { removedEvent = TRUE; userAgent = eventData->mpEventSpecificUserAgent == mpDefaultUserAgent ? NULL : eventData->mpEventSpecificUserAgent; eventStateCompositor = eventData->mpEventSpecificStateCompositor == mpDefaultCompositor ? NULL : eventData->mpEventSpecificStateCompositor; eventStateMgr = eventData->mpEventSpecificStateMgr == mpDefaultEventStateMgr ? NULL : eventData->mpEventSpecificStateMgr; // Unregister interest in PUBLISH requests for this event type eventData->mpEventSpecificUserAgent->removeMessageObserver(*(getMessageQueue())); delete eventData; eventData = NULL; } else { userAgent = NULL; eventStateCompositor = NULL; eventStateMgr = NULL; } unlockForWrite(); return(removedEvent); }
UtlBoolean SipPublishServer::enableEventType(const char* eventTypeToken, SipUserAgent* userAgent, SipPublishServerEventStateMgr* eventStateMgr, SipPublishServerEventStateCompositor* eventStateCompositor) { UtlBoolean addedEvent = FALSE; UtlString eventName(eventTypeToken ? eventTypeToken : ""); lockForWrite(); // Only add the event support if it does not already exist; PublishServerEventData* eventData = (PublishServerEventData*) mEventDefinitions.find(&eventName); if(!eventData) { addedEvent = TRUE; eventData = new PublishServerEventData(); *((UtlString*)eventData) = eventName; eventData->mpEventSpecificUserAgent = userAgent ? userAgent : mpDefaultUserAgent; eventData->mpEventSpecificStateCompositor = eventStateCompositor ? eventStateCompositor : mpDefaultCompositor; eventData->mpEventSpecificStateMgr = eventStateMgr ? eventStateMgr : mpDefaultEventStateMgr; mEventDefinitions.insert(eventData); // Register an interest in PUBLISH requests for this event type eventData->mpEventSpecificUserAgent->addMessageObserver(*(getMessageQueue()), SIP_PUBLISH_METHOD, TRUE, // requests FALSE, // not reponses TRUE, // incoming FALSE, // no outgoing eventName, NULL, NULL); } unlockForWrite(); return(addedEvent); }
/// Terminate all subscriptions and accept no new ones. void SipSubscribeServer::shutdown(const char* reason) { // If reason is NULL, use the default reason established by the constructor. if (!reason) { reason = mDefaultTermination; } OsSysLog::add(FAC_SIP, PRI_DEBUG, "SipSubscribeServer::shutdown reason '%s'", reason ? reason : "[null]"); lockForRead(); // Select the subscriptionChange value to describe what we're doing // with the subscriptions. enum SipSubscriptionMgr::subscriptionChange change; // Select the correct format for generating the Subscription-State value. UtlString* formatp = NULL; // We may need a temp UtlString. const char* format; if (reason == NULL) { format = "active;expires=%ld"; change = SipSubscriptionMgr::subscriptionContinues; } else if (strcmp(reason, terminationReasonSilent) == 0) { // Do not admit that the subscription is ending. format = "active;expires=%ld"; change = SipSubscriptionMgr::subscriptionTerminatedSilently; } else if (strcmp(reason, terminationReasonNone) == 0) { format = "terminated"; change = SipSubscriptionMgr::subscriptionTerminated; } else { // Allocate a UtlString and assemble the Subscription-State format in it. formatp = new UtlString(); formatp->append("terminated;reason="); formatp->append(reason); format = formatp->data(); change = SipSubscriptionMgr::subscriptionTerminated; } // For each event type that is registered, delete all the subscriptions. UtlHashBagIterator event_itor(mEventDefinitions); SubscribeServerEventData* eventData; while ((eventData = dynamic_cast <SubscribeServerEventData*> (event_itor()))) { // Unregister interest in SUBSCRIBE requests and NOTIFY // responses for this event type, so we do not service new subscriptions. eventData->mpEventSpecificUserAgent->removeMessageObserver(*(getMessageQueue())); int numSubscriptions = 0; SipMessage** notifyArray = NULL; UtlString** acceptHeaderValuesArray = NULL; UtlString** resourceIdArray = NULL; UtlString** eventTypeKeyArray = NULL; // :TODO: The four situations where NOTIFYs are generated should // be factored into a series of methods in // mpEventSpecificSubscriptionMgr that generate NOTIFYs // sequentially, and for each NOTIFY, call a common service // method that does the remaining operations and sends the // NOTIFY. // Construct a NOTIFY (without body) for every subscription, containing // the dialog-related information about each subscription. eventData->mpEventSpecificSubscriptionMgr-> createNotifiesDialogInfoEvent(static_cast <const UtlString&> (*eventData), format, numSubscriptions, acceptHeaderValuesArray, notifyArray, resourceIdArray, eventTypeKeyArray); OsSysLog::add(FAC_SIP, PRI_DEBUG, "SipSubscribeServer::shutdown eventType = '%s', numSubscriptions = %d", eventData->data(), numSubscriptions); // For each NOTIFY, add the subscription-related information and then // send it. for (int notifyIndex = 0; notifyIndex < numSubscriptions; notifyIndex++) { SipMessage* notify = notifyArray[notifyIndex]; // Check to see if the dialog information could be added. // (The subscription might have been destroyed between when // it was decided to respond to it, and when the dialog information // was retrieved.) UtlString callId; notify->getCallIdField(&callId); if (!callId.isNull()) { if (change != SipSubscriptionMgr::subscriptionTerminatedSilently) { // Fill in the NOTIFY request body/content eventData->mpEventSpecificHandler-> getNotifyContent(*(resourceIdArray[notifyIndex]), *(eventTypeKeyArray[notifyIndex]), *eventData, *(eventData->mpEventSpecificContentMgr), *(acceptHeaderValuesArray[notifyIndex]), *notify, eventData->mEventSpecificFullState, NULL); // Call the application callback to edit the NOTIFY // content if that is required for this event type. // Also gets 'version' (if relevant) and 'savedEventTypeKey'. int version; UtlString savedEventTypeKey; eventData->mpEventSpecificSubscriptionMgr-> updateNotifyVersion(eventData->mpEventSpecificContentVersionCallback, *notify, version, savedEventTypeKey); // Set the Contact header. setContact(notify); // Send the NOTIFY request. eventData->mpEventSpecificUserAgent->send(*notify); } // Remove the record of the subscription. UtlString dialogHandle; notify->getDialogHandle(dialogHandle); eventData->mpEventSpecificSubscriptionMgr-> endSubscription(dialogHandle, change); } } // Free the NOTIFY requests and accept header field values. SipSubscriptionMgr::freeNotifies(numSubscriptions, acceptHeaderValuesArray, notifyArray); // Free the resource and event type arrays. for (int index = 0; index < numSubscriptions; index++) { delete resourceIdArray[index]; delete eventTypeKeyArray[index]; } delete[] resourceIdArray; delete[] eventTypeKeyArray; // Remove eventData from mEventDefinitions. mEventDefinitions.removeReference(eventData); delete eventData; } unlockForRead(); // Free the temporary UtlString, if necessary. if (formatp) { delete formatp; } lockForWrite(); mEventDefinitions.destroyAll(); unlockForWrite(); }
bool RenderThinker::start() { int halfWidth = resultSize.width() / 2; int halfHeight = resultSize.height() / 2; QImage image(resultSize, QImage::Format_RGB32); const int NumPasses = 8; int pass = 0; while (pass < NumPasses) { const int MaxIterations = (1 << (2 * pass + 6)) + 32; const int Limit = 4; bool allBlack = true; for (int y = -halfHeight; y < halfHeight; ++y) { if (wasPauseRequested()) return; uint *scanLine = reinterpret_cast<uint *>(image.scanLine(y + halfHeight)); double ay = centerY + (y * scaleFactor); for (int x = -halfWidth; x < halfWidth; ++x) { double ax = centerX + (x * scaleFactor); double a1 = ax; double b1 = ay; int numIterations = 0; do { ++numIterations; double a2 = (a1 * a1) - (b1 * b1) + ax; double b2 = (2 * a1 * b1) + ay; if ((a2 * a2) + (b2 * b2) > Limit) break; ++numIterations; a1 = (a2 * a2) - (b2 * b2) + ax; b1 = (2 * a2 * b2) + ay; if ((a1 * a1) + (b1 * b1) > Limit) break; } while (numIterations < MaxIterations); if (numIterations < MaxIterations) { *scanLine++ = colormap[numIterations % ColormapSize]; allBlack = false; } else { *scanLine++ = qRgb(0, 0, 0); } } } if (allBlack && pass == 0) { pass = 4; } else { lockForWrite(); writable().image = image; writable().scaleFactor = scaleFactor; unlock(); ++pass; } } return true; }