📄 eb_gcontext.h
字号:
/***************************************************************************
EB_GContext.h - KREB's global context
-------------------
begin : Tue May 24 2004
copyright : (C) 2004-2005 by DigitalAirways
email : info@digitalairways.com
***************************************************************************/
/*
* 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.
*
*/
#ifndef __EB_GCONTEXT__
#define __EB_GCONTEXT__
#define BUILD_NUMBER 226
#define KREB_INTERNAL_NUMBER 0
#define KCURRENTFILEVERSION 35
#define KREB_BUILD_NUMBER BUILD_NUMBER
#define KREB_CUSTOMER "ROOT"
#define KREB_PATCH_NUMBER 0
#include "EB_Utils.h"
#include "EB_EBContext.h"
#include "KR_KRContext.h"
#include "EB_RsrcMgr.h"
#ifdef DEV_PROFILE
#define MAX_PROFILING_STAMPS 20
#define LOAD_HTML 0
#define PARSE_HTML 1
#define LOAD_BIN 2
#define RESTORE_BIN 3
#define LOAD_BMP 4
#define ACCESS_BMP 5
#define DRAW_STRING 6
#define MODEL_ACTIVATE 7
#define MODEL_RENDER 8
#define DRAW_SCREEN 9
#define DRAW_BITMAP 10
#define PROF_USER1 11
#define PROF_USER2 12
#define PROF_USER3 13
#define PROF_USER4 14
#define PROF_USER5 15
#endif // def DEV_PROFILE
// Type is a bloc that has been xmalloc'ed: it must be xfree'd
#define VALTYPE_MEM 0x00000001
#define VALTYPE_OBJ 0x00000002
// Built-in global context's key names
#define _KEY_GROUPFOCUS "_groupFocus-"
#define _KEY_ACTIONVALUE "_actionValue"
#define _KEY_LASTINPUT "_lastInput"
#define _KEY_CALLERID "_callerID"
#define _KEY_PENDINGCALLNUMBER "_pendingCallNumber"
class KREBDLIBS_API GContext
{
private:
// For very short term uses
char* tmpBuffer;
int tmpBufferLen;
EBContext* ebContext ;
KRContext* krContext ;
void* suiteContext ;
void* userContext ;
void* threadRef ;
RsrcMgr* rsrcMgr ;
EBContext* getEBContext()
{ return ebContext; }
KRContext* getKRContext()
{ return krContext; }
//
boolean screenHasChanged;
public:
DEFINE_NEW(GContext);
DEFINE_DELETE(GContext);
GContext(void* newUserContext=0)
{
ebContext = XNEW(EBContext) (this) ;
krContext = XNEW(KRContext) () ;
threadRef = NULL;
rsrcMgr = XNEW(RsrcMgr) (this) ;
userContext = newUserContext ;
suiteContext= NULL ;
tmpBufferLen = MAX_TMPBUFFER_LEN;
tmpBuffer = (char*) xmalloc(tmpBufferLen);
// CRITICAL: if we cannot allocate this buffer at this early stage, there is a huge problem elsewhere
#ifdef DEV_PROFILE
begStackChecking();
#endif /* def DEV_PROFILE */
screenUpdated();
}
virtual ~GContext()
{
SAFE_DELETE(ebContext) ;
SAFE_DELETE(krContext) ;
SAFE_DELETE(rsrcMgr) ;
SAFE_FREE(tmpBuffer);
}
static int getBuildNumber(); // This should not be inlined in order to check compatibility
void setSuiteContext(void* newSuiteContext)
{ suiteContext = newSuiteContext; }
void* getSuiteContext()
{ return suiteContext; }
void setUserContext(void* newUserContext)
{ userContext = newUserContext; }
void* getUserContext()
{ return userContext; }
char* resizeTmpBuffer(int newLen)
{
char* oldBuffer = tmpBuffer;
int oldLen = tmpBufferLen;
tmpBufferLen = newLen;
if(newLen>0)
{
tmpBuffer = (char*) xmalloc(tmpBufferLen);
if(!tmpBuffer)
{
tmpBufferLen = oldLen;
return oldBuffer;
}
}
else
{
tmpBuffer = NULL;
tmpBufferLen=0;
}
SAFE_FREE(oldBuffer);
return tmpBuffer;
}
char* getTmpBuffer()
{ return tmpBuffer ; }
int getTmpBufferLen()
{ return tmpBufferLen; }
void setThreadRef(void* newThreadRef)
{ threadRef = newThreadRef; }
void* getThreadRef()
{ return threadRef; }
//
// EBContext related methods
//
// Resources Manager
RsrcMgr* getRsrcMgr()
{ return rsrcMgr ; }
// Global store
/*
<api>
<class>GContext</class>
<method>_addData</method>
<java></java>
<cpp>void _addData(char* key, void* value)</cpp>
<descr>
<p>Adds a new data associated with a key.</p>
<p>key is duplicated by addData and the copy will be disposed when not used anymore. Thus addData does NOT take ownership of key. Static Strings can be used as keys. Another dispose mechanism should be provided somewhere if key is not a static string (not the general case)</p>
<p>value is only referenced. Thus addData does NOT take ownership of value. Another dispose mechanism should be provided somewhere is value if not a static string (general case).</p>
</descr>
</api>
*/
void _addData(const char* key, void* value)
{ebContext->addData((char*) key, value);}
/*
<api>
<class>GContext</class>
<method>_replaceData</method>
<java></java>
<cpp>void _replaceData(const char* key, void* value)</cpp>
<descr>
<p>Replaces the current value associated to the key with a new one.</p>
</descr>
</api>
*/
void _replaceData(const char* key, void* value)
{ebContext->replaceData((char*) key, value);}
void replaceObjectData(const char* key, void* value)
{ebContext->replaceObjectData((char*) key, value);}
/*
<api>
<class>GContext</class>
<method>replaceMemData</method>
<java></java>
<cpp>void replaceMemData(const char* key, void* value)</cpp>
<descr>
<p>Replaces the current value associated to the key with a new one. Value is considered as having been
allocated like a BLOB, so any value previously associated to this key is freed. The transferred object
is not duplicated and will not be freed by the context, except if the same method is called for the
same key.</p>
</descr>
</api>
*/
void replaceMemData(const char* key, void* value)
{ebContext->replaceMemData((char*) key, value);}
/*
<api>
<class>GContext</class>
<method>replaceIntData</method>
<java></java>
<cpp> void replaceIntData(const char* key, void* value)</cpp>
<descr>
<p>.</p>
</descr>
</api>
*/
void replaceIntData(const char* key, void* value)
{ebContext->replaceIntData((char*) key, value);}
/*
<api>
<class>GContext</class>
<method>replaceIntData</method>
<java></java>
<cpp>void replaceIntData(const char* key, int value) </cpp>
<descr>
<p>Replaces the current value associated to the key with a new one.</p>
</descr>
</api>
*/
void replaceIntData(const char* key, int value)
{ebContext->replaceIntData((char*) key, (void*) value);}
/*
<api>
<class>GContext</class>
<method>findData</method>
<java></java>
<cpp>void* findData(const char* key)</cpp>
<descr>
<p>Returns the value currently associated to the key, or NULL if it does not exist.</p>
<p>As the ownership was not taken in the addData(), findData does not return ownership of the value.</p>
</descr>
</api>
*/
void* findData(const char* key)
{return ebContext->findData((char*) key);}
/*
<api>
<class>GContext</class>
<method>findData</method>
<java></java>
<cpp>int findData(const char* key, int defValue)</cpp>
<descr>
<p>Returns the int value currently associated to the key, or defValue if it does not exist.</p>
</descr>
</api>
*/
int findData(const char* key, int defValue)
{return ebContext->findData((char*) key, defValue);}
/*
<api>
<class>GContext</class>
<method>takeDatas</method>
<java></java>
<cpp>void takeDatas(const char* keyBegin) </cpp>
<descr>
<p>This method deletes from the global store all the entries whose key is beginning with keyBegin.
Note that the key names are freed.</p>
</descr>
</api>
*/
void takeDatas(const char* keyBegin)
{ebContext->takeDatas((char*) keyBegin);}
/*
<api>
<class>GContext</class>
<method>packDatas</method>
<java></java>
<cpp> void packDatas(boolean verbose=false) </cpp>
<descr>
<p> This method destroys in the global store all the entries where the associated value is NULL.</p>
</descr>
</api>
*/
void packDatas(boolean verbose=false)
{ebContext->packDatas(verbose);}
/*
<api>
<class>GContext</class>
<method>_removeData</method>
<java></java>
<cpp>void _removeData(long i)</cpp>
<descr>
<p>Removes the record currently associated to the key.</p>
</descr>
</api>
*/
void _removeData(const char* key)
{ebContext->removeData((char*) key);}
/*
<api>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -