⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eb_slicer.h

📁 这是法国Kaleido公司提供了一个手机mmi设计平台
💻 H
字号:
/***************************************************************************
                          EB_Slicer.h  -  
                             -------------------
    begin                : Tue Sep 27 2005
    copyright            : (C) 2005 by DigitalAirways
    email                : info@digitalairways.com
 ***************************************************************************/

/*
 * Copyright (c) 2005 DigitalAirways, sarl. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * DigitalAirways, sarl. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with DigitalAirways.
 * A copy of this license is included in the licence.txt file included
 * in this software package.
*/

/*
**************************************************************
* RELEASE NOTES
**************************************************************
- The times used here are related to the system time.
- The queues are never supposed to contain holes.
- This queue manager is not optimized for constrained targets.

**************************************************************
* HISTORY
**************************************************************
- 

**************************************************************
* TODO
**************************************************************
- 


*/

#ifndef __EB_SLICER__
#define __EB_SLICER__

#include "EB_GContext.h"


// Default maximum number of pending messages in a queue
#define SLICER_QUEUE_LEN	100

// Actions on the sliced function
#define SLCMSG_ABORT		0x00000001 /* Abort the function (if possible...) In this case, the function MUST delete the current session, even if it's not owning it */

// Typing of the transferred keys...
//#define SLCMSG_OPT_INMEM	0x00000100 /* The inKey is containing a memory bloc */
//#define SLCMSG_OPT_INOBJ	0x00000200 /* The inKey is containing a EBSliceContext */
//#define SLCMSG_OPT_ININT	0x00000400 /* The inkey is containing an int */
//#define SLCMSG_OPT_OUTMEM	0x00000800 /* The outKey is containing a memory bloc */
//#define SLCMSG_OPT_OUTOBJ	0x00001000 /* The outKey is containing a EBSliceContext */
//#define SLCMSG_OPT_OUTINT	0x00002000 /* The outkey is containing an int */

class EBSliceContext {
	private:
		// owner is a reference on the owner of the object. 
		// When owner!=NULL, nobody but the owner is supposed to delete the object.
		void* owner ; 
		int iPhase ;
		KALEIDO_TIME_TYPE ttl ;
	public:
		DEFINE_NEW(EBSliceContext);
		DEFINE_DELETE(EBSliceContext);
		EBSliceContext(void* newOwner=NULL) 
			{ 
			owner = newOwner;
			iPhase=1;
			ttl=KALEIDO_MAX_TIME_VALUE ; // forever
			}
		virtual ~EBSliceContext() 
			{ 
			}
		void setOwner(void* newOwner) { owner=newOwner ;}
		void* getOwner() { return owner ;}
		void setPhase(int newPhase) { iPhase= newPhase; }
		void incPhase() { iPhase++; }
		int getPhase() { return iPhase; }
		void setTTL(KALEIDO_TIME_TYPE newTTL) { ttl=newTTL; }
		KALEIDO_TIME_TYPE getTTL() { return ttl; }
	} ;


class EBSliceMsgs ;

typedef void (*slicedFunction) (EBSliceMsgs* slicesQueue, GContext* gContext, void* funContext, int msgComplete, int actComplete, unsigned long option) ;

class EBSliceMsg {
	public:
		KALEIDO_TIME_TYPE msgScheduled ; // At what time should this message be used ?
		slicedFunction slcdFunction;
		GContext* gContext;
		void* funContext;
		long msgComplete;
		long actComplete;
		unsigned long option;
	public:
		//
		DEFINE_NEW(EBSliceMsg);
		DEFINE_DELETE(EBSliceMsg);
		EBSliceMsg()
			{
			msgScheduled = 0 ; 
			slcdFunction = NULL;
			gContext     = NULL;
			funContext   = NULL;
			msgComplete  = 0;
			actComplete  = 0;
			option       = 0;
			}			

		~EBSliceMsg()
			{
			}			

		KALEIDO_TIME_TYPE getSchedule() { return msgScheduled; }
			
		/*
		 * This method does not delete this object, it erases its content. 
		 * The owned references are not deleted !
		 */
		void erase()
			{
			memset(this, 0, sizeof(EBSliceMsg));
			}

		void setValues(KALEIDO_TIME_TYPE newMsgScheduled, slicedFunction newSlcdFunction, GContext* newGContext, void* newFunContext, int newMsgComplete, int newActComplete, unsigned long newOption)
			{
			msgScheduled = newMsgScheduled ; 
			slcdFunction = newSlcdFunction;
			gContext     = newGContext;
			funContext   = newFunContext;
			msgComplete  = newMsgComplete;
			actComplete  = newActComplete;
			option       = newOption;
			return ;
			}

