os dependency with ifdef

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

os dependency with ifdef

Marc Santhoff
Hi,

I' like to know how I should write code for different system. SInce I'm
no Linux user nor have any experience on MacOS I need to know how to
wrap platform dependant code.

Since I'm still fiddling with reading the serial port I have the idea
that linux and even MacOS may be very similar to my main os FreeBSD.

I do know Win32 is different, but how similar are the other os'ses?

Is there any code in the FCL or the like I can study for getting my
ifdefs right?

TIA,
Marc


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: os dependency with ifdef

Tomas Hajny
Marc Santhoff wrote:


Hi,

> I' like to know how I should write code for different system. SInce I'm
> no Linux user nor have any experience on MacOS I need to know how to
> wrap platform dependant code.
>
> Since I'm still fiddling with reading the serial port I have the idea
> that linux and even MacOS may be very similar to my main os FreeBSD.
>
> I do know Win32 is different, but how similar are the other os'ses?
>
> Is there any code in the FCL or the like I can study for getting my
> ifdefs right?

If you really want to create it prepared for current and future platforms,
don't do it via IFDEFs first of all. The procedural solution would be to
design a logical layer for functionality you need (get permissions for
accessing port, open port, set characteristics, read data, write data,
close port) in common interface part of a unit created as an include file,
possibly create (an)other include file(s) with shared parts of the
implementation too and create standalone units for the different platforms
you need to support.

Alternative solution (slightly more OOP-like and, somewhat easier to
implement and providing more flexibility) is to use create a "manager"
record for your particular functionality - see e.g. the heap management
and thread management routines, plus keyboard, mouse and video management
provided in units of the same name.

Tomas

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: os dependency with ifdef

Marc Santhoff
Am Freitag, den 17.03.2006, 11:11 +0100 schrieb Tomas Hajny:

> Marc Santhoff wrote:
>
>
> Hi,
>
> > I' like to know how I should write code for different system. SInce I'm
> > no Linux user nor have any experience on MacOS I need to know how to
> > wrap platform dependant code.
> >
> > Since I'm still fiddling with reading the serial port I have the idea
> > that linux and even MacOS may be very similar to my main os FreeBSD.
> >
> > I do know Win32 is different, but how similar are the other os'ses?
> >
> > Is there any code in the FCL or the like I can study for getting my
> > ifdefs right?
>
> If you really want to create it prepared for current and future platforms,
> don't do it via IFDEFs first of all. The procedural solution would be to
> design a logical layer for functionality you need (get permissions for
> accessing port, open port, set characteristics, read data, write data,
> close port) in common interface part of a unit created as an include file,
> possibly create (an)other include file(s) with shared parts of the
> implementation too and create standalone units for the different platforms
> you need to support.

This is what I'm beginning to do at the moment, after some information
retrieval about how serial ports on Win32 work I've come to the
conclusion that porting the unit rtl/unix/serial.pp would be the best
thing for my special task.

I'm only bothered by the design of that stuff, no result codes
(procedure not function) in some important areas. But I will not make
changes breaking old code, I hope some exception throwing will do ...

> Alternative solution (slightly more OOP-like and, somewhat easier to
> implement and providing more flexibility) is to use create a "manager"
> record for your particular functionality - see e.g. the heap management
> and thread management routines, plus keyboard, mouse and video management
> provided in units of the same name.

Yes, if I had to design it from the start I would think about making it
a really universally usable and technically perfect solution. But for
now my goal is to get some very simple communication running on windows
(slow, no handshake).

Thanks,
Marc


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: os dependency with ifdef

Felipe Monteiro de Carvalho
In reply to this post by Marc Santhoff
Hello,

On 3/16/06, Marc Santhoff <[hidden email]> wrote:
> Since I'm still fiddling with reading the serial port I have the idea
> that linux and even MacOS may be very similar to my main os FreeBSD.
>
> I do know Win32 is different, but how similar are the other os'ses?

You can mostly assume that if it works for Linux, then it will work
for FreeBSD and all other BSDs and even Solaris (and vice-versa).

This isn´t true for Mac OS X. Althought it is based on FreeBSD, it is
very, very different from standard unix boxes.

> Is there any code in the FCL or the like I can study for getting my
> ifdefs right?

I used ifdefs to write two cross-platform projects: TTrayIcon
component and the Virtual Magnifying Glass. You can see their codes on
the internet.

For the magnifier, look for the LoadBitmap procedure to see a example
of how to use a ifdef to implement a function that is very different
on both platforms

http://cvs.sourceforge.net/viewcvs.py/magnifier/magnifierv3/glass.pas?rev=1.14&view=auto

TTrayIcon code is here:

http://www.freepascal.org/cgi-bin/viewcvs.cgi/trunk/components/trayicon/?root=lazarus

thanks,
--
Felipe Monteiro de Carvalho
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: os dependency with ifdef

Marc Santhoff
Am Freitag, den 17.03.2006, 15:26 -0300 schrieb Felipe Monteiro de
Carvalho:

> Hello,
>
> On 3/16/06, Marc Santhoff <[hidden email]> wrote:
> > Since I'm still fiddling with reading the serial port I have the idea
> > that linux and even MacOS may be very similar to my main os FreeBSD.
> >
> > I do know Win32 is different, but how similar are the other os'ses?
>
> You can mostly assume that if it works for Linux, then it will work
> for FreeBSD and all other BSDs and even Solaris (and vice-versa).
>
> This isn´t true for Mac OS X. Althought it is based on FreeBSD, it is
> very, very different from standard unix boxes.

I see, this is very valuable information.

> > Is there any code in the FCL or the like I can study for getting my
> > ifdefs right?
>
> I used ifdefs to write two cross-platform projects: TTrayIcon
> component and the Virtual Magnifying Glass. You can see their codes on
> the internet.

Since I'm dealing with non-visible, non-component code I'll try making
portable units out of it.

Maybe I'm coming back on this when the basics are done and the code
using these units is in shape for building a component.

Thank you very much,
Marc


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: os dependency with ifdef

Jonas Maebe-2
In reply to this post by Felipe Monteiro de Carvalho

On 17 Mar 2006, at 19:26, Felipe Monteiro de Carvalho wrote:

> You can mostly assume that if it works for Linux, then it will work
> for FreeBSD and all other BSDs and even Solaris (and vice-versa).
>
> This isn´t true for Mac OS X. Althought it is based on FreeBSD, it is
> very, very different from standard unix boxes.

It shares at least 90% of the rtl with the other BSD's, so it isn't  
that different at the basic unix level. It's mainly different if you  
want to use OS X-specific functionality (like its gui environment  
instead of X11). Regarding serial port stuff: none of the Macs which  
can run the latest version of Mac OS X still has a serial port. There  
are USB-serial converters out there though, and their drivers (.e.g  
from Keyspan) create a regular serial port device in /dev which works  
identically to those under other unixes.

It's not because other interfaces are available, that there is no  
compatibility with the traditional unix way of working.


Jonas_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal