comp.lang.ada
 help / color / mirror / Atom feed
From: michael bode <m.g.bode@web.de>
Subject: Re: The "black magic" of ioctl
Date: Fri, 22 Oct 2010 22:16:00 +0200
Date: 2010-10-22T22:16:00+02:00	[thread overview]
Message-ID: <i9sre1$21t$1@online.de> (raw)
In-Reply-To: <cbc04455-d43b-4cca-ab56-51b6273fdc08@j18g2000yqd.googlegroups.com>

Am 21.10.2010 13:31, schrieb Francesco Piraneo Giuliano:

> But my application still need to be written and has to run under linux
> so to collect some data about linux' framebuffer I have to use ioctl;
> the only solution is to write all low level interfacing (open the
> device, get informations about, map it into memory) in C then write
> the upper level in Ada?


Look here http://www.pegasoft.ca/resources/boblap/book.html for
information on how to program for Linux in Ada. You can call ioctl from
an Ada program, you only have to arrange the parameters. For example
this is part of a thin binding to Vide4Linux2 API:

with Posix.Io;
with Interfaces.C;
with Interfaces.C.Strings;

private package Video_4_Linux_2.Ioctls is

   package C renames Interfaces.C;
   VIDIOC_QUERYCAP : constant := -2140645888;

...

   type C_V4l2_Capability is record
      Driver       : C.Char_Array(0 .. 15);
      Card         : C.Char_Array(0 .. 31);
      Bus_Info     : C.Char_Array(0 .. 31);
      Version      : Unsigned32;
      Capabilities : Bits32;
      Reserved     : U32_Array(0 .. 3);
   end record;

   pragma Convention (C, C_V4l2_Capability);

   function Ioctl (Fd  : POSIX.IO.File_Descriptor;
                   Cmd : C.int;
                   Arg : access C_V4l2_Capability) return C.int;
   pragma Import (C, Ioctl, "ioctl");

And you use this ioctl like this:

   type Capability_array is array(Capability_Index) of boolean;

   type V4l2_Capability is record
      Driver : String(1 .. 16);
      Card : String(1 .. 32);
      Bus_Info : String(1 .. 32);
      Version : Natural;
      Capabilities : Capability_Array;
   end record;

   procedure Get_Capability (Device :     Video_Device;
                             Cap    : out V4l2_Capability)
   is
      C_Cap : aliased C_V4l2_Capability;
   begin
      if 0 = Ioctl (Device.Fd, VIDIOC_QUERYCAP, C_Cap'access) then
         Cap.Driver(1..C.To_Ada (C_Cap.Driver)'Length) :=
		C.To_Ada (C_Cap.Driver);
         Cap.Driver(C.To_Ada (C_Cap.Driver)'Length+1..16) :=
		(others => ' ');
...



  parent reply	other threads:[~2010-10-22 20:16 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-21  9:13 The "black magic" of ioctl Francesco Piraneo Giuliano
2010-10-21 10:20 ` Ludovic Brenta
2010-10-21 11:31   ` Francesco Piraneo Giuliano
2010-10-21 11:50     ` Mark Lorenzen
2010-10-21 12:04     ` Ludovic Brenta
2010-10-22 16:46       ` Francesco Piraneo Giuliano
2010-10-22 16:47       ` Francesco Piraneo Giuliano
2010-10-21 12:05     ` Simon Wright
2010-10-22 20:16     ` michael bode [this message]
2010-10-23 12:13       ` Simon Wright
2010-10-23 13:27         ` michael bode
2010-10-23 16:25           ` Simon Wright
2010-10-23 18:12             ` michael bode
2010-10-23 20:26     ` Florian Weimer
2010-10-24 11:08       ` Simon Wright
2010-10-24 17:58         ` Florian Weimer
2010-10-24 12:41       ` Frank J. Lhota
2010-10-24 17:56         ` Florian Weimer
2010-10-24 18:36           ` Simon Wright
2010-10-25  0:45             ` Frank J. Lhota
2010-10-25  1:13           ` Frank J. Lhota
2010-10-25 18:56             ` Florian Weimer
2010-10-21 11:46   ` Colin Paul Gloster
2010-10-25  7:08   ` Yannick Duchêne (Hibou57)
2010-10-21 13:40 ` Julian Leyh
2010-10-21 13:58   ` Simon Wright
2010-10-21 20:45 ` Randy Brukardt
2010-10-22 16:40   ` Francesco Piraneo Giuliano
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox