00001 #ifndef SINGLETON_APPLICATION_IMPLEMENTATION_FILE 00002 #define SINGLETON_APPLICATION_IMPLEMENTATION_FILE 00003 00004 /*****************************************************************************\ 00005 * * 00006 * Name : singleton_application * 00007 * Author : Chris Koeritz * 00008 * * 00009 ******************************************************************************* 00010 * Copyright (c) 2006-$now By Author. This program is free software; you can * 00011 * redistribute it and/or modify it under the terms of the GNU General Public * 00012 * License as published by the Free Software Foundation; either version 2 of * 00013 * the License or (at your option) any later version. This is online at: * 00014 * http://www.fsf.org/copyleft/gpl.html * 00015 * Please send any updates to: fred@gruntose.com * 00016 \*****************************************************************************/ 00017 00018 #include "filename.h" 00019 #include "rendezvous.h" 00020 #include "singleton_application.h" 00021 00022 #include <basis/function.h> 00023 00024 singleton_application::singleton_application(const istring &application_name, 00025 const istring &user_name) 00026 : _app_lock(new rendezvous(filename(application_name).basename().raw() 00027 + "__" + user_name)), 00028 _got_lock(false) 00029 { 00030 } 00031 00032 singleton_application::~singleton_application() 00033 { 00034 if (_got_lock) { 00035 _app_lock->unlock(); 00036 } 00037 WHACK(_app_lock); 00038 _got_lock = false; 00039 } 00040 00041 bool singleton_application::allow_this_instance() 00042 { 00043 if (_got_lock) return true; // already grabbed it. 00044 _got_lock = _app_lock->lock(rendezvous::IMMEDIATE_RETURN); 00045 return _got_lock; 00046 } 00047 00048 00049 #endif //SINGLETON_APPLICATION_IMPLEMENTATION_FILE 00050
1.5.1