		void setValues(EBSliceMsg* from)
			{
			memcpy(this, from, sizeof(EBSliceMsg)); 
//			from->erase(); // Don't do that when copying in reverse order !
			return ;
			}

		void execute(EBSliceMsgs* slicesQueue)
			{ //
			(*slcdFunction)(slicesQueue, gContext, funContext, msgComplete, actComplete, option) ;			
			return;
			}

		void* getSlicedFunction() { return (void*) slcdFunction; }

	} ;

typedef EBSliceMsg* pEBSliceMsg ;

class KREBDLIBS_API EBSliceMsgs {
	private:
		pEBSliceMsg* queueData ;
		pEBSliceMsg currentMessage ;
		int queueLen ;      // Lenght of the queue
		int pQueuePending ;  // Pending messages
		int queueWrite ;    // Next index to write
		int queueRead ;     // Next index to read		
		// This method allows to drop a message.
		// All the messages are moved down in order to fill the free place.
		// It returns the number of free slots.
		int dropMessage(int index);
		// This method allows to insert a message.
		// All the messages are moved up in order to get the necessary place.
		// It returns the number of free slots, or -1 if there is not enough place to
		// complete the action.
		int insertMessage(int index, KALEIDO_TIME_TYPE newMsgScheduled, slicedFunction newSlcdFunction, GContext* newGContext, void* newFunContext, int newMsgComplete, int newActComplete, unsigned long newOption);
		//
		int findMessage(slicedFunction newSlcdFunction, GContext* newGContext);
	public:
		DEFINE_NEW(EBSliceMsgs);
		DEFINE_DELETE(EBSliceMsgs);
		//
		EBSliceMsgs(int len=SLICER_QUEUE_LEN) ;
		virtual ~EBSliceMsgs() ;
		// This method allows to push a message on the current queue.
		// If there is no more free room to achieve that, the message is dropped.
		// It returns the number of free slots, or -1 if there is not enough place to
		// complete the action.
		virtual int pushMessage(KALEIDO_TIME_TYPE newMsgScheduled, slicedFunction newSlcdFunction, GContext* newGContext, void* newFunContext, int newMsgComplete, int newActComplete, unsigned long newOption) ;
		// This method allows to add and schedule a new message in the current queue.
		// This means that the message is going to be inserted at the right
		// place in the queue, depending on its msgScheduled arg.
		// If there is no more free room to achieve that, the message is dropped.
		// It returns the index of the inserted message, or -1 if there is no room
		// to store the new message.
		virtual int scheduleMessage(KALEIDO_TIME_TYPE newMsgScheduled, slicedFunction newSlcdFunction, GContext* newGContext, void* newFunContext, int newMsgComplete, int newActComplete, unsigned long newOption);
		// This method allows to pop the oldest message from the current queue.
		// It returns NULL if there is no available message.
		virtual EBSliceMsg* popMessage();
		// This method allows to peek a message from the current queue.
		// The returned message is left in the queue.
		// It returns NULL if there is no available message.			
		virtual EBSliceMsg* peekMessage();
		virtual int getPending();
		virtual void processMessages(KALEIDO_TIME_TYPE currentTime);
		/*
		 * This methods allows to mutualize some behaviour when a function is over.
		 * It MAY be called ONLY from inside a message processing.
		 */
		virtual void cleanCurrentCall();
#ifdef DEV_DEBUG
		virtual void dump(KALEIDO_TIME_TYPE currentTime, pchar prefix= (pchar) "") ;
#endif // def DEV_DEBUG
		// This method allows update the first message found in the queue and whose msgType
		// is the same as the submitted one.
		// If such a message is not yet in the queue, it's created as new one.
		// If such a message is already in the queue:
		//  - If the queue is scheduled: the queue is updated.
		//  - If the queue is not scheduled: the message's place is kept if it was already existing.
		// It returns the number of free slots, or -1 if there is not enough place to
		// complete the action.
		virtual int updateMessage(KALEIDO_TIME_TYPE msgScheduled, slicedFunction newSlcdFunction, GContext* newGContext, void* newFunContext, int newMsgComplete, int newActComplete, unsigned long newOption, int checkEarlier=0);

	} ;


#endif // ndef __EB_SLICER__

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -