Skip to content

Commit

Permalink
Add x3core and swig.rule
Browse files Browse the repository at this point in the history
  • Loading branch information
rhcad committed Nov 9, 2011
1 parent 67c60b2 commit 8687104
Show file tree
Hide file tree
Showing 13 changed files with 530 additions and 57 deletions.
10 changes: 2 additions & 8 deletions code/pkg_Core/Interface/PluginManager/PluginManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,8 @@ class CPluginManager
bool enableDelayLoading = true)
{
const wchar_t plugins[] =
L"LogManager.plugin" PLNEXT
L",LogWriter.plugin" PLNEXT
L",ConfigXml.plugin" PLNEXT
L",StringTable.plugin" PLNEXT
L",ChangeManager.plugin" PLNEXT
L",FileUtility.plugin" PLNEXT
L",TextUtility.plugin" PLNEXT
L",PluginManagerEx.plugin" PLNEXT;
L"LogManager LogWriter ConfigXml StringTable ChangeManager "
L"FileUtility TextUtility PluginManagerEx";

if (!LoadPluginManager(subdir, instance))
{
Expand Down
2 changes: 2 additions & 0 deletions code/pkg_Core/Modules/PluginManager/Cx_PluginLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ long Cx_PluginLoader::LoadPluginFiles(const wchar_t* path,
MAX_PATH - len0 < j - i ? MAX_PATH - len0 : j - i);
nameend[j - i] = 0;
ReplaceSlashes(filename);
if (wcschr(nameend, L'.') == NULL)
wcscat_s(filename, MAX_PATH, L".plugin" PLNEXT);
filenames.push_back(filename);
}
i = j;
Expand Down
35 changes: 14 additions & 21 deletions code/pkg_Platform/Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,14 @@
# Makefile

ROOTDIR = ../..
include $(ROOTDIR)/config.mk

SUBDIRS = $(filter-out Interface/, $(sort $(dir $(wildcard */))))
CLEANSUBDIRS = $(addsuffix .clean, $(SUBDIRS))

.PHONY: Modules

Modules:
@echo
@echo Making all in subdirectory $@...
$(MAKE) -C Modules

clean: $(CLEANSUBDIRS)

$(CLEANSUBDIRS):
@cd $(basename $@) ; $(MAKE) clean


ROOTDIR = ../../../..
include $(ROOTDIR)/config.mk

CFLAGS_SO += -I$(INCLUDE_DIR)/pkg_Core/Interface
CFLAGS_SO += -I$(INCLUDE_DIR)/pkg_Platform/Interface

all:
$(CC) $(CFLAGS_SO) -c Cx_Example.cpp
$(CC) $(CFLAGS_SO) -c Plugin.cpp
$(CC) $(CFLAGS_SO) -c Module.cpp
$(CC) $(C_FLAGS_SO) -o $(PLUGINS_DIR)/libx3c_swig.so *.o
clean:
rm -rf *.so
rm -rf *.o
85 changes: 85 additions & 0 deletions code/pkg_Platform/Modules/x3core/Module.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include <UtilFunc/PluginInc.h>
#include <PluginManager/PluginManager.h>
#include <PluginManager/XComCreator.h>
#include <UtilFunc/ConvStr.h>
#include <PluginManager/Ix_PluginLoader2.h>

#ifdef _MSC_VER // hide warnings
#pragma warning(disable:4505) // unreferenced local function has been removed
#pragma warning (push, 2)
#pragma warning(disable:4701) // potentially uninitialized local variable used
#pragma warning(disable:4706) // assignment within conditional expression
#endif
#include "x3core_wrap.cxx"
#ifdef _MSC_VER // hide warnings
#pragma warning (pop)
#endif

static CPluginManager s_loader;
static HMODULE s_hmod = NULL;

#ifdef APIENTRY
BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
s_hmod = (HMODULE)hModule;
}
return TRUE;
}
#endif

bool LoadCorePlugins()
{
return s_loader.LoadCorePlugins(L"../plugins", s_hmod);
}

bool LoadAllPlugins()
{
if (!s_loader.LoadCorePlugins(L"../plugins", s_hmod))
return false;

Ix_PluginLoader* loader = s_loader.GetPluginLoader();
long n;

n = loader->LoadPlugins(L"../plugins");
n = loader->LoadPlugins(L"../plugins", L".pyd");
n = loader->InitializePlugins();

return n >= 0;
}

bool LoadPluginFiles(const char* files)
{
if (!s_loader.Handle())
{
s_loader.LoadPluginManager(L"../plugins", s_hmod);
}

Ix_PluginLoader* loader = s_loader.GetPluginLoader();

return loader->LoadPluginFiles(L"../plugins", x3::a2w(files).c_str(), s_hmod) > 0
&& loader->InitializePlugins() > 0;
}

void UnloadPlugins()
{
s_loader.Unload();
}

