/* * Checks incoming conflicts of br, returns 1 if there exists * incoming conflict that clashes with direction dir. */ char hasIncomingConflict( branch *br, char dir, block **bblist, int start, int num_bb ) { int i, j, id, brid, pid; branch *bc; assign *assg; if( !br->num_active_incfs ) return 0; pid = br->bb->pid; for( i = start; i < num_bb; i++ ) { id = bblist[i]->bbid; if( br->in_conflict[id] ) { // if conflict is from branch bc = branchlist[pid][id]; if( bc != NULL ) { brid = findBranch( br, bc->conflicts, bc->num_conflicts ); if( brid != -1 && ( bc->conflictdir_jump[brid] == dir || bc->conflictdir_fall[brid] == dir )) return 1; } // if conflict is from assign for( j = 0; j < num_assign[pid][id]; j++ ) { assg = assignlist[pid][id][j]; brid = findBranch( br, assg->conflicts, assg->num_conflicts ); if( brid != -1 && assg->conflictdir[brid] == dir ) return 1; } } } return 0; }
void Urls::Impl::handleUrlChanged(const std::string& path) { UrlTreeBranch* branch = findBranch(path); // If we didn't find any branches to handle the request, this is a bad url if (branch == nullptr) throw NotFound(path); branch->onSelected(path); }
char BAconflictInPath( block *bu, block *bv, path *pv, block **bblist, int num_bb ) { int cf, ln, id; char res; assign *assg; branch *br; for( ln = 0; ln < num_assign[bu->pid][bu->bbid]; ln++ ) { assg = assignlist[bu->pid][bu->bbid][ln]; for( cf = 0; cf < assg->num_conflicts; cf++ ) { br = assg->conflicts[cf]; id = findBranch( br, pv->branch_eff, pv->branch_len ); if( id == -1 ) continue; res = pv->branch_dir[id]; if( assg->conflictdir[cf] == res ) { // check cancellation of effect by assignment id = effectCancelled( br, assg, pv, bblist, num_bb ); if( id == -1 ) { return 1; } } } } return 0; }
char BBconflictInPath( branch *bru, char direction, block *bv, path *pv, block **bblist, int num_bb ) { int cf, id; char res; branch *br; // check for each branch conflicting with bru, whether it occurs in this path for( cf = 0; cf < bru->num_conflicts; cf++ ) { br = bru->conflicts[cf]; id = findBranch( br, pv->branch_eff, pv->branch_len ); if( id == -1 ) continue; res = pv->branch_dir[id]; if( ( direction == bru->jump_cond && bru->conflictdir_jump[cf] == res ) || ( direction == neg( bru->jump_cond ) && bru->conflictdir_fall[cf] == res ) ) { // check cancellation of effect by assignment id = effectCancelled( br, NULL, pv, bblist, num_bb ); if( id == -1 ) { return 1; } } } return 0; }
IfCodeNodePtr findBranch(StatementPtr stmt, StatementPtr& ref) { assert(stmt); if (CodeNodePtr e = stmt->getExpression()) { if (IfCodeNodePtr f = findBranch(e)) { ref = stmt; return f; } } StatementList children = stmt->getChildren(); for (size_t i = 0; i < children.size(); ++i) { if (IfCodeNodePtr f = findBranch(children[i], ref)) { return f; } } return IfCodeNodePtr(); }
void GLSLShader::splitBranches() { // Conversion to StatementPtr overload is ambiguous otherwise. StatementPtr main_stmt(main); StatementPtr ref; while (IfCodeNodePtr p = findBranch(main_stmt, ref)) { CodeNodePtr condition = p->getChildren()[0]; CodeNodePtr truePart = p->getChildren()[1]; CodeNodePtr falsePart = p->getChildren()[2]; string name = newRegisterName(); CodeNodePtr nameReference( new NameCodeNode( name, p->getType(), p->getFrequency(), NullValue, ValueNode::BUILTIN)); // suitable substitute for local replace(main_stmt, p, nameReference); DeclarationPtr decl(new Declaration(p->getType(), name)); AssignmentPtr assignTrue(new Assignment); assignTrue->define = false; assignTrue->lhs = name; assignTrue->rhs = truePart; AssignmentPtr assignFalse(new Assignment); assignFalse->define = false; assignFalse->lhs = name; assignFalse->rhs = falsePart; IfStatementPtr ifst(new IfStatement); ifst->condition = condition; ifst->setTrue(assignTrue); ifst->setFalse(assignFalse); BlockPtr newBlock(new Block); newBlock->statements.push_back(decl); newBlock->statements.push_back(ifst); newBlock->statements.push_back(ref); if (main_stmt == ref) { REN_DYNAMIC_CAST_PTR(main, Block, ref); assert(main); main_stmt = main; } else { replace(main_stmt, ref, newBlock); } } }
IfCodeNodePtr findBranch(CodeNodePtr node) { assert(node); if (REN_DYNAMIC_CAST_PTR(p, IfCodeNode, node)) { return p; } CodeNodeList args = node->getChildren(); for (size_t i = 0; i < args.size(); ++i) { IfCodeNodePtr c = findBranch(args[i]); if (c) { return c; } } return IfCodeNodePtr(); }
void SIPTransaction::sendResponse( const SIPMessage::Ptr& pResponse, const OSS::IPAddress& sendAddress) { if (!pResponse->isResponse()) throw OSS::SIP::SIPException("Sending a REQUEST using sendResponse() is illegal!"); SIPTransaction::Ptr pParent = getParent(); if (!_transport && isParent()) throw OSS::SIP::SIPException("Transport Not Ready!"); else if (!isParent() && pParent) _transport = pParent->_transport; if (_sendAddress.getPort() == 0) _sendAddress = sendAddress; SIPTransaction::Ptr pBranch = findBranch(pResponse); if (pBranch) { pBranch->sendResponse(pResponse, sendAddress); return; } else { // // No branch is found. This instance will handle the response // if (_transport && _transport->isReliableTransport()) { if (_transport->writeKeepAlive()) { writeMessage(pResponse); } else { // // Keep-alive failed so create a new transport // if (_localAddress.isValid() && _sendAddress.isValid()) { // // According to RFC 3261, if there is any transport failure, we must try to // re-estabish a connectoin to the via sentby parameter instead // std::string transport; if (SIPVia::msgGetTopViaTransport(pResponse.get(), transport)) { _transport = _transportService->createClientTransport(_localAddress, _sendAddress, transport); writeMessage(pResponse); } } else { OSS_LOG_ERROR("SIPTransaction::sendResponse - Unable to re-establish transport to send response."); } } } else if (_transport) { // // This is UDP so a keep-alive check won't do us any good // writeMessage(pResponse, _sendAddress); } else { OSS_LOG_ERROR("SIPTransaction::sendResponse - Transport is NULL."); } } }
void SIPTransaction::onReceivedMessage(SIPMessage::Ptr pMsg, SIPTransportSession::Ptr pTransport) { OSS::mutex_lock lock(_mutex); bool isAck = pMsg->isRequest("ACK"); if (pMsg->isRequest() && !_pInitialRequest && !isAck) _pInitialRequest = pMsg; if (_logId.empty()) _logId = pMsg->createContextId(true); if (!_transport) _transport = pTransport; if (!_localAddress.isValid()) _localAddress = pTransport->getLocalAddress(); if (!_remoteAddress.isValid()) _remoteAddress = pTransport->getRemoteAddress(); if (SIPXOR::isEnabled() && !_isXOREncrypted) { std::string isXOR; _isXOREncrypted = pMsg->getProperty("xor", isXOR) && isXOR == "1"; } if (isParent()) { std::ostringstream logMsg; logMsg << _logId << "<<< " << pMsg->startLine() << " LEN: " << pTransport->getLastReadCount() << " SRC: " << _remoteAddress.toIpPortString() << " DST: " << _localAddress.toIpPortString() << " EXT: " << "[" << pTransport->getExternalAddress() << "]" << " FURI: " << pMsg->hdrGet("from") << " ENC: " << _isXOREncrypted << " PROT: " << pTransport->getTransportScheme(); OSS::log_information(logMsg.str()); if (OSS::log_get_level() >= OSS::PRIO_DEBUG) OSS::log_debug(pMsg->createLoggerData()); } // // If this is a request and is not an ACK, then the parent IST fsm must always handle it // if (isParent() && pMsg->isRequest() && !isAck) { _fsm->onReceivedMessage(pMsg, pTransport); } else if (!pMsg->isRequest() || isAck) { // // This is a response or an ACK and the transaction could have branched out // if (!isParent()) { _fsm->onReceivedMessage(pMsg, pTransport); } else { SIPTransaction::Ptr pBranch = findBranch(pMsg); if (pBranch) pBranch->onReceivedMessage(pMsg, pTransport); else _fsm->onReceivedMessage(pMsg, pTransport); } } }