Field3D
PluginLoader.cpp File Reference

Contains implementations of plugin loading functions. More...

#include <dlfcn.h>
#include <sys/types.h>
#include <dirent.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <boost/tokenizer.hpp>
#include "ClassFactory.h"
#include "PluginLoader.h"

Go to the source code of this file.

Functions

int filter (std::string &name)
 
bool getDirSos (std::vector< std::string > &sos, std::string &dir)
 

Detailed Description

Contains implementations of plugin loading functions.

Definition in file PluginLoader.cpp.

Function Documentation

◆ filter()

int filter ( std::string &  name)

Definition at line 96 of file PluginLoader.cpp.

Referenced by getDirSos().

97 {
98  std::string delimiters = ".";
99  std::vector <std::string> items;
100 
101  tokenize(name, delimiters, items);
102 
103  if (items.size() == 0) {
104  return 0;
105  }
106 
107  if (items[items.size() -1] == "so") {
108  return 1;
109  }
110 
111  return 0;
112 }

◆ getDirSos()

bool getDirSos ( std::vector< std::string > &  sos,
std::string &  dir 
)

Definition at line 116 of file PluginLoader.cpp.

References filter().

Referenced by PluginLoader::loadPlugins().

117 {
118  struct dirent *dirent;
119 
120  const char *ds = dir.c_str();
121  DIR *dirfd = opendir(ds);
122  if (!dirfd) {
123  std::string er =
124  "Field3D_plugin loader: could not open directory " + dir + "\n";
125  //perror(er.c_str());
126  return false;
127  }
128 
129  dirent = readdir(dirfd);
130  while (dirent != NULL) {
131 
132  std::string name = dirent->d_name;
133 
134  if (filter(name)) {
135  name = dir + "/" + name;
136  sos.push_back(name);
137  }
138 
139  dirent = readdir(dirfd);
140  }
141 
142  closedir(dirfd);
143 
144  return true;
145 }
int filter(std::string &name)