// ---------------------------------------------------------------------------
// CCsConversationCacheHelper::HandleProcessConversationL()
// Process Conversation and update cache
// ---------------------------------------------------------------------------
//
void CCsConversationCacheHelper::HandleProcessConversationL()
{
    iConversationEvent = GetNextEvent();
    // check to see if all the events are consumed
    // then mark cache as caching done..
    if (!iConversationEvent)
    {
        iConversationCache->CachingCompletedL();
        return;
    }

    CCsConversationEntry* conEntry =
            iConversationEvent->ClientConversation()->GetConversationEntry();

    //handle add, modify events
    if (iConversationEvent->Event() != KConversationEventDelete)
    {
        TUint8 SpecialId = NeedsSpecialProcessing(conEntry);

        if (SpecialId)
        {
            // this is for draft(unlnown)/BT/IR processing            
            iState = ECsSpecialConversation;
        }
        // check only if contact is a valid address
        else if (conEntry->Contact())
        {
            iCurrentConversationIndex
                    = iConversationCache->FindConversation(* (conEntry->Contact()));
            if (iCurrentConversationIndex != KErrNotFound)
            {
                iState = ECsConversationFoundInCache;
            }
            else
            {
                iState = ECsResolveConversation;
            }
        }
        else
        {
            // this is when contact number is NULL
            // delete the entry from temp list
            DeleteEvent(*iConversationEvent);
            iState = ECsProcessConversation;
        }
    }
    else
    {
        //handle delete event
        DeleteConversationEntryL(conEntry);
        DeleteEvent(*iConversationEvent);
        iState = ECsProcessConversation;
    }
    //move to other state
    IssueRequest();
}
Exemple #2
0
/**
 *******************************************************************************
 * @brief      Delete a queue	  
 * @param[in]  id     Event ID. 	
 * @param[in]  opt    Delete option. 	 
 * @param[out] None   
 * @retval     E_INVALID_ID         Invalid event ID.
 * @retval     E_INVALID_PARAMETER  Invalid parameter.
 * @retval     E_TASK_WAITTING      Tasks waitting for the event,delete fail.
 * @retval     E_OK                 Event deleted successful. 
 *
 * @par Description
 * @details    This function is called to delete a queue. 
 * @note 
 *******************************************************************************
 */
