Back to index

avfs  1.0.1
Classes | Defines | Functions
modload.c File Reference
#include "avfs.h"
#include <dirent.h>
#include <stdio.h>
#include <string.h>
#include <dlfcn.h>

Go to the source code of this file.

Classes

struct  vmodule

Defines

#define MAX_MODULENAME   32
#define MODULEPREFIX   "avfs_module_"
#define MODULEPREFIXLEN   12

Functions

static void * load_module (const char *modname, const char *moduledir)
static void delete_module (struct vmodule *module)
static int init_module (void *lib_handle, const char *initname)
static char * get_modulename (const char *filename)
static void check_moduledir_entry (const char *moduledir, const char *filename)
void av_init_dynamic_modules (void)

Class Documentation

struct vmodule

Definition at line 19 of file modload.c.

Class Members
void * handle

Define Documentation

#define MAX_MODULENAME   32

Definition at line 15 of file modload.c.

#define MODULEPREFIX   "avfs_module_"

Definition at line 16 of file modload.c.

#define MODULEPREFIXLEN   12

Definition at line 17 of file modload.c.


Function Documentation

void av_init_dynamic_modules ( void  )

Definition at line 106 of file modload.c.

{
    DIR *dirp;
    struct dirent *ent;
    char *moduledir;

    moduledir = av_get_config("moduledir");
    if(moduledir == NULL)
        return;

    dirp = opendir(moduledir);
    if(dirp != NULL) {
        while((ent = readdir(dirp)) != NULL)
            check_moduledir_entry(moduledir, ent->d_name);

        closedir(dirp);
    }
    av_free(moduledir);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void check_moduledir_entry ( const char *  moduledir,
const char *  filename 
) [static]

Definition at line 81 of file modload.c.

{            
    int res;
    char *modulename;
    void *lib_handle;

    modulename = get_modulename(filename);
    if(modulename == NULL)
        return;

    lib_handle = load_module(filename, moduledir);
    if(lib_handle != NULL) {
        char *initname;
        void *lib_handle = NULL;

        initname = av_stradd(NULL, "av_init_module_", modulename, NULL);
        res = init_module(lib_handle, initname);
        if(res < 0 && lib_handle != NULL)
            dlclose(lib_handle);

        av_free(initname);
    }
    av_free(modulename);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void delete_module ( struct vmodule module) [static]

Definition at line 39 of file modload.c.

{
    dlclose(module->handle);
}

Here is the caller graph for this function:

static char* get_modulename ( const char *  filename) [static]

Definition at line 65 of file modload.c.

{
    int i;

    if(strncmp(filename, MODULEPREFIX, MODULEPREFIXLEN) != 0)
        return NULL;
    
    filename += MODULEPREFIXLEN;

    for(i = 0; filename[i] && filename[i] != '.'; i++);
    if(strcmp(filename + i, ".so") != 0)
        return NULL;

    return  av_strndup(filename, i);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int init_module ( void *  lib_handle,
const char *  initname 
) [static]

Definition at line 44 of file modload.c.

{
    int (*initfunc) (struct vmodule *);
    struct vmodule *module;
    int res;

    initfunc = (int (*)(struct vmodule *)) dlsym(lib_handle, initname);
    if(initfunc == NULL) {
        av_log(AVLOG_ERROR, "init_module: %s", dlerror());
        return -EFAULT;
    }

    AV_NEW_OBJ(module, delete_module);
    module->handle = lib_handle;

    res = (*initfunc)(module);
    av_unref_obj(module);
    
    return res;
}

Here is the call graph for this function:

static void* load_module ( const char *  modname,
const char *  moduledir 
) [static]

Definition at line 23 of file modload.c.

{
    char *modpath;
    void *lib_handle;

    modpath = av_stradd(NULL, moduledir, "/", modname, NULL);

    lib_handle = dlopen(modpath, RTLD_NOW);
    if(lib_handle == NULL)
        av_log(AVLOG_ERROR, "load_module: %s", dlerror());

    av_free(modpath);
  
    return lib_handle;
}

Here is the call graph for this function:

Here is the caller graph for this function: