ScriptDebugListener::SkipPauseRequest InspectorDebuggerAgent::shouldSkipExceptionPause(RefPtr<JavaScriptCallFrame>& topFrame)
{
    if (m_skipAllPauses)
        return ScriptDebugListener::Continue;

    String topFrameScriptUrl = scriptURL(topFrame.get());
    if (m_cachedSkipStackRegExp && !topFrameScriptUrl.isEmpty() && m_cachedSkipStackRegExp->match(topFrameScriptUrl) != -1)
        return ScriptDebugListener::Continue;

    // Prepare top frame parameters;
    int topFrameLineNumber = topFrame->line();
    int topFrameColumnNumber = topFrame->column();

    // Match against breakpoints.
    if (topFrameScriptUrl.isEmpty())
        return ScriptDebugListener::NoSkip;

    RefPtr<JSONObject> breakpointsCookie = m_state->getObject(DebuggerAgentState::javaScriptBreakpoints);
    for (JSONObject::iterator it = breakpointsCookie->begin(); it != breakpointsCookie->end(); ++it) {
        RefPtr<JSONObject> breakpointObject = it->value->asObject();
        bool isAntibreakpoint;
        breakpointObject->getBoolean(DebuggerAgentState::isAnti, &isAntibreakpoint);
        if (!isAntibreakpoint)
            continue;

        int breakLineNumber;
        breakpointObject->getNumber(DebuggerAgentState::lineNumber, &breakLineNumber);
        int breakColumnNumber;
        breakpointObject->getNumber(DebuggerAgentState::columnNumber, &breakColumnNumber);

        if (breakLineNumber != topFrameLineNumber)
            continue;

        if (breakColumnNumber != -1 && breakColumnNumber != topFrameColumnNumber)
            continue;

        bool isRegex;
        breakpointObject->getBoolean(DebuggerAgentState::isRegex, &isRegex);
        String url;
        breakpointObject->getString(DebuggerAgentState::url, &url);
        if (!matches(topFrameScriptUrl, url, isRegex))
            continue;

        return ScriptDebugListener::Continue;
    }

    return ScriptDebugListener::NoSkip;
}
ScriptDebugListener::SkipPauseRequest InspectorDebuggerAgent::shouldSkipStepPause(RefPtr<JavaScriptCallFrame>& topFrame)
{
    if (m_skipAllPauses)
        return ScriptDebugListener::Continue;

    if (m_cachedSkipStackRegExp) {
        String scriptUrl = scriptURL(topFrame.get());
        if (!scriptUrl.isEmpty() && m_cachedSkipStackRegExp->match(scriptUrl) != -1) {
            if (m_skipStepInCount > 0) {
                --m_skipStepInCount;
                return ScriptDebugListener::StepInto;
            }
            return ScriptDebugListener::StepOut;
        }
    }
    return ScriptDebugListener::NoSkip;
}
void EntityEditFilters::addFilter(EntityItemID entityID, QString filterURL) {

    QUrl scriptURL(filterURL);
    
    // setting it to an empty string is same as removing 
    if (filterURL.size() == 0) {
        removeFilter(entityID);
        return;
    }
   
    // The following should be abstracted out for use in Agent.cpp (and maybe later AvatarMixer.cpp)
    if (scriptURL.scheme().isEmpty() || (scriptURL.scheme() == HIFI_URL_SCHEME_FILE)) {
        qWarning() << "Cannot load script from local filesystem, because assignment may be on a different computer.";
        scriptRequestFinished(entityID);
        return;
    }
   
    // first remove any existing info for this entity
    removeFilter(entityID);
    
    // reject all edits until we load the script
    FilterData filterData;
    filterData.rejectAll = true;

    _lock.lockForWrite();
    _filterDataMap.insert(entityID, filterData);
    _lock.unlock();
   
    auto scriptRequest = DependencyManager::get<ResourceManager>()->createResourceRequest(
        this, scriptURL, true, -1, "EntityEditFilters::addFilter");
    if (!scriptRequest) {
        qWarning() << "Could not create ResourceRequest for Entity Edit filter.";
        scriptRequestFinished(entityID);
        return;
    }
    // Agent.cpp sets up a timeout here, but that is unnecessary, as ResourceRequest has its own.
    connect(scriptRequest, &ResourceRequest::finished, this, [this, entityID]{ EntityEditFilters::scriptRequestFinished(entityID);} );
    // FIXME: handle atp rquests setup here. See Agent::requestScript()
    scriptRequest->send();
    qDebug() << "script request sent for entity " << entityID;
}
Beispiel #4
0
void Agent::run() {
    NodeList::getInstance()->setOwnerType(NODE_TYPE_AGENT);
    NodeList::getInstance()->setNodeTypesOfInterest(&NODE_TYPE_VOXEL_SERVER, 1);
    
    QNetworkAccessManager manager;
    
    // figure out the URL for the script for this agent assignment
    QString scriptURLString("http://%1:8080/assignment/%2");
    scriptURLString = scriptURLString.arg(NodeList::getInstance()->getDomainIP().toString(),
                                         this->getUUIDStringWithoutCurlyBraces());
    QUrl scriptURL(scriptURLString);
    
    qDebug() << "Attemping download of " << scriptURL << "\n";
    
    QNetworkReply* reply = manager.get(QNetworkRequest(scriptURL));
    
    QEventLoop loop;
    QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
    loop.exec();
    
    QString scriptString = QString(reply->readAll());
    
    QScriptEngine engine;
    
    QScriptValue agentValue = engine.newQObject(this);
    engine.globalObject().setProperty("Agent", agentValue);
    
    VoxelScriptingInterface voxelScripter;
    QScriptValue voxelScripterValue =  engine.newQObject(&voxelScripter);
    engine.globalObject().setProperty("Voxels", voxelScripterValue);
    
    qDebug() << "Downloaded script:" << scriptString << "\n";
    qDebug() << "Evaluated script:" << engine.evaluate(scriptString).toString() << "\n";
    
    timeval thisSend;
    timeval lastDomainServerCheckIn = {};
    int numMicrosecondsSleep = 0;
    
    const long long DATA_SEND_INTERVAL_USECS = (1 / 60.0f) * 1000 * 1000;
    
    sockaddr_in senderAddress;
    unsigned char receivedData[MAX_PACKET_SIZE];
    ssize_t receivedBytes;
    
    while (!_shouldStop) {
        // update the thisSend timeval to the current time
        gettimeofday(&thisSend, NULL);
        
        // if we're not hearing from the domain-server we should stop running
        if (NodeList::getInstance()->getNumNoReplyDomainCheckIns() == MAX_SILENT_DOMAIN_SERVER_CHECK_INS) {
            break;
        }
        
        // send a check in packet to the domain server if DOMAIN_SERVER_CHECK_IN_USECS has elapsed
        if (usecTimestampNow() - usecTimestamp(&lastDomainServerCheckIn) >= DOMAIN_SERVER_CHECK_IN_USECS) {
            gettimeofday(&lastDomainServerCheckIn, NULL);
            NodeList::getInstance()->sendDomainServerCheckIn();
        }
        
        // allow the scripter's call back to setup visual data
        emit preSendCallback();
        // flush the voxel packet queue
        voxelScripter.getVoxelPacketSender()->process();
        
        if (NodeList::getInstance()->getNodeSocket()->receive((sockaddr*) &senderAddress, receivedData, &receivedBytes)) {
            NodeList::getInstance()->processNodeData((sockaddr*) &senderAddress, receivedData, receivedBytes);
        }
        
        // sleep for the correct amount of time to have data send be consistently timed
        if ((numMicrosecondsSleep = DATA_SEND_INTERVAL_USECS - (usecTimestampNow() - usecTimestamp(&thisSend))) > 0) {
            usleep(numMicrosecondsSleep);
        }
    }
    
}