Exemplo n.º 1
0
Node *buildExpressionTree(char *expression) {

	NodeStack *operands = createNodeStack();
	NodeStack *result = createNodeStack();
	
	char *start = expression;
	char *end; // = expression;	
	char *beginning = expression;

	Stack *target;
	Node *node;
	Node *operand1;
	Node *operand2;
	
	while((start - beginning) < strlen(expression)) {
		if(start[0] - 0 == 39) {
			end = strstr(start + 1, "'") + 1;
		} else {
			end = strstr(start, " ");	
			if(!end) {
				end = start;
				while(end[0] != '\0')
					++end;
			}
		}
		
		char *token = malloc((end - start) + 1);
		strlcpy(token, start, (end - start) + 1);
		start = end + 1;	

		node = createNode(token);

		if(isBinaryOperator(token)) {
			target = result;
		} else if(isLogicalOperator(token)) { 
			target = operands;
		} else { 
			pushNode(operands, node);		
			continue;
		}		
	
		operand1 = popNode(target);
		operand2 = popNode(target);		
		node->right = operand1;
		node->left = operand2;

		// add this to stack
		pushNode(result, node);
	}

	// return the first node in the list (not the top)
    	return rootNode(result);
}
Exemplo n.º 2
0
static short BWLimiterProcess(PacketNode *head, PacketNode *tail)
{
	int dropped = 0;

	DWORD currentTime = timeGetTime();
	PacketNode *pac = tail->prev;
	// pick up all packets and fill in the current time
	while (pac != head) 
	{
		if (checkDirection(pac->addr.Direction, BWLimiterInbound, BWLimiterOutbound)) 
		{
			if ( bufSizeByte >= ((DWORD)BWQueueSizeValue*1024))
			{
				LOG("droped with chance, direction %s",
					BOUND_TEXT(pac->addr.Direction));
				freeNode(popNode(pac));
				++dropped;
			}
			else
			{
				insertAfter(popNode(pac), bufHead)->timestamp = timeGetTime();
				++bufSize;
				bufSizeByte += pac->packetLen;
				pac = tail->prev;
			}
		} 
		else 
		{
			pac = pac->prev;
		}
	}


	while (!isBufEmpty() && canSendPacket(currentTime))
	{
		PacketNode *pac = bufTail->prev;
		bufSizeByte -= pac->packetLen;
		recordSentPacket(currentTime, pac->packetLen);
		insertAfter(popNode(bufTail->prev), head); 
		--bufSize;
	}

	if (bufSize > 0)
	{
		LOG("Queued buffers : %d",
			bufSize);
	}


	return (bufSize>0) || (dropped>0);
}
Exemplo n.º 3
0
void dumpBT(std::ostream& out, NodePtr<BacktraceFrame> frame) {
    if (frame == nullptr)
        return;
    auto value = frame->get();
    out << " " << std::get<1>(value) << "(" << std::get<0>(value) << ")";
    dumpBT(out, popNode(frame));
}
Exemplo n.º 4
0
char *OpenDDLParser::parseStructure( char *in, char *end ) {
    if( ddl_nullptr == in || in == end ) {
        return in;
    }

    bool error( false );
    in = lookForNextToken( in, end );
    if( *in == *Grammar::OpenBracketToken) {
        // loop over all children ( data and nodes )
        do {
            in = parseStructureBody( in, end, error );
            if(in == ddl_nullptr){
                return ddl_nullptr;
            }
        } while ( *in != *Grammar::CloseBracketToken);
        ++in;
    } else {
        ++in;
        logInvalidTokenError( in, std::string( Grammar::OpenBracketToken ), m_logCallback );
        return ddl_nullptr;
    }
    in = lookForNextToken( in, end );

    // pop node from stack after successful parsing
    if( !error ) {
        popNode();
    }

    return in;
}
Exemplo n.º 5
0
void CreateScene::visit(ColladaNode* colladaNode) {
	Node* newNode = product->createNode();

	concatNode(newNode);

	pushNode(newNode);

	for(ColladaTransformation* transformation : colladaNode->getTransformations())
		transformation->accept(this);

	for(ColladaNode* child : colladaNode->getNodes())
		child->accept(this);

	for(ColladaInstanceNode* instanceNode : colladaNode->getInstanceNodes()) {
		ColladaNode* node = document->findNode(instanceNode->getUrl());

		if(node)
			node->accept(this);
	}

	for(ColladaInstanceGeometry* instanceGeometry : colladaNode->getInstanceGeometries())
		instanceGeometry->accept(this);

	popNode();
}
Exemplo n.º 6
0
bool ContentLayer::popLastNode() {
	if (_nodes.size() > 1) {
		popNode(_nodes.back());
		return true;
	}
	return false;
}
Exemplo n.º 7
0
static void clearBufPackets(PacketNode *tail) {
    PacketNode *oldLast = tail->prev;
    LOG("Cap end, send all %d packets. Buffer at max: %s", bufSize, bufSize);
    while (!isBufEmpty()) {
        insertAfter(popNode(bufTail->prev), oldLast);
        --bufSize;
    }
}
Exemplo n.º 8
0
static void clearBufPackets(PacketNode *tail) {
    PacketNode *oldLast = tail->prev;
    LOG("Throttled end, send all %d packets. Buffer at max: %s", bufSize, bufSize == KEEP_AT_MOST ? "YES" : "NO");
    while (!isBufEmpty()) {
		 bufSizeByte -= bufTail->prev->packetLen;
        insertAfter(popNode(bufTail->prev), oldLast);
        --bufSize;
    }
    BWLimiterStartTick = 0;
}
Exemplo n.º 9
0
bool Node::removeNode(Index index) const
{
  if (moveNodeToLast(index) == false)
    return false;

  if (popNode() == false) {
    moveNodeToLast(index);
    return false;
  }

  return true;
}
Exemplo n.º 10
0
void printLevelTree(node* root, queueNode *head) {
	addToQueue(&head,root);
	while(head != NULL) {
		queueNode* levelNode = popNode(&head);
		printf("%d ", levelNode->treeNode->data);

		if(levelNode->treeNode->left != NULL) {
			addToQueue(&head,levelNode->treeNode->left);
		}
		
		if(levelNode->treeNode->right != NULL) {
			addToQueue(&head,levelNode->treeNode->right);
		}

		free(levelNode);
	}
}
Exemplo n.º 11
0
static short dropProcess(PacketNode *head, PacketNode* tail) {
    int dropped = 0;
    while (head->next != tail) {
        PacketNode *pac = head->next;
        // chance in range of [0, 1000]
        if (checkDirection(pac->addr.Direction, dropInbound, dropOutbound)
            && calcChance(chance)) {
            LOG("dropped with chance %.1f%%, direction %s",
                chance/10.0, BOUND_TEXT(pac->addr.Direction));
            freeNode(popNode(pac));
            ++dropped;
        } else {
            head = head->next;
        }
    }

    return dropped > 0;
}
Exemplo n.º 12
0
void CreateScene::visit(ColladaScene* scene) {
	ColladaInstanceVisualScene* instanceVisualScene = scene->getInstanceVisualScene();

	ColladaVisualScene* visualScene = document->findVisualScene(instanceVisualScene->getUrl());

	if(!visualScene)
		return;

	product = new Scene(visualScene->getId(), manager);

	pushNode(product->getRoot());

	for(ColladaNode* node : visualScene->getNodes()) {
		if(!node->getInstanceControllers().empty()) //TODO animation
			continue;

		node->accept(this);
	}

	popNode();
}
Exemplo n.º 13
0
static int sendAllListPackets() {
    // send packet from tail to head and remove sent ones
    int sendCount = 0;
    UINT sendLen;
    PacketNode *pnode;
#ifdef _DEBUG
    // check the list is good
    // might go into dead loop but it's better for debugging
    PacketNode *p = head;
    do {
        p = p->next;
    } while (p->next);
    assert(p == tail);
#endif

    while (!isListEmpty()) {
        pnode = popNode(tail->prev);
        sendLen = 0;
        assert(pnode != head);
        // FIXME inbound injection on any kind of packet is failing with a very high percentage
        //       need to contact windivert auther and wait for next release
        if (!WinDivertSend(divertHandle, pnode->packet, pnode->packetLen, &(pnode->addr), &sendLen)) {
            PWINDIVERT_ICMPHDR icmp_header;
            PWINDIVERT_ICMPV6HDR icmpv6_header;
            PWINDIVERT_IPHDR ip_header;
            PWINDIVERT_IPV6HDR ipv6_header;
            LOG("Failed to send a packet. (%lu)", GetLastError());
            dumpPacket(pnode->packet, pnode->packetLen, &(pnode->addr));
            // as noted in windivert help, reinject inbound icmp packets some times would fail
            // workaround this by resend them as outbound
            // TODO not sure is this even working as can't find a way to test
            //      need to document about this
            WinDivertHelperParsePacket(pnode->packet, pnode->packetLen, &ip_header, &ipv6_header,
                &icmp_header, &icmpv6_header, NULL, NULL, NULL, NULL);
            if ((icmp_header || icmpv6_header) && IS_INBOUND(pnode->addr.Direction)) {
                BOOL resent;
                pnode->addr.Direction = WINDIVERT_DIRECTION_OUTBOUND;
                if (ip_header) {
                    UINT32 tmp = ip_header->SrcAddr;
                    ip_header->SrcAddr = ip_header->DstAddr;
                    ip_header->DstAddr = tmp;
                } else if (ipv6_header) {
                    UINT32 tmpArr[4];
                    memcpy(tmpArr, ipv6_header->SrcAddr, sizeof(tmpArr));
                    memcpy(ipv6_header->SrcAddr, ipv6_header->DstAddr, sizeof(tmpArr));
                    memcpy(ipv6_header->DstAddr, tmpArr, sizeof(tmpArr));
                }
                resent = WinDivertSend(divertHandle, pnode->packet, pnode->packetLen, &(pnode->addr), &sendLen);
                LOG("Resend failed inbound ICMP packets as outbound: %s", resent ? "SUCCESS" : "FAIL");
                InterlockedExchange16(&sendState, SEND_STATUS_SEND);
            } else {
                InterlockedExchange16(&sendState, SEND_STATUS_FAIL);
            }
        } else {
            if (sendLen < pnode->packetLen) {
                // TODO don't know how this can happen, or it needs to be resent like good old UDP packet
                LOG("Internal Error: DivertSend truncated send packet.");
                InterlockedExchange16(&sendState, SEND_STATUS_FAIL);
            } else {
                InterlockedExchange16(&sendState, SEND_STATUS_SEND);
            }
        }


        freeNode(pnode);
        ++sendCount;
    }
    assert(isListEmpty()); // all packets should be sent by now

    return sendCount;
}
Exemplo n.º 14
0
int CScatteredManage::processJobs()
{
	SCNode nd;
	SCJob sj;
	tcps_Array<PCC_ModuleFile> moudleFiles;
	PCC_ModuleIndex index;
	//bool b_rest = true,b_r2 = false;
	int pre_node_num =-1;
	while (1)
	{
		if(pre_node_num != getNodeCounts())
		{
			printf("##当前可调度节点数:%d,待处理作业数:%d\n",pre_node_num = getNodeCounts(),getJobsCounts());
			
		}
		
		//检测job队列
		if(popJob(sj))
		{
			
			printf("当前可调度节点数:%d,待处理作业数:%d\n",getNodeCounts(),getJobsCounts()+1);

			//先判断jobkey对应的会话是否有效 //这一步看需求,是否支持不要回调通知的作业提交,这里标志以回调有效的方式处理
            if(!isValidJobRequest(sj.jobKey))
				continue;//忽略

			while(1)//轮询等待有空余节点可做scattered计算
			{
				
				if(popNode(nd))// 注意节点要在作业处理完后收回
				{
				    
					//nd.ps->m_ss = sj.ss;//回调senssion句柄 要是m_ss的servece_s的客户端断开了连接,这个指针会失效//jobkey
					
                    
					nd.ps->m_jobkey = sj.jobKey;
					printf("节点%p处理作业:%lld\n",nd.ps,sj.jobKey);
					index.moduleKey = sj.moduleKey;
					//确保节点端存在 moduleKey指定的模块
					moudleFiles.Release();
				    BOOL isFound = false;
					if(TCPS_OK ==nd.ps->FindModule(sj.moduleKey,isFound) )// 节点端没有,同步此模块
					{
						if(!isFound)
						{
							//读取模块 填充 index,moudleFiles
							if(getModules(index,moudleFiles))
							{
								//再次调用接口
								if(nd.ps->AddModule(sj.moduleKey,moudleFiles) != TCPS_OK)
								{
									nd.ps->m_ss = NULL;//for mark
									pushNode(nd.key,nd.ps);
									NPLogError(("模块更新失败,作业无法调度\n"));
									break;
								}
							}
							else
							{
								nd.ps->m_ss = NULL;//for mark
								pushNode(nd.key,nd.ps);
								NPLogError(("模块读取失败,作业无法调度\n"));
								break;
							}
						}
					}
					else
					{
						pushNode(nd.key,nd.ps);
						NPLogError(("无法获取模块状态!\n"));
						break;
					}
					//节点暂时分离出去了
					//这里应当添加节点处理超时
					nd.ps->Compute(sj.moduleKey,
					sj.jobKey,
					sj.info.dataInputUrl,
					sj.info.dataOutputUrl,
					sj.info.programParam);
					//nd.ps->AddMoudle(index,moudleFiles);
					//nd.ps->RemoveModule(0);
				
					break;
				}
				Sleep(1);
			}
		}
		
		Sleep(1);
	}
	return 0;
}
Exemplo n.º 15
0
static short capProcess(PacketNode *head, PacketNode *tail) {
    short capped = FALSE;
    PacketNode *pac, *pacTmp, *oldLast;
    DWORD curTick = timeGetTime();
    DWORD deltaTick = curTick - capLastTick;
    int bytesCapped = (int)(deltaTick * 0.001 * kps * FIXED_EPSILON * 1024);
    int totalBytes = 0;
    LOG("kps val: %d, capped kps %.2f, capped at %d bytes", kps, kps * FIXED_EPSILON, bytesCapped);
    capLastTick = curTick;


    // process buffered packets
    oldLast = tail->prev;
    while (!isBufEmpty()) {
        // TODO should check direction in buffer?
        // sends at least one from buffer or it would get stuck
        pac = bufTail->prev;
        totalBytes += pac->packetLen;
        insertAfter(popNode(pac), oldLast);
        --bufSize;

        LOG("sending out packets of %d bytes", totalBytes);

        if (totalBytes > bytesCapped) {
            break;
        }   
    }

    // process live packets
    pac = oldLast;
    while (pac != head) {
        if (!checkDirection(pac->addr.Direction, capInbound, capOutbound)) {
            pac = pac->prev;
            continue;
        }

        // live packets can all be kept
        totalBytes += pac->packetLen;

        if (totalBytes > bytesCapped) {
            int capCnt = 0;
            capped = TRUE;
            // buffer from pac to head 
            while (bufSize < KEEP_AT_MOST && pac != head) {
                pacTmp = pac->prev;
                insertAfter(popNode(pac), bufHead);
                ++bufSize;
                ++capCnt;
                pac = pacTmp;
            }

            if (pac != head) {
                LOG("! hitting cap max, dropping all remaining");
                while (pac != head) {
                    pacTmp = pac->prev;
                    freeNode(pac);
                    pac = pacTmp;
                }
            }
            assert(pac == head);
            LOG("capping %d packets", capCnt);
            break;
        } else {
            pac = pac->prev;
        }
    }

    return capped;
}