Using the CLI on Non-Windows Platforms


Of course, your CLI-based applications may not necessarily be targeted at computers running the Windows operating system; you may want to deploy them on non-Windows operating systems, too. Nothing in the design of the CLI ties it exclusively to either the Windows operating system or Intel processors. This section highlights this platform portability; specifically , it considers the Compact Framework, a version of the CLI for handheld devices such as Pocket PCs that use a variety of processors, and the Shared Source version of the CLI (SSCLI), which runs on operating systems such as Windows XP and BSD UNIX.

In general, this book has discussed the CLR, CLI, and.NET Framework as though only one implementation existed ”the implementation provided in the .NET Framework SDK. In truth, Microsoft provides several implementations of the CLR, and potentially other developers might write more. At this point, it is important to reiterate that the CLR and CLI are ECMA standards, of which numerous implementations are possible, in the same way that different vendors provide numerous implementations of the CORBA standard.

The ECMA CLI Standards

Before delving into the issues involved in porting the CLI to other platforms, it is important to understand how the ECMA standards define the CLI and assist in the porting process.

Profiles and Libraries

The ECMA CLI standard specifies a number of profiles; each profile essentially defines a set of functionality, as implemented by a group of libraries. Implementations of the CLI on various platforms specify which profiles ”that is, which set of libraries ”they support. Initially, there are two profiles of interest: the Kernel profile and the Compact Framework profile.

The Kernel profile is the base profile that is supported by all implementations of the CLI. It consists of the Runtime Infrastructure Library (RIL) and the Base Class Library (BCL). The RIL provides fundamental types and facilities such as those needed by compilers that target the CLI and those needed to load and execute types. The BCL provides basic types and services, such as strings, custom attributes, security, and collections.

The Compact Framework profile is a profile designed for mobile devices. It includes the Kernel profile as well as the Networking library, the Reflection library, and the XML library.

Figure 6.4 illustrates the relationship between these profiles and libraries.

Figure 6.4. Relationship between profiles and libraries in the CLI

graphics/06fig04.gif

Some other libraries, such as the floating-point library, are not part of any specific profile but can be supported by various implementations of the CLI. A complete discussion of the ECMA standard is beyond the scope of this book, but interested readers are advised that the specifications are available online at the ECMA Web site or at mirror sites.

Platform Adaptation Layer

An issue that arises with porting any software architecture, such as the CLR, to different platforms is the variation in interfaces and services exposed by the underlying operating system. To reduce this mismatch, the CLR uses a Platform Adaptation Layer (PAL). The PAL provides an application program interface (API) to the CLR; this API interacts with the underlying operating system's API to translate calls from the CLR into calls on the operating system. As a result, the PAL provides a consistent API to the CLR on any platform. When the CLR is ported to another platform, much of the work therefore remains confined to retargeting the PAL source code at the different operating system.

The interface provided by the PAL to the CLR is similar to the Win32 API. As such, on platforms such as Windows-based platforms, the PAL is fairly simple; that is, the interface expected by the CLR and the API provided by the operating system are a very close match. On other operating systems, such as BSD UNIX, the PAL may be quite complicated. For example, if the windowing or threading model provided by the operating system differs significantly from the one expected by the CLR (or possibly is not even provided at all), then the PAL may need to either provide this functionality, such as threading, or offer complex translations to map one windowing system to another.

Figure 6.5 illustrates the relationships among the CLR, PAL, and the operating system.

Figure 6.5. Relationships among the CLI, PAL, and operating system

graphics/06fig05.gif

Compact Framework

The Compact Framework is, naturally, an implementation of the Compact Framework profile; as such, it targets mobile devices, such as the Pocket PC. These devices are often referred to as resource constrained, reflecting the fact they traditionally have had significantly more limited capabilities, such as memory and screen size, than their desktop counterparts. For this reason, the functionality provided by the Compact Framework is a subset of the desktop CLI. The Compact Framework profile provides functionality such as the Windows Forms library, XML, and ADO.NET.

