summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGluzskiy Alexandr <sss123next@list.ru>2010-11-22 04:34:42 +0200
committerGluzskiy Alexandr <sss123next@list.ru>2010-11-22 04:34:42 +0200
commitba3095b937bd051ca1438a837245d21db300a0d6 (patch)
tree886b316e24f52e60314d6fb1d4b63ea741f0506e
parentbaba7489c48a759bdf6479e718a28f1339aaac54 (diff)
core services
-rw-r--r--api/ec_pluginapi.h10
-rw-r--r--core/basic-services.cpp75
-rw-r--r--core/commonheaders.h3
-rw-r--r--core/constants.h2
-rw-r--r--core/core.project1
-rw-r--r--core/main.cpp49
-rw-r--r--core/utf8.cpp1
7 files changed, 117 insertions, 24 deletions
diff --git a/api/ec_pluginapi.h b/api/ec_pluginapi.h
index 6e4073b..4176819 100644
--- a/api/ec_pluginapi.h
+++ b/api/ec_pluginapi.h
@@ -19,13 +19,17 @@
#define PLUGINAPI_H_INCLUDED
/*
-this is genereic plugin api header, only baisc c/c++ here
-we need to support also non wxwidgets plugins
-*/
+ * this is genereic plugin api header, only baisc c/c++ here
+ * we need to support also non wxwidgets plugins
+ */
typedef void* (*SERVICE)(void*);
+/*
+ * CreateServiceFunction should be called with service name like: PluginName/ServiceName
+ * EC/* reserved for core services
+ */
typedef struct
{
diff --git a/core/basic-services.cpp b/core/basic-services.cpp
index 536a718..2cfcecb 100644
--- a/core/basic-services.cpp
+++ b/core/basic-services.cpp
@@ -22,8 +22,83 @@ void *get_version(void*)
return (void*)ec_version;
}
+void *get_service_list(void*)
+{
+ extern std::list<service*> services;
+ if(!services.empty())
+ {
+ extern boost::mutex service_list_mutex;
+ std::string svclist;
+ service_list_mutex.lock();
+ std::list<service*>::iterator end = services.end();
+ for(std::list<service*>::iterator i = services.begin(); i != end; ++i)
+ {
+ svclist.append((*i)->getName());
+ svclist.append("\n");
+ }
+ service_list_mutex.unlock();
+ svclist.erase((std::string::size_type)svclist.length(), 1);
+ char *str = new char [svclist.length()+1];
+ ACE_OS::strcpy(str, svclist.c_str());
+ return str;
+ }
+ return 0;
+}
+
+void *get_plugin_list(void*)
+{
+ extern std::list<plugin*> plugins;
+ if(!plugins.empty())
+ {
+ extern boost::mutex plugin_list_mutex;
+ plugin_list_mutex.lock();
+ pluglist *plugs = new pluglist;
+ int count = 0;
+ std::list<plugin*>::iterator end = plugins.end();
+ for(std::list<plugin*>::iterator i = plugins.begin(); i != end; ++i, ++count)
+ {
+// plugs->plugins[count] = new PLUGININFO*;
+ plugs->plugins[count] = (PLUGININFO*)(*i)->get_plugininfo();
+ }
+ plugin_list_mutex.unlock();
+ plugs->count = count;
+ return plugs;
+ }
+ return 0;
+}
+
+void *halt_request(void*)
+{
+ extern bool halt_requested;
+ extern void terminate();
+ halt_requested = true;
+ terminate();
+ return 0;
+}
+
+void *toutf16(void* utf8)
+{
+ return wcsdup(toUTF16((char*)utf8).c_str());
+}
+void *wchartoutf8(void* utf8)
+{
+ return ACE_OS::strdup(toUTF8((wchar_t*)utf8).c_str());
+}
+
+void *chartoutf8(void* utf8)
+{
+ return ACE_OS::strdup(toUTF8((char*)utf8).c_str());
+}
+
void register_core_services()
{
CreateServiceFunction("EC/GetVersionInt", (SERVICE)get_version);
+ CreateServiceFunction("EC/GetServiceList", (SERVICE)get_service_list);
+ CreateServiceFunction("EC/RequestHalt", (SERVICE)halt_request);
+ CreateServiceFunction("EC/GetPluginList", (SERVICE)get_plugin_list);
+
+ CreateServiceFunction("EC/toUtf16", (SERVICE)toutf16);
+ CreateServiceFunction("EC/WCHARtoUtf8", (SERVICE)wchartoutf8);
+ CreateServiceFunction("EC/CHARtoUtf8", (SERVICE)chartoutf8);
}
diff --git a/core/commonheaders.h b/core/commonheaders.h
index a5bd4ef..a838775 100644
--- a/core/commonheaders.h
+++ b/core/commonheaders.h
@@ -40,7 +40,8 @@
#include "constants.h"
#include "../api/ec_pluginapi.h"
#include "services.h"
-#include "modules.h"
+#include "modules.h"
+#include "../api/ec_services.h"
#include "globals.h"
#include "utf8.h"
diff --git a/core/constants.h b/core/constants.h
index d183c35..0d7564d 100644
--- a/core/constants.h
+++ b/core/constants.h
@@ -17,6 +17,6 @@
#ifndef CONSTANTS_H
#define CONSTANTS_H
-const unsigned long ec_version = 0x00000001;
+const unsigned long ec_version = 0x00000001; //dword encoded 00.00.00.00
#endif \ No newline at end of file
diff --git a/core/core.project b/core/core.project
index aa4654e..c576751 100644
--- a/core/core.project
+++ b/core/core.project
@@ -22,6 +22,7 @@
<File Name="modules.h"/>
<File Name="services.h"/>
<File Name="../api/ec_pluginapi.h"/>
+ <File Name="../api/ec_services.h"/>
</VirtualDirectory>
<Settings Type="Executable">
<Configuration Name="Debug" CompilerType="gnu gcc" DebuggerType="GNU gdb debugger" Type="Executable" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
diff --git a/core/main.cpp b/core/main.cpp
index 64c14d5..4a71738 100644
--- a/core/main.cpp
+++ b/core/main.cpp
@@ -22,10 +22,32 @@ boost::mutex plugin_list_mutex;
std::list<service*> services;
boost::mutex service_list_mutex;
ACE_Log_Msg logger;
+bool halt_requested = false;
PLUGINLINK pluglink = {&CreateServiceFunction, &CallService, &ServiceExists};
+int on_exit()
+{
+ plugin_list_mutex.lock();
+ 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)
+ delete *i;
+ services.clear();
+ }
+ if(!plugins.empty())
+ {
+ std::list<plugin*>::iterator end = plugins.end();
+ for(std::list<plugin*>::iterator i = plugins.begin(); i != end; ++i)
+ delete *i;
+ plugins.clear();
+ }
+ return 0;
+}
+
#ifdef _WIN32
HINSTANCE hInst;
int __stdcall WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPSTR lpCmdLine, __in int nShowCmd )
@@ -47,27 +69,16 @@ int ACE_MAIN(int argc, char *argv[])
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
+ boost::this_thread::sleep(boost::posix_time::seconds(5));
+ if(halt_requested)
+ break;
}
return 0;
}
-
-int on_exit()
+void terminate()
{
- if(!services.empty())
- {
- std::list<service*>::iterator end = services.end();
- for(std::list<service*>::iterator i = services.begin(); i != end; ++i)
- delete *i;
- services.clear();
- }
- if(!plugins.empty())
- {
- std::list<plugin*>::iterator end = plugins.end();
- for(std::list<plugin*>::iterator i = plugins.begin(); i != end; ++i)
- delete *i;
- plugins.clear();
- }
- return 0;
-} \ No newline at end of file
+ if(on_exit())
+ logger.log(LM_DEBUG, "Something bad happened on exit");
+}
+
diff --git a/core/utf8.cpp b/core/utf8.cpp
index 7b091a8..c5e83e1 100644
--- a/core/utf8.cpp
+++ b/core/utf8.cpp
@@ -36,6 +36,7 @@ std::string toUTF8(std::string str)
}
+
std::wstring toUTF16(std::string str) //convert as much as possible
{
std::wstring ustr;