PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

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