summaryrefslogtreecommitdiff
path: root/plugins/Db3x_mmap/src/dbintf.cpp
diff options
context:
space:
mode:
authorVadim Dashevskiy <watcherhd@gmail.com>2012-07-23 06:41:38 +0000
committerVadim Dashevskiy <watcherhd@gmail.com>2012-07-23 06:41:38 +0000
commit9126d2b133d00b836fca640f847a0948f7579e02 (patch)
tree7e915c08cc0e52aaa6244e709acffa91a31715a3 /plugins/Db3x_mmap/src/dbintf.cpp
parent33e535df429971555b212f4abaff1b6adb8e7c23 (diff)
Db3x_mmap,Db_autobackups: changed folder structure
git-svn-id: http://svn.miranda-ng.org/main/trunk@1107 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/Db3x_mmap/src/dbintf.cpp')
-rw-r--r--plugins/Db3x_mmap/src/dbintf.cpp174
1 files changed, 174 insertions, 0 deletions
diff --git a/plugins/Db3x_mmap/src/dbintf.cpp b/plugins/Db3x_mmap/src/dbintf.cpp
new file mode 100644
index 0000000000..83ae3aa4ca
--- /dev/null
+++ b/plugins/Db3x_mmap/src/dbintf.cpp
@@ -0,0 +1,174 @@
+/*
+
+Miranda NG: the free IM client for Microsoft* Windows*
+
+Copyright 2012 Miranda NG project,
+all portions of this codebase are copyrighted to the people
+listed in contributors.txt.
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+*/
+
+#include "commonheaders.h"
+
+DBSignature dbSignature = {"Miranda ICQ DB",0x1A};
+
+static int stringCompare(const char* p1, const char* p2)
+{
+ return strcmp(p1+1, p2+1);
+}
+
+static int stringCompare2(const char* p1, const char* p2)
+{
+ return strcmp(p1, p2);
+}
+
+static int compareGlobals(const DBCachedGlobalValue* p1, const DBCachedGlobalValue* p2)
+{
+ return strcmp(p1->name, p2->name);
+}
+
+static int ModCompare(const ModuleName *mn1, const ModuleName *mn2 )
+{
+ return strcmp( mn1->name, mn2->name );
+}
+
+static int OfsCompare(const ModuleName *mn1, const ModuleName *mn2 )
+{
+ return ( mn1->ofs - mn2->ofs );
+}
+
+CDdxMmap::CDdxMmap(const TCHAR* tszFileName) :
+ m_hDbFile(INVALID_HANDLE_VALUE),
+ m_safetyMode(TRUE),
+ m_lSettings(100, stringCompare),
+ m_lContacts(50, LIST<DBCachedContactValueList>::FTSortFunc(HandleKeySort)),
+ m_lGlobalSettings(50, compareGlobals),
+ m_lResidentSettings(50, stringCompare2),
+ m_lMods(50, ModCompare),
+ m_lOfs(50, OfsCompare)
+{
+ m_tszProfileName = mir_tstrdup(tszFileName);
+
+ InitializeCriticalSection(&m_csDbAccess);
+
+ SYSTEM_INFO sinf;
+ GetSystemInfo(&sinf);
+ m_ChunkSize = sinf.dwAllocationGranularity;
+
+ m_codePage = CallService(MS_LANGPACK_GETCODEPAGE, 0, 0);
+ m_hCacheHeap = HeapCreate(0, 0, 0);
+ m_hModHeap = HeapCreate(0,0,0);
+}
+
+CDdxMmap::~CDdxMmap()
+{
+ // destroy settings
+ HeapDestroy(m_hCacheHeap);
+ m_lContacts.destroy();
+ m_lSettings.destroy();
+ m_lGlobalSettings.destroy();
+ m_lResidentSettings.destroy();
+
+ // destroy modules
+ HeapDestroy(m_hModHeap);
+ m_lMods.destroy();
+ m_lOfs.destroy();
+
+ // destroy map
+ KillTimer(NULL,m_flushBuffersTimerId);
+ if (m_pDbCache) {
+ FlushViewOfFile(m_pDbCache, 0);
+ UnmapViewOfFile(m_pDbCache);
+ }
+ if (m_hMap)
+ CloseHandle(m_hMap);
+ if (m_pNull)
+ free(m_pNull);
+
+ // update profile last modified time
+ DWORD bytesWritten;
+ SetFilePointer(m_hDbFile, 0, NULL, FILE_BEGIN);
+ WriteFile(m_hDbFile, &dbSignature, 1, &bytesWritten, NULL);
+ CloseHandle(m_hDbFile);
+
+ DeleteCriticalSection(&m_csDbAccess);
+
+ mir_free(m_tszProfileName);
+}
+
+int CDdxMmap::Load(bool bSkipInit)
+{
+ log0("DB logging running");
+
+ DWORD dummy = 0;
+ m_hDbFile = CreateFile(m_tszProfileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL);
+ if ( m_hDbFile == INVALID_HANDLE_VALUE )
+ return 1;
+
+ if ( !ReadFile(m_hDbFile,&m_dbHeader,sizeof(m_dbHeader),&dummy,NULL)) {
+ CloseHandle(m_hDbFile);
+ return 1;
+ }
+
+ if ( !bSkipInit) {
+ if (InitCache()) return 1;
+ if (InitModuleNames()) return 1;
+
+ hContactDeletedEvent = CreateHookableEvent(ME_DB_CONTACT_DELETED);
+ hContactAddedEvent = CreateHookableEvent(ME_DB_CONTACT_ADDED);
+ hSettingChangeEvent = CreateHookableEvent(ME_DB_CONTACT_SETTINGCHANGED);
+
+ hEventAddedEvent = CreateHookableEvent(ME_DB_EVENT_ADDED);
+ hEventDeletedEvent = CreateHookableEvent(ME_DB_EVENT_DELETED);
+ hEventFilterAddedEvent = CreateHookableEvent(ME_DB_EVENT_FILTER_ADD);
+ }
+ return 0;
+}
+
+int CDdxMmap::Create()
+{
+ m_hDbFile = CreateFile(m_tszProfileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, 0, NULL);
+ return ( m_hDbFile == INVALID_HANDLE_VALUE );
+}
+
+STDMETHODIMP_(void) CDdxMmap::SetCacheSafetyMode(BOOL bIsSet)
+{
+ { mir_cslock lck(m_csDbAccess);
+ m_safetyMode = bIsSet;
+ }
+ DBFlush(1);
+}
+
+void CDdxMmap::EncodeCopyMemory(void *dst, void *src, size_t size)
+{
+ MoveMemory(dst, src, size);
+}
+
+void CDdxMmap::DecodeCopyMemory(void *dst, void *src, size_t size)
+{
+ MoveMemory(dst, src, size);
+}
+
+void CDdxMmap::EncodeDBWrite(DWORD ofs, void *src, int size)
+{
+ DBWrite(ofs, src, size);
+}
+
+void CDdxMmap::DecodeDBWrite(DWORD ofs, void *src, int size)
+{
+ DBWrite(ofs, src, size);
+}
+