8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-31 14:43:04 +01:00
firebird-mirror/src/jrd/trace/TraceConfigStorage.h

174 lines
3.4 KiB
C
Raw Normal View History

2009-02-01 23:07:35 +01:00
/*
* PROGRAM: Firebird Trace Services
* MODULE: TraceConfigStorage.h
* DESCRIPTION: Trace API shared configurations storage
*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
*
* Software distributed under the License is distributed AS IS,
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
* See the License for the specific language governing rights
* and limitations under the License.
*
* The Original Code was created by Khorsun Vladyslav
* for the Firebird Open Source RDBMS project.
*
* Copyright (c) 2008 Khorsun Vladyslav <hvlad@users.sourceforge.net>
* and all contributors signed below.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*
*/
#ifndef JRD_TRACECONFIGSTORAGE_H
#define JRD_TRACECONFIGSTORAGE_H
#include "../../common/classes/array.h"
#include "../../common/classes/fb_string.h"
#include "../../common/classes/init.h"
#include "../../jrd/isc.h"
#include "../../jrd/trace/TraceSession.h"
namespace Jrd {
class ConfigStorage : public Firebird::GlobalStorage
2009-02-01 23:07:35 +01:00
{
public:
ConfigStorage();
~ConfigStorage();
2009-02-02 15:46:24 +01:00
void addSession(Firebird::TraceSession& session);
bool getNextSession(Firebird::TraceSession& session);
2009-02-01 23:07:35 +01:00
void removeSession(ULONG id);
void restart();
2009-02-02 15:46:24 +01:00
void updateSession(Firebird::TraceSession& session);
2009-02-01 23:07:35 +01:00
ULONG getChangeNumber() const
{ return m_base ? m_base->change_number : 0; }
void acquire();
void release();
private:
static void checkMutex(const TEXT*, int);
2009-04-02 10:53:25 +02:00
static void initShMem(void*, sh_mem*, bool);
2009-02-01 23:07:35 +01:00
void checkFile();
void checkDirty()
{
2009-04-04 18:39:31 +02:00
if (m_dirty)
2009-02-01 23:07:35 +01:00
{
//_commit(m_cfg_file);
m_dirty = false;
}
}
void setDirty()
{
2009-04-04 18:39:31 +02:00
if (!m_dirty)
2009-02-01 23:07:35 +01:00
{
m_base->change_number++;
m_dirty = true;
}
}
struct ShMemHeader
{
ULONG version;
volatile ULONG change_number;
volatile ULONG session_number;
ULONG cnt_uses;
2009-02-01 23:07:35 +01:00
char cfg_file_name[MAXPATHLEN];
#ifndef WIN_NT
struct mtx mutex;
#endif
};
// items in every session record at sessions file
enum ITEM
{
tagID = 1, // session ID
tagName, // session Name
tagUserName, // creator user name
2009-02-05 15:50:57 +01:00
tagFlags, // session flags
2009-02-01 23:07:35 +01:00
tagConfig, // configuration
tagStartTS, // date+time when started
tagLogFile, // log file name, if any
2009-02-01 23:07:35 +01:00
tagEnd
};
void putItem(ITEM tag, ULONG len, const void* data);
bool getItemLength(ITEM& tag, ULONG& len);
2009-02-01 23:07:35 +01:00
2009-04-02 10:53:25 +02:00
sh_mem m_handle;
2009-02-02 15:46:24 +01:00
ShMemHeader* m_base;
2009-02-01 23:07:35 +01:00
#ifdef WIN_NT
struct mtx m_mutex;
#endif
int m_cfg_file;
bool m_dirty;
};
class StorageInstance : private Firebird::InstanceControl
{
private:
2009-02-01 23:07:35 +01:00
Firebird::Mutex initMtx;
2009-02-02 15:46:24 +01:00
ConfigStorage* storage;
2009-02-01 23:07:35 +01:00
public:
void dtor()
2009-02-01 23:07:35 +01:00
{
delete storage;
storage = 0;
}
StorageInstance() :
2009-02-02 15:46:24 +01:00
storage(NULL)
2009-02-01 23:07:35 +01:00
{}
2009-02-02 15:46:24 +01:00
ConfigStorage* getStorage()
2009-02-01 23:07:35 +01:00
{
if (!storage)
{
Firebird::MutexLockGuard guard(initMtx);
if (!storage)
{
storage = new ConfigStorage;
new Firebird::InstanceControl::InstanceLink<StorageInstance>(this);
}
2009-02-01 23:07:35 +01:00
}
return storage;
}
};
class StorageGuard
{
public:
explicit StorageGuard(ConfigStorage* storage) :
2009-02-01 23:07:35 +01:00
m_storage(storage)
{
m_storage->acquire();
}
~StorageGuard()
{
m_storage->release();
}
private:
2009-02-02 15:46:24 +01:00
ConfigStorage* m_storage;
2009-02-01 23:07:35 +01:00
};
}
#endif