source: trunk/Plugins/rdtscTimeSource/Plugin.cpp @ 1

Revision 1, 3.2 KB checked in by art, 13 years ago (diff)
Line 
1
2
3#include <nrEngine.h>
4#include <boost/shared_ptr.hpp>
5
6#include "Cpu.h"
7#include "TimeSource.h"
8
9
10using namespace nrEngine;
11
12//---------------------------------------------------------
13// Some globals
14//---------------------------------------------------------
15Engine*                                                         mRoot = NULL;
16
17boost::shared_ptr<Cpu>                          mCpu;
18boost::shared_ptr<rdtscTimeSource>      mTimeSource;
19boost::shared_ptr<TimeSource>           mOldTimeSource;
20
21//std::vector<Plugin::PlgMethod>                mMethods;
22
23
24//---------------------------------------------------------
25// Initialize the plugin
26//---------------------------------------------------------
27extern "C" int plgInitialize(Engine* root)
28{
29       
30        mRoot = root;
31       
32        // create cpu instance
33        mCpu.reset(new Cpu());
34        NR_Log(Log::LOG_PLUGIN, "rdtscTimeSource: Retrieve CPU Information");
35        mCpu->detect();
36        NR_Log(Log::LOG_PLUGIN, "rdtscTimeSource: %s", mCpu->getCPUDescription().c_str());
37       
38        // create Time Source
39        mTimeSource.reset( new rdtscTimeSource(mCpu) );
40
41        // get the current time source
42        mOldTimeSource = mRoot->sClock()->getTimeSource();
43               
44        // now set new time source to the clock
45        NR_Log(Log::LOG_PLUGIN, "rdtscTimeSource: Set the high performance time source for the clock");
46        mRoot->sClock()->setTimeSource(mTimeSource);
47
48        // declare new function to the scripting engine
49        //std::vector<ScriptParam> param;
50        //param.push_back(mCpu.get());
51        mRoot->sScriptEngine()->add("getCpuString", Cpu::getCpuString, VarArg(mCpu.get()));
52               
53        return 0;       
54} 
55 
56
57//---------------------------------------------------------
58// Get the engines version number for which this plugin was wrote
59//---------------------------------------------------------
60extern "C" unsigned int plgEngineVersion( void )
61{
62        return createVersionInteger(0,0,5);
63}
64
65
66//---------------------------------------------------------
67// Get full string according to the plugin version
68//---------------------------------------------------------
69extern "C" char* plgVersionString( void )
70{
71        return "High Performance Time Source v0.1 (rdtsc & cpuid instruction using)";
72}
73
74
75//---------------------------------------------------------
76// Return a string according to the given error code
77//---------------------------------------------------------
78extern "C" char* plgError(int err)
79{
80        return "Unknown";
81}
82
83
84//---------------------------------------------------------
85// Release the plugin
86//---------------------------------------------------------
87extern "C" void plgRelease( void )
88{
89        // free pointers
90        mCpu.reset();
91        mTimeSource.reset();
92
93        // set the old time source to the clock back
94        mRoot->sClock()->setTimeSource(mOldTimeSource);
95               
96        // some log
97        NR_Log(Log::LOG_PLUGIN, "rdtscTimeSource: Set old time source back and good bye!");
98}
99
100//---------------------------------------------------------
101// Get information about provided subroutines
102//---------------------------------------------------------
103/*extern "C" void plgGetMethods( std::vector<Plugin::PlgMethod>& methods)
104{
105        methods = mMethods;
106}
107
108
109//---------------------------------------------------------
110// Call certain subroutine
111//---------------------------------------------------------
112extern "C" void plgCall(const std::string& name, std::vector<Plugin::PlgParam>& params)
113{
114
115        if (name == "getCpuInfo"){
116                getCpuInfoString();
117        }
118       
119}*/
120
Note: See TracBrowser for help on using the repository browser.