comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <nobody@nowhere.fi>
Subject: Re: Using Ada (or SPARK) in Ada-unaware environment
Date: Thu, 19 Jan 2006 12:16:27 +0200
Date: 2006-01-19T12:16:27+02:00	[thread overview]
Message-ID: <43cf66fc$0$7484$39db0f71@news.song.fi> (raw)
In-Reply-To: <dqnkoj$pb4$1@sunnews.cern.ch>

Maciej Sobczak wrote:
> Hi,
> 
> Imagine a control system (to be developed) which needs to interact with 
> some devices. Those devices are supplied with C drivers and libraries.

Been there a couple of times.

> What is the recommended practice for developing this control system in 
> Ada (or SPARK)? I basically see two options for this:
> 
> 1. Enjoy Ada's ability to interface with C libraries (pragma Import) and 
> write everything in Ada.

I have always used this option. It works well *unless* the C 
libraries try to interact with the OS/kernel using signals or 
timers (sleeps), or create their own threads.

Sometimes the C library interface (C header files) relies heavily 
on #define macros, which can make writing the Ada specs rather 
boring. It helps to put one layer of application-specific C 
routines between the C libraries and the Ada code, presenting a 
simpler, application-specific C-Ada interface.

> 2. Write separate programs in C (or C++) that will be responsible only 
> for talking to the devices via their C access libraries. Write the main 
> controller in Ada, as another separate program, and use some form of 
> interprocess communication to have all those components talk.

I would do that only if the C libraries use the OS features I 
mentioned above, in which case it would be easier to isolate the C 
code in its own process (= program). Still, you would need an Ada 
run-time (tasking) that connects well to the interprocess 
communication primitives, eg. lets an Ada task wait on an OS mutex 
or signal.

> The advantage of the second option is that the controller part can be 
> easily tested in isolation or in a fake environment.

Hmmm... I have usually done that in option 1 by implementing a 
test/fake version of the C libraries themselves. The only reason 
why this could be simpler in option 2 is if the test/fake code 
must be written in C and needs to use the OS features mentioned 
above. In option 1, the test/fake code can be written in Ada and 
use Ada tasking and I/O if necessary, which seems a lot simpler to me.

My 2 cents...

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .



  reply	other threads:[~2006-01-19 10:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-19  9:05 Using Ada (or SPARK) in Ada-unaware environment Maciej Sobczak
2006-01-19 10:16 ` Niklas Holsti [this message]
2006-01-19 10:21 ` Peter Amey
2006-01-19 20:05   ` Jeffrey R. Carter
2006-01-20  5:08   ` tmoran
2006-01-19 15:00 ` Steve
2006-01-19 15:45   ` Maciej Sobczak
2006-01-19 20:26     ` Simon Wright
2006-01-20  0:50 ` John
replies disabled

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