Bailey O.H.Embedded systems.Desktop integration.2005
.pdf
450 |
Chapter 11 / Cross-Platform Application Development |
|
|
The User Application Layer
The user application layer can be implemented using a number of methods, languages, and tools. Now you may be asking exactly how we can write applications that execute unchanged on several different platforms. Let’s start by looking at our choices for application development.
Commercial Compilers
We have an assortment of commercial products to aid in our cross-platform efforts. For our purpose we will examine two commercial products: C++ Builder and Delphi, both from Borland International. There are actually three flavors of these two languages.
Delphi/Kylix
Delphi evolved from the old Turbo Pascal from the DOS days. Several years ago Borland introduced Kylix, which is Delphi for Linux. Both products support extended controls for their native platforms, but a cross-platform library called CLX is also included. Developing a program on one platform using the CLX controls allows the project to be ported to the other platform and compiled with little or no changes (if the proper development steps have been taken).
C++Builder
This product is the C++ equivalent of Delphi/Kylix. Unlike the Pascal products, C++Builder is named the same for both Windows and Linux. Also, like the Pascal version, native control libraries are available to take advantage of platform-specific controls, or the CLX library can be used. Again, using the CLX library provides easy cross-platform porting and compiling.
452 |
Chapter 11 / Cross-Platform Application Development |
|
|
be developed on one platform and then compiled on other platforms while providing the same look and feel on all of them. What’s more, some of these platforms can be integrated into cross-platform compilers, allowing development and compiling from within the same development environment on multiple platforms.
Common Application Layers
This differs from the application framework because the execution layer has been separated from the compile and link layers. In short, the same program image runs on multiple platforms without change. This is the newest of the technologies and this design is prevalent in the .NET framework. Now .NET doesn’t run on Linux but the open source equivalent Mono does. I have been able to compile a program on Mono for Windows and run the executable on the Linux Mono runtime. By the time this book hits the market there should be tools and languages that allow you to develop a program on .NET and run it on .NET or Mono on any platform. Stay tuned to www.time-lines.com for this.
The Device Interface Layer
OK, so we have several options in writing cross-platform applications: What about USB, RS-232, and Ethernet?
Well, the answer to this lies in the design and implementation of our shared libraries or DLLs. None of the host communications methods is functionally the same on Windows and UNIX/Linux. In order to accomplish a single-source solution, we will have to write a middle layer that provides a consistent functional interface between the application and device layers. In this layer we will hide the platform-dependent code and distribute the shared objects in executable form only. This will allow us
456 |
Chapter 11 / Cross-Platform Application Development |
|
|
Visual vs. Code Solutions
As we’ve just seen there are two different solutions available on the Delphi/Kylix platforms. These same solutions are also available on the C++ Builder/Kylix C++ platforms as visual controls.
But what about the standard function library being used in a cross-platform environment? Well, as it turns out the standard function library is an excellent choice for use with C++BuilderX. The following is a C++BuilderX DLL project on Windows. The standard function library only requires we use an ANSI C compiler, and all of the C++BuilderX supported compilers meet that criteria. Figure 11-3 shows the DLL project being edited on the Windows platform.
Figure 11-3
With C++BuilderX we can create a project that can be accessed on each platform. In this particular case we will create a separate project for Linux because the structure of a shared library is slightly different from a DLL on Windows.
458Chapter 11 / Cross-Platform Application Development
Note:
For more information on cross-compiling on C++BuilderX, please visit www.time-lines.com.
Socket Implementation
The host system is the UDP client in this case. Here’s how the communications will work. The host will attempt to connect to any thermostat listing on a specific port number. It will broadcast its request to establish a connection. The thermostat will “listen” for a connection request. When the request is received, it will check to see if the sender’s IP address is in a list of accepted connections. If it is, the thermostat will accept the connection and request a password. If the proper password is sent in response, the connection will be opened. If the password is incorrect, the connection will be closed and the thermostat will go back into listen mode.
It’s a little difficult to show how the code for this works in print. The best way to explain this further is to have you download the code for Chapter 11. In the Chapter 11 folder there will be two other folders — UDPSvr and UDBCli. Within each of these folders are Windows, Linux, and Embedded folders. You can set up a working UDB client and server using Windows or Linux. The Embedded folder only contains the UDP server since it is not initiating the client side of UDP.
