예제 #1
0
std::string XmlConfigFile::_GetAttributeName( const std::string& key )
{
	StringArray elements = _Split(key, ELEMENT_SPLIT_CHAR);
	StringArray attributes =  _Split((*(--elements.end())).c_str(), ATTRIBUTE_SPLIT_CHAR);
	if (attributes.size() == 2)
		return attributes[1];
	else
		return "";
}
예제 #2
0
파일: cli_lib.c 프로젝트: Undrizzle/apps
ULONG  _StrToIPAddr(char  *string, ULONG  *ulRet)
{
    char  stemp[300];
    ULONG  a,b,c,d;

    if (_Split(&string,stemp,'.',300)!=1)
        return TBS_FAILED;

    if (!*stemp)
        return TBS_FAILED;

    if (_atou(stemp,&a))
        return TBS_FAILED;

    if (a>255)
        return TBS_FAILED;

    if (_Split(&string,stemp,'.',300)!=1)
        return TBS_FAILED;

    if (!*stemp)
        return TBS_FAILED;

    if (_atou(stemp,&b))
        return TBS_FAILED;

    if (b>255)
        return TBS_FAILED;

    if (_Split(&string,stemp,'.',300)!=1)
        return TBS_FAILED;

    if (!*stemp)
        return TBS_FAILED;

    if (_atou(stemp,&c))
        return TBS_FAILED;

    if (c>255)
        return TBS_FAILED;

    if (_Split(&string,stemp,'\0',300)!=1)
        return TBS_FAILED;

    if (!*stemp)
        return TBS_FAILED;

    if (_atou(stemp,&d))
        return TBS_FAILED;

    if (d>255)
        return TBS_FAILED;

    *ulRet =htonl((a<<24)+(b<<16)+(c<<8)+d);

    return TBS_SUCCESS;
}
예제 #3
0
tinyxml2::XMLNode* XmlConfigFile::_GetXmlNode( const std::string& key )
{
	tinyxml2::XMLNode* pCurElement = m_xmlDoc.GetDocument();
	if (pCurElement == NULL)
		return NULL;

	StringArray elements = _Split(key, ELEMENT_SPLIT_CHAR);
	tinyxml2::XMLNode* pTempElement = pCurElement;
	for (StringArray::const_iterator iter = elements.begin(); iter != elements.end(); ++iter)
	{
		pTempElement = pTempElement->FirstChildElement((*iter).c_str());
		if(pTempElement == NULL)
		{			
			StringArray sameElements =  _Split(*iter, ELEMENT_INDEX_SPLIT_CHAR);
			if (sameElements.size() == 2)
			{
				std::string strEleName = sameElements[0];
				pTempElement = pCurElement->FirstChildElement(strEleName.c_str());
				if (pTempElement != NULL)
				{
					int nEleNumber = atoi(sameElements[1].c_str());
					for (int nNum = 2; nNum <= nEleNumber; ++nNum)
					{	
						pTempElement = pTempElement->NextSiblingElement(strEleName.c_str());
					}
					pCurElement = pTempElement;
				}	
				else
				{
					return NULL;
				}
			}
			else
			{
				StringArray attribute =  _Split(*iter, ATTRIBUTE_SPLIT_CHAR);
				if (attribute.size() == 2)
				{
					std::string strEleName = attribute[0];					
					return pCurElement->FirstChildElement(strEleName.c_str());						
				}	
				return NULL;
			}
		}
		else
		{
			pCurElement = pTempElement;
		}
	}
	return pCurElement;
}
예제 #4
0
int XmlConfigFile::GetKeyCount( const std::string& key )
{
	int nCount = 0;
	if (key.empty())
	{
		LOGE<<"key is empty.";
		return nCount;
	}
	tinyxml2::XMLNode* pNode = _GetXmlNode(key);
	if (pNode == nullptr)
	{
		LOGE<<"pNode is null.";
		return nCount;
	}

	tinyxml2::XMLElement* pXmlElement = pNode->ToElement();	
	if (pXmlElement != NULL)
	{
		if (_IsAttribute(key))
		{
			nCount = 1;
		}
		else
		{
			nCount = 0;
			StringArray elements = _Split(key, ELEMENT_SPLIT_CHAR);
			const char* strLastElement = (*(--elements.end())).c_str();
			while(pXmlElement != NULL)
			{
				++nCount;
				pXmlElement = pXmlElement->NextSiblingElement(strLastElement);
			}
		}
	}
	return nCount;
}
void ZBspTree::_GetSortedFaceList( D3DXPLANE* pPlane, ZBspFace* pFaces, ZBspFace** fr , ZBspFace** bk )
{
	ZBspFace * pFront = NULL, * pBack = NULL, * pNext = NULL;
	ZBspFace * pCurrentFace = NULL;
	if( !pFaces )
	{
		*fr = NULL;
		*bk = NULL;
		return;
	}

	for( pCurrentFace = pFaces ; pCurrentFace ; pCurrentFace = pFaces )
	{
		pFaces = pFaces->GetNext();
		D3DXVECTOR3 planeNormal( pPlane->a, pPlane->b, pPlane->c );
		D3DXVECTOR3 currentNormal( pCurrentFace->GetPlane()->a, pCurrentFace->GetPlane()->b, pCurrentFace->GetPlane()->c );
		float val;
		int res = ZClassifyByPlane::WhereIsFace( pPlane, pCurrentFace->GetVerts(), pCurrentFace->GetVertCount() );
		switch( res )
		{
			case ZClassifyByPlane::FRONT:
				pCurrentFace->AddNext( pFront );
				pFront = pCurrentFace;
				break;

			case ZClassifyByPlane::BACK:
				pCurrentFace->AddNext( pBack );
				pBack = pCurrentFace;
				break;

			case ZClassifyByPlane::ON:
				pCurrentFace->SetUsed( TRUE );

				val = D3DXVec3Dot( &planeNormal, &currentNormal );
				if( val >= 0.0f )
				{
					pCurrentFace->AddNext( pFront );
					pFront = pCurrentFace;
				}
				else
				{
					pCurrentFace->AddNext( pBack );
					pBack = pCurrentFace;
				}
				break;

			case ZClassifyByPlane::SPLIT:
				ZBspFace * front = NULL, * back = NULL;
				_Split( pPlane, pCurrentFace, &front, &back );
				if( !front && !back )
					break;
				if( front->GetNext() )
				{
					front->GetNext()->AddNext( pFront );
					pFront = front;
				}
				else 
				{
					front->AddNext( pFront );
					pFront = front;
				}
				if( back->GetNext() )
				{
					back->GetNext()->AddNext( pBack );
					pBack = back;
				}
				else
				{
					back->AddNext( pBack );
					pBack = back;
				}

				// 분할된 face는 새롭게 front, back으로 분할되었으므로
				// 메모리에서 반드시 삭제해야한다.
				pCurrentFace->AddNext( NULL );
				delete pCurrentFace;
				break;
		}
	}
	*fr = pFront;
	*bk = pBack;
}
/*******************************************************************************
**
**  gckVIDMEM_AllocateLinear
**
**  Allocate linear memory from the gckVIDMEM object.
**
**  INPUT:
**
**      gckVIDMEM Memory
**          Pointer to an gckVIDMEM object.
**
**      gctSIZE_T Bytes
**          Number of bytes to allocate.
**
**      gctUINT32 Alignment
**          Byte alignment for allocation.
**
**      gceSURF_TYPE Type
**          Type of surface to allocate (use by bank optimization).
**
**  OUTPUT:
**
**      gcuVIDMEM_NODE_PTR * Node
**          Pointer to a variable that will hold the allocated memory node.
*/
gceSTATUS
gckVIDMEM_AllocateLinear(
    IN gckVIDMEM Memory,
    IN gctSIZE_T Bytes,
    IN gctUINT32 Alignment,
    IN gceSURF_TYPE Type,
#ifdef __QNXNTO__
    IN gctHANDLE Handle,
#endif
    OUT gcuVIDMEM_NODE_PTR * Node
    )
{
    gceSTATUS status;
    gcuVIDMEM_NODE_PTR node;
    gctUINT32 alignment;
    gctINT bank, i;
    gctBOOL acquired = gcvFALSE;

    gcmkHEADER_ARG("Memory=0x%x Bytes=%lu Alignment=%u Type=%d",
                   Memory, Bytes, Alignment, Type);

    /* Verify the arguments. */
    gcmkVERIFY_OBJECT(Memory, gcvOBJ_VIDMEM);
    gcmkVERIFY_ARGUMENT(Bytes > 0);
    gcmkVERIFY_ARGUMENT(Node != gcvNULL);
#ifdef __QNXNTO__
    gcmkVERIFY_ARGUMENT(Handle != gcvNULL);
#endif

    /* Acquire the mutex. */
    gcmkONERROR(
        gckOS_AcquireMutex(Memory->os, Memory->mutex, gcvINFINITE));

    acquired = gcvTRUE;

    if (Bytes > Memory->freeBytes)
    {
        /* Not enough memory. */
        gcmkONERROR(gcvSTATUS_OUT_OF_MEMORY);
    }

    /* Find the default bank for this surface type. */
    gcmkASSERT((gctINT) Type < gcmCOUNTOF(Memory->mapping));
    bank      = Memory->mapping[Type];
    alignment = Alignment;

    /* Find a free node in the default bank. */
    node = _FindNode(Memory, bank, Bytes, &alignment);

    /* Out of memory? */
    if (node == gcvNULL)
    {
        /* Walk all lower banks. */
        for (i = bank - 1; i >= 0; --i)
        {
            /* Find a free node inside the current bank. */
            node = _FindNode(Memory, i, Bytes, &alignment);
            if (node != gcvNULL)
            {
                break;
            }
        }
    }

    if (node == gcvNULL)
    {
        /* Walk all upper banks. */
        for (i = bank + 1; i < gcmCOUNTOF(Memory->sentinel); ++i)
        {
            if (Memory->sentinel[i].VidMem.nextFree == gcvNULL)
            {
                /* Abort when we reach unused banks. */
                break;
            }

            /* Find a free node inside the current bank. */
            node = _FindNode(Memory, i, Bytes, &alignment);
            if (node != gcvNULL)
            {
                break;
            }
        }
    }

    if (node == gcvNULL)
    {
        /* Out of memory. */
        gcmkONERROR(gcvSTATUS_OUT_OF_MEMORY);
    }

    /* Do we have an alignment? */
    if (alignment > 0)
    {
        /* Split the node so it is aligned. */
        if (_Split(Memory->os, node, alignment))
        {
            /* Successful split, move to aligned node. */
            node = node->VidMem.next;

            /* Remove alignment. */
            alignment = 0;
        }
    }

    /* Do we have enough memory after the allocation to split it? */
    if (node->VidMem.bytes - Bytes > Memory->threshold)
    {
        /* Adjust the node size. */
        _Split(Memory->os, node, Bytes);
    }

    /* Remove the node from the free list. */
    node->VidMem.prevFree->VidMem.nextFree = node->VidMem.nextFree;
    node->VidMem.nextFree->VidMem.prevFree = node->VidMem.prevFree;
    node->VidMem.nextFree                  =
    node->VidMem.prevFree                  = gcvNULL;

    /* Fill in the information. */
    node->VidMem.alignment = alignment;
    node->VidMem.memory    = Memory;
#ifdef __QNXNTO__
    node->VidMem.logical   = gcvNULL;
    node->VidMem.handle    = Handle;
#endif

    /* Adjust the number of free bytes. */
    Memory->freeBytes -= node->VidMem.bytes;

    /* Release the mutex. */
    gcmkVERIFY_OK(gckOS_ReleaseMutex(Memory->os, Memory->mutex));

    /* Return the pointer to the node. */
    *Node = node;

    gcmkTRACE_ZONE(gcvLEVEL_INFO, gcvZONE_VIDMEM,
                   "Allocated %u bytes @ 0x%x [0x%08X]",
                   node->VidMem.bytes, node, node->VidMem.offset);

    /* Success. */
    gcmkFOOTER_ARG("*Node=0x%x", *Node);
    return gcvSTATUS_OK;

OnError:
    if (acquired)
    {
     /* Release the mutex. */
        gcmkVERIFY_OK(gckOS_ReleaseMutex(Memory->os, Memory->mutex));
    }

    /* Return the status. */
    gcmkFOOTER();
    return status;
}
예제 #7
0
bool XmlConfigFile::_IsAttribute( const std::string& key )
{
	StringArray elements = _Split(key, ELEMENT_SPLIT_CHAR);
	StringArray attributes =  _Split((*(--elements.end())).c_str(), ATTRIBUTE_SPLIT_CHAR);
	return attributes.size() == 2 ? true:false;
}
int memory_engine_allocate(memory_engine_t *engine, size_t size,
								size_t alignment, memory_node_t **node)
{
	int res = 0;
	memory_node_t *new_node = NULL;
	struct task_struct *grptask = NULL;

	shm_debug("memory_engine_allocate start. (%d, %d)\n", size, alignment);

	if ((engine == NULL) || (node == NULL))
		return -EINVAL;

#ifdef SHM_GUARD_BYTES_ENABLE
	//add gurad bytes.
	if (engine->m_cache_or_noncache == SHM_CACHE){
		size += SHM_GUARD_BYTES;
	}
#endif

	down(&(engine->m_mutex));

	if (size > engine->m_size_free) {
		shm_error("heap has not enough (%u) bytes for (%u) bytes\n", engine->m_size_free, size);
		res = -ENOMEM;
		goto err_exit;
	}

	/* Find a free node in heap */
	new_node = _FindNode_size(engine, size, alignment);
	if (new_node == NULL) {
		memory_node_t *pLastNode = NULL;
		pLastNode = engine->m_root.m_prev_free;
		if (pLastNode)
			shm_error("heap has not enough liner memory for (%u) bytes, free blocks:%u(max free block:%u)\n",
					size, engine->m_num_freeblock, pLastNode->m_size);
		else
			shm_error("heap has not enough liner memory, no free blocks!!!\n");
		res = -ENOMEM;
		goto err_exit;
	}

	/* Do we have enough memory after the allocation to split it? */
	if (MEMNODE_ALIGN_SIZE(new_node) - size > engine->m_threshold)
		_Split(engine, new_node, size + new_node->m_offset);/* Adjust the node size. */
	else
		engine->m_num_freeblock--;

	engine->m_num_usedblock++;

	/* Remove the node from the free list. */
	new_node->m_prev_free->m_next_free = new_node->m_next_free;
	new_node->m_next_free->m_prev_free = new_node->m_prev_free;
	new_node->m_next_free =
	new_node->m_prev_free = NULL;

	/* Fill in the information. */
	new_node->m_alignment = alignment;
	/*record pid/thread name in node info, for debug usage*/
	new_node->m_threadid = task_pid_vnr(current);/*(current)->pid;*/

	/* qzhang@marvell
	 * record creating task id,user task id
	 * by default user task id is creating task id
	 * until memory_engine_lock invoked
	 */
	new_node->m_taskid   =
	new_node->m_usrtaskid= task_tgid_vnr(current);
	strncpy(new_node->m_threadname, current->comm, 16);
	grptask = pid_task(task_tgid(current),PIDTYPE_PID);
	if (NULL != grptask) {
		strncpy(new_node->m_taskname,grptask->comm,16);
		strncpy(new_node->m_usrtaskname,grptask->comm,16);
	} else {
		memset(new_node->m_taskname,0,16);
		memset(new_node->m_usrtaskname,0,16);
	}
	new_node->m_phyaddress = MEMNODE_ALIGN_ADDR(new_node);
	memory_engine_insert_shm_node(&(engine->m_shm_root), new_node);

	/* Adjust the number of free bytes. */
	engine->m_size_free -= new_node->m_size;
	engine->m_size_used += new_node->m_size;

	engine->m_peak_usedmem = max(engine->m_peak_usedmem, engine->m_size_used);

	/* Return the pointer to the node. */
	*node = new_node;

#ifdef SHM_GUARD_BYTES_ENABLE
	//fill gurad bytes with SHM_GUARD_DATA
	if (engine->m_cache_or_noncache == SHM_CACHE) {
		memset((void *)(MEMNODE_ALIGN_ADDR(new_node)- engine->m_base
			+ engine->m_virt_base + MEMNODE_ALIGN_SIZE(new_node)
			- SHM_GUARD_BYTES), SHM_GUARD_DATA, SHM_GUARD_BYTES);
	}
#endif

	up(&(engine->m_mutex));

	shm_debug("Allocated %u (%u) bytes @ 0x%08X (0x%08X) for align (%u)\n",
			MEMNODE_ALIGN_SIZE(new_node), new_node->m_size,
			MEMNODE_ALIGN_ADDR(new_node), new_node->m_addr,
			new_node->m_alignment);

	shm_debug("memory_engine_allocate OK.\n");

	return 0;

err_exit:

	up(&(engine->m_mutex));
	*node = NULL;

	shm_error("memory_engine_allocate failed !!! (%d, %d) (%d %s)\n",
							size, alignment, current->pid, current->comm);
	return res;
}