Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Bailey O.H.Embedded systems.Desktop integration.2005

.pdf
Скачиваний:
70
Добавлен:
23.08.2013
Размер:
9.53 Mб
Скачать

100

Chapter 4 / Designing Cross-Platform User Applications

 

 

VNC

Monitor

Keyboard

Mouse

Server

 

 

 

 

Display Output

 

 

 

VNC Server

 

 

Hardware Layer

 

 

 

Display

 

 

VNC Client

Keyboard / Mouse

 

 

Hardware Layer

 

Figure 4-5

VNC intercepts display and keyboard data and echoes the complete display to the client machine. All applications running on the desktop are available to the client in a view-only or full-access mode. X Windows provides more security since only the application running remotely is displayed, not the complete desktop.

Chapter 4 / Designing Cross-Platform User Applications

101

 

 

Alternatives to Cross-Platform

Development

Before leaving this topic we need to explore other alternatives to developing cross-platform applications. We’ve explored the native graphic interfaces for both Windows and UNIX, but there is one more approach yet to be mentioned. Several years ago Red Hat developed an interface layer for Windows that allowed many of the native UNIX desktops to run on Windows. This was accomplished by building a UNIX interface layer as illustrated in the following figure.

 

 

 

 

Development Tools and

 

GNU C / C++ / Objective C / Fortran

 

 

 

 

Frameworks

 

Qt

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Graphic Desktop

 

 

 

 

 

 

 

Cygwin

 

 

Motif / KDE / GNOME / X-Open Desktop Manager

Remote Client

 

 

Managers

 

 

 

 

 

Windows API

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Application Program

 

 

 

 

 

 

 

 

 

 

Console Mode Manager

X Display Manager

 

 

 

 

Support

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

MS-Windows Kernel

 

 

 

 

 

 

 

 

 

 

Scheduler

Device Drivers

System Services

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Hardware Layer

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Figure 4-6

Named Cygwin, this product is designed to provide UNIX shell emulation on Windows. A custom version of the GNU compiler collection was developed to support the Cygwin architecture.

When invoked under Windows, the Cygwin product opens a Windows console window that provides a UNIX shell as shown in Figure 4-7.

Chapter 4

102

Chapter 4 / Designing Cross-Platform User Applications

 

 

Figure 4-7

Once this shell is running we can start an X Windows session just as we would under Linux or UNIX. Figure 4-8 shows a native X Windows session running on a Windows XP machine.

Figure 4-8

Chapter 4 / Designing Cross-Platform User Applications

103

 

 

The familiar Windows title bar at the top is the only indicator that X Windows is running on a Windows XP machine. Now this in and of itself isn’t anything other than a couple of applications running on Windows XP and emulating a UNIX command shell and X Windows server and client. However, as shown in Figure 4-6, desktop managers also run in this environment. KDE, GNOME, and several other desktop managers work well within this context.

Emulation vs. Native Execution

What makes this a unique approach is where the emulation is handled. The Cygwin emulator sits between the application layer and the Windows API. It translates Windows API calls to native calls for the chosen desktop manager. This allows developers to compile their existing UNIX/Linux applications by using the Cygwin libraries to generate a cross-platform target. In short, only two rules apply. First, a desktop manager must be chosen that is supported under Cygwin. Second, the platform in which the application is compiled must support the Cygwin target. Both of these subjects will be covered in detail in Part II.

Programming Languages

Next in our list of cross-platform considerations is the choice of programming languages. A suitable programming language can have a dramatic effect on project length and required resources. There are many factors to consider when choosing a programming language for multiplatform development. Not all languages and compilers are available on multiple platforms, which makes choosing a language and compiler less daunting, but the choice is very important nonetheless.

Chapter 4

104

Chapter 4 / Designing Cross-Platform User Applications

 

 

Employee Skill Sets

Above all else, employee or contractor skill sets must play a role in choosing the right languages. If you select a language without considering the skills of the developers, you may lose much more than you gain. Choose a programming language level that matches the skill level of the team. Before we delve into the specifics of programming language selection, consider the following factors before making a final decision.

Are my developers experienced in the languages being considered?

If they are not, have they had experience with a similar type of language?

