diff options
| author | Gluzskiy Alexandr <sss123next@list.ru> | 2010-08-05 00:46:19 +0300 | 
|---|---|---|
| committer | Gluzskiy Alexandr <sss123next@list.ru> | 2010-08-05 00:46:19 +0300 | 
| commit | a8527496d9c8eb81710e718be7be8a9ae62a48b4 (patch) | |
| tree | 962767f520dd3dea8f23fbd7161114fcab1431ff /core | |
| parent | 03951c212bc3054a6b89a9fff9a125bace52224d (diff) | |
	new file:   api/core_services.h
	modified:   api/pluginapi.h
	modified:   core/main.cpp
	modified:   core/plugin.h
	new file:   core/sqlite3.dll
	new file:   lib/libsqlite3.a
	new file:   modules/dbsqlite/Makefile
	new file:   modules/dbsqlite/main.cpp
	new file:   modules/dbsqlite/sqlite3.h
	modified:   modules/example/main.cpp
Diffstat (limited to 'core')
| -rw-r--r-- | core/main.cpp | 54 | ||||
| -rw-r--r-- | core/plugin.h | 11 | ||||
| -rw-r--r-- | core/sqlite3.dll | bin | 0 -> 541683 bytes | 
3 files changed, 38 insertions, 27 deletions
diff --git a/core/main.cpp b/core/main.cpp index b5ff8e4..1068193 100644 --- a/core/main.cpp +++ b/core/main.cpp @@ -13,12 +13,15 @@ using namespace std;  list<plugin*> plugins;  list<service*> services; +bool shutdown_called = false; +  int LoadModules();  INT_PTR CallService(const char *name, WPARAM w, LPARAM l);  HANDLE CreateServiceFunction(const char *name, SERVICE pService);  DWORD WINAPI OnModulesLoadedThread( LPVOID lpParam );  int ServiceExists(const char *name);  SERVICE Test(WPARAM, LPARAM); +SERVICE Shutdown(WPARAM, LPARAM);  PLUGINLINK link = {&CreateServiceFunction, &CallService, &ServiceExists}; @@ -26,11 +29,12 @@ int main(int argc, char *argv[])  {  	if(LoadModules())  		return 1; //something wrong +	CreateServiceFunction("Core/Test", (SERVICE)Test); +	CreateServiceFunction("Core/Shutdown", (SERVICE)Shutdown);  	for(list<plugin*>::iterator p = plugins.begin(); p != plugins.end(); p++) //initializing plugins  	{  		(*p)->getFuncs().load(&link);  	} -	CreateServiceFunction("Test", (SERVICE)Test);  	for(list<plugin*>::iterator p = plugins.begin(); p != plugins.end(); p++)  	{  		if((*p)->getFuncs().loaded) @@ -38,9 +42,24 @@ int main(int argc, char *argv[])  			CreateThread(NULL, 0, OnModulesLoadedThread, (LPVOID)(*p)->getFuncs().loaded, 0, 0);  		}  	} -	CallService("GetPluginInfoList", 0, 0);  	for(;;) +	{ +		if(shutdown_called) +		{ +			plugin *db; +			for(list<plugin*>::iterator p = plugins.begin(); p != plugins.end(); p++) +			{ +				if((*p)->getPluginInfo()->flags == F_DB_PLUGIN) +					db = (*p); +				else +					delete (*p); //is it right? , at least do not crasing... +			} +			delete db; +			plugins.clear(); +			break; +		}  		Sleep(1000); +	}  	return 0;  } @@ -61,10 +80,11 @@ int LoadModules()  		funcs.info = (SetPluginInfo)GetProcAddress(hPlugin, "SetPluginInfo");  		funcs.load = (Load)GetProcAddress(hPlugin, "Load");  		funcs.loaded = (OnModulesLoaded)GetProcAddress(hPlugin, "OnModulesLoaded"); +		funcs.unload = (Unload)GetProcAddress(hPlugin, "Unload");  		if(funcs.info && funcs.load)  		{  			PLUGININFO *pi = funcs.info(); -			plugins.push_back(new plugin(hPlugin, funcs, pi->shortName)); +			plugins.push_back(new plugin(hPlugin, funcs, pi));  		}  		else  			FreeLibrary(hPlugin); @@ -86,38 +106,25 @@ int plugin::setHandle(const HMODULE &hMod)  	return 0;  } -int plugin::setName(const char *name) -{ -	if(strlen(name)< 2) -		return 1; -	szPluginName = new char [strlen(name)+1]; -	strcpy(szPluginName, name); -	return 0; -} - -const char* plugin::getName() -{ -	return szPluginName; -}  const plugin::exported_funcs_s plugin::getFuncs()  {  	return funcs;  } -const PLUGININFO plugin::getPluginInfo() +PLUGININFO *plugin::getPluginInfo()  {  	return pluginInfo;  } -plugin::plugin(const HMODULE hMod, const exported_funcs_s fnct, const char *name) +plugin::plugin(const HMODULE hMod, const exported_funcs_s fnct, PLUGININFO *info)  {  	hModule = hMod;  	funcs = fnct; -	szPluginName = new char [strlen(name)+1]; -	strcpy(szPluginName, name); +	pluginInfo = info;  }  plugin::~plugin()  { +	if(funcs.unload) +		funcs.unload();  	FreeLibrary(hModule); -	free(szPluginName);  }  service::service(const char *name, SERVICE service)  { @@ -164,6 +171,11 @@ SERVICE Test(WPARAM, LPARAM)  	return 0;  } +SERVICE Shutdown(WPARAM, LPARAM) +{ +	shutdown_called = true; +} +  DWORD WINAPI OnModulesLoadedThread( LPVOID lpParam )  {  	OnModulesLoaded &l = (OnModulesLoaded&)lpParam; diff --git a/core/plugin.h b/core/plugin.h index f79c2de..c84ea0b 100644 --- a/core/plugin.h +++ b/core/plugin.h @@ -7,6 +7,7 @@  typedef PLUGININFO * (__cdecl * SetPluginInfo) ();  typedef int (__cdecl * Load) (PLUGINLINK *link);  typedef int (__cdecl * OnModulesLoaded) (); +typedef int (__cdecl * Unload) ();  class plugin   { @@ -16,19 +17,17 @@ public:  		SetPluginInfo info;  		Load load;  		OnModulesLoaded loaded; +		Unload unload;  	};  	const HMODULE getHmodule();  	const exported_funcs_s getFuncs(); -	const PLUGININFO getPluginInfo(); +	PLUGININFO *getPluginInfo();  	int setHandle(const HMODULE &hMod); -	int setName(const char *name); -	const char *getName(); -	plugin(const HMODULE hModule, const exported_funcs_s fnct, const char *name); +	plugin(const HMODULE hModule, const exported_funcs_s fnct, PLUGININFO *info);  	~plugin();  private:  	HMODULE hModule; -	char *szPluginName;  	exported_funcs_s funcs; -	PLUGININFO pluginInfo; +	PLUGININFO *pluginInfo;  };  #endif diff --git a/core/sqlite3.dll b/core/sqlite3.dll Binary files differnew file mode 100644 index 0000000..829c80e --- /dev/null +++ b/core/sqlite3.dll  | 