StatusType CoDelQueue(OS_EventID id,U8 opt)
{
    P_ECB   pecb;
    P_QCB   pqcb;
    StatusType err;
#if CFG_PAR_CHECKOUT_EN >0      
    if(id >= CFG_MAX_EVENT)	                     
    {
        return E_INVALID_ID;            /* Invalid id,return error            */
    }
#endif

    pecb = &EventTbl[id];
#if CFG_PAR_CHECKOUT_EN >0
    if( pecb->eventType != EVENT_TYPE_QUEUE)
    {
        return E_INVALID_ID;            /* The event is not queue,return error*/	
    }
#endif
    pqcb = (P_QCB)pecb->eventPtr;       /* Point at queue control block       */
    err  = DeleteEvent(pecb,opt);       /* Delete the event control block     */
    if(err == E_OK)                   /* If the event block have been deleted */
    {
        QueueIDVessel &= ~((U32)(1<<(pqcb->id)));   /* Update free queue list             */
        pqcb->qStart   = NULL;
		    pqcb->id       = 0;
        pqcb->head     = 0;
        pqcb->tail     = 0;
        pqcb->qMaxSize = 0;
        pqcb->qSize    = 0;
    }
    return err;	
}
Exemple #3
0
void DeleteEventList( const ModuleEvent *eventlistptr )
{
	if( !eventlistptr )
	{
		nlog( LOG_ERROR, "DeleteEventList: eventlistptr passed as NULL" );
		return;
	}
	while( eventlistptr->event != EVENT_NULL )
	{
		DeleteEvent( eventlistptr->event );
		eventlistptr++;
	}
}
// ---------------------------------------------------------------------------
// CCsConversationCacheHelper::HandleConversationInCacheL()
// Handle the case when the conversation is found in the cache
// so there is no need for resolving the contact
// ---------------------------------------------------------------------------
//
void CCsConversationCacheHelper::HandleConversationInCacheL()
{
    CCsConversationEntry* conEntry =
            iConversationEvent->ClientConversation()->GetConversationEntry();

    AddConversationEntryL(conEntry, iCurrentConversationIndex);

    DeleteEvent(*iConversationEvent);

    // reset back the conversation index
    iCurrentConversationIndex = KErrNotFound;
    iState = ECsProcessConversation;
    IssueRequest();
}
Exemple #5
0
	int RunOnce() {

	    struct epoll_event ev[kMaxEpoll];
	    int ev_num = 0;
	    int error = 0;
	    
	    // get timeout
	    int next_wake = 0;
	    struct timeval now;
	    gettimeofday(&now, 0);
	    Timer *first_timer = timer_queue_.front();
	    next_wake = (first_timer->fire_time().tv_sec - now.tv_sec) * 1000;
	    next_wake += (first_timer->fire_time().tv_usec - now.tv_usec) / 1000;

	    ev_num = kMaxEpoll;
	    int ret = epoll_wait(epoll_fd_, &ev, ev_num, next_wake);
	    if (ret == 0) {
		Timer *t = timer_queue_.front();
		timer_queue_.pop();
		if (t->Handler() == 0) {
		    timer_queue_.push(t);
		} else {
		    delete t;
		}
		return 1;
	    }

	    if (ret < 0) {
		if (errno == EAGAIN || errno == EINTR) {
		    continue;
		}
		return -1;
	    }
	    // process events
	    for (int i = 0; i < ev_num; i++) {
		assert(ev[i].data.ptr);
		Event *e = reinterpret_cast<Event*>(ev[i].data.ptr);
		e->set_epoll_events(ev[i].events);
		if (e->Handler() <= 0) {
		    DeleteEvent(e->fd());
		    delete e;
		}
		// mod epoll
		ev[i].events = e->get_epoll_events();
		e->ModEvent(e);
	    }

	    return 0;
	};
Exemple #6
0
void ShutdownEvents ( void )
{
   eventtype * event;

   if (eventsystemstarted==false)
      return;
   eventsystemstarted=false;

   event=firstevent;
   while (event != NULL)
      {
      eventtype * nextevent;

      nextevent=event->next;
      DeleteEvent(event);
      event=nextevent;
      }
}
Exemple #7
0
/**
 *******************************************************************************
 * @brief      Delete a mailbox	   
 * @param[in]  id     Event ID.
 * @param[in]  opt    Delete option.	 
 * @param[out] None   	 
 * @retval     E_INVALID_ID         Invalid event ID.
 * @retval     E_INVALID_PARAMETER  Invalid parameter.
 * @retval     E_TASK_WAITTING      Tasks waitting for the event,delete fail.
 * @retval     E_OK                 Event deleted successful. 
 *
 * @par Description
 * @details    This function is called to delete a mailbox.	 
 * @note 
 *******************************************************************************
 */
StatusType CoDelMbox(OS_EventID id,U8 opt)
{
    P_ECB pecb;
    
#if CFG_PAR_CHECKOUT_EN >0
    if(id >= CFG_MAX_EVENT)               /* Judge id is valid or not?        */ 
    {
        return E_INVALID_ID;              /* Id is invalid ,return error      */
    }
#endif
    pecb = &EventTbl[id];
#if CFG_PAR_CHECKOUT_EN >0
    if(pecb->eventType != EVENT_TYPE_MBOX)/* Validate event control block type*/    
    {
        return E_INVALID_ID;              /* The event is not mailbox         */	
    }
#endif	
    return (DeleteEvent(pecb,opt)); /* Delete the mailbox event control block */
}
// ---------------------------------------------------------------------------
// CCsConversationCacheHelper::HandleSpecialConversationL()
// Hnadle the case when the conversation has no contact,
// BlueTooth/IrDa messages
// ---------------------------------------------------------------------------
//
void CCsConversationCacheHelper::HandleSpecialConversationL()
{
    CCsConversationEntry* conEntry =
        iConversationEvent->ClientConversation()->GetConversationEntry();

    if (ECsBlueTooth == conEntry->GetType()|| ECsBlueTooth_VCard == conEntry->GetType()|| ECsBlueTooth_VCal == conEntry->GetType())
    {
        AddConversationEntryL(conEntry, KBluetoothMsgsConversationId);
    }
    else
    {
        AddConversationEntryL(conEntry, KUnknownConversationId);
    }
    DeleteEvent(*iConversationEvent);
    iState = ECsProcessConversation;
    IssueRequest();

    PRINT ( _L("CCsConversationCacheHelper::HandleSpecialConversationL") );
}
	// Frees resources
	GaMultithreadingAlgorithm::~GaMultithreadingAlgorithm()
	{
		// free resources used by threads
		if( _threads )
		{
			for( int i = 0; i < _numberOfThreads; i++ )
			{
				if( _threads[ i ] )
					delete _threads[ i ];
			}

			// free thread pool
			delete[] _threads;
		}

		// free resources used by synchronization
		DeleteSemaphore( _workerForkSync );
		DeleteSemaphore( _workerJoinSync );
		DeleteEvent( _controlSync );
	}
