modify sharedLibManager,not complete yet

This commit is contained in:
an-tao 2018-06-13 18:07:48 +08:00
parent 50bbd2d946
commit 975f76c2f7
1 changed files with 47 additions and 0 deletions

View File

@ -14,6 +14,50 @@
#include "SharedLibManager.h" #include "SharedLibManager.h"
#include <trantor/utils/Logger.h> #include <trantor/utils/Logger.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <dirent.h>
static void forEachFileIn(const std::string &path,const std::function<void (const std::string &filename)> &cb)
{
DIR* dp;
struct dirent* dirp;
struct stat st;
/* open dirent directory */
if((dp = opendir(path.c_str())) == NULL)
{
perror("opendir");
return;
}
/**
* read all files in this dir
**/
while((dirp = readdir(dp)) != NULL)
{
/* ignore hidden files */
if(dirp->d_name[0] == '.')
continue;
/* get dirent status */
std::string filename=dirp->d_name;
std::string fullname=path;
fullname.append("/").append(filename);
if(stat(fullname.c_str(), &st) == -1)
{
perror("stat");
return;
}
/* if dirent is a directory, continue */
if(S_ISDIR(st.st_mode))
continue;
cb(dirp->d_name);
}
return;
}
using namespace drogon; using namespace drogon;
SharedLibManager::SharedLibManager(trantor::EventLoop *loop,const std::string viewPath): SharedLibManager::SharedLibManager(trantor::EventLoop *loop,const std::string viewPath):
@ -27,4 +71,7 @@ _viewPath(viewPath)
void SharedLibManager::managerLibs() void SharedLibManager::managerLibs()
{ {
//LOG_DEBUG<<"manager .so libs in path "<<_viewPath; //LOG_DEBUG<<"manager .so libs in path "<<_viewPath;
forEachFileIn("./",[](const std::string &filename){
LOG_DEBUG<<filename;
});
} }