I am using Ruby to talk to a device using ioctl calls. This works great, but
I have a case where I need to pass a pointer of the data area in a packet
and then reference the data, which is structure that varies according the
type of event that is returned.
I got everything working for the cases that do not involve pointers. I am
not sure how to do it.
I am doing something like…
class Control
item1: input (int)
item2: output (int)
GetEZPacket = Struct.new(“Get Easy Packet”, :item1, :item2)
eventQueue: input (int)
eventNumber: output (int)
eventData: input/output (pointer)
GetEventPacket = Struct.new(“Get Event Packet”, :eventQueue, :eventNumber,
:eventData)
stuff1: output (int)
stuff2: output (int)
EventDataFor1 = Struct.new(“Event Data For 1”, :stuff1, :stuff2)
stuff3: output (int)
stuff4: output (int)
stuff5: output (int)
EventDataFor2 = Struct.new(“Event Data For 2”, :stuff3, :stuff4, :stuff5)
This works for cases without pointers
def getEZStuff( device, item )
ezPacket = GetEZPacket.new( item, 0 )
arg = ezPacket.to_a.pack(“ii”)
device.ioctl( IOCTL_EZ, arg )
result = arg.unpack(“ii”)
result[1]
end
This is where I need help
def getEvent( device, queue )
# How do I set the pointer argument to point to a data region big
# enough to hold either different return structures?
area = " " * 256
gep = GetEventPacket.new( queue, 0, area )
arg = gep.to_a.pack(“iiP256”)
device.ioctl( IOCTL_EVENT, arg )
result = arg,unpack(“iiP256”)
if result[1] == 1 then
# Is this how I unpack the pointer and associate it with my Struct?
ra = result[2].unpack("i,i")
edf1 = EventDataFor1.new( ra[0], ra[1] )
if edf1.stuff1 == BLAH then
... once I get to here everything is a breeze
end
end
Any advice appreciated.
Thanks,
Dale