Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
Gray::cAppState Class Reference

#include <cAppState.h>

Inheritance diagram for Gray::cAppState:
Gray::cSingleton< cAppState > Gray::cSingletonStatic< TYPE > Gray::cSingletonRegister Gray::CObject Gray::cHeapObject Gray::IHeapObject

Public Member Functions

APPSTATE_TYPE_ get_AppState () const noexcept
 
void put_AppState (APPSTATE_TYPE_ eAppState) noexcept
 
void InitAppState () noexcept
 
THREADID_t get_MainThreadId () const noexcept
 
cStringF get_TempDir ()
 
cStringF GetTempFile (const FILECHAR_t *pszFileTitle)
 
cStringF GetTempDir (const FILECHAR_t *pszFileDir, bool bCreate=true)
 
void SetArgValid (ITERATE_t i)
 
cStringF get_InvalidArgs () const
 
void InitArgsF (const FILECHAR_t *pszCommandArgs)
 
void InitArgs2 (int argc, APP_ARGS_t argv)
 
const void * get_HeapPtr () const noexcept override
 Get the top level (outermost, freeable) class pointer. I can delete get_HeapPtr(). More...
 
- Public Member Functions inherited from Gray::CObject
virtual ~CObject ()
 
virtual bool isValidCheck () const noexcept
 < memory allocation and structure definitions are valid. More...
 
virtual void AssertValid () const
 < memory allocation and structure definitions are valid. More...
 
virtual void Serialize (cArchive &a)
 
- Public Member Functions inherited from Gray::cHeapObject
 cHeapObject ()
 
virtual ~cHeapObject ()
 
bool IsValidInsideN (INT_PTR index) const
 
bool IsValidInsidePtr (void const *pTest) const
 
virtual size_t GetHeapStatsThis (OUT ITERATE_t &iAllocCount) const
 
virtual bool isValidCheck () const noexcept
 

Static Public Member Functions

static cStringF __stdcall get_AppFilePath ()
 The full path+name of the current EXE/PE. More...
 
static cStringF __stdcall get_AppFileTitle ()
 File name no Ext. More...
 
static cStringF __stdcall get_AppFileDir ()
 
static HRESULT CheckValidSignature (UINT32 nGrayCoreVer, size_t nSizeofThis)
 
static APPSTATE_TYPE_ __stdcall GetAppState ()
 
static bool __stdcall isInCInit ()
 
static bool __stdcall isAppRunning ()
 
static bool __stdcall isAppStateRun ()
 
static bool __stdcall isInCExit ()
 
static bool __stdcall isDebuggerPresent ()
 
static bool __stdcall isRemoteSession ()
 
static void __stdcall SetExecutionState (bool bActiveCPU, bool bActiveGUI)
 
static bool __stdcall isCurrentUserAdmin ()
 
static cString __stdcall GetCurrentUserName (bool bForce=false)
 
static cStringF __stdcall GetCurrentUserDir (const FILECHAR_t *pszSubFolder=nullptr, bool bCreate=true)
 Get Root folder the user has write access to. More...
 
static PROCESSID_t __stdcall get_CurrentProcessId ()
 
static HMODULE __stdcall get_HModule ()
 
static UINT __stdcall get_LibVersion ()
 _INC_GrayCore_H More...
 
static StrLen_t __stdcall GetEnvironStr (const FILECHAR_t *pszVarName, FILECHAR_t *pszValue, StrLen_t iLenMax) noexcept
 
static cStringF __stdcall GetEnvironStr (const FILECHAR_t *pszVarName) noexcept
 environment variable. from (system,user,app) More...
 
static ITERATE_t __stdcall GetEnvironArray (cArrayString< FILECHAR_t > &a)
 
static bool __stdcall SetEnvironStr (const FILECHAR_t *pszVarName, const FILECHAR_t *pszVal)
 
static StrLen_t __stdcall GetCurrentDir (FILECHAR_t *pszDir, StrLen_t iSizeMax)
 Current default directory for the app. More...
 
static cStringF __stdcall get_CurrentDir ()
 For the process. Not applicable to WINCE. More...
 
static bool __stdcall SetCurrentDir (const FILECHAR_t *pszDir)
 