Given that the Compact Framework provides a subset of the functionality provided by the .NET Framework, developers familiar with the desktop CLI need learn no more concepts or libraries if they wish to target the Compact Framework. At worst, developers who are familiar with the desktop CLI need to know only which libraries are not available on the Compact Framework.

What types of functionality are currently not available in the Compact Framework? While developers can call COM components, COM components cannot be authored within this framework. Likewise, no support is provided for Reflection.Emit or the Remoting services. Also, facilities such as JIT compilation at installation time, which is otherwise provided by ngen , is not available under the Compact Framework.

Smart Device Extensions

A version of the Compact Framework implementation, called the Smart Device Extensions (SDE), is currently available in beta form. The SDE makes the development of programs that target the Compact Framework much simpler. By integrating the SDE into Visual Studio, developers can produce applications that run on mobile devices but use the abilities of Visual Studio to do so. For example, services such as the Forms Designer, remote debugging, and device emulation simplify development of Compact Framework applications under Visual Studio. When a programmer is developing applications for the Compact Framework, Visual Studio automatically filters the developer's views, removing components and facilities that are not available under the Compact Framework (see Figure 6.6).

Figure 6.6. Designing an application with Smart Device Extensions

graphics/06fig06.gif

If the application depicted in Figure 6.6 is compiled, downloaded to a Pocket PC, and executed, it produces the output shown in Figure 6.7.

Figure 6.7. Output produced by an SDE-generated application

graphics/06fig07.gif

Shared Source Common Language Infrastructure

The SSCLI is an implementation of the CLI that runs on both Windows XP and BSD UNIX. It includes both C# and ECMA script compilers and is available for noncommercial use. Potential users are strongly urged to read the SSCLI license before installing the source code to ensure that the license meets their needs. A major goal of the SSCLI is to promote experimentation by developers on a real version of the CLI, and it is anticipated that researchers and universities will make extensive use of the SSCLI. The source code has been designed and documented to facilitate porting to other platforms (porting the SSCLI to another platform is left as an exercise for the reader).

The SSCLI is distributed as source code and compiled after installation on a machine. The current source code tree consists of approximately 12MB; this download is a single compressed file. When expanded, the SSCLI includes almost 2 million lines of source code and nearly 6000 individual source files; the majority of this code ( roughly 1.1 million lines) is written in C/C++. In addition, the SSCLI include some 600,000 lines of C#, some CIL code, and some processor-specific assembly code. The distribution contains an assembler, disassembler, linker, and debugger.

Be forewarned: There are a number of simplifications in and omissions from the SSCLI as compared with the commercial version of the .NET Framework. Some of these decisions were made for technical reasons ”for example, COM Interoperability mechanisms are not provided because COM is not available on platforms other than Windows. Windows Forms, the library that wraps the Windows GUI components, is also not supported. In addition, because the SSCLI is an implementation of the CLI, it does not provide an implementation of all of the libraries built on top of the CLI, such as ASP.NET.

To make the SSCLI more approachable for developers and to increase its chances of adoption by universities in the teaching setting (and to differentiate it from the commercially available product), the SSCLI contains some components that are less complicated than their commercial counterparts. For example, its garbage collector is a much simpler and less optimized component than the commercial product. Similarly, the class library that ships with the SSCLI is a subset of the class library available with the .NET Framework.

The following program output was generated by running one of the previous sample applications (Listing 4.5) under the Windows SSCLI execution engine. No recompilation or modification of any sort was required.

 C:\Project7\Demos\AssemblyEvidence>c:\sscli\build\v1.x86fst  chk.rotor\clix.exe AssemblyEvidence.exe <System.Security.Policy.Zone version="1">   <Zone>MyComputer</Zone> </System.Security.Policy.Zone> <System.Security.Policy.Url version="1"> <Url>file://C:/sscli/build/v1.x86fstchk.rotor/mscorlib.dll </Url> </System.Security.Policy.Url> <StrongName version="1"             Key="00000000000000000400000000000000"             Name="mscorlib"             Version="1.0.3300.0"/> 


Programming in the .NET Environment
Programming in the .NET Environment
ISBN: 0201770180
EAN: 2147483647
Year: 2002
Pages: 146

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net