Skip to content

Commit

Permalink
Add GetLogObserver() export function in LogWriter.plugin
Browse files Browse the repository at this point in the history
Auto call x3UninitializePlugin() when a plugin is unloading.
  • Loading branch information
rhcad committed Nov 8, 2011
1 parent 6b1549e commit 69a1a0e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 15 deletions.
5 changes: 5 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
x3c - C++ Plugin Framework

2011-11-08

* Add GetLogObserver() export function in LogWriter.plugin
* Auto call x3UninitializePlugin() when a plugin is unloading.

2011-11-01

* Add HookManager plugin and test case.
Expand Down
2 changes: 1 addition & 1 deletion code/pkg_Core/Interface/Log/Ix_LogObserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#ifndef X3_LOG_ILOGOBSERVER_H_
#define X3_LOG_ILOGOBSERVER_H_

#include "Ix_Object.h"
#include <string>

//! logging output observer interface.
/*! Use RegisterLogObserver(Ix_LogObserver*) to register a observer,
Expand Down
4 changes: 4 additions & 0 deletions code/pkg_Core/Interface/Module/XModuleImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ Cx_Module::~Cx_Module()

void Cx_Module::ClearModuleItems()
{
typedef void (*F)();
F f = (F)GetProcAddress(m_hModule, "x3UninitializePlugin");
if (f) f();

Cx_ModuleItem::ClearModuleItems();
}

Expand Down
16 changes: 14 additions & 2 deletions code/pkg_Core/Modules/LogWriter/Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ static CLogObserver* s_pObserver = NULL;

OUTAPI bool x3InitializePlugin()
{
ASSERT(!s_pObserver);
s_pObserver = new CLogObserver;
if (!s_pObserver)
{
s_pObserver = new CLogObserver;
}

return true;
}
Expand All @@ -16,3 +18,13 @@ OUTAPI void x3UninitializePlugin()
{
x3::SafeDelete(s_pObserver);
}

OUTAPI Ix_LogObserver* GetLogObserver()
{
if (!s_pObserver)
{
s_pObserver = new CLogObserver;
}

return s_pObserver;
}
26 changes: 14 additions & 12 deletions tools/makeplugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
Function: Create a plugin project based on Win32DllTempl or MFCExtTempl.
This script has been tested with ActivePython 2.7.
Usage: makeplugin.py projname pkgname basetype
Usage: python makeplugin.py projname [pkgname] [basetype] [basepkg]
or double click the file 'makeplugin.py'.
projname: name of the new project.
pkgname: package name of the new project, the default value
is 'pkg_Example'.
basetype: 'mfc', 'win32', 'view' or project name in pkg_Example,
the default value is 'win32'.
pkgname: package name of the new project, the default value is 'pkg_Example'.
basetype: 'mfc', 'win32', 'view' or project name in pkg_Example, the default value is 'win32'.
basepkg: package name of the template project, the default value is 'pkg_Example'.
Creator: ooyg <rhcad@hotmail.com>
Date: 2011.10.9
Expand All @@ -27,7 +28,7 @@ def xlat(match):
return rx.sub(xlat, text)

def copyfiles(srcdir, destdir, pairs, callback=None):
if srcdir.find(".svn") > 0:
if srcdir.find(".svn") > 0 or srcdir.find(".user") > 0:
return
if not os.path.exists(destdir):
os.makedirs(destdir)
Expand All @@ -49,9 +50,9 @@ def copyfiles(srcdir, destdir, pairs, callback=None):
else:
print(destfile)

def makeproj(projname, pkgname, baseproj):
def makeproj(projname, pkgname, baseproj, basepkg):
codepath = os.path.abspath('../code')
basepath = os.path.join(codepath, 'pkg_Example', 'Modules', baseproj)
basepath = os.path.join(codepath, basepkg, 'Modules', baseproj)

if not os.path.exists(basepath):
raise OSError, basepath
Expand All @@ -61,7 +62,7 @@ def makeproj(projname, pkgname, baseproj):
raise AttributeError, projname

destdir = os.path.join(codepath, pkgname, 'Modules', projname)
pairs = {baseproj:projname, 'pkg_Example':pkgname}
pairs = {baseproj:projname, basepkg:pkgname}

def matchfile(filename, pairs):
if filename.find(".dsp") > 0 or filename.find(".vc") > 0:
Expand All @@ -78,7 +79,7 @@ def matchproj(filename, pairs):
copyfiles(projects, projects, pairs, matchproj)

if __name__=="__main__":
def inputparam(index, prompt, default=''):
def inputparam(index, prompt, the default=''):
if len(sys.argv) > index:
ret = sys.argv[index]
else:
Expand All @@ -87,12 +88,13 @@ def inputparam(index, prompt, default=''):
return ret

projname = inputparam(1, 'Project name: ')
pkgname = inputparam(2, 'Package name (pkg_Example): ', 'pkg_Example')
pkgname = inputparam(2, 'Target package name (pkg_Example): ', 'pkg_Example')
baseproj = inputparam(3, 'Template project (win32, mfc, view, ' \
'or project name in pkg_Example): ', 'win32')
basepkg = inputparam(4, 'Source package name (pkg_Example): ', 'pkg_Example')

if baseproj == 'win32': baseproj = 'Win32DllTempl'
if baseproj == 'mfc': baseproj = 'MFCExtTempl'
if baseproj == 'view': baseproj = 'HelloView'

makeproj(projname, pkgname, baseproj)
makeproj(projname, pkgname, baseproj, basepkg)

0 comments on commit 69a1a0e

Please sign in to comment.