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"
|
2011-03-31 15:44:22 +02:00
|
|
|
#include "../../common/classes/RefCounted.h"
|
2009-02-01 23:07:35 +01:00
|
|
|
|
|
|
|
namespace Jrd {
|
|
|
|
|
2010-06-25 13:55:11 +02:00
|
|
|
struct TraceCSHeader : public 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];
|
2010-06-25 13:55:11 +02:00
|
|
|
};
|
2009-02-01 23:07:35 +01:00
|
|
|
|
2010-06-25 13:55:11 +02:00
|
|
|
class ConfigStorage : public Firebird::GlobalStorage, public SharedMemory<TraceCSHeader>
|
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
|
2010-06-25 13:55:11 +02:00
|
|
|
{ return sh_mem_header ? sh_mem_header->change_number : 0; }
|
2009-02-01 23:07:35 +01:00
|
|
|
|
|
|
|
void acquire();
|
|
|
|
void release();
|
|
|
|
|
|
|
|
private:
|
2010-06-25 13:55:11 +02:00
|
|
|
void mutexBug(int osErrorCode, const char* text);
|
|
|
|
bool initialize(bool);
|
2009-02-01 23:07:35 +01:00
|
|
|
|
|
|
|
void checkFile();
|
2011-03-16 12:04:04 +01:00
|
|
|
void touchFile();
|
|
|
|
|
2011-05-19 18:24:46 +02:00
|
|
|
class TouchFile : public Firebird::RefCntIface<Firebird::ITimer, FB_TIMER_VERSION>
|
2011-03-16 12:04:04 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
void FB_CARG handler();
|
|
|
|
void start(const char* fName);
|
|
|
|
void stop();
|
2011-03-31 15:44:22 +02:00
|
|
|
int FB_CARG release();
|
2011-03-16 12:04:04 +01:00
|
|
|
private:
|
|
|
|
const char* fileName;
|
|
|
|
};
|
2011-03-31 15:44:22 +02:00
|
|
|
Firebird::RefPtr<TouchFile> 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
|
|
|
{
|
2010-06-25 13:55:11 +02:00
|
|
|
sh_mem_header->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
|
2009-02-02 14:11:48 +01:00
|
|
|
tagLogFile, // log file name, if any
|
2009-02-01 23:07:35 +01:00
|
|
|
tagEnd
|
|
|
|
};
|
|
|
|
|
2009-02-10 12:32:11 +01:00
|
|
|
void putItem(ITEM tag, ULONG len, const void* data);
|
|
|
|
bool getItemLength(ITEM& tag, ULONG& len);
|
2009-02-01 23:07:35 +01:00
|
|
|
|
2011-10-27 03:04:14 +02:00
|
|
|
int m_recursive;
|
2011-10-16 16:10:48 +02:00
|
|
|
FB_THREAD_ID 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 : private Firebird::InstanceControl
|
|
|
|
{
|
2009-03-04 11:26:16 +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
|
|
|
|
2009-03-04 11:26:16 +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)
|
2009-03-04 11:26:16 +01:00
|
|
|
{
|
|
|
|
storage = new ConfigStorage;
|
|
|
|
new Firebird::InstanceControl::InstanceLink<StorageInstance>(this);
|
|
|
|
}
|
2009-02-01 23:07:35 +01:00
|
|
|
}
|
|
|
|
return storage;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class StorageGuard
|
|
|
|
{
|
|
|
|
public:
|
2009-02-08 12:23:46 +01:00
|
|
|
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
|