Are there languages available that the developers have experience in and that are available on all required platforms?

If not, can the developers become fluent in using the selected languages quickly and still bring the project in on time?

Taking these factors into account early in the language selection process can save not only time but frustration as well. If necessary, ask the developers for their input and encourage them to be honest. There is nothing wrong if an individual is uncomfortable with or inexperienced in a given language or programming discipline.

Visual Application Development or Hand Coding

It wasn’t so long ago that we hand-coded everything. Reusable code was defined as collections of functions that were added to libraries and the libraries were distributed with the products.

Designing a graphical user interface in the old days meant adding color to the text and using crude ASCII characters that gave us block text graphics. Today it’s an entirely different world. Almost all new user applications are graphic based. Today, input is managed by events instead of a program loop. This gives much better control over program flow, and the graphical user interfaces

Chapter 4 / Designing Cross-Platform User Applications

105

 

 

provide bells and whistles never even thought of 10 years ago. Event-driven software is designed much differently than the old DOS or text mode programs.

Hand coding event-driven software is a tedious and time-con- suming job. It can easily be necessary to define thousands of variables that manage the user interface or capture mouse events. To streamline this process (and spend less than a lifetime writing a single application), we have visual designers and visual development systems that allow the developer to focus on the application rather than the mechanics. Visual development tools come in many forms and price ranges. There are complete development systems that include language compiler, visual controls, linkers, and even program installers. These products range from free to several thousand dollars depending on features, number of supported platforms, and other factors. Borland, Microsoft, and Metrowerks are just a few of the companies that offer these programming tools.

Visual Development vs. Development

Framework

Development frameworks, mentioned earlier, provide a visual designer and libraries that work with several languages and/or platforms rather than a complete development platform. Instead of providing a complete development environment, a visual designer and libraries are provided that work with several languages and/or platforms. Again, these tools vary widely in price and features. In the UNIX/Linux environment many of these tools are open source, which means you can get the source code in addition to the object code. Many products may be available that perform a certain task. One example of this is visual designers. There are a wide variety of vendors that provide visual designers for these application frameworks. In some cases purchasing the add-on components to make the framework useful can be very expensive. You may also be dealing with many vendors instead of just one. In short, you need to examine these

Chapter 4

106

Chapter 4 / Designing Cross-Platform User Applications

 

 

tools to see if they really provide a cost advantage or are more trouble than they are worth. Qt, GTK+, wxWindows, and the Zinc interface library are some examples of application frameworks.

Free vs. Commercial Products

Some of these tools and compilers have both free and commercially sold versions. This can be confusing! When can I use a free version and when do I have to purchase a commercial version? In most cases, if you are developing an open-source product that will be given away, then you qualify to use the free version and you can also distribute any required libraries for free. If, however, you are developing products for sale or you do not want to give away the source code, then you may be required to purchase a commercial license. If you develop an open-source product and later decide to sell it or no longer distribute the source code, you may need to purchase a commercial license at that time. You need to check each product you intend to use to see what the license states. Some products are bundled with commercial products and are freely redistributable only when using the compiler or language it was originally included with, so again check the license to see what your rights are.

GNU vs. GPL Licensing

There are also several types of open-source licensing. The two most common are GPL and GNU licensing. One license encourages free distribution of products both open source and commercially, while the other is much more restrictive when it comes to commercial distribution. Again, check the license and ask the advice of a lawyer. A few dollars spent on legal fees now may help you avoid buying your lawyer a nice house in the future.

Chapter 4 / Designing Cross-Platform User Applications

107

 

 

Programming Language Selection

The most popular language used in the Microsoft Windows environment is Visual Basic. Visual Basic has English-like syntax and a coding style that most people find easy to learn and use, and are comfortable with. Visual Basic is very popular among people who are not professional programmers but have a need to write an application. For developers who like Visual Basic-like syntax but need more access to the operating system, there is Delphi. Delphi provides a visual environment much like Visual Basic, but is more object oriented and is based on the Pascal language, which has more robust type-checking and very strict programming rules.

More experienced developers who need more control over a device or the operating system and are less concerned with syntax and more concerned with language features may also choose C or C++. The C language has been around longer than Pascal and some programmers prefer it or are simply more comfortable with the language.

For those who want the ultimate in portability at the application level, don’t need to interface with device drivers or operating system services, and are not concerned about execution speed, Java is an option. Java is object oriented, similar in syntax to C++, and is compiled to machine code at run time, much like the .NET programs. Java has been around longer than

.NET and is written and supported by Sun Microsystems. Java is free to use and distribute and can be run on almost any computer from embedded systems to mainframes.

It’s important to note that not all languages are cross-plat- form compatible. As with libraries, prices range from free to thousands of dollars depending on many factors. The following table lists by platform which languages are supported.

Chapter 4

108

Chapter 4 / Designing Cross-Platform User Applications

 

 

 

 

 

 

 

Table 4-1: Platform language support

 

 

 

 

 

 

 

 

Vendor/Compiler

Windows Support

UNIX/Linux Support

 

 

 

 

 

 

 

Microsoft C++

Yes

No

 

 

 

 

 

 

 

Borland C++

Yes*

Yes*

 

 

 

 

 

 

 

Borland Delphi

Yes*

Yes*

 

 

 

 

 

 

 

Borland Kylix

No

Yes

 

 

 

 

 

 

 

CodeWarrior

Yes

No

 

 

C/C++

 

 

 

 

 

 

 

 

 

Intel C++ Suite

Yes

Yes**

 

 

 

 

 

 

 

GNU C/C++

Yes

Yes

 

 

 

 

 

*Cross-platform support uses CLX library. ** Intel architecture only

As you can see, Microsoft compilers only support Windows platforms in native code form. Borland provides several suites of tools that offer two different mechanisms of cross-platform development. With the exception of Visual Studio .NET, Microsoft compilers only support Windows executables and native Windows API and generate machine code. They support cross-platform development for Windows and Linux using their CLX visual controls (CLX is based on the Qt graphic library). When you purchase a Windows version of Borland C++Builder or Delphi (Pascal) you also receive the Linux version of that language. Borland compilers that run on Linux are named Kylix (although they are the Linux version of Delphi). If you purchase Kylix as a separate product, you receive both the C++ and Delphi versions of the compilers. Borland has begun shipping Delphi 2005, which is Delphi for .NET and C#Builder for .NET. Using Delphi you can write a cross-platform program using CLX, which will generate a native executable for each platform or a

.NET program that can be run using the .NET framework. Borland also supports cross-platform development for the C# language, which is exclusive to .NET. The Borland product is C#Builder and is a visual development environment for developers who are familiar with Delphi or C++Builder development environments and the C# language.

Chapter 4 / Designing Cross-Platform User Applications

109

 

 

CodeWarrior from Metrowerks supports Windows and Macintosh native compilers. Intel provides C, C++, and Fortran compilers for the Windows and Linux platforms, although I have not used them.

And now we have reached the GNU compiler suite. GNU compilers have been around for many years and support more platforms and processors than the other compilers mentioned here combined. The GNU compilers support all Windows/UNIX/ Linux platforms on all supported processors for these operating systems, and are mature and full featured. Now the bad news: The compilers do not come with a standard IDE like the other products do. This means that no visual development environment exists that allows a user application interface to be visually created and integrated into the finished program, which means you may need to use several tools or even construct the user interface by hand. Using a trial-and-error method can take many hours to construct even the most simple user interface.

Programmer Editors

This is a final category of cross-platform tools. Again, there are products that range from free to several thousand dollars. Emacs is a free product developed originally for the UNIX and Linux environments. There are versions for UNIX, Linux, Windows, and several other systems as well.

Borland has introduced C++BuilderX, which is a development environment that supports multiple platforms and compilers. It includes Borland’s own compiler in the Windows version and also supports Visual C++ 6 and GNU for Windows. The product is also available for Linux and Solaris. While I have not worked with C++BuilderX very much, it provides UML diagramming in the commercial versions and allows multiple targets to be generated with the GNU compiler suite. The product does not offer a visual GUI designer so other products would need to be acquired for the interface development. Metrowerks also offers a Linux editor for developing programs with the GNU

Chapter 4

Соседние файлы в предмете Электротехника