Main Page   Class Hierarchy   Compound List   File List   Compound Members  

ExternalMethodDef.cpp

00001 /*
00002  *  This program is free software; you can redistribute it and/or modify
00003  *  it under the terms of the GNU General Public License as published by
00004  *  the Free Software Foundation; either version 2 of the License, or
00005  *  (at your option) any later version.
00006  *
00007  *  This program is distributed in the hope that it will be useful,
00008  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00009  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00010  *  GNU General Public License for more details.
00011  *
00012  *  You should have received a copy of the GNU General Public License
00013  *  along with this program; if not, write to the Free Software
00014  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00015  *
00016  * (c)Copyright 2006 Hewlett-Packard Development Company, LP.
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 }

Generated on Wed Mar 7 14:44:59 2007 for Seagull by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002