static void __stdcall AbortApp (APP_EXITCODE_t uExitCode=APP_EXITCODE_ABORT)
 
- Static Public Member Functions inherited from Gray::cSingleton< cAppState >
static cAppState *__stdcall get_Single ()
 
static TYPE2 *__stdcall get_SingleT ()
 
static cAppState &__stdcall I ()
 
- Static Public Member Functions inherited from Gray::cSingletonStatic< TYPE >
static bool isSingleCreated () noexcept
 
static TYPEget_SingleU () noexcept
 
static TYPEget_Single ()
 
template<class TYPE2 >
static TYPE2 *__stdcall get_SingleCast ()
 
static TYPEI () noexcept
 
- Static Public Member Functions inherited from Gray::cSingletonRegister
static void __stdcall ReleaseModule (HMODULE hMod)
 

Public Attributes

const cObjectSignature m_Sig
 Used to check for compatible build/compile config and alignments. (_INC_GrayCore_H, sizeof(cAppState)) More...
 
cThreadLocalSysT< boolm_ThreadModuleLoading
 any thread is currently loading a DLL/SO? isInCInit(). use cAppStateModuleLoad More...
 
cAppArgs m_Args
 Application Command line arguments. [0] = app name. More...
 
cBitmask m_ArgsValid
 Track which command line args are valid/used in m_Args. assume any left over are not. More...
 

Static Public Attributes

static HMODULE sm_hInstance = HMODULE_NULL
 the current applications HINSTANCE handle/base address. _IMAGE_DOS_HEADER, HMODULE=HINSTANCE More...
 
- Static Public Attributes inherited from Gray::cSingletonRegister
static cThreadLockFast sm_LockSingle
 common lock for all cSingleton. More...
 

Protected Member Functions

 cAppState ()
 
virtual ~cAppState ()
 
- Protected Member Functions inherited from Gray::cSingleton< cAppState >
 cSingleton (cAppState *pObject, const TYPEINFO_t &rAddrCode=typeid(cAppState)) noexcept
 
virtual ~cSingleton ()
 
- Protected Member Functions inherited from Gray::cSingletonStatic< TYPE >
 cSingletonStatic (TYPE *pObject) noexcept
 
virtual ~cSingletonStatic () noexcept
 
- Protected Member Functions inherited from Gray::cSingletonRegister
 cSingletonRegister (const TYPEINFO_t &rAddrCode) noexcept
 
virtual ~cSingletonRegister ()
 
void RegisterSingleton ()
 
- Protected Member Functions inherited from Gray::cHeapObject
const void * get_HeapPtr () const noexcept override
 Get the top level (outermost, freeable) class pointer. I can delete get_HeapPtr(). More...
 

Protected Attributes

THREADID_t m_nMainThreadId
 The thread we started with. main(). More...
 
APPSTATE_TYPE_ m_eAppState
 The main state of the application. use isInCInit() for loading DLL's. More...
 
cString m_sUserName
 Applications assigned login/user name. Cache/Read this just once. More...
 
cStringF m_sTempDir
 Cache my temporary files directory path. More...
 
bool m_bTempDirWritable
 I have test written to the temp directory. its good. More...
 
- Protected Attributes inherited from Gray::cSingletonRegister
HMODULE m_hModuleLoaded
 What modules loaded this ? So singletons can be destroyed if DLL/SO unloads. More...
 

Friends

class cSingleton< cAppState >
 
class cAppImpl
 
class cAppStateMain
 
class cUnitTestAppState
 
class cAppStateTests
 

Additional Inherited Members

- Static Protected Attributes inherited from Gray::cSingletonStatic< TYPE >
static TYPEsm_pThe = nullptr
 pointer to the one and only object of this TYPE. ASSUME automatically init to = nullptr. More...
 

Detailed Description

Singleton to track the state of the current running app/process. Don't combine this with CWinApp/cAppImpl since we may be a (dll/Shared) library or using this in static init. Track when static init is complete and when static destructors are called.

Todo:
What desktop/session is this app and user attached to?
Note
Use _WIN32 CSIDL_WINDOWS etc to find special app folders.
see CWinApp/cAppImpl for my app specialization stuff.

Constructor & Destructor Documentation

◆ cAppState()

Gray::cAppState::cAppState ( )
protected

Cache the OS params for this process/app ?

◆ ~cAppState()

Gray::cAppState::~cAppState ( )
protectedvirtual

Member Function Documentation

◆ AbortApp()

void GRAYCALL Gray::cAppState::AbortApp ( APP_EXITCODE_t  uExitCode = APP_EXITCODE_ABORT)
static

Abort the application from some place other than the main() or WinMain() fall through. Call this instead of abort() or exit() to preclude naughty libraries from exiting badly.

  • uExitCode = APP_EXITCODE_t like return from "int main()" APP_EXITCODE_ABORT = 3 = like abort()

◆ CheckValidSignature()

static HRESULT Gray::cAppState::CheckValidSignature ( UINT32  nGrayCoreVer,
size_t  nSizeofThis 
)
inlinestatic

Is this the correct version of cAppState? Must be agreed to by all users. sizeof(cAppState) for checking alignments of structures. Ensure that some external DLL/SO caller has the same structure packing that we have.

  • nGrayCoreVer = _INC_GrayCore_H (from the callers perspective)
  • nSizeofThis = sizeof(cAppState) (from the callers perspective)

◆ get_AppFileDir()

cStringF GRAYCALL Gray::cAppState::get_AppFileDir ( )
static

Get the directory the app EXE is in.

◆ get_AppFilePath()

cStringF GRAYCALL Gray::cAppState::get_AppFilePath ( )
static

The full path+name of the current EXE/PE.

like _pgmptr in POSIX

Returns
The full path of the app EXE now

◆ get_AppFileTitle()

cStringF GRAYCALL Gray::cAppState::get_AppFileTitle ( )
static

File name no Ext.

Get the title of the app EXE file. No extension.

◆ get_AppState()

APPSTATE_TYPE_ Gray::cAppState::get_AppState ( ) const
inlinenoexcept

use isInCInit() for loading DLL's.

◆ get_CurrentDir()

cStringF GRAYCALL Gray::cAppState::get_CurrentDir ( )
static

For the process. Not applicable to WINCE.

Returns
the current directory path for the process.

◆ get_CurrentProcessId()

static PROCESSID_t __stdcall Gray::cAppState::get_CurrentProcessId ( )
inlinestatic

similar to cOSProcess

◆ get_HeapPtr()

const void* Gray::cAppState::get_HeapPtr ( ) const
inlineoverridevirtualnoexcept

Get the top level (outermost, freeable) class pointer. I can delete get_HeapPtr().

Implements Gray::IHeapObject.

◆ get_HModule()

HMODULE GRAYCALL Gray::cAppState::get_HModule ( )
static

Same as HINSTANCE Passed to app at start in _WIN32 WinMain(HINSTANCE hInstance)

Returns
the HMODULE to the current running EXE module. for resources.

◆ get_InvalidArgs()

cStringF Gray::cAppState::get_InvalidArgs ( ) const

Get a list of args NOT marked as valid. Not IN m_ValidArgs

◆ get_LibVersion()

UINT GRAYCALL Gray::cAppState::get_LibVersion ( )
static

_INC_GrayCore_H

◆ get_MainThreadId()

THREADID_t Gray::cAppState::get_MainThreadId ( ) const
inlinenoexcept

The thread we started with.

◆ get_TempDir()

cStringF Gray::cAppState::get_TempDir ( )

Get a directory i can place temporary files. ends with '\' This is decided based on the OS,User,App, Similar to _FNF(::SHGetFolderPath)(CSIDL_INTERNET_CACHE) Assume cInstallDir::IsInstallDirRestricted()

◆ GetAppState()

APPSTATE_TYPE_ GRAYCALL Gray::cAppState::GetAppState ( )
static

◆ GetCurrentDir()

StrLen_t GRAYCALL Gray::cAppState::GetCurrentDir ( FILECHAR_t pszDir,
StrLen_t  iSizeMax 
)
static

Current default directory for the app.

Note
UNDER_CE has no such thing. just use the root.

return the current directory for the process. In linux and _WIN32 the Process has a current/default directory. UNDER_CE does not.

