//Poll and notify main thread if responses exists in queue void CCHttpRequest::httpRequestCallback(float delta) { delta; std::queue<HttpResponsePacket *> *pQueue = s_responseQueue; pthread_mutex_lock(&s_responseQueueMutex); if (pQueue->empty()) { pthread_mutex_unlock(&s_responseQueueMutex); } else { HttpResponsePacket *packet = pQueue->front(); pQueue->pop(); pthread_mutex_unlock(&s_responseQueueMutex); --s_asyncRequestCount; if (0 == s_asyncRequestCount) { CCDirector::sharedDirector()->getScheduler()->unscheduleSelector(schedule_selector(CCHttpRequest::httpRequestCallback), this); } HttpRequestPacket *orgRequest = packet->request; CCObject *pTarget = orgRequest->pTarget; SEL_CallFuncND pSelector = orgRequest->pSelector; if (pTarget && pSelector) { (pTarget->*pSelector)((CCNode *)this, packet); pTarget->release(); } delete orgRequest; delete packet; } }
void Facade::clear() { map<int,CCObject*>::iterator iter; for (iter=mediatorVector.begin();iter!=mediatorVector.end();iter++) { CCObject* r = iter->second; r->release(); } mediatorVector.clear(); }
DBData::~DBData() { CCDictElement* pElement = NULL; CCDICT_FOREACH(m_dic, pElement) { CCObject* pObj = pElement->getObject(); if (pObj) { pObj->release(); } }
void CCJSONConverter::convertJsonToDictionary(cJSON *json, CCDictionary *dictionary) { dictionary->removeAllObjects(); cJSON * j = json->child; while (j) { CCObject * obj = getJsonObj(j); dictionary->setObject(obj, j->string); obj->release(); j = j->next; } }
CCDictionary* CAUIHelper::createCAWidgetWithJsonFile(const char *filename) { std::string fullpath= CCFileUtils::sharedFileUtils()->fullPathForFilename(filename); CCLog("%s",fullpath.c_str()); unsigned long size = 0; char *des = (char*) CCFileUtils::sharedFileUtils()->getFileData(filename, "r", &size); CSJson::Reader reader; CSJson::Value root; CSJson::Value description; CSJson::Value rect; CCObject *ui = new CCObject(); if (!reader.parse(des, root)) { CCLog("error"); return NULL; } CCLog("%s",des); for (int i = 0; i<root.size(); i++) { description = root[i]; CAType type = (CAType)description["typeMode"].asInt(); rect = description["rect"]; std::string name = description["name"].asString(); float width = rect["width"].asFloat(); float height = rect["height"].asFloat(); float x = rect["x"].asFloat(); float y = rect ["y"].asFloat(); CCRect uirect = CCRectMake(x, y, width, height); // ui=CAButton::createWithFrame(CCRectMake(x, y, width, height)); if (type == CATypeButton) { ui = addButton(description, uirect); } else if(type == CATypeLabel) { ui = addLabel(description, uirect); } else if(type == CATypeImage) { } m_UIDictionary->setObject(ui, name.c_str()); } ui->release(); return m_UIDictionary; }
void FloatTips::clear() { if(ftPool) { CCObject* ft; int count = ftPool->count(); for (int i = 0; i < count; i++) { ft = ftPool->objectAtIndex(i); //谁retain谁就负责release ft->release(); CCLOG("retainCount %i", ft->retainCount()); } ftPool->removeAllObjects(); } }
void AsyncLoadPlist::loadPlistAsyncCallBack(float dt) { // the image is generated in loading thread std::queue<ImageInfo*> *imagesQueue = s_pImageQueue; pthread_mutex_lock(&s_ImageInfoMutex); if (imagesQueue->empty()) { pthread_mutex_unlock(&s_ImageInfoMutex); } else { ImageInfo *pImageInfo = imagesQueue->front(); imagesQueue->pop(); pthread_mutex_unlock(&s_ImageInfoMutex); LoadStruct *pLoadStruct = pImageInfo->loadStruct; CCImage *pImage = pImageInfo->image; CCObject *target = pLoadStruct->target; SEL_CallFuncO selector = pLoadStruct->selector; std::string texturePath = pLoadStruct->texturePath; // 从texturePath中取文件名 如/../../filename.png 则filename.png std::string textureFileName = texturePath.substr(texturePath.rfind('/') + 1); CCTextureCache::sharedTextureCache()->addUIImage(pImage, textureFileName.c_str()); if (target && selector) { (target->*selector)(CCString::create(pLoadStruct->plistFileName)); target->release(); } pImage->release(); delete pLoadStruct; delete pImageInfo; --s_nAsyncRefCount; if (0 == s_nAsyncRefCount) { CCDirector::sharedDirector()->getScheduler()->unscheduleSelector(schedule_selector(AsyncLoadPlist::loadPlistAsyncCallBack), this); } } }
WebSocket::~WebSocket(){ if(readyState != CLOSED){ this->fire("close", NULL); this->proxy_fire("close", NULL); readyState = CLOSED; } CCAssert(!pthread_equal(m_networkThread, pthread_self()), "websocket instance should not release in sub thread!"); pthread_mutex_lock(&m_responseQueueMutex); CCObject* obj; CCARRAY_FOREACH(m_responseMessage, obj){ obj->release(); } m_responseMessage->release(); pthread_mutex_unlock(&m_responseQueueMutex); pthread_mutex_destroy(&m_responseQueueMutex); if(NULL != s_pool && s_pool->containsObject(this)){ pthread_mutex_lock(&s_socketsMutex); s_pool->removeObject(this); pthread_mutex_unlock(&s_socketsMutex); } if(NULL != s_pool && s_pool->count() <= 0){ pthread_mutex_lock(&s_requestQueueMutex); //s_requestMessageQueue->removeAllObjects(); CCObject* obj; CCARRAY_FOREACH(s_requestMessageQueue, obj){ s_requestMessageQueue->removeObject(obj); JsonData* msg = (JsonData*)obj; CC_SAFE_DELETE(msg); }
void CCMsgManager::update() { // >> locked m_bDispatchMsgLocked = true; if(!m_vMsgQueue.empty()) { vector<ccMESSAGE4>::iterator citr = m_vMsgQueue.begin(); vector<ccMESSAGE4>::iterator cend = m_vMsgQueue.end(); for(; citr != cend; ++citr ) { ccMESSAGE4& tagMsg = *citr; vector<CCMsgDelegate*>::iterator hitr = m_vMsgDelegates.begin(); vector<CCMsgDelegate*>::iterator hend = m_vMsgDelegates.end(); for(; hitr != hend; ++hitr ) { (*hitr)->onMessage(tagMsg.uMsg, tagMsg.pMsgObj, tagMsg.wParam, tagMsg.lParam); } CC_SAFE_RELEASE(tagMsg.pMsgObj); } m_vMsgQueue.clear(); } if(!m_vTargetMsgQueue.empty()) { vector<ccTARGETMESSAGE4>::iterator citr = m_vTargetMsgQueue.begin(); vector<ccTARGETMESSAGE4>::iterator cend = m_vTargetMsgQueue.end(); for(; citr != cend; ++citr ) { ccTARGETMESSAGE4& tagTarget = *citr; ccMESSAGE4& tagMsg = tagTarget.tMessage; tagTarget.pDelegate->onMessage(tagMsg.uMsg, tagMsg.pMsgObj, tagMsg.wParam, tagMsg.lParam); CCObject* pObj = dynamic_cast<CCObject*>(tagTarget.pDelegate); CC_SAFE_RELEASE(pObj); CC_SAFE_RELEASE(tagMsg.pMsgObj); } m_vTargetMsgQueue.clear(); } m_bDispatchMsgLocked = false; // << unlocked while(!m_vMsgDelegatesAdded.empty()) { CCMsgDelegate* pDelegate = m_vMsgDelegatesAdded.front(); m_vMsgDelegates.insert(m_vMsgDelegates.begin(), pDelegate); m_vMsgDelegatesAdded.erase(m_vMsgDelegatesAdded.begin()); } while(!m_vMsgDelegatesRemoved.empty()) { CCMsgDelegate* pDelegate = m_vMsgDelegatesRemoved.front(); vector<CCMsgDelegate*>::iterator itr = std::find(m_vMsgDelegates.begin(),m_vMsgDelegates.end(),pDelegate); if( itr != m_vMsgDelegates.end() ) { m_vMsgDelegates.erase(itr); } CCObject* pObject = dynamic_cast<CCObject*>(pDelegate); pObject->release(); m_vMsgDelegatesRemoved.erase(m_vMsgDelegatesRemoved.begin()); } if(!m_vMsgTemps.empty()) { m_vMsgQueue.insert(m_vMsgQueue.end(), m_vMsgTemps.begin(), m_vMsgTemps.end()); m_vMsgTemps.clear(); } if(!m_vTargetMsgTemps.empty()) { m_vTargetMsgQueue.insert(m_vTargetMsgQueue.end(), m_vTargetMsgTemps.begin(), m_vTargetMsgTemps.end()); m_vTargetMsgTemps.clear(); } }