summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2012-07-26 20:58:32 +0000
committerGeorge Hazan <george.hazan@gmail.com>2012-07-26 20:58:32 +0000
commit2c6fdda841bfff2425a29c17a0a52a9aa189db42 (patch)
tree603155af17803cb0a826aaeeadfd9a2654c9008b
parentecdc78ceeab06693142db6b3c1b44169cc035e7a (diff)
service plugins' load order
git-svn-id: http://svn.miranda-ng.org/main/trunk@1205 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
-rw-r--r--include/newpluginapi.h14
-rw-r--r--plugins/CrashDumper/src/crshdmp.cpp12
-rw-r--r--plugins/DbEditorPP/src/main.cpp2
-rw-r--r--plugins/VersionInfo/src/services.cpp2
-rw-r--r--src/core/modules.cpp17
-rw-r--r--src/modules/plugins/newplugins.cpp40
6 files changed, 56 insertions, 31 deletions
diff --git a/include/newpluginapi.h b/include/newpluginapi.h
index 2437a0b1d2..5d2ed29b00 100644
--- a/include/newpluginapi.h
+++ b/include/newpluginapi.h
@@ -92,7 +92,19 @@ typedef struct _MUUID {
#define MIID_SERVICEMODE {0x8a92c026, 0x953a, 0x4f5f, { 0x99, 0x21, 0xf2, 0xc2, 0xdc, 0x19, 0x5e, 0xc5}}
-/* Each service mode plugin must implement MS_SERVICEMODE_LAUNCH */
+/* Each service mode plugin must implement MS_SERVICEMODE_LAUNCH
+ This service might return one of the following values:
+ SERVICE_CONTINUE - load Miranda normally, like there's no service plugins at all
+ SERVICE_ONLYDB - load database and then execute service plugin only
+ SERVICE_MONOPOLY - execute only service plugin, even without database
+ SERVICE_FAILED - terminate Miranda execution
+*/
+
+#define SERVICE_CONTINUE 0
+#define SERVICE_ONLYDB 1
+#define SERVICE_MONOPOLY 2
+#define SERVICE_FAILED (-1)
+
#define MS_SERVICEMODE_LAUNCH "ServiceMode/Launch"
typedef struct PLUGININFOEX_tag
diff --git a/plugins/CrashDumper/src/crshdmp.cpp b/plugins/CrashDumper/src/crshdmp.cpp
index 77bfc05501..39aa930072 100644
--- a/plugins/CrashDumper/src/crshdmp.cpp
+++ b/plugins/CrashDumper/src/crshdmp.cpp
@@ -41,7 +41,7 @@ bool servicemode;
bool clsdates;
bool dtsubfldr;
-static const PLUGININFOEX pluginInfoEx =
+static const PLUGININFOEX pluginInfoEx =
{
sizeof(PLUGININFOEX),
"Crash Dumper",
@@ -59,7 +59,7 @@ static const PLUGININFOEX pluginInfoEx =
const PLUGININFOEX* GetPluginInfoEx(void) { return &pluginInfoEx; }
-extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirVersion)
+extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirVersion)
{
::mirandaVersion = mirVersion;
return (PLUGININFOEX*)&pluginInfoEx;
@@ -84,7 +84,7 @@ INT_PTR StoreVersionInfoToFile(WPARAM, LPARAM lParam)
HANDLE hDumpFile = CreateFile(path, GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
- if (hDumpFile != INVALID_HANDLE_VALUE)
+ if (hDumpFile != INVALID_HANDLE_VALUE)
{
bkstring buffer;
@@ -143,7 +143,7 @@ INT_PTR ViewVersionInfo(WPARAM wParam, LPARAM)
if (hRichModule == NULL && GetModuleHandle(TEXT("Riched20.dll")) == NULL)
hRichModule = LoadLibrary(TEXT("Riched20.dll"));
- CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_VIEWVERSION), NULL,
+ CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_VIEWVERSION), NULL,
DlgProcView, wParam ? (VI_FLAG_PRNVAR | VI_FLAG_PRNDLL) : VI_FLAG_PRNVAR);
return 0;
@@ -167,7 +167,7 @@ INT_PTR OpenUrl(WPARAM wParam, LPARAM)
INT_PTR ServiceModeLaunch(WPARAM, LPARAM)
{
servicemode = true;
- return 0;
+ return SERVICE_ONLYDB;
}
@@ -341,7 +341,7 @@ static int ModulesLoaded(WPARAM, LPARAM)
if (servicemode) ViewVersionInfo(0, 0);
else
{
- if (DBGetContactSettingByte(NULL, PluginName, "UploadChanged", 0) && !ProcessVIHash(false))
+ if (DBGetContactSettingByte(NULL, PluginName, "UploadChanged", 0) && !ProcessVIHash(false))
UploadVersionInfo(0, 0xa1);
}
diff --git a/plugins/DbEditorPP/src/main.cpp b/plugins/DbEditorPP/src/main.cpp
index 729cde6ebe..4ad0588629 100644
--- a/plugins/DbEditorPP/src/main.cpp
+++ b/plugins/DbEditorPP/src/main.cpp
@@ -269,7 +269,7 @@ int PreShutdown(WPARAM wParam,LPARAM lParam)
INT_PTR ServiceMode(WPARAM wParam,LPARAM lParam)
{
bServiceMode = TRUE;
- return 0;
+ return SERVICE_ONLYDB; // load database and then call us
}
INT_PTR ImportFromFile(WPARAM wParam,LPARAM lParam)
diff --git a/plugins/VersionInfo/src/services.cpp b/plugins/VersionInfo/src/services.cpp
index 4efa482404..0efdb387f4 100644
--- a/plugins/VersionInfo/src/services.cpp
+++ b/plugins/VersionInfo/src/services.cpp
@@ -72,5 +72,5 @@ INT_PTR ServiceModeService(WPARAM wParam, LPARAM lParam)
{
bServiceMode = 1;
DoDebugTo(TO_ASK);
- return 0;
+ return SERVICE_ONLYDB; // load database and open a window
}
diff --git a/src/core/modules.cpp b/src/core/modules.cpp
index 1023506247..6ada0cf650 100644
--- a/src/core/modules.cpp
+++ b/src/core/modules.cpp
@@ -25,7 +25,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "../modules/plugins/plugins.h"
// other static variables
-static BOOL bServiceMode = FALSE;
static DWORD mainThreadId;
static HANDLE hMainThread;
static HANDLE hMissingService;
@@ -67,6 +66,7 @@ void UnloadUtilsModule(void);
void UnloadButtonModule(void);
void UnloadClcModule(void);
void UnloadContactListModule(void);
+void UnloadDatabase(void);
void UnloadEventsModule(void);
void UnloadSslModule(void);
void UnloadNetlibModule(void);
@@ -101,11 +101,16 @@ int LoadDefaultModules(void)
// if ( LoadErrorsModule()) return 1;
- bServiceMode = LoadServiceModePlugin();
- switch (bServiceMode) {
- case 1: return 0; // stop loading here
- case 0: break;
- default: return 1;
+ switch ( LoadServiceModePlugin()) {
+ case SERVICE_CONTINUE: // continue loading Miranda normally
+ break;
+ case SERVICE_ONLYDB: // load database and go to the message cycle
+ return 0;
+ case SERVICE_MONOPOLY: // unload database and go to the message cycle
+ UnloadDatabase();
+ return 0;
+ default: // smth went wrong, terminating
+ return 1;
}
if ( LoadSkinSounds()) return 1;
diff --git a/src/modules/plugins/newplugins.cpp b/src/modules/plugins/newplugins.cpp
index dec6102770..32214a1c52 100644
--- a/src/modules/plugins/newplugins.cpp
+++ b/src/modules/plugins/newplugins.cpp
@@ -592,18 +592,21 @@ void SetServiceModePlugin(pluginEntry *p)
int LoadServiceModePlugin(void)
{
if (serviceModePlugin == NULL)
- return 0;
-
- if (serviceModePlugin->bpi.Load() == 0) {
- serviceModePlugin->pclass |= PCLASS_LOADED;
- if (CallService(MS_SERVICEMODE_LAUNCH, 0, 0) != CALLSERVICE_NOTFOUND)
- return 1;
+ return SERVICE_CONTINUE;
- MessageBox(NULL, TranslateT("Unable to load plugin in Service Mode!"), serviceModePlugin->pluginname, 0);
- return -1;
+ // plugin load failed - terminating Miranda
+ if (serviceModePlugin->bpi.Load() != ERROR_SUCCESS) {
+ Plugin_Uninit(serviceModePlugin);
+ return SERVICE_FAILED;
}
- Plugin_Uninit(serviceModePlugin);
- return -1;
+
+ serviceModePlugin->pclass |= PCLASS_LOADED;
+ INT_PTR res = CallService(MS_SERVICEMODE_LAUNCH, 0, 0);
+ if (res != CALLSERVICE_NOTFOUND)
+ return res;
+
+ MessageBox(NULL, TranslateT("Unable to load plugin in Service Mode!"), serviceModePlugin->pluginname, 0);
+ return SERVICE_FAILED;
}
/////////////////////////////////////////////////////////////////////////////////////////
@@ -754,6 +757,16 @@ int LoadNewPluginsModuleInfos(void)
// Plugins module unloading
// called at the end of module chain unloading, just modular engine left at this point
+void UnloadDatabase(void)
+{
+ if (currDb != NULL) {
+ db_setCurrent(NULL);
+ currDblink->Unload(currDb);
+ currDb = NULL;
+ currDblink = NULL;
+ }
+}
+
void UnloadNewPluginsModule(void)
{
if ( !bModuleInitialized)
@@ -771,12 +784,7 @@ void UnloadNewPluginsModule(void)
if (pluginList_crshdmp)
Plugin_Uninit(pluginList_crshdmp);
- // unload the DB
- if (currDb != NULL) {
- db_setCurrent(NULL);
- currDblink->Unload(currDb);
- currDb = NULL;
- }
+ UnloadDatabase();
for (int k = pluginList.getCount()-1; k >= 0; k--) {
pluginEntry* p = pluginList[k];