Exemple #10
0
/*
===============
=
= UpdateCinematicEvents
=
===============
*/
void UpdateCinematicEvents ( int time )
{
   eventtype * event;

   for (event=firstevent;event != NULL;)
      {
      if (event->time==time)
         {
         eventtype * nextevent;

         nextevent=event->next;
         SpawnCinematicActor ( event->effecttype, event->effect );
         DeleteEvent(event);
         event=nextevent;
         }
      else if (event->time>time)
         break;
      else
         event=event->next;
      }
}
Exemple #11
0
/**
 *******************************************************************************
 * @brief      Delete a semaphore	   
 * @param[in]  id    Event ID which to be deleted.
 * @param[in]  opt   Delete option.	 
 * @arg        == OPT_DEL_ANYWAY    Delete semaphore always   
 * @arg        == OPT_DEL_NO_PEND	Delete semaphore only when no task pending on.
 * @param[out] None   
 * @retval     E_INVALID_ID         Invalid event ID.
 * @retval     E_INVALID_PARAMETER  Invalid parameter.
 * @retval     E_TASK_WAITTING      Tasks waitting for the event,delete fail.
 * @retval     E_OK                 Event deleted successful. 	 
 *
 * @par Description
 * @details    This function is called to delete a semaphore. 
 *
 * @note 
 *******************************************************************************
 */
