Ejemplo n.º 1
0
//return */0:不存在;1:获取;-1:空间不足
int UnistorStoreMemCache::fetch(char const* szKey,
                 CWX_UINT16 unKeyLen,
                 char* szData,
                 CWX_UINT32& uiDataLen,
                 CWX_UINT32& uiExpire,
                 CWX_UINT32  uiCurExpireTime,
                 bool bTouch)
{
    char key_buf[UnistorStoreMemCacheItem::calKeySize(unKeyLen , 0)];
    UnistorStoreMemCacheItem* key = (UnistorStoreMemCacheItem*)key_buf;
    memcpy(key->m_szBuf, szKey, unKeyLen);
    key->m_unKeyLen = unKeyLen;
    UnistorStoreMemCacheIter iter;
    iter.m_uiHash = UnistorStoreMemCacheItem::m_fnHash(key->getKey(), key->getKeyLen())%m_bucket_num;
    {
        CwxReadLockGuard<CwxRwLock> lock(&m_rwLock);
        if (!_findKey(key, iter)) return 0;
        if (uiDataLen < iter.m_pFind->getDataLen()) return -1;
        if (iter.m_pFind->m_uiExpire && (iter.m_pFind->m_uiExpire <= uiCurExpireTime)){///<超时
            return 0;
        }
        memcpy(szData, iter.m_pFind->getData(), iter.m_pFind->getDataLen());
        uiDataLen = iter.m_pFind->getDataLen();
        uiExpire = iter.m_pFind->m_uiExpire;
        if(bTouch) {
            CWX_UINT32 uiIndex = iter.m_pFind->index();
            CwxMutexGuard<CwxMutexLock> lock(m_chainMutexArr[uiIndex%UNISTOR_STORE_MEM_CACHE_CHAIN_LOCK_NUM]);
            _touch(iter.m_pFind, uiIndex);
        }
        return 1;
    }
}    
Ejemplo n.º 2
0
void long_touch(struct device_info * dev, unsigned int x, unsigned int y)
{
	if (AT_DBG)
		printf("%s, x = %d, y = %d\n", __func__, x, y);

	_touch(dev, x, y, 3);
}
Ejemplo n.º 3
0
int UnistorReadCacheEx2::fetch(char const* szKey,
                 CWX_UINT16 unKeyLen,
                 char* szData,
                 CWX_UINT32& uiDataLen,
                 bool bTouch)
{
    char key_buf[UnistorReadCacheItemEx2::calKeySize(unKeyLen , 0)];
    UnistorReadCacheItemEx2* key = (UnistorReadCacheItemEx2*)key_buf;
    memcpy(key->m_szBuf, szKey, unKeyLen);
    key->m_unKeyLen = unKeyLen;
    UnistorReadCacheExIter iter;
    iter.m_uiHash = UnistorReadCacheItemEx2::m_fnHash(key->getKey(), key->getKeyLen())%m_bucket_num;
    {
        CwxReadLockGuard<CwxRwLock> lock(this->m_rwLock);
        if (!_findKey(key, iter)) return 0;
        if (uiDataLen < iter.m_pFind->getDataLen()) return -1;
        memcpy(szData, iter.m_pFind->getData(), iter.m_pFind->getDataLen());
        uiDataLen = iter.m_pFind->getDataLen();
        if(bTouch) {
            CWX_UINT32 uiIndex = iter.m_pFind->index();
            CwxMutexGuard<CwxMutexLock> lock(m_chainMutexArr[uiIndex%UNISTOR_READ_CACHE_CHAIN_LOCK_NUM]);
            _touch(iter.m_pFind, uiIndex);
        }
        return 1;
    }
}    
Ejemplo n.º 4
0
void long_press_homekey(struct device_info *dev)
{
	if (AT_DBG)
		printf("%s\n", __func__);

	if(!strcmp(dev->name, "woodduck"))
		_touch(dev, 159, 510, 3);
	else
		_press_key(dev, KEY_HOME, 1);
}
Ejemplo n.º 5
0
int touch_proc(const char *buf, int fileNo) {
	char arg[CMDBUF] = "";
	
	if (_touch_Arg(buf, arg) == -1)
		return(-1);
	
	if (_touch(arg, fileNo) == -1)
		return(-1);
	
	return(0);
}
Ejemplo n.º 6
0
void UnistorStoreMemCache::touch(char const* szKey, ///<key
                  CWX_UINT16 unKeyLen ///<key的长度
                  )
{
    char key_buf[UnistorStoreMemCacheItem::calKeySize(unKeyLen , 0)];
    UnistorStoreMemCacheItem* key = (UnistorStoreMemCacheItem*)key_buf;
    memcpy(key->m_szBuf, szKey, unKeyLen);
    key->m_unKeyLen = unKeyLen;
    UnistorStoreMemCacheIter iter;
    iter.m_uiHash = UnistorStoreMemCacheItem::m_fnHash(key->getKey(), key->getKeyLen())%m_bucket_num;
    {
        CwxReadLockGuard<CwxRwLock> lock(&m_rwLock);
        if (_findKey(key, iter)){
            CWX_UINT32 uiIndex = iter.m_pFind->index();
            CwxMutexGuard<CwxMutexLock> lock(m_chainMutexArr[uiIndex%UNISTOR_STORE_MEM_CACHE_CHAIN_LOCK_NUM]);
            _touch(iter.m_pFind, uiIndex);
        }
    }
}
Ejemplo n.º 7
0
void UnistorStoreMemCache::insert(char const* szKey,
            CWX_UINT16 unKeyLen,
            char const* szData,
            CWX_UINT32 uiDataLen,
            CWX_UINT32* uiExpire)
{
    ///key的长度不能为0
    if (!unKeyLen) return;
    CWX_UINT32 uiOldExpire = 0;
    CWX_UINT32 uiIndex = 0;
    char key_buf[UnistorStoreMemCacheItem::calKeySize(unKeyLen , 0)];
    UnistorStoreMemCacheItem* key = (UnistorStoreMemCacheItem*)key_buf;
    memcpy(key->m_szBuf, szKey, unKeyLen);
    key->m_unKeyLen = unKeyLen;
    UnistorStoreMemCacheIter iter;

    CWX_UINT32 uiKeySize = UnistorStoreMemCacheItem::calKeySize(unKeyLen , uiDataLen);
    ///若key的空间大小大于slot,则不cache
    if (uiKeySize > UNISTOR_STORE_MEM_CACHE_MAX_ITEM_SIZE) return;

    iter.m_uiHash = UnistorStoreMemCacheItem::m_fnHash(key->getKey(), key->getKeyLen())%m_bucket_num;
    {
        CwxWriteLockGuard<CwxRwLock> lock(&m_rwLock);
        ///如果key存在
        if(_findKey(key, iter)){
            if (uiKeySize == iter.m_pFind->size()){///属于同一个slot
                ///修改空间
                m_usedDataSize -= iter.m_pFind->getDataLen();
                m_usedDataSize += uiDataLen;
                iter.m_pFind->m_uiDataLen = uiDataLen;
                if (uiExpire) iter.m_pFind->m_uiExpire = *uiExpire;
                if (uiDataLen){
                    memcpy((char*)iter.m_pFind->getData(), szData, uiDataLen);  
                }
                uiIndex = iter.m_pFind->index();
                _touch(iter.m_pFind, uiIndex);
                return;
            }
            uiOldExpire = iter.m_pFind->m_uiExpire;
            ///属于不同的slot,首先溢出,此时拥有hash锁、链表锁、及统计锁
            _remove(iter);
        }
        ///计算索引
        uiIndex = UnistorStoreMemCacheItem::calKeyIndex(unKeyLen , uiDataLen);
        ///优先使用空闲的key
        if (m_chainArr[uiIndex].m_freeHead){
            key = m_chainArr[uiIndex].m_freeHead;
            m_chainArr[uiIndex].m_freeHead = m_chainArr[uiIndex].m_freeHead->m_next;
            ///修改空间
            m_chainArr[uiIndex].m_uiFreeNum--;
            m_freeSize -= uiKeySize;
            m_freeCapacity -= (uiKeySize - sizeof(UnistorStoreMemCacheItem));
            m_freeItemCount --;
        }else if ((m_cacheBufArrIndex + 1 < m_cacheBufArrSize) ||  ///从新内存分配key
            (m_cacheBufArrPos + uiKeySize < UNISTOR_STORE_MEM_CACHE_SLOT_SIZE))
        {
            if (m_cacheBufArrPos + uiKeySize > UNISTOR_STORE_MEM_CACHE_SLOT_SIZE){///<使用新slot
                m_cacheBufArrIndex ++;
                m_cacheBufArrPos = 0;
            }
            ///分配新空间
            key = (UnistorStoreMemCacheItem*)(m_cacheBufArr[m_cacheBufArrIndex] + m_cacheBufArrPos);
            m_cacheBufArrPos += uiKeySize;
        }else if (m_chainArr[uiIndex].m_usedTail){///释放已有空间
            key = m_chainArr[uiIndex].m_usedTail;
            iter.m_uiHash = UnistorStoreMemCacheItem::m_fnHash(key->getKey(), key->getKeyLen())%m_bucket_num;
            _findKey(key, iter);
            if (iter.m_pFind != key){
                CWX_ASSERT(0);
            }
            ///从hash中删除key
            _removeKey(iter);
            m_chainArr[uiIndex].m_usedTail = m_chainArr[uiIndex].m_usedTail->m_prev;
            if (!m_chainArr[uiIndex].m_usedTail){
                m_chainArr[uiIndex].m_usedHead = NULL;
            }else{
                m_chainArr[uiIndex].m_usedTail->m_next = NULL;
            }
            m_chainArr[uiIndex].m_uiUsedNum--;
            m_usedSize -= uiKeySize;
            m_usedCapacity -= uiKeySize - sizeof(UnistorStoreMemCacheItem);
            m_usedDataSize -= key->m_uiDataLen + key->m_unKeyLen;
            m_cachedKeyCount--;
            m_cachedItemCount--;
        }else{ ///没有空间可用,不cache
            return ;
        }
        ///copy数据
        key->m_uiKeyIndex = uiIndex; ///<设置key的index
        key->m_unKeyLen = unKeyLen;
        key->m_uiDataLen = uiDataLen;
        key->m_ucState = UnistorStoreMemCacheItem::UNISTOR_MEM_ITEM_STATE_USED;
        key->m_uiExpire = uiExpire?*uiExpire:uiOldExpire;
        if (unKeyLen)  memcpy((char*)key->getKey(), szKey, unKeyLen);
        if (uiDataLen) memcpy((char*)key->getData(), szData, uiDataLen);
        _addKey(uiIndex, uiKeySize, key);
    }
}
Ejemplo n.º 8
0
int main(int argc, char * argv[], char * env[])
{
	char line[128], command[128], pathname[128];
	int ID;
	
	// DEVICE SELECT
	get_device();

	// INITIALIZE 
	init();
	
	// MOUNT ROOT
	mount_root();

	// PROCESS LOOP
	while(1)
	{
		strcpy(line, "");
		strcpy(command, "");
		strcpy(pathname, "");
		strcpy(completePath, "");

		printf("\n\ninput a command (type help for more info): ");
		//read a line containting  command [pathname]; // [ ] means optional
		fgets(line, 256, stdin);
		line[strlen(line)-1] = '\0';

		//Find the command string and call the corresponding function;
		parseString(line, arg1, command, pathname);

		compPath(pathname);
		
		
		printf("PATHNAME: %s\n", pathname);
		ID = findCommand(command);
		switch(ID)
		{
			case -1 : printDir(running->cwd->ino);	break;
			case  0 : _menu  (arg1, pathname);	break;
			case  1 : _ls    (arg1, pathname);	break;
			case  2 : _cd    (arg1, pathname);	break;
			case  3 : _mkdir (arg1, pathname);	break;
			case  4 : _rmdir (arg1, pathname);	break;
			case  5 : _pwd   (arg1, pathname);	break;
			case  6 : _creat0(arg1, pathname);	break;
			case  7 : _rm    (arg1, pathname);	break;
			case  8 : _stat  (arg1, pathname);	break;
			case  9 : compPath(arg1); _link(arg1, pathname); break;
			case  10: _unlink(arg1, pathname); break;
			case  11: compPath(arg1); _symlink(arg1, pathname); break;
			case  12: _touch (arg1, pathname);	break;
			case  13: _chmod (arg1, pathname);	break;
			case  14: _chown (arg1, pathname);	break;
			case  15: _chgrp (arg1, pathname);	break;
			case  16: _open  (arg1, pathname);	break;
			case  17: _close (arg1, pathname);	break;
			case  18: _read  (arg1, pathname);	break;
			case  19: _write (arg1, pathname);	break;
			case  20: _pfd   (arg1, pathname);	break;
			case  21: _lseek (arg1, pathname);	break;
			case  22: _cat   (arg1, pathname);	break;
			case  23: _cp    (arg1, pathname);	break;
			case  24: _mv    (arg1, pathname);	break;
			case  25: __exit (arg1, pathname);	break;
		}
	}
	
	quit();
	return 0;
}