std::vector<std::wstring> GetPluginFiles()
{
Cx_Interface<Ix_PluginLoader2> loader(s_loader.GetPluginLoader());
ASSERT(loader.IsNotNull());

std::vector<std::wstring> filenames;
HMODULE hdll;
std::wstring filename;

for (int i = 0; loader->GetPluginFileName(i, hdll, filename); i++)
{
filenames.push_back(filename);
}

return filenames;
}
33 changes: 33 additions & 0 deletions code/pkg_Platform/Modules/x3core/Version.rc2
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Version.rc2 - resources Microsoft Visual C++ does not edit directly
//
// TODO: Change values of FILEVERSION and FileVersion
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,1
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "000004b0"
BEGIN
VALUE "FileDescription", "Adaptor module for python.\0"
VALUE "FileVersion", "1.0.0.1\0"
VALUE "LegalCopyright", "(C) 2008-2011, X3 C++ PluginFramework\0"
VALUE "OriginalFilename", "_x3core.pyd\0"
VALUE "ProductName", "X3 C++ PluginFramework\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0, 1200
END
END
7 changes: 7 additions & 0 deletions code/pkg_Platform/Modules/x3core/testcore.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import x3core as C

assert(C.LoadPluginFiles("ChangeManager"))
files = C.GetPluginFiles()
print(files)

C.UnloadPlugins()
24 changes: 24 additions & 0 deletions code/pkg_Platform/Modules/x3core/x3core.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
%module x3core

%{
#include <UtilFunc/vecfunc.h>
using namespace std;
typedef vector<wstring> WStrVector;

bool LoadCorePlugins();
bool LoadAllPlugins();
bool LoadPluginFiles(const char* files);
void UnloadPlugins();
std::vector<std::wstring> GetPluginFiles();
%}

%include stl.i
using namespace std;

%template(WStrVector) vector<wstring>;

bool LoadCorePlugins();
bool LoadAllPlugins();
bool LoadPluginFiles(const char* files);
void UnloadPlugins();
WStrVector GetPluginFiles();
76 changes: 76 additions & 0 deletions code/pkg_Platform/Modules/x3core/x3core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 2.0.4
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.



from sys import version_info
if version_info >= (2,6,0):
def swig_import_helper():
from os.path import dirname
import imp
fp = None
try:
fp, pathname, description = imp.find_module('_x3core', [dirname(__file__)])
except ImportError:
import _x3core
return _x3core
if fp is not None:
try:
_mod = imp.load_module('_x3core', fp, pathname, description)
finally:
fp.close()
return _mod
_x3core = swig_import_helper()
del swig_import_helper
else:
import _x3core
del version_info
try:
_swig_property = property
except NameError:
pass # Python < 2.2 doesn't have 'property'.
def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
if (name == "thisown"): return self.this.own(value)
if (name == "this"):
if type(value).__name__ == 'SwigPyObject':
self.__dict__[name] = value
return
method = class_type.__swig_setmethods__.get(name,None)
if method: return method(self,value)
if (not static):
self.__dict__[name] = value
else:
raise AttributeError("You cannot add attributes to %s" % self)

def _swig_setattr(self,class_type,name,value):
return _swig_setattr_nondynamic(self,class_type,name,value,0)

def _swig_getattr(self,class_type,name):
if (name == "thisown"): return self.this.own()
method = class_type.__swig_getmethods__.get(name,None)
if method: return method(self)
raise AttributeError(name)

def _swig_repr(self):
try: strthis = "proxy of " + self.this.__repr__()
except: strthis = ""
return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)

try:
_object = object
_newclass = 1
except AttributeError:
class _object : pass
_newclass = 0



def LoadPlugins():
return _x3core.LoadPlugins()
LoadPlugins = _x3core.LoadPlugins
# This file is compatible with both classic and new-style classes.


6 changes: 6 additions & 0 deletions code/pkg_Platform/Modules/x3core/x3core.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifdef _WIN32
#include <winver.h>
LANGUAGE 0, 0 // LANG_NEUTRAL, SUBLANG_NEUTRAL
#pragma code_page(1252)
#include "Version.rc2"
#endif
8 changes: 4 additions & 4 deletions projects/msvc/vcproj/swig.rule
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
>
<Rules>
<CustomBuildRule
Name="Swig Convertor"
DisplayName="swig"
CommandLine="swig.exe -c++ -I$(ProjectDir)..\..\..\code\pkg_Core\Interface -python $(InputPath)"
Outputs="$(IntDir)\$(InputName)._swig"
Name="swig -python"
DisplayName="swig -python"
CommandLine="swig.exe -c++ -python -I$(ProjectDir)..\..\..\code\pkg_Core\Interface -outdir $(OutDir) $(InputPath)"
Outputs="$(InputName)._swig"
FileExtensions="*.i"
ExecutionDescription="swig generating"
>
Expand Down
Loading

0 comments on commit 8687104

Please sign in to comment.