source: Plugins/dynamicResources/Plugin.cpp @ 32

Revision 32, 2.7 KB checked in by art, 12 years ago (diff)
Line 
1#include <nrEngine/nrEngine.h>
2
3#if NR_PLATFORM == NR_PLATFORM_WIN32
4        #define _PluginExport __declspec( dllexport )
5#else
6        #define _PluginExport
7#endif
8
9
10using namespace nrEngine;
11
12#include "Monitor.h"
13
14//---------------------------------------------------------
15// Some globals
16//---------------------------------------------------------
17Engine*  mRoot = NULL;
18bool     mThreaded = true;
19SharedPtr<Monitor>  mTask;
20TaskId   mTaskId = 0;
21
22//---------------------------------------------------------
23// Get full string according to the plugin version
24//---------------------------------------------------------
25extern "C" _PluginExport char* plgVersionString( void )
26{
27        return "Dynamic Resources v0.1 for nrEngine";
28}
29
30//---------------------------------------------------------
31// Initialize the plugin
32//---------------------------------------------------------
33extern "C" _PluginExport int plgInitialize(Engine* root, PropertyList* args)
34{
35        NR_Log(Log::LOG_PLUGIN, "dynamicResources: %s", plgVersionString());
36
37        // check if we user watn to start the monitor in a thread
38        if (args)
39        {
40                if (args->exists("isThreade"))
41                {
42                        Property& prop = (*args)["isThreaded"];
43                        NR_Log(Log::LOG_PLUGIN, "dynamicResources: Parameter 'isThreaded' is given, use it!");
44                        try{
45                                mThreaded = prop.get<bool>();
46                        }catch(boost::bad_any_cast& err)
47                        {
48                                if (!prop.hasUserData())
49                                {
50                                        NR_Log(Log::LOG_PLUGIN, "dynamicResources: Parameter 'isThreaded' does not contain valid value nor user data!");
51                                }else
52                                        mThreaded = *(static_cast<bool*>(prop.getUserData()));
53                        }
54                }
55       
56        }
57               
58        // initilize monitoring task and add it to the kernel
59        mTask.reset(new Monitor(root));
60        if (mThreaded)
61                mTaskId = mRoot->sKernel()->AddTask(mTask, ORDER_LOW, TASK_IS_THREAD);
62        else
63                mTaskId = mRoot->sKernel()->AddTask(mTask, ORDER_LOW);
64       
65        // initialize the new kind of loader
66        mRoot = root;
67       
68        return 0;       
69}
70 
71
72//---------------------------------------------------------
73// Get the engines version number for which this plugin was wrote
74//---------------------------------------------------------
75extern "C" _PluginExport  unsigned int plgEngineVersion( void )
76{
77        return createVersionInteger(0,0,8);
78}
79
80
81//---------------------------------------------------------
82// Return a string according to the given error code
83//---------------------------------------------------------
84extern "C" _PluginExport  char* plgError(int err)
85{
86        return "Unknown";
87}
88
89
90//---------------------------------------------------------
91// Release the plugin
92//---------------------------------------------------------
93extern "C" _PluginExport  void plgRelease( void )
94{
95        // remove monitor task
96        mRoot->sKernel()->RemoveTask(mTaskId);
97        mTask.reset();
98       
99        // log
100        NR_Log(Log::LOG_PLUGIN, "dynamicResources: Plugin closed and removed");
101}
Note: See TracBrowser for help on using the repository browser.