stat and get added
[gp-arc-client-c.git] / ruby / test.rb
1 require 'ffi'
2 require 'pp'
3
4 ENV["ARC_LOCATION"] = "/opt/local"
5
6 jobdesc = File.read "/Users/tamas/quick/arc/arex/simple.jsdl"
7 args = [""] #optparser cuts the first arg
8 #args += "-c ARC1:https://localhost:60000/arex -e".split
9 args << "-e"
10 args << jobdesc
11
12 module ArcClientCLibrary
13
14   class SubmitResult < FFI::Struct
15     layout      :message,  :string,\
16                         :job_id,  :string
17   end
18
19
20   extend FFI::Library
21   
22   ffi_lib "/Users/tamas/work/iface/grid/ws/gp-arc-client-c/build/Debug/libarcclientc.dylib"
23   
24   attach_function :initialize, [], :string
25   
26   attach_function :submit, [:int, :pointer], :pointer
27
28 end
29
30 argv = FFI::MemoryPointer.new(:pointer, args.size)
31 argv.write_array_of_pointer(args.map {|arg| FFI::MemoryPointer.from_string(arg.to_s)})  
32
33 p "the version is: " + ArcClientCLibrary.initialize
34
35
36 p "args:" + args.inspect
37 2.times do |i|
38         p "running No. #{i}"
39         
40         argv = FFI::MemoryPointer.new(:pointer, args.size)
41         argv.write_array_of_pointer(args.map {|arg| FFI::MemoryPointer.from_string(arg.to_s)}) 
42         #you can not share argv between submit calls, i do not know why (it might be freed by optparser?)
43         
44         result = ArcClientCLibrary.submit(args.size, argv)
45         submitResult = ArcClientCLibrary::SubmitResult.new(result)
46         p (submitResult)[:message].to_s
47         p (submitResult)[:job_id].to_s
48 end
49
50 p "Done."