summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2012-07-28 12:35:00 +0000
committerGeorge Hazan <george.hazan@gmail.com>2012-07-28 12:35:00 +0000
commita7001dfd139fbb9d5cf5434fc40370f8da0cf04c (patch)
tree844416b2bc429054557bda440e75f466f1e30bf7
parentd5defc979cd71a5f2bb5176382fa2f5f50f23d1b (diff)
perversive error reporting schema in DATABASELINK removed
git-svn-id: http://svn.miranda-ng.org/main/trunk@1223 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--include/m_db_int.h4
-rw-r--r--plugins/Db3x/src/commonheaders.h1
-rw-r--r--plugins/Db3x/src/init.cpp77
-rw-r--r--plugins/Db3x_mmap/src/commonheaders.h1
-rw-r--r--plugins/Db3x_mmap/src/init.cpp55
-rw-r--r--plugins/Dbx_mmap_SA/src/commonheaders.h1
-rw-r--r--plugins/Dbx_mmap_SA/src/init.cpp77
-rw-r--r--plugins/Dbx_tree/DatabaseLink.cpp29
-rw-r--r--plugins/testplugin/testplug.c10
-rw-r--r--src/modules/database/database.cpp10
-rw-r--r--src/modules/database/dbintf.cpp4
11 files changed, 88 insertions, 181 deletions
diff --git a/include/m_db_int.h b/include/m_db_int.h
index 64bbcbd9e5..e201626232 100644
--- a/include/m_db_int.h
+++ b/include/m_db_int.h
@@ -124,7 +124,7 @@ struct DATABASELINK
the time of this call, profile will be C:\..\<name>.dat
Returns: 0 on success, non zero on failure - error contains extended error information, see EMKPRF_*
*/
- int (*makeDatabase)(const TCHAR *profile, int *error);
+ int (*makeDatabase)(const TCHAR *profile);
/*
profile: [in] a null terminated string to file path of selected profile
@@ -136,7 +136,7 @@ struct DATABASELINK
etc.
Returns: 0 on success, non zero on failure
*/
- int (*grokHeader)(const TCHAR *profile, int *error);
+ int (*grokHeader)(const TCHAR *profile);
/*
Affect: Tell the database to create all services/hooks that a 3.xx legacy database might support into link,
diff --git a/plugins/Db3x/src/commonheaders.h b/plugins/Db3x/src/commonheaders.h
index 5175ad67b9..e12db161bc 100644
--- a/plugins/Db3x/src/commonheaders.h
+++ b/plugins/Db3x/src/commonheaders.h
@@ -39,6 +39,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <io.h>
#include <string.h>
#include <direct.h>
+#include <memory>
#include <newpluginapi.h>
#include <win2k.h>
diff --git a/plugins/Db3x/src/init.cpp b/plugins/Db3x/src/init.cpp
index 6f021aa283..513731b824 100644
--- a/plugins/Db3x/src/init.cpp
+++ b/plugins/Db3x/src/init.cpp
@@ -46,56 +46,23 @@ LIST<CDb3x> g_Dbs(1, (LIST<CDb3x>::FTSortFunc)HandleKeySort);
/////////////////////////////////////////////////////////////////////////////////////////
// returns 0 if the profile is created, EMKPRF*
-static int makeDatabase(const TCHAR *profile, int *error)
+static int makeDatabase(const TCHAR *profile)
{
- CDb3x *tmp = new CDb3x(profile);
- if (tmp->Create() == ERROR_SUCCESS) {
- tmp->CreateDbHeaders();
- delete tmp;
- return 0;
- }
- delete tmp;
- if (error != NULL) *error = EMKPRF_CREATEFAILED;
- return 1;
+ std::auto_ptr<CDb3x> db(new CDb3x(profile));
+ if (db->Create() != ERROR_SUCCESS)
+ return EMKPRF_CREATEFAILED;
+
+ return db->CreateDbHeaders();
}
// returns 0 if the given profile has a valid header
-static int grokHeader(const TCHAR *profile, int *error)
+static int grokHeader(const TCHAR *profile)
{
- CDb3x *tmp = new CDb3x(profile);
- if (tmp->Load(true) != ERROR_SUCCESS) {
- delete tmp;
- if (error != NULL) *error = EGROKPRF_CANTREAD;
- return 1;
- }
+ std::auto_ptr<CDb3x> db(new CDb3x(profile));
+ if (db->Load(true) != ERROR_SUCCESS)
+ return EGROKPRF_CANTREAD;
- int chk = tmp->CheckDbHeaders();
- delete tmp;
- if ( chk == 0 ) {
- // all the internal tests passed, hurrah
- if (error != NULL) *error = 0;
- return 0;
- }
-
- // didn't pass at all, or some did.
- switch ( chk ) {
- case 1:
- // "Miranda ICQ DB" wasn't present
- if (error != NULL) *error = EGROKPRF_UNKHEADER;
- break;
-
- case 2:
- // header was present, but version information newer
- if (error != NULL) *error = EGROKPRF_VERNEWER;
- break;
-
- case 3:
- // header/version OK, internal data missing
- if (error != NULL) *error = EGROKPRF_DAMAGED;
- break;
- }
-
- return 1;
+ return db->CheckDbHeaders();
}
// returns 0 if all the APIs are injected otherwise, 1
@@ -104,14 +71,12 @@ static MIDatabase* LoadDatabase(const TCHAR *profile)
// set the memory, lists & UTF8 manager
mir_getLP( &pluginInfo );
- CDb3x* db = new CDb3x(profile);
- if (db->Load(false) != ERROR_SUCCESS) {
- delete db;
+ std::auto_ptr<CDb3x> db(new CDb3x(profile));
+ if (db->Load(false) != ERROR_SUCCESS)
return NULL;
- }
- g_Dbs.insert(db);
- return db;
+ g_Dbs.insert(db.get());
+ return db.release();
}
static int UnloadDatabase(MIDatabase* db)
@@ -121,24 +86,22 @@ static int UnloadDatabase(MIDatabase* db)
return 0;
}
-MIDatabaseChecker* CheckDb(const TCHAR* ptszFileName, int *error)
+MIDatabaseChecker* CheckDb(const TCHAR* profile, int *error)
{
- CDb3x *tmp = new CDb3x(ptszFileName);
- if (tmp->Load(true) != ERROR_SUCCESS) {
- delete tmp;
+ std::auto_ptr<CDb3x> db(new CDb3x(profile));
+ if (db->Load(true) != ERROR_SUCCESS) {
if (error != NULL) *error = EGROKPRF_CANTREAD;
return NULL;
}
- int chk = tmp->CheckDbHeaders();
+ int chk = db->CheckDbHeaders();
if (chk != ERROR_SUCCESS) {
- delete tmp;
*error = chk;
return NULL;
}
*error = 0;
- return tmp;
+ return db.release();
}
static DATABASELINK dblink =
diff --git a/plugins/Db3x_mmap/src/commonheaders.h b/plugins/Db3x_mmap/src/commonheaders.h
index 8fe5b1f87f..a0ad519e4d 100644
--- a/plugins/Db3x_mmap/src/commonheaders.h
+++ b/plugins/Db3x_mmap/src/commonheaders.h
@@ -36,6 +36,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <io.h>
#include <string.h>
#include <direct.h>
+#include <memory>
#ifndef __GNUC__
#include <crtdbg.h>
#endif
diff --git a/plugins/Db3x_mmap/src/init.cpp b/plugins/Db3x_mmap/src/init.cpp
index d1ad13f859..2e2490dc66 100644
--- a/plugins/Db3x_mmap/src/init.cpp
+++ b/plugins/Db3x_mmap/src/init.cpp
@@ -46,32 +46,23 @@ LIST<CDb3Mmap> g_Dbs(1, (LIST<CDb3Mmap>::FTSortFunc)HandleKeySort);
/////////////////////////////////////////////////////////////////////////////////////////
// returns 0 if the profile is created, EMKPRF*
-static int makeDatabase(const TCHAR *profile, int *error)
+static int makeDatabase(const TCHAR *profile)
{
- CDb3Mmap *tmp = new CDb3Mmap(profile);
- if (tmp->Create() == ERROR_SUCCESS) {
- tmp->CreateDbHeaders();
- delete tmp;
- return 0;
- }
- delete tmp;
- if (error != NULL) *error = EMKPRF_CREATEFAILED;
- return 1;
+ std::auto_ptr<CDb3Mmap> db( new CDb3Mmap(profile));
+ if (db->Create() != ERROR_SUCCESS)
+ return EMKPRF_CREATEFAILED;
+
+ return db->CreateDbHeaders();
}
// returns 0 if the given profile has a valid header
-static int grokHeader(const TCHAR *profile, int *error)
+static int grokHeader(const TCHAR *profile)
{
- CDb3Mmap *tmp = new CDb3Mmap(profile);
- if (tmp->Load(true) != ERROR_SUCCESS) {
- delete tmp;
- if (error != NULL) *error = EGROKPRF_CANTREAD;
- return 1;
- }
+ std::auto_ptr<CDb3Mmap> db( new CDb3Mmap(profile));
+ if (db->Load(true) != ERROR_SUCCESS)
+ return EGROKPRF_CANTREAD;
- *error = tmp->CheckDbHeaders();
- delete tmp;
- return (*error == 0) ? 0 : 1;
+ return db->CheckDbHeaders();
}
// returns 0 if all the APIs are injected otherwise, 1
@@ -80,14 +71,12 @@ static MIDatabase* LoadDatabase(const TCHAR *profile)
// set the memory, lists & UTF8 manager
mir_getLP( &pluginInfo );
- CDb3Mmap* db = new CDb3Mmap(profile);
- if (db->Load(false) != ERROR_SUCCESS) {
- delete db;
+ std::auto_ptr<CDb3Mmap> db( new CDb3Mmap(profile));
+ if (db->Load(false) != ERROR_SUCCESS)
return NULL;
- }
- g_Dbs.insert(db);
- return db;
+ g_Dbs.insert(db.get());
+ return db.release();
}
static int UnloadDatabase(MIDatabase* db)
@@ -97,24 +86,22 @@ static int UnloadDatabase(MIDatabase* db)
return 0;
}
-MIDatabaseChecker* CheckDb(const TCHAR* ptszFileName, int *error)
+MIDatabaseChecker* CheckDb(const TCHAR* profile, int *error)
{
- CDb3Mmap *tmp = new CDb3Mmap(ptszFileName);
- if (tmp->Load(true) != ERROR_SUCCESS) {
- delete tmp;
- if (error != NULL) *error = EGROKPRF_CANTREAD;
+ std::auto_ptr<CDb3Mmap> db( new CDb3Mmap(profile));
+ if (db->Load(true) != ERROR_SUCCESS) {
+ *error = EGROKPRF_CANTREAD;
return NULL;
}
- int chk = tmp->CheckDbHeaders();
+ int chk = db->CheckDbHeaders();
if (chk != ERROR_SUCCESS) {
- delete tmp;
*error = chk;
return NULL;
}
*error = 0;
- return tmp;
+ return db.release();
}
static DATABASELINK dblink =
diff --git a/plugins/Dbx_mmap_SA/src/commonheaders.h b/plugins/Dbx_mmap_SA/src/commonheaders.h
index 27c7036adf..da38757088 100644
--- a/plugins/Dbx_mmap_SA/src/commonheaders.h
+++ b/plugins/Dbx_mmap_SA/src/commonheaders.h
@@ -43,6 +43,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <string.h>
#include <direct.h>
#include <crtdbg.h>
+#include <memory>
//miranda headers
#include <newpluginapi.h>
diff --git a/plugins/Dbx_mmap_SA/src/init.cpp b/plugins/Dbx_mmap_SA/src/init.cpp
index a59ae1bc09..f7d96822a8 100644
--- a/plugins/Dbx_mmap_SA/src/init.cpp
+++ b/plugins/Dbx_mmap_SA/src/init.cpp
@@ -49,56 +49,25 @@ LIST<CDdxMmapSA> g_Dbs(1, (LIST<CDdxMmapSA>::FTSortFunc)HandleKeySort);
/////////////////////////////////////////////////////////////////////////////////////////
// returns 0 if the profile is created, EMKPRF*
-static int makeDatabase(const TCHAR *profile, int *error)
+static int makeDatabase(const TCHAR *profile)
{
- CDdxMmapSA *tmp = new CDdxMmapSA(profile);
- if (tmp->Create() == ERROR_SUCCESS) {
- tmp->CreateDbHeaders();
- delete tmp;
+ std::auto_ptr<CDdxMmapSA> db( new CDdxMmapSA(profile));
+ if (db->Create() == ERROR_SUCCESS) {
+ db->CreateDbHeaders();
return 0;
}
- delete tmp;
- if (error != NULL) *error = EMKPRF_CREATEFAILED;
- return 1;
+
+ return EMKPRF_CREATEFAILED;
}
// returns 0 if the given profile has a valid header
-static int grokHeader(const TCHAR *profile, int *error)
+static int grokHeader(const TCHAR *profile)
{
- CDdxMmapSA *tmp = new CDdxMmapSA(profile);
- if (tmp->Load(true) != ERROR_SUCCESS) {
- delete tmp;
- if (error != NULL) *error = EGROKPRF_CANTREAD;
- return 1;
- }
+ std::auto_ptr<CDdxMmapSA> db( new CDdxMmapSA(profile));
+ if (db->Load(true) != ERROR_SUCCESS)
+ return EGROKPRF_CANTREAD;
- int chk = tmp->CheckDbHeaders();
- delete tmp;
- if ( chk == 0 ) {
- // all the internal tests passed, hurrah
- if (error != NULL) *error = 0;
- return 0;
- }
-
- // didn't pass at all, or some did.
- switch ( chk ) {
- case 1:
- // "Miranda ICQ DB" wasn't present
- if (error != NULL) *error = EGROKPRF_UNKHEADER;
- break;
-
- case 2:
- // header was present, but version information newer
- if (error != NULL) *error = EGROKPRF_VERNEWER;
- break;
-
- case 3:
- // header/version OK, internal data missing
- if (error != NULL) *error = EGROKPRF_DAMAGED;
- break;
- }
-
- return 1;
+ return db->CheckDbHeaders();
}
// returns 0 if all the APIs are injected otherwise, 1
@@ -107,14 +76,12 @@ static MIDatabase* LoadDatabase(const TCHAR *profile)
// set the memory, lists & UTF8 manager
mir_getLP( &pluginInfo );
- CDdxMmapSA* db = new CDdxMmapSA(profile);
- if (db->Load(false) != ERROR_SUCCESS) {
- delete db;
+ std::auto_ptr<CDdxMmapSA> db( new CDdxMmapSA(profile));
+ if (db->Load(false) != ERROR_SUCCESS)
return NULL;
- }
- g_Dbs.insert(db);
- return db;
+ g_Dbs.insert(db.get());
+ return db.release();
}
static int UnloadDatabase(MIDatabase* db)
@@ -124,24 +91,22 @@ static int UnloadDatabase(MIDatabase* db)
return 0;
}
-MIDatabaseChecker* CheckDb(const TCHAR* ptszFileName, int *error)
+MIDatabaseChecker* CheckDb(const TCHAR* profile, int *error)
{
- CDdxMmapSA *tmp = new CDdxMmapSA(ptszFileName);
- if (tmp->Load(true) != ERROR_SUCCESS) {
- delete tmp;
- if (error != NULL) *error = EGROKPRF_CANTREAD;
+ std::auto_ptr<CDdxMmapSA> db( new CDdxMmapSA(profile));
+ if (db->Load(true) != ERROR_SUCCESS) {
+ *error = EGROKPRF_CANTREAD;
return NULL;
}
- int chk = tmp->CheckDbHeaders();
+ int chk = db->CheckDbHeaders();
if (chk != ERROR_SUCCESS) {
- delete tmp;
*error = chk;
return NULL;
}
*error = 0;
- return tmp;
+ return db.release();
}
static DATABASELINK dblink =
diff --git a/plugins/Dbx_tree/DatabaseLink.cpp b/plugins/Dbx_tree/DatabaseLink.cpp
index ec71cdeca1..579076613d 100644
--- a/plugins/Dbx_tree/DatabaseLink.cpp
+++ b/plugins/Dbx_tree/DatabaseLink.cpp
@@ -34,13 +34,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Note: Do not initialise internal data structures at this point!
Returns: 0 on success, non zero on failure - error contains extended error information, see EMKPRF_*
*/
-static int makeDatabase(const TCHAR *profile, int* error)
-{
- if (gDataBase) delete gDataBase;
- gDataBase = new CDataBase(profile);
- *error = gDataBase->CreateDB();
- return *error;
+static int makeDatabase(const TCHAR *profile)
+{
+ std::auto_ptr<CDataBase> db( new CDataBase(profile));
+ return gDataBase->CreateDB();
}
/*
@@ -53,13 +51,10 @@ static int makeDatabase(const TCHAR *profile, int* error)
etc.
Returns: 0 on success, non zero on failure
*/
-static int grokHeader(const TCHAR *profile, int* error)
+static int grokHeader(const TCHAR *profile)
{
- if (gDataBase) delete gDataBase;
- gDataBase = new CDataBase(profile);
-
- *error = gDataBase->CheckDB();
- return *error;
+ std::auto_ptr<CDataBase> db( new CDataBase(profile));
+ return gDataBase->CheckDB();
}
/*
@@ -70,9 +65,7 @@ Returns: 0 on success, nonzero on failure
static MIDatabase* LoadDatabase(const TCHAR *profile)
{
- if (gDataBase) delete gDataBase;
gDataBase = new CDataBase(profile);
-
gDataBase->OpenDB();
return gDataBase;
}
@@ -82,12 +75,12 @@ Affect: The database plugin should shutdown, unloading things from the core and
Returns: 0 on success, nonzero on failure
Note: Unload() might be called even if Load(void) was never called, wasLoaded is set to 1 if Load(void) was ever called.
*/
+
static int UnloadDatabase(MIDatabase* db)
{
- if (gDataBase)
- delete gDataBase;
-
- gDataBase = NULL;
+ if (gDataBase == db)
+ gDataBase = NULL;
+ delete db;
return 0;
}
diff --git a/plugins/testplugin/testplug.c b/plugins/testplugin/testplug.c
index 219f10f81e..46f9d0f398 100644
--- a/plugins/testplugin/testplug.c
+++ b/plugins/testplugin/testplug.c
@@ -48,10 +48,6 @@ __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion)
}
extern "C" __declspec(dllexport) const MUUID interfaces[] = {MIID_TESTPLUGIN, MIID_LAST};
-__declspec(dllexport) const MUUID* MirandaPluginInterfaces(void)
-{
- return interfaces;
-}
int __declspec(dllexport) Load(PLUGINLINK *link)
{
@@ -64,12 +60,12 @@ int __declspec(dllexport) Load(PLUGINLINK *link)
mi.flags=0;
mi.hIcon=LoadSkinnedIcon(SKINICON_OTHER_MIRANDA);
mi.pszName=LPGEN("&Test Plugin...");
- mi.pszService="TestPlug/MenuCommand";
- CallService(MS_CLIST_ADDMAINMENUITEM,0,(LPARAM)&mi);
+ mi.pszService ="TestPlug/MenuCommand";
+ Menu_AddMenuItem(&mi);
return 0;
}
int __declspec(dllexport) Unload(void)
{
return 0;
-} \ No newline at end of file
+}
diff --git a/src/modules/database/database.cpp b/src/modules/database/database.cpp
index 71ad7102ce..24b220cd44 100644
--- a/src/modules/database/database.cpp
+++ b/src/modules/database/database.cpp
@@ -359,7 +359,7 @@ int makeDatabase(TCHAR *profile, DATABASELINK * link, HWND hwndDlg)
}
// ask the database to create the profile
CreatePathToFileT(profile);
- if (link->makeDatabase(profile, &err)) {
+ if ((err = link->makeDatabase(profile)) != ERROR_SUCCESS) {
mir_sntprintf(buf, SIZEOF(buf), TranslateT("Unable to create the profile '%s', the error was %x"), file, err);
MessageBox(hwndDlg, buf, TranslateT("Problem creating profile"), MB_ICONERROR|MB_OK);
return 0;
@@ -376,8 +376,8 @@ int tryOpenDatabase(const TCHAR* tszProfile)
DATABASELINK* p = arDbPlugins[i];
// liked the profile?
- int err = 0;
- if ( p->grokHeader(tszProfile, &err) == 0) {
+ int err = p->grokHeader(tszProfile);
+ if (err == ERROR_SUCCESS) {
// added APIs?
MIDatabase* pDb = p->Load(tszProfile);
if (pDb) {
@@ -413,8 +413,8 @@ static int tryCreateDatabase(const TCHAR* ptszProfile)
for (int i=0; i < arDbPlugins.getCount(); i++) {
DATABASELINK* p = arDbPlugins[i];
- int err;
- if (p->makeDatabase(tszProfile, &err) == 0) {
+ int err = p->makeDatabase(tszProfile);
+ if (err == ERROR_SUCCESS) {
if ( !p->Load(tszProfile)) {
fillProfileName(tszProfile);
return 0;
diff --git a/src/modules/database/dbintf.cpp b/src/modules/database/dbintf.cpp
index 4c5e19607c..62850c55da 100644
--- a/src/modules/database/dbintf.cpp
+++ b/src/modules/database/dbintf.cpp
@@ -178,8 +178,8 @@ static INT_PTR srvRegisterPlugin(WPARAM wParam,LPARAM lParam)
static INT_PTR srvFindPlugin(WPARAM wParam,LPARAM lParam)
{
for (int i=0; i < arDbPlugins.getCount(); i++) {
- int error;
- if (arDbPlugins[i]->grokHeader((TCHAR*)lParam, &error) == ERROR_SUCCESS)
+ int error = arDbPlugins[i]->grokHeader((TCHAR*)lParam);
+ if (error == ERROR_SUCCESS)
return (INT_PTR)arDbPlugins[i];
}