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

180 lines
3.9 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"
2010-10-12 10:02:57 +02:00
#include "../../common/isc_s_proto.h"
2009-02-01 23:07:35 +01:00
#include "../../jrd/trace/TraceSession.h"
#include "../../common/classes/RefCounted.h"
2009-02-01 23:07:35 +01:00
namespace Jrd {
struct TraceCSHeader : public Firebird::MemoryHeader
{
volatile ULONG change_number;
volatile ULONG session_number;
ULONG cnt_uses;
2010-06-26 03:18:53 +02:00
char cfg_file_name[MAXPATHLEN];
};
2009-02-01 23:07:35 +01:00
class ConfigStorage FB_FINAL : public Firebird::GlobalStorage, public Firebird::IpcObject, public Firebird::Reasons
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_sharedMemory && m_sharedMemory->getHeader() ? m_sharedMemory->getHeader()->change_number : 0; }
2009-02-01 23:07:35 +01:00
void acquire();
void release();
private:
void mutexBug(int osErrorCode, const char* text);
bool initialize(Firebird::SharedMemoryBase*, bool);
2009-02-01 23:07:35 +01:00
void checkFile();
void touchFile();
class TouchFile FB_FINAL : public Firebird::RefCntIface<Firebird::ITimerImpl<TouchFile, Firebird::CheckStatusWrapper> >
{
public:
2014-09-29 13:03:47 +02:00
void handler();
void start(const char* fName);
void stop();
2014-09-29 13:03:47 +02:00
int release();
private:
const char* fileName;
};
Firebird::RefPtr<TouchFile> m_timer;
2009-02-01 23:07:35 +01:00
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
{
if (m_sharedMemory && m_sharedMemory->getHeader())
m_sharedMemory->getHeader()->change_number++;
2009-02-01 23:07:35 +01:00
m_dirty = true;
}
}
// 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
Firebird::AutoPtr<Firebird::SharedMemory<TraceCSHeader> > m_sharedMemory;
2011-10-27 03:04:14 +02:00
int m_recursive;
ThreadId m_mutexTID;
2011-10-27 03:04:14 +02:00
int m_cfg_file;
2009-02-01 23:07:35 +01:00
bool m_dirty;
};
class StorageInstance
2009-02-01 23:07:35 +01:00
{
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:
2013-12-29 01:35:50 +01:00
explicit StorageInstance(Firebird::MemoryPool&) :
storage(NULL)
{}
~StorageInstance()
2009-02-01 23:07:35 +01:00
{
delete storage;
}
2009-02-02 15:46:24 +01:00
ConfigStorage* getStorage()
2009-02-01 23:07:35 +01:00
{
if (!storage)
{
Firebird::MutexLockGuard guard(initMtx, FB_FUNCTION);
2009-02-01 23:07:35 +01:00
if (!storage)
{
storage = new ConfigStorage;
}
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