This repository has been archived by the owner on Dec 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
module.c
83 lines (71 loc) · 1.96 KB
/
module.c
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
75
76
77
78
79
80
81
82
83
/*
Copyright (c) 2021, Stephen P. Shoecraft
All rights reserved.
This source code is licensed under the BSD-style license found in the
LICENSE file in the root directory of this source tree.
*/
#define _GNU_SOURCE
#ifndef __WIN32
#include <dlfcn.h>
#endif
#include "mybmm.h"
extern mybmm_module_t jk_module;
#if !defined(__WIN32) && !defined(__WIN64)
extern mybmm_module_t bt_module;
extern mybmm_module_t can_module;
#endif
extern mybmm_module_t ip_module;
extern mybmm_module_t serial_module;
mybmm_module_t *mybmm_get_module(mybmm_config_t *conf, char *name, int type) {
mybmm_module_t *mp;
dprintf(3,"name: %s, type: %d\n", name, type);
list_reset(conf->modules);
while((mp = list_get_next(conf->modules)) != 0) {
dprintf(3,"mp->name: %s, mp->type: %d\n", mp->name, mp->type);
if (strcmp(mp->name,name)==0 && mp->type == type) {
dprintf(3,"found.\n");
return mp;
}
}
dprintf(3,"NOT found.\n");
return 0;
}
mybmm_module_t *mybmm_load_module(mybmm_config_t *conf, char *name, int type) {
mybmm_module_t *mp;
list_reset(conf->modules);
while((mp = list_get_next(conf->modules)) != 0) {
dprintf(3,"mp->name: %s, mp->type: %d\n", mp->name, mp->type);
if (strcmp(mp->name,name)==0 && mp->type == type) {
dprintf(3,"found.\n");
return mp;
}
}
dprintf(3,"NOT found.\n");
if (strcmp(name,"jk")==0) {
mp = &jk_module;
#if !defined(__WIN32) && !defined(__WIN64)
#if defined(BLUETOOTH)
} else if (strcmp(name,"bt")==0) {
mp = &bt_module;
#endif
} else if (strcmp(name,"can")==0) {
mp = &can_module;
#endif
} else if (strcmp(name,"ip")==0) {
mp = &ip_module;
} else if (strcmp(name,"serial")==0) {
mp = &serial_module;
} else {
return 0;
}
/* Call the init function */
dprintf(3,"init: %p\n", mp->init);
if (mp->init && mp->init(conf)) {
printf("%s init function returned error, aborting.\n",mp->name);
return 0;
}
/* Add this module to our list */
dprintf(3,"adding module: %s\n", mp->name);
list_add(conf->modules,mp,0);
return mp;
}