File: CAFPlugin.cc

package info (click to toggle)
gnuift 0.1.14%2Bds-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 5,632 kB
  • ctags: 2,973
  • sloc: cpp: 15,867; sh: 8,281; ansic: 1,812; perl: 1,007; php: 651; makefile: 483; lisp: 344
file content (74 lines) | stat: -rw-r--r-- 2,080 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "libMRML/include/CAFPlugin.h"
#include "libMRML/include/CAccessorFactoryContainer.h"
#include "libMRML/include/GIFTExceptions.h"

/** makes a CAccessor object*/
CAccessor* CAFPlugin::makeAccessor(const CXMLElement& inXMLElement)const{
  return (*mMakeAccessor)(inXMLElement);
}
/** gets the name of the plugin*/
char* CAFPlugin::getName(){
  return (*mGetName)();
};

/** makes the CAFPlugin. All it needs is:
    @param inLibraryFileName the file name of the shared object 
    to be treated */
CAFPlugin::CAFPlugin(string inLibraryDirName,
		     string inLibraryFileName,
		     string inLibraryName):
  mGetName(0),
  mMakeAccessor(0),
  mName("no name given"),
  mIsSane(0){
  
  const char* lError;
  string lLibraryPath=inLibraryDirName+"/"+inLibraryFileName;
  string lStringGetClassName(inLibraryName+"_getClassName");
  string lStringMakeAccessor(inLibraryName+"_makeAccessor");

  mDlOpenHandle = dlopen (lLibraryPath.c_str(), RTLD_LAZY);
  if (!mDlOpenHandle) {
    cerr << "Could not open library: " << endl
	 << dlerror() << endl;
    //throw VEConfigurationError(dlerror());
    mIsSane=0;
  }else{
  
    mGetName = (typeof(mGetName))dlsym(mDlOpenHandle, 
				       lStringGetClassName.c_str());
    if ((lError = dlerror()) != NULL)  {
      cerr << "Could not link to symbol " << lStringGetClassName << ":" << lError << endl;
    }else{
      mName=(*mGetName)();
      mMakeAccessor=(typeof(mMakeAccessor))dlsym(mDlOpenHandle,
						 lStringMakeAccessor.c_str());
      if ((lError = dlerror()) != NULL)  {
	cerr << "Could not link to symbol " << lStringMakeAccessor << ":" << lError << endl;
      }else{
	mIsSane=1;
      }
    }
  }
}

CAFPlugin::CAFPlugin(CAFPlugin& inPlugin):
  mGetName(inPlugin.mGetName),
  mMakeAccessor(inPlugin.mMakeAccessor),
  mName(inPlugin.mName){
}

CAFPlugin::~CAFPlugin(){
  if(mDlOpenHandle){
    dlclose(mDlOpenHandle);
  }
}

bool CAFPlugin::isSane()const{
  return mIsSane;
}

void CAFPlugin::registerFactory(CAccessorFactoryContainer& outContainer){
  outContainer.registerFactory(this,
			       getName());
};