00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 #include "ExternalMethodDef.hpp"
00021 #include "TextUtils.hpp"
00022 #include "GeneratorError.h"
00023 #include "GeneratorTrace.hpp"
00024 #include "dlfcn_t.hpp"
00025 
00026 T_ExternalMethod create_external_method (char *P_args) {
00027   
00028   T_ExternalMethod            L_ret          = NULL          ;
00029   char                       *L_lib_name     = NULL          ;
00030   char                       *L_fun_name     = NULL          ;
00031   void                       *L_library_handle               ; 
00032   void                       *L_function                     ;
00033 
00034   L_lib_name = find_text_value(P_args,(char*)"lib")  ;
00035   if (L_lib_name == NULL ) {
00036     GEN_ERROR(E_GEN_FATAL_ERROR,
00037               "no name for the library for the filter (lib=...)");
00038   } else {
00039     L_library_handle = dlopen(L_lib_name, RTLD_LAZY);
00040     if (L_library_handle == NULL) {
00041       GEN_ERROR(E_GEN_FATAL_ERROR, 
00042                 "Unable to open library file [" 
00043                 << L_lib_name
00044                 << "] error [" << dlerror() << "]");
00045     }
00046   }
00047 
00048   L_fun_name = find_text_value(P_args,(char*)"function") ;
00049   if (L_fun_name == NULL ) {
00050     GEN_ERROR(E_GEN_FATAL_ERROR,
00051               "no name for the function for the parser (function=...)");
00052   } else {
00053     if (L_library_handle) { 
00054       L_function = dlsym(L_library_handle, L_fun_name);
00055       if (L_function == NULL) {
00056         GEN_ERROR(E_GEN_FATAL_ERROR, "Error [" << dlerror() << "]");
00057       } else {
00058         L_ret = (T_ExternalMethod) L_function ;
00059       }
00060     }
00061   }
00062 
00063   return (L_ret) ;
00064 }