diff options
| author | Gluzskiy Alexandr <sss123next@list.ru> | 2010-10-19 11:31:43 +0300 | 
|---|---|---|
| committer | Gluzskiy Alexandr <sss123next@list.ru> | 2010-10-19 11:31:43 +0300 | 
| commit | 5d367f0e54fd1bf62f22b869ef75765ec9383e2c (patch) | |
| tree | a3d2f900faab225b53d59bd8fb5add98520c589a /core | |
| parent | b50a786c2758a34eff01a491ef103bd5a053ba90 (diff) | |
hz..
Diffstat (limited to 'core')
| -rw-r--r-- | core/commonheaders.h | 30 | ||||
| -rw-r--r-- | core/main.cpp | 20 | ||||
| -rw-r--r-- | core/modules.cpp | 49 | ||||
| -rw-r--r-- | core/modules.h | 30 | ||||
| -rw-r--r-- | core/services.cpp | 58 | ||||
| -rw-r--r-- | core/services.h | 12 | 
6 files changed, 98 insertions, 101 deletions
diff --git a/core/commonheaders.h b/core/commonheaders.h index ab42690..1bf5866 100644 --- a/core/commonheaders.h +++ b/core/commonheaders.h @@ -1,37 +1,21 @@  #ifndef COMMONHEADERS_H_INCLUDED
  #define COMMONHEADERS_H_INCLUDED
 -/*// For compilers that support precompilation, includes "wx.h". -#include <wx/wxprec.h> */ - -/* -#ifdef __BORLANDC__ -#pragma hdrstop -#endif - -#ifndef WX_PRECOMP -// Include your minimal set of headers here, or wx.h -#include <wx/wx.h> -#endif -*/ -/* -#include <wx/dynlib.h> -#include <wx/dir.h> -#include <wx/log.h> -#include <wx/stdpaths.h> -#include <wx/thread.h> -*/  #include <list> -//#include <boost/thread/mutex.hpp>  #include <boost/thread.hpp> -#include <boost/filesystem.hpp> +#include <boost/filesystem.hpp>
 +#include <ace/ACE.h>  #include <ace/DLL.h> -#include <ace/DLL_Manager.h> +#include <ace/OS_main.h>
 +#include <ace/OS_NS_string.h>
 +#include <ace/OS_NS_stdlib.h>
 +#include <ace/Log_Msg.h>  #include "../api/ec_pluginapi.h"  #include "services.h"  #include "modules.h"
 +#include "globals.h"
  #endif // COMMONHEADERS_H_INCLUDED
 diff --git a/core/main.cpp b/core/main.cpp index a724bc8..13de647 100644 --- a/core/main.cpp +++ b/core/main.cpp @@ -8,6 +8,7 @@ boost::mutex service_list_mutex;  void CreateServiceFunction(const char* name, SERVICE svc);  void* CallService(const char *,void*);  int ServiceExists(const char *); +ACE_Log_Msg logger;  PLUGINLINK pluglink = {&CreateServiceFunction, &CallService, &ServiceExists}; @@ -16,19 +17,24 @@ PLUGINLINK pluglink = {&CreateServiceFunction, &CallService, &ServiceExists};  HINSTANCE hInst;  int __stdcall WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPSTR lpCmdLine, __in int nShowCmd )  #else -int main() +int ACE_MAIN(int argc, char *argv[])  #endif  {  #ifdef _WIN32  	hInst = hInstance;  #endif -    void load_modules(); -    void run_plugins(); -    load_modules(); -    run_plugins(); -    while(true) +	void load_modules(); +	void run_plugins(); +	logger.log(LM_DEBUG, "Loading plugins...\n"); +	load_modules(); +	logger.log(LM_DEBUG, "Running plugins...\n"); +	run_plugins(); +	while(true) +	{ +		logger.log(LM_DEBUG, "Main threas sleeping...\n");  		boost::this_thread::sleep(boost::posix_time::seconds(10)); //warning from compiller on this string can be safely ignored -    return 0; +	} +	return 0;  } diff --git a/core/modules.cpp b/core/modules.cpp index 4910d71..8df3288 100644 --- a/core/modules.cpp +++ b/core/modules.cpp @@ -7,17 +7,24 @@ extern PLUGINLINK pluglink;  void load_modules()  {  	std::string path = boost::filesystem::initial_path().directory_string(); //need some workaround for windows than called indirectly -    path.append("/plugins"); +	path.append("/plugins"); +	logger.log(LM_DEBUG, "Loading plugins...\n");  	boost::filesystem::path pth(path);  	if(!boost::filesystem::is_directory(pth))  		return; -	boost::filesystem::directory_iterator i(pth), end = boost::filesystem::directory_iterator(); +	boost::filesystem::directory_iterator i(pth), end;  	while(i != end)  	{ -		if(boost::filesystem::is_directory((*i).status())) //we not look in subdirectories +		if(boost::filesystem::is_directory(*i)) //we not look in subdirectories +		{ +			++i;  			continue; +		}  		if(!boost::filesystem::status_known((*i).status())) +		{ +			++i;  			continue; +		}  		bool is_plugin = true;  		plugin::exported_functions_s *funcs = new plugin::exported_functions_s;  		memset(&funcs,0,sizeof(plugin::exported_functions_s)); @@ -39,34 +46,34 @@ void load_modules()  			delete dll;  			continue;  		} -        PLUGININFO *info = funcs->SetPluginInfo(); -        plugins.push_back(new plugin(dll, info, funcs)); +		PLUGININFO *info = funcs->SetPluginInfo(); +		plugins.push_back(new plugin(dll, info, funcs));  		++i;		  	}  }  void run_plugins()  { //now for testing only -    if(!plugins.empty()) -    { -        std::list<plugin*>::iterator end = plugins.end(); -        for(std::list<plugin*>::iterator i = plugins.begin(); i != end; ++i) -        { -            (*i)->get_exported_functions()->Load(&pluglink); -            (*i)->get_exported_functions()->OnModulesLoaded(); -        } -    } +	if(!plugins.empty()) +	{ +		std::list<plugin*>::iterator end = plugins.end(); +		for(std::list<plugin*>::iterator i = plugins.begin(); i != end; ++i) +		{ +			(*i)->get_exported_functions()->Load(&pluglink); +			(*i)->get_exported_functions()->OnModulesLoaded(); +		} +	}  }  plugin::plugin(ACE_DLL *lib, PLUGININFO *info, exported_functions_s *funcs)  { -    if(lib) -        plug = lib; -    if(info) -        plugininfo = info; -    if(funcs) -        exported_funcs = funcs; +	if(lib) +		plug = lib; +	if(info) +		plugininfo = info; +	if(funcs) +		exported_funcs = funcs;  }  const plugin::exported_functions_s* plugin::get_exported_functions()  { -    return exported_funcs; +	return exported_funcs;  } diff --git a/core/modules.h b/core/modules.h index 9894894..5ba7a11 100644 --- a/core/modules.h +++ b/core/modules.h @@ -9,22 +9,22 @@ typedef int (*unload)();  class plugin  {  public: -    struct exported_functions_s -    { -        load Load; -        on_modules_loaded OnModulesLoaded; -        unload Unload; -        set_plugin_info SetPluginInfo; -    }; -    ACE_DLL *get_plugin(); -    void set_plugin(); -    const exported_functions_s *get_exported_functions(); -    plugin(ACE_DLL *lib, PLUGININFO *info, exported_functions_s *funcs); -    ~plugin(); +	struct exported_functions_s +	{ +		load Load; +		on_modules_loaded OnModulesLoaded; +		unload Unload; +		set_plugin_info SetPluginInfo; +	}; +	ACE_DLL *get_plugin(); +	void set_plugin(); +	const exported_functions_s *get_exported_functions(); +	plugin(ACE_DLL *lib, PLUGININFO *info, exported_functions_s *funcs); +	~plugin();  private: -    ACE_DLL *plug; -    exported_functions_s *exported_funcs; -    PLUGININFO *plugininfo; +	ACE_DLL *plug; +	exported_functions_s *exported_funcs; +	PLUGININFO *plugininfo;  };
  #endif // MODULE_H_INCLUDED
 diff --git a/core/services.cpp b/core/services.cpp index 836b4c6..3c4baed 100644 --- a/core/services.cpp +++ b/core/services.cpp @@ -6,54 +6,54 @@ extern boost::mutex service_list_mutex;  int ServiceExists(const char *name);  void CreateServiceFunction(const char* name, SERVICE svc)  { -    if(!ServiceExists(name)) -        services.push_back(new service(name, svc)); +	if(!ServiceExists(name)) +		services.push_back(new service(name, svc));  }  void* CallService(const char *name,void* data)  { -    if(!services.empty()) -    { -        service_list_mutex.lock(); -        std::list<service*>::iterator end = services.end(); -        for(std::list<service*>::iterator i = services.begin(); i != end; ++i) -        { -            if(!strcmp((*i)->getName(), name)) -                return (*i)->getService()(data); -        } -        service_list_mutex.unlock(); -    } -    return 0; +	if(!services.empty()) +	{ +		service_list_mutex.lock(); +		std::list<service*>::iterator end = services.end(); +		for(std::list<service*>::iterator i = services.begin(); i != end; ++i) +		{ +			if(!ACE_OS::strcmp((*i)->getName(), name)) +				return (*i)->getService()(data); +		} +		service_list_mutex.unlock(); +	} +	return 0;  }  int ServiceExists(const char *name)  { -    service_list_mutex.lock(); -    if(!services.empty()) -    { -        std::list<service*>::iterator end = services.end(); -        for(std::list<service*>::iterator i = services.begin(); i != end; ++i) -            if(!strcmp((*i)->getName(), name)) -                return 1; -    } -    service_list_mutex.unlock(); -    return 0; +	service_list_mutex.lock(); +	if(!services.empty()) +	{ +		std::list<service*>::iterator end = services.end(); +		for(std::list<service*>::iterator i = services.begin(); i != end; ++i) +			if(!ACE_OS::strcmp((*i)->getName(), name)) +				return 1; +	} +	service_list_mutex.unlock(); +	return 0;  }  service::service(const char* name, SERVICE svc)  { -    pService = svc; -    szName = strdup(name); +	pService = svc; +	szName = ACE_OS::strdup(name);  }  const char* service::getName()  { -    return szName; +	return szName;  }  const SERVICE service::getService()  { -    return pService; +	return pService;  }  service::~service()  { -    free(szName); +	ACE_OS::free(szName);  } diff --git a/core/services.h b/core/services.h index eebe16d..a915294 100644 --- a/core/services.h +++ b/core/services.h @@ -4,13 +4,13 @@  class service  {  public: -    const char *getName(); -    const SERVICE getService(); -    service(const char *name, SERVICE service); -    ~service(); +	const char *getName(); +	const SERVICE getService(); +	service(const char *name, SERVICE service); +	~service();  private: -    char *szName; -    SERVICE pService; +	char *szName; +	SERVICE pService;  };
  #endif // SERVICES_H_INCLUDED
  | 
