add module loading files

This commit is contained in:
jussi 2019-09-24 00:49:28 +03:00
parent 5d79e59db0
commit fb044ba9f2
9 changed files with 63 additions and 2 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
build
/*kdev*

View File

@ -9,9 +9,15 @@ enum tc_module_category {
TC_CATEGORY_INTERFACE
};
// Function name the module loader uses to get the module_t describing the module
#define TC_MODULE_INFO_FUNCTION_NAME "tc_get_module_handle"
typedef struct tc_module_t {
enum tc_module_category category;
// Short name of the module like nvidia, qt
const char *name;
// Longer description
const char *description;
// Initializes the module's internal state
int8_t (*init_callback)();
@ -19,3 +25,12 @@ typedef struct tc_module_t {
int8_t (*close_callback)();
} tc_module_t;
// Try to return the module handle matching the category and name. If it doesn't exist or there was a problem loading the module, returns NULL.
tc_module_t *tc_module_find(enum tc_module_category category, const char *name);
// Wrappers for platform-specific functions for loading libraries (modules) at runtime
void *tc_dlopen(const char *path);
void *tc_dlsym(void *handle, const char *name);
void tc_dlclose(void *handle);
char *tc_dlerror();

View File

@ -0,0 +1 @@

9
src/lib/posix/module.c Normal file
View File

@ -0,0 +1,9 @@
#include <tc_module.h>
#include <tc_common.h>
#include <dlfcn.h>
void *tc_dlopen(const char *path) {
return dlopen(path, RTLD_LAZY);
}

8
src/lib/tc_module.c Normal file
View File

@ -0,0 +1,8 @@
#include <stddef.h>
#include <tc_module.h>
tc_module_t *tc_module_find(enum tc_module_category category, const char *name) {
return NULL;
}

4
src/main/meson.build Normal file
View File

@ -0,0 +1,4 @@
executable('tuxclocker',
'tuxclocker.c',
include_directories : incdir,
link_with : libtuxclocker)

View File

@ -1 +1,12 @@
// Main executable for TuxClocker. Responsible for loading an interface
#include <tc_common.h>
#include <tc_module.h>
#include <stdio.h>
int main(int argc, char **argv) {
// Load an interface here
return 0;
}

View File

@ -1,7 +1,16 @@
# Define libtuxclocker target here since others depend on it
libtuxclocker_posix_sources = ['lib/posix/module.c']
libtuxclocker_posix_libs = [cc.find_library('dl')]
libtuxclocker = shared_library('libtuxclocker',
['lib/tc_assignable.c'],
include_directories : incdir)
['lib/tc_assignable.c',
'lib/tc_module.c',
libtuxclocker_posix_sources],
include_directories : incdir,
dependencies : libtuxclocker_posix_libs)
subdir('modules')
subdir('main')
subdir('lib')

View File

@ -5,9 +5,11 @@
#include <tc_assignable.h>
#include <tc_common.h>
#include <tc_module.h>
#define MAX_GPUS 32
// Local function declarations
static int8_t init();
static int8_t close();