Kicking it Olde Sküül! Burgerlib on Github Follow Olde Sküül on Twitter Burgerbecky on LinkedIn Burgerbecky on LinkedIn
Loading...
Searching...
No Matches
Burger::DetectMultiLaunch Class Reference

Class to detect multiple launches of a desktop application. More...

Public Member Functions

 DetectMultiLaunch () noexcept
 Initialize the object to a power up state.
 
 ~DetectMultiLaunch ()
 Teardown on exit.
 
uint_t is_multi_launched (const char *pSignature) noexcept
 Test if this is the only instance of this class systemwide.
 

Private Member Functions

 DetectMultiLaunch (const DetectMultiLaunch &)=delete
 
DetectMultiLaunchoperator= (const DetectMultiLaunch &)=delete
 
 DetectMultiLaunch (DetectMultiLaunch &&)=delete
 
DetectMultiLaunchoperator= (DetectMultiLaunch &&)=delete
 

Private Attributes

void * m_hInstanceLock
 Windows handle to an instance lock (Windows only)
 
char * m_pName
 Name of the sem_t record (MacOSX/Linux only)
 

Detailed Description

Class to detect multiple launches of a desktop application.


For some applications, it's desired that only a single instance is allowed to be running systemwide. This class will create a global object that's visible systemwide and if this object is in existence when this class is queried, then it means that this class is running multiple times. If the function is_multi_launched() returns TRUE, then immediately exit the application since another is running elsewhere in the same system

void main()
{
// This must exist during the entire run of the application
Burger::DetectMultiLaunch OneInstanceTest;
if (OneInstanceTest.is_multi_launched("MyAwesome App")) {
exit(10); // Already running
}
DoStuff();
}
Class to detect multiple launches of a desktop application.
Definition burger.h:18626
uint_t is_multi_launched(const char *pSignature) noexcept
Test if this is the only instance of this class systemwide.

Constructor & Destructor Documentation

◆ DetectMultiLaunch() [1/3]

Burger::DetectMultiLaunch::DetectMultiLaunch ( const DetectMultiLaunch & )
privatedelete

◆ DetectMultiLaunch() [2/3]

Burger::DetectMultiLaunch::DetectMultiLaunch ( DetectMultiLaunch && )
privatedelete

◆ DetectMultiLaunch() [3/3]

Burger::DetectMultiLaunch::DetectMultiLaunch ( )
noexcept

Initialize the object to a power up state.


Variables are initialized but no action is taken

◆ ~DetectMultiLaunch()

Burger::DetectMultiLaunch::~DetectMultiLaunch ( )

Teardown on exit.


If is_multi_launched() is called, a global object exists. Once the class is destroyed, so is the object.

Member Function Documentation

◆ is_multi_launched()

uint_t Burger::DetectMultiLaunch::is_multi_launched ( const char * pSignature)
noexcept

Test if this is the only instance of this class systemwide.


An object is created, for Windows, it's a FileMapping object of 32 bytes that stays in memory. If executed again, the recreation of the object will return a ERROR_ALREADY_EXISTS error that will tell the app there is already an instance running.

For Darwin, a named sem_t is created and if it's already created, it's assumed another instance already exists.

Parameters
pSignaturePointer to a UTF8 "C" string that's unique to the application
Returns
TRUE if there is another instance of the application already running, FALSE if this is the only instance.

◆ operator=() [1/2]

DetectMultiLaunch & Burger::DetectMultiLaunch::operator= ( const DetectMultiLaunch & )
privatedelete

◆ operator=() [2/2]

DetectMultiLaunch & Burger::DetectMultiLaunch::operator= ( DetectMultiLaunch && )
privatedelete

Member Data Documentation

◆ m_hInstanceLock

void* Burger::DetectMultiLaunch::m_hInstanceLock
private

Windows handle to an instance lock (Windows only)

◆ m_pName

char* Burger::DetectMultiLaunch::m_pName
private

Name of the sem_t record (MacOSX/Linux only)