feisty meow concerns codebase 2.140
singleton_application.h
Go to the documentation of this file.
1#ifndef SINGLETON_APPLICATION_CLASS
2#define SINGLETON_APPLICATION_CLASS
3
4/*****************************************************************************\
5* *
6* Name : singleton_application *
7* Author : Chris Koeritz *
8* *
9*******************************************************************************
10* Copyright (c) 2006-$now By Author. This program is free software; you can *
11* redistribute it and/or modify it under the terms of the GNU General Public *
12* License as published by the Free Software Foundation; either version 2 of *
13* the License or (at your option) any later version. This is online at: *
14* http://www.fsf.org/copyleft/gpl.html *
15* Please send any updates to: fred@gruntose.com *
16\*****************************************************************************/
17
19
26#include <basis/astring.h>
27#include <basis/contracts.h>
29
30namespace application {
31
33{
34public:
35 singleton_application(const basis::astring &application_name,
36 const basis::astring &user_name = basis::astring::empty_string());
38
44 virtual ~singleton_application();
45
46 DEFINE_CLASS_NAME("singleton_application");
47
48 bool already_tried() const;
50
53
56 bool already_running();
58
60 void release_lock();
62
64private:
65 int c_initial_try;
66 /* if c_initial_try is zero, no attempt made yet. if it's 1, then tried
67 and succeeded. if it's greater than one, then tried and failed. */
68 processes::rendezvous *_app_lock;
69 bool _got_lock;
70};
71
72} //namespace.
73
74#endif
75
bool allow_this_instance()
the application must check this before starting up.
DEFINE_CLASS_NAME("singleton_application")
void release_lock()
let's go of the application lock, if we had previously gotten it.
bool already_running()
returns false if this program is not already running.
bool already_tried() const
returns true if the singleton has already tried to lock.
Provides a dynamically resizable ASCII character string.
Definition astring.h:35
static const astring & empty_string()
useful wherever empty strings are needed, e.g., function defaults.
Definition astring.cpp:128
An inter-process synchronization primitive.
Definition rendezvous.h:34
Implements an application lock to ensure only one is running at once.