NERvDN Library
0.2.0.20160420-0019
NERvLibrary - Nerve Gear Developer Network
|
This tutorial will show you how to write a minimal plug-in for SAO Utils with the just-fit and completed codes. You can also find all the details and hints after the sample codes.
The completed project is located in the
samples\Plug-in Demo
folder.
I would like to start with one single CPP with all the source codes for a minimal completed plug-in to show you how simple it is to write a plug-in for SAO Utils.
And that's ALL! Quite simple, isn't it?
#include <NERvGear/plugin.h>
This header file implements PluginImpl
class which implements the NERvGear::IPlugin
interface and complete most of the essential codes for a plug-in component.
#include <NERvGear/object.h>
This header file includes many things that you need to implement a component. Actually the NERvGear/plugin.h
header also requires this file because plug-in is one kind of component.
#include <NERvGear/NERvSDK.h>
This header file includes almost everything(except two headers listed above and some interfaces) of the SDK in it, and it also manage the version of the APIs. You can always include this when you are confused with the API entries.
We recommend you to use the using-directive syntax such as using namespace NERvGear
in your source files and use scope resolution operator syntax such as ::NERvGear::FooBar
in your header files.
The NERvGear::PluginImpl
class helps you with most of the codes to implement NERvGear::IPlugin
interface. You can override some of the methods of NERvGear::IPlugin
on demand then pass to superclass using return PluginImpl::OnXXX()
at the end if your plug-in goes without any problems.
NERvGear calls these methods of NERvGear::IPlugin
when:
Methods | Timing | Component Resources |
---|---|---|
OnInitial() | On program startup or enabling a plug-in | May be unavailable |
OnReady() | On both plug-in and program are ready | Available |
OnConfig() | When user trying to config a plug-in | Available |
OnRelease() | On program exit or disabling a plug-in | May be unavailable |
See NERvGear Interfaces Reference for more details about
NERvGear::IPlugin
interface.
We strongly recommend developers to enable the /DEBUG
linker switch even for the release builds, and if you want a method-resolved call stack when your plug-in crashes, you can use
instead of
to declare your classes.
IPlugin::OnInitial()
should return E_FAILED
if your plug-in could not be initialized or some of the resources are not available. NERvGear will stop loading a plug-in when its OnInitial()
method failed.
IPlugin::OnRelease()
could return E_PENDING
when your plug-in is still busying doing something or there're some reasons that your plug-in could not be terminated immediately. NERvGear will stop unloading a plug-in if its OnRelease()
method failed.
We use a macro block to declare information for a plug-in, like:
Same as other components, each SAO Utils plug-in must contain this block to describe itself, but components use NVG_*_OBJECT_INFO
macros to do this work.
A plug-in can provide or expose implementations(objects) of some components to other plug-ins by registering them explicitly in the component registeration macro block like:
Or if your plug-in does not serve any objects, just simply declare as:
See Aggregation (COM) for details about object aggregation.