/src/lib/foreign_interface/foreign_dll.e

http://github.com/tybor/Liberty · Specman e · 77 lines · 47 code · 7 blank · 23 comment · 2 complexity · b32214e1d302ec7d0a838d961b1d9a3c MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. class FOREIGN_DLL
  5. create {FOREIGN_DLL_LOADER}
  6. make
  7. feature {ANY}
  8. filename: FIXED_STRING
  9. do
  10. Result ::= dso.name
  11. end
  12. function (name: ABSTRACT_STRING; a_parameter_types: TRAVERSABLE[FOREIGN_TYPE]; a_result_type: FOREIGN_TYPE): FOREIGN_AGENT
  13. require
  14. name /= Void
  15. local
  16. fn_name: FIXED_STRING
  17. p: POINTER
  18. do
  19. fn_name := name.intern
  20. Result := functions.fast_reference_at(fn_name)
  21. if Result = Void then
  22. p := dso.symbol(fn_name)
  23. if p.is_not_null then
  24. create {FOREIGN_DLL_FUNCTION} Result.make(p, a_parameter_types, a_result_type)
  25. end
  26. else
  27. check
  28. a_parameter_types = Void implies Result.parameter_types = Void
  29. a_parameter_types /= Void implies Result.parameter_types /= Void and then Result.parameter_types.is_equal(a_parameter_types)
  30. Result.result_type = a_result_type
  31. end
  32. end
  33. end
  34. feature {}
  35. make (a_dso: like dso)
  36. require
  37. a_dso /= Void
  38. do
  39. dso := a_dso
  40. create {HASHED_DICTIONARY[FOREIGN_DLL_FUNCTION, FIXED_STRING]} functions.make
  41. ensure
  42. dso = a_dso
  43. end
  44. feature {FOREIGN_DLL_HANDLER}
  45. dso: DYNAMIC_SHARED_OBJECT
  46. functions: DICTIONARY[FOREIGN_DLL_FUNCTION, FIXED_STRING]
  47. invariant
  48. dso /= Void
  49. functions /= Void
  50. end -- class FOREIGN_DLL
  51. --
  52. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  53. --
  54. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  55. -- of this software and associated documentation files (the "Software"), to deal
  56. -- in the Software without restriction, including without limitation the rights
  57. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  58. -- copies of the Software, and to permit persons to whom the Software is
  59. -- furnished to do so, subject to the following conditions:
  60. --
  61. -- The above copyright notice and this permission notice shall be included in
  62. -- all copies or substantial portions of the Software.
  63. --
  64. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  65. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  66. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  67. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  68. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  69. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  70. -- THE SOFTWARE.