summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss123next@list.ru>2010-10-15 08:53:21 +0300
committerGluzskiy Alexandr <sss123next@list.ru>2010-10-15 08:53:21 +0300
commit7890dccf61ba5e92d76e79c121b926ac515d6747 (patch)
tree52b74bdb31abbf0e18fde416683fe57e3a79807c
parent076c9cfcf33e06218805ad0412a806005c3c63f7 (diff)
services
-rw-r--r--api/pluginapi.h2
-rw-r--r--core/main.cpp8
-rw-r--r--core/modules.cpp13
-rw-r--r--core/services.cpp54
4 files changed, 70 insertions, 7 deletions
diff --git a/api/pluginapi.h b/api/pluginapi.h
index 274db17..3e9649b 100644
--- a/api/pluginapi.h
+++ b/api/pluginapi.h
@@ -12,7 +12,7 @@ typedef void* (*SERVICE)(void*);
typedef struct
{
- void* (*CreateServiceFunction)(const char *,SERVICE);
+ void (*CreateServiceFunction)(const char *,SERVICE);
void* (*CallService)(const char *,void*);
int (*ServiceExists)(const char *);
} PLUGINLINK;
diff --git a/core/main.cpp b/core/main.cpp
index 20b8501..716b7b0 100644
--- a/core/main.cpp
+++ b/core/main.cpp
@@ -1,8 +1,14 @@
#include "commonheaders.h"
+std::list<plugin*> plugins;
+std::list<service*> services;
+void CreateServiceFunction(const char* name, SERVICE svc);
+void* CallService(const char *,void*);
+int ServiceExists(const char *);
-PLUGINLINK pluglink;
+
+PLUGINLINK pluglink = {&CreateServiceFunction, &CallService, &ServiceExists};
class EvilCore: public wxApp
{
diff --git a/core/modules.cpp b/core/modules.cpp
index b509c6f..09ee63b 100644
--- a/core/modules.cpp
+++ b/core/modules.cpp
@@ -1,6 +1,6 @@
#include "commonheaders.h"
-std::list<plugin*> plugins;
+extern std::list<plugin*> plugins;
extern PLUGINLINK pluglink;
@@ -80,12 +80,15 @@ void load_modules()
}
void run_plugins()
-{
+{ //now for testing only
if(!plugins.empty())
- for(std::list<plugin*>::iterator i = plugins.begin(); i != plugins.end(); i++)
{
- (*i)->get_exported_functions()->Load(&pluglink);
- (*i)->get_exported_functions()->OnModulesLoaded();
+ 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();
+ }
}
}
diff --git a/core/services.cpp b/core/services.cpp
new file mode 100644
index 0000000..56ee05e
--- /dev/null
+++ b/core/services.cpp
@@ -0,0 +1,54 @@
+#include "commonheaders.h"
+
+extern std::list<service*> services;
+
+int ServiceExists(const char *name);
+void CreateServiceFunction(const char* name, SERVICE svc)
+{
+ if(!ServiceExists(name))
+ services.push_back(new service(name, svc));
+}
+
+void* CallService(const char *name,void* data)
+{
+ 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 (*i)->getService()(data);
+ }
+ }
+ return 0;
+}
+int ServiceExists(const char *name)
+{
+ 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;
+ }
+ return 0;
+}
+
+service::service(const char* name, SERVICE svc)
+{
+ pService = svc;
+ szName = strdup(name);
+}
+
+const char* service::getName()
+{
+ return szName;
+}
+const SERVICE service::getService()
+{
+ return pService;
+}
+service::~service()
+{
+ free(szName);
+}