StatusType CoDelSem(OS_EventID id,U8 opt)
{
    P_ECB pecb;

#if CFG_PAR_CHECKOUT_EN >0
    if(id >= CFG_MAX_EVENT)	                 
    {
        return E_INVALID_ID;
    }
#endif

    pecb = &EventTbl[id];

#if CFG_PAR_CHECKOUT_EN >0
    if(pecb->eventType != EVENT_TYPE_SEM)  
    {
        return E_INVALID_ID;             /* The event type is not semaphore   */	
    }	
#endif

    return (DeleteEvent(pecb,opt));/* Delete the semaphore event control block*/
}
//分派时钟/IO事件
bool EventServerEpoll::DispatchEvents()
{
	uint64_t now;
	GetCurTime(now);
	uint32_t wait_time = WAIT_TIME_LARGE;           //io事件等待时间(单位ms)

	list<EventInfo*> timeout_list;
	EventInfo *event_info = NULL;
	//收集时钟超时事件,同时设置wait_time
	LOG_TRACE(logger, "start to collect timeout event");
	while((event_info=(EventInfo*)m_TimerHeap.Top()) != NULL)
	{
		if(event_info->expire_time <= now)    //时钟超时
		{
			timeout_list.push_back(event_info);
			m_TimerHeap.Pop();
			if(event_info->fd > 0)            //删除超时fd的io事件
			{
				LOG_DEBUG(logger, "delete event because of timeout. fd="<<event_info->fd);
				if(epoll_ctl(m_EpFd, EPOLL_CTL_DEL, event_info->fd, NULL) != 0)
				{
					LOG_ERROR(logger, "delete event failed. fd="<<event_info->fd<<",errno=%d"<<errno<<"("<<strerror(errno)<<").");
				}
			}
			continue;
		}

		if((wait_time=event_info->expire_time-now) > WAIT_TIME_LARGE)    //取最小值
			wait_time = WAIT_TIME_LARGE;
		break;
	}

	if(timeout_list.size()>0 && wait_time>WAIT_TIME_SMALL)
		wait_time = WAIT_TIME_SMALL;

	LOG_TRACE(logger, "collect timeout event finished. count="<<timeout_list.size()<<".start to collect and process IO event. wait_time="<<wait_time);

	//处理io事件
	int32_t event_count = 0;
	if((event_count=epoll_wait(m_EpFd, (struct epoll_event*)m_EventData, m_MaxEvents, wait_time)) == -1)
	{
		event_count = 0;
		if(errno != EINTR)
			LOG_ERROR(logger, "wait events error. errno="<<errno<<"("<<strerror(errno)<<").");
	}
	int32_t i;
	for(i=0; i<event_count; ++i)
	{
		struct epoll_event* ep_event = ((struct epoll_event*)m_EventData)+i;
		EventInfo *event_info = (EventInfo*)ep_event->data.ptr;
		LOG_DEBUG(logger, "io event occur. fd="<<event_info->fd<<",epoll_event="<<ep_event->events);

		bool no_error = true;
		ERROR_CODE error_code = ECODE_SUCC;
		EventType del_type = ET_EMPTY;
		if(ep_event->events & (EPOLLERR|EPOLLRDHUP|EPOLLHUP))    //发生错误
		{
			LOG_ERROR(logger, "error occur on fd="<<event_info->fd<<",errno="<<errno<<"("<<strerror(errno)<<").");
			error_code = ECODE_ERROR;
			no_error = false;
			del_type = ET_RDWT;
		}

		if(no_error && (ep_event->events&EPOLLIN))
		{
			IEventHandler *event_handler = event_info->handler;
			error_code = event_handler->OnEventRead(event_info->fd, now);
			if(error_code==ECODE_ERROR || error_code==ECODE_PEER_CLOSE)
				no_error = false;
			if(!no_error)
				del_type = ET_RDWT;
			else if(error_code!=ECODE_PENDING && !ET_IS_PERSIST(event_info->type))    //去掉非持续读事件,pending不去掉
				del_type |= ET_READ;
		}

		if(no_error && (ep_event->events&EPOLLOUT))
		{
			error_code = event_info->handler->OnEventWrite(event_info->fd, now);
			if(error_code==ECODE_ERROR || error_code==ECODE_PEER_CLOSE)
				no_error = false;
			if(!no_error || error_code!=ECODE_PENDING)    //pending不去掉
				del_type |= ET_WRITE;    //直接去掉读事件
		}

		//发生读写事件并且没有错误,修改超时时间
		if(no_error && event_info->timeout_ms>0)
		{
			if(!m_TimerHeap.Remove((HeapItem*)event_info))    //先删除
			{
				LOG_WARN(logger, "update expire_time failed(remove timer). fd="<<event_info->fd<<",timeout="<<event_info->timeout_ms<<"(ms)");
			}
			else
			{
				SetTimerInfo(event_info, event_info->timeout_ms);
				if(!m_TimerHeap.Insert((HeapItem*)event_info))  //再插入
				{
					LOG_WARN(logger, "update expire_time failed(add timer). fd="<<event_info->fd<<",timeout="<<event_info->timeout_ms<<"(ms)");
				}
				else
				{
					LOG_DEBUG(logger, "update expire_time succ. fd="<<event_info->fd<<",timeout="<<event_info->timeout_ms<<"(ms)");
				}
			}
		}

		//移除需要删除的事件
		if(!ET_IS_EMPTY(del_type))
		{
			LOG_DEBUG(logger, "delete event from event server. fd="<<event_info->fd<<",error_code="<<error_code<<"("<<ErrCodeStr(error_code)<<"),del_type="<<del_type<<"("<<EventStr(del_type)<<").");
			DeleteEvent(event_info->fd, del_type);
			if(!no_error)
				event_info->handler->OnEventError(event_info->fd, now, error_code);
		}
	}

	uint64_t now1 = now;
	if(event_count > 0)
		GetCurTime(now1);
	if(now1-now > 500)   //超过500ms
		LOG_WARN(logger, "deal with IO events="<<event_count<<",cost_time="<<now1-now);
	else
		LOG_TRACE(logger, "deal with IO events="<<event_count<<",cost_time="<<now1-now);
	now = now1;

	LOG_TRACE(logger, "process IO event finished. start to process timeout event.");

	//处理超时事件
	event_count = timeout_list.size();
	while(!timeout_list.empty())
	{
		EventInfo *event_info = timeout_list.front();
		timeout_list.pop_front();

		if(event_info->fd >= 0)    //io超时
		{
			event_info->handler->OnEventError(event_info->fd, now, ECODE_TIMEOUT);
			m_FDMap.erase(event_info->fd);
			m_ObjectPool.Recycle((void*)event_info);
		}
		else    //时钟超时
		{
			event_info->handler->OnTimeout(now);
			if(ET_IS_PERSIST(event_info->type))
			{
				event_info->heap_item.index = -1;
				event_info->expire_time = event_info->timeout_ms+now;
				if(m_TimerHeap.Insert((HeapItem*)event_info))
					continue;
				LOG_ERROR(logger, "add timer failed.");
			}
			delete event_info;
		}
	}

	if(event_count)
		GetCurTime(now1);
	if(now1-now > 500)   //超过500ms
		LOG_WARN(logger, "deal with timeout events="<<event_count<<",cost_time="<<now1-now);
	else
		LOG_TRACE(logger, "deal with timeout events="<<event_count<<",cost_time="<<now1-now);

	return true;
}
CMyTaskThread::~CMyTaskThread()
{
	DeleteMutex(m_Mutex);
	DeleteEvent(m_Notify);
}
Exemple #14
0
void ExportManager::DeleteExportedEvents()
{
	for (size_t j = 0; j < eventList.size(); ++j)
		for (size_t i = 0; i < eventList[j].size(); ++i)
			DeleteEvent(eventList[j][i]);
}
SpiderThread::~SpiderThread()
{
	if(isRun())
		End();
	DeleteEvent(m_EndEvent);
}
// ----------------------------------------------------------------------------
// CCsConversationCacheHelper::ContactResolved
// Handle a contact resolved in the contact database
// ----------------------------------------------------------------------------
void CCsConversationCacheHelper::ResolveContact(
                                                CCsConversationEvent* aConverastionEvent)
{
    CCsContactDetail contactDetail;

    //get contact from event
    CCsConversationEntry* ConvEntry =
            aConverastionEvent->ClientConversation()->GetConversationEntry();

    if (ConvEntry)
    {
        HBufC* Contact = ConvEntry->Contact();
        if (Contact)
        {
            QString contactAddress =
                    XQConversions::s60DescToQString(Contact->Des());

            iConversationCache->ContactsManager()->resolver()->resolveContact(contactAddress,
                                                                              contactDetail);

            int contactId = contactDetail.contactId;
            TInt cIndex = iConversationCache->FindConversation(contactId);

            if (cIndex == KErrNotFound)
            {
                // Add as new conversation
                HBufC* displayName = NULL;
                if(!contactDetail.displayName.isEmpty())
                {
                    displayName=XQConversions::qStringToS60Desc(contactDetail.displayName);
                }
                TRAPD(error, AddNewConversationL( aConverastionEvent->
                                ClientConversation()->GetConversationEntry(),
                                contactId,
                                displayName));

                if (displayName) delete displayName;                

                if (error != KErrNone)
                {
                    // handle error
                }
            }
            else
            {
                // this is when two contacts are having same contact Id,
                // in that case it should add into an existing conversation
                TRAPD(error, AddConversationEntryL( 
                        aConverastionEvent->ClientConversation(
                                )->GetConversationEntry(), cIndex));
                if (error != KErrNone)
                {
                    // handle error
                }
            }

            // now remove the entry from event list
            DeleteEvent(*aConverastionEvent);

            // call start update cache
            StartCacheUpdate();
        }
    }
}