Note
Windows services start with current directory = windows system directory.
Returns
Length of the directory string.

◆ GetCurrentUserDir()

cStringF GRAYCALL Gray::cAppState::GetCurrentUserDir ( const FILECHAR_t pszSubFolder = nullptr,
bool  bCreate = true 
)
static

Get Root folder the user has write access to.

get a folder the user has write access to. for placing log files and such.

  • pszSubFolder = create the sub folder if necessary.

◆ GetCurrentUserName()

cString GRAYCALL Gray::cAppState::GetCurrentUserName ( bool  bForce = false)
static

Get the current system user name for the process/app.

Note
Can't call this "GetUserName" because _WIN32 has a "#define" on that.
  • bForce = Read the UserName from the OS, It may change by impersonation. (i have this users accounts privs)

◆ GetEnvironArray()

ITERATE_t GRAYCALL Gray::cAppState::GetEnvironArray ( cArrayString< FILECHAR_t > &  a)
static

Get the full block of environ strings for this process. similar to cVarMap or cIniSectionData Each entry is in the form "Var1=Value1" http://linux.die.net/man/7/environ

◆ GetEnvironStr() [1/2]

cStringF GRAYCALL Gray::cAppState::GetEnvironStr ( const FILECHAR_t pszVarName)
staticnoexcept

environment variable. from (system,user,app)

Get a named environment variable by name.

  • pszVarName = nullptr = get a list of all variable names for the process?
    Note
    environment variables can be cascaded for System:User:Process. no way to tell which level by name.
    environment variables are very similar to a default block AppProfile.ini or registry entry.

◆ GetEnvironStr() [2/2]

StrLen_t GRAYCALL Gray::cAppState::GetEnvironStr ( const FILECHAR_t pszVarName,
FILECHAR_t pszValue,
StrLen_t  iLenMax 
)
staticnoexcept

Get a named environment variable by name.

Returns
pszValue = the value for the Tag name Length of the pszValue string. 0 = none

◆ GetTempDir()

cStringF Gray::cAppState::GetTempDir ( const FILECHAR_t pszFileDir,
bool  bCreate = true 
)

Get/Create a temporary folder in temporary folder space.

  • bCreate = create the sub directory if it doesn't already exist.

◆ GetTempFile()

cStringF Gray::cAppState::GetTempFile ( const FILECHAR_t pszFileTitle)

Create a temporary file to store stuff. Make sure its not colliding.

Note
if pszFileTitle == nullptr then just make a new random named file.

◆ InitAppState()

void Gray::cAppState::InitAppState ( )
noexcept

The main app thread has started. often called by cAppStateMain or via InitInstance() in _MFC_VER.

◆ InitArgs2()

void Gray::cAppState::InitArgs2 ( int  argc,
APP_ARGS_t  argv 
)

POSIX main() style init. If called by ServiceMain this might be redundant.

◆ InitArgsF()

void Gray::cAppState::InitArgsF ( const FILECHAR_t pszCommandArgs)

Windows style (unparsed) arguments. WinMain() Command line arguments honor "quoted strings" as a single argument. can get similar results from the win32 GetCommandLine(); (which includes the app path as arg 0) similar to _WIN32 shell32 CommandLineToArgvW( pszCommandArgs, &(dwArgc));

◆ isAppRunning()

GRAYCORE_LINK bool GRAYCALL Gray::cAppState::isAppRunning ( )
static

Not in static init or destruct. Indicate the process/app is DONE initializing static variables. Thought it may be setting up or tearing down. Almost exit. Use cAppStateMain inmain;

◆ isAppStateRun()

GRAYCORE_LINK bool GRAYCALL Gray::cAppState::isAppStateRun ( )
static

the process/app is in APPSTATE_Run? Use cAppStateMain inmain;

◆ isCurrentUserAdmin()

bool GRAYCALL Gray::cAppState::isCurrentUserAdmin ( )
static

This routine returns 'true' if the caller's process is a member of the Administrators local group. Caller is NOT expected to be impersonating anyone and is expected to be able to open its own process and process token.

Returns
true - Caller has Administrators local group. false - Caller does not have Administrators local group. –

◆ isDebuggerPresent()

bool GRAYCALL Gray::cAppState::isDebuggerPresent ( )
static
Note
kernel debuggers like SoftIce can fool this.

◆ isInCExit()

GRAYCORE_LINK bool GRAYCALL Gray::cAppState::isInCExit ( )
static

is the app exiting right now ? outside main() extern "C" int _C_Termination_Done; // undocumented C runtime variable - set to true during auto-finalization return _C_Termination_Done; // undocumented symbol is not good in DLL.

Note
_C_Termination_Done wouldn't work properly in a DLL.

◆ isInCInit()

GRAYCORE_LINK bool GRAYCALL Gray::cAppState::isInCInit ( )
static

Indicate the process/app is currently initializing static variables. not yet reached main() Also set for a thread loading a DLL/SO.

◆ isRemoteSession()

bool GRAYCALL Gray::cAppState::isRemoteSession ( )
static

Should we act different if this is a remote terminal?

◆ put_AppState()

void Gray::cAppState::put_AppState ( APPSTATE_TYPE_  eAppState)
inlinenoexcept

Indicate the process/app has changed state. use cAppStateModuleLoad for DLL/SO loading.

◆ SetArgValid()

void Gray::cAppState::SetArgValid ( ITERATE_t  i)

◆ SetCurrentDir()

bool GRAYCALL Gray::cAppState::SetCurrentDir ( const FILECHAR_t pszDir)
static

set the current directory path for the current app. like chdir() or _chdir()

Returns
true = OK

◆ SetEnvironStr()

bool Gray::cAppState::SetEnvironStr ( const FILECHAR_t pszVarName,
const FILECHAR_t pszVal 
)
static

ASSUME pszVarName is valid format.

  • pszVal = nullptr = (or "") to erase it.

◆ SetExecutionState()

void GRAYCALL Gray::cAppState::SetExecutionState ( bool  bActiveCPU,
bool  bActiveGUI 
)
static

Tell the system it should not sleep/hibernate if it is active. I have a big task to complete. try this for Vista, it will fail on XP

Friends And Related Function Documentation

◆ cAppImpl

friend class cAppImpl
friend

◆ cAppStateMain

friend class cAppStateMain
friend

◆ cAppStateTests

friend class cAppStateTests
friend

◆ cSingleton< cAppState >

friend class cSingleton< cAppState >
friend

◆ cUnitTestAppState

friend class cUnitTestAppState
friend

Member Data Documentation

◆ m_Args

cAppArgs Gray::cAppState::m_Args

Application Command line arguments. [0] = app name.

◆ m_ArgsValid

cBitmask Gray::cAppState::m_ArgsValid

Track which command line args are valid/used in m_Args. assume any left over are not.

◆ m_bTempDirWritable

bool Gray::cAppState::m_bTempDirWritable
protected

I have test written to the temp directory. its good.

◆ m_eAppState

APPSTATE_TYPE_ Gray::cAppState::m_eAppState
protected

The main state of the application. use isInCInit() for loading DLL's.

◆ m_nMainThreadId

THREADID_t Gray::cAppState::m_nMainThreadId
protected

The thread we started with. main().

◆ m_Sig

const cObjectSignature Gray::cAppState::m_Sig

Used to check for compatible build/compile config and alignments. (_INC_GrayCore_H, sizeof(cAppState))

◆ m_sTempDir

cStringF Gray::cAppState::m_sTempDir
protected

Cache my temporary files directory path.

◆ m_sUserName

cString Gray::cAppState::m_sUserName
protected

Applications assigned login/user name. Cache/Read this just once.

◆ m_ThreadModuleLoading

cThreadLocalSysT<bool> Gray::cAppState::m_ThreadModuleLoading

any thread is currently loading a DLL/SO? isInCInit(). use cAppStateModuleLoad

◆ sm_hInstance

HMODULE Gray::cAppState::sm_hInstance = HMODULE_NULL
static

the current applications HINSTANCE handle/base address. _IMAGE_DOS_HEADER, HMODULE=HINSTANCE

the current applications HINSTANCE handle/base address. _IMAGE_DOS_HEADER


The documentation for this class was generated from the following files: