1 // you can bind many libs in one file 2 module manylibs; 3 4 import ssll; 5 6 mixin SSLL_INIT; 7 8 LibHandler mosquittoLibHandler; 9 LibHandler libsshLibHandler; 10 11 version (Posix) 12 { 13 private enum mosquittoLibNames = ["libmosquitto.so", "libmosquitto.so.1"]; 14 private enum libsshLibNames = ["libssh.so"]; 15 } 16 version (Windows) 17 { 18 private enum mosquittoLibNames = ["mosquitto.dll"]; 19 private enum libsshLibNames = ["libssh.dll"]; 20 } 21 22 void loadManyLibs() 23 { 24 import core.stdc.stdio; 25 import core.stdc.string : memcpy; 26 27 char[256] buf; 28 29 static char* stringz(string n, char[] buf) 30 { 31 memcpy(buf.ptr, n.ptr, n.length); 32 buf[n.length] = 0; 33 return buf.ptr; 34 } 35 36 foreach (name; mosquittoLibNames) 37 { 38 printf("try load '%s'... ", stringz(name, buf)); 39 mosquittoLibHandler = loadLibrary(name); 40 if (mosquittoLibHandler is null) printf("fail\n"); 41 else { printf("success\n"); break; } 42 } 43 if (mosquittoLibHandler is null) printf("can't load mosquitto library"); 44 45 foreach (name; libsshLibNames) 46 { 47 printf("try load '%s'... ", stringz(name, buf)); 48 libsshLibHandler = loadLibrary(name); 49 if (libsshLibHandler is null) printf("fail\n"); 50 else { printf("success\n"); break; } 51 } 52 if (libsshLibHandler is null) printf("can't load libssh library"); 53 54 loadApiSymbols(LoadApiSymbolsVerbose.message); 55 } 56 57 void unloadManyLibs() 58 { 59 unloadLibrary(mosquittoLibHandler); 60 unloadLibrary(libsshLibHandler); 61 } 62 63 @api("mosquittoLibHandler") 64 { 65 void mosquitto_lib_init() { mixin(SSLL_CALL); } 66 int mosquitto_lib_version(int* major, int* minor, int* revision) { mixin(SSLL_CALL); } 67 } 68 69 @api("libsshLibHandler") 70 { 71 void* ssh_new() { mixin(SSLL_CALL); } 72 void ssh_free(void* session) { mixin(SSLL_CALL); } 73 int ssh_get_version(void* session) { mixin(SSLL_CALL); } 74 }