[go: up one dir, main page]

Menu

[r669]: / mia2 / idl / idlmia.c  Maximize  Restore  History

Download this file

112 lines (90 with data), 2.9 kB

  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
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
/* -*- mia-c++ -*-
* Copyright (c) 2007 Gert Wollny <gert at die.upm.es>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <stdio.h>
#include <idl_export.h>
#include <string.h>
#include <assert.h>
#include <config.h>
#include <miaconfig.h>
#ifdef WIN32
#include <windows.h>
typedef HINSTANCE ModuleHandle;
#define dlopen(name, flags) LoadLibrary(name)
#define dlclose(handle) FreeLibrary(handle)
#define dlsym(handle, symbol) (void*)GetProcAddress(handle, symbol);
#define dlerror() "unable to load DLL"
#define MODULE_SUFFIX "dll"
#define EXPORT __declspec(dllexport)
#else
#include <dlfcn.h>
typedef void *ModuleHandle;
#define MODULE_SUFFIX "so"
#include <dlfcn.h>
#define EXPORT
#endif
typedef IDL_SYSFUN_DEF2* (*f_get_map)(int *n);
#ifdef WIN32
static const char *searchpath ="idlmia_proxy."MODULE_SUFFIX;
#else
static const char *searchpath =PLUGIN_SEARCH_PATH"idl/idlmia_proxy."MODULE_SUFFIX;
#endif
static const char *test_searchpath ="./idlmia_proxy."MODULE_SUFFIX;
static ModuleHandle do_load_dll()
{
ModuleHandle handle = NULL;
handle = dlopen(searchpath, RTLD_NOW|RTLD_GLOBAL);
if (!handle) {
handle = dlopen(test_searchpath, RTLD_NOW|RTLD_GLOBAL);
}
if (!handle) {
IDL_Message(IDL_M_NAMED_GENERIC, IDL_MSG_RET, "unable to load 'idlmia_proxy'");
return NULL;
}
return handle;
}
static f_get_map do_get_interface(void *handle, const char *name)
{
f_get_map f = (f_get_map)dlsym(handle, name);
if (!f)
IDL_Message(IDL_M_NAMED_GENERIC, IDL_MSG_RET, name);
return f;
}
static ModuleHandle g_handle = 0;
EXPORT int IDL_Load(void)
{
IDL_SYSFUN_DEF2 *function_addr;
IDL_SYSFUN_DEF2 *procedure_addr;
int n_p = 0;
int n_f = 0;
f_get_map f_getter = NULL;
f_get_map p_getter = NULL;
g_handle = do_load_dll();
if (!g_handle)
return IDL_FALSE;
f_getter = do_get_interface(g_handle, "get_function_list");
if (!f_getter)
return IDL_FALSE;
function_addr = f_getter(&n_f);
p_getter = do_get_interface(g_handle, "get_procedure_list");
if (!p_getter)
return IDL_FALSE;
function_addr = f_getter(&n_f);
procedure_addr = p_getter(&n_p);
return IDL_SysRtnAdd(function_addr, TRUE, n_f) && IDL_SysRtnAdd(procedure_addr, FALSE, n_p);
}