/src/lib/foreign_interface/foreign_agent.e

http://github.com/tybor/Liberty · Specman e · 83 lines · 53 code · 7 blank · 23 comment · 1 complexity · aa3de8067d4d131a9d5aa0e9012b092d MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. deferred class FOREIGN_AGENT
  5. feature {ANY}
  6. call (parameters: FOREIGN_PARAMETERS)
  7. require
  8. parameters.match_types(parameter_types)
  9. result_type = types.nothing
  10. local
  11. null: POINTER
  12. do
  13. ffi_call.invoke(null, parameters.as_arrayed_collection)
  14. end
  15. item (parameters: FOREIGN_PARAMETERS): FOREIGN_OBJECT
  16. require
  17. parameters.match_types(parameter_types)
  18. result_type /= types.nothing
  19. do
  20. Result := result_type.new
  21. ffi_call.invoke(Result.as_pointer, parameters.as_arrayed_collection)
  22. ensure
  23. Result.match_type(result_type)
  24. end
  25. parameter_types: TRAVERSABLE[FOREIGN_TYPE]
  26. result_type: FOREIGN_TYPE
  27. feature {}
  28. ffi_call: FFI_CALL
  29. types: FOREIGN_TYPES
  30. prepare (a_function: POINTER)
  31. require
  32. ffi_call = Void
  33. a_function.is_not_null
  34. local
  35. p: FAST_ARRAY[POINTER]
  36. i: INTEGER
  37. do
  38. if not parameter_types.is_empty then
  39. create p.with_capacity(parameter_types.count)
  40. from
  41. i := parameter_types.lower
  42. until
  43. i > parameter_types.upper
  44. loop
  45. p.add_last(parameter_types.item(i).ffi_type)
  46. i := i + 1
  47. end
  48. end
  49. create ffi_call.prepare(a_function, result_type.ffi_type, p)
  50. ensure
  51. ffi_call /= Void
  52. end
  53. invariant
  54. ffi_call /= Void
  55. parameter_types /= Void
  56. end -- class FOREIGN_AGENT
  57. --
  58. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  59. --
  60. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  61. -- of this software and associated documentation files (the "Software"), to deal
  62. -- in the Software without restriction, including without limitation the rights
  63. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  64. -- copies of the Software, and to permit persons to whom the Software is
  65. -- furnished to do so, subject to the following conditions:
  66. --
  67. -- The above copyright notice and this permission notice shall be included in
  68. -- all copies or substantial portions of the Software.
  69. --
  70. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  71. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  72. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  73. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  74. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  75. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  76. -- THE SOFTWARE.