Carbon (API)

Carbon (API)

Infobox software
name = Carbon

developer = Apple Inc.
latest_release_version =
latest_release_date =
latest_preview_version =
latest_preview_date =
programming language =
operating_system = Mac OS X
genre = Widget toolkit
license = Proprietary
website = [http://developer.apple.com/carbon/ developer.apple.com/carbon/]

Carbon is Apple Inc.'s procedural API for the Macintosh operating system, which permits a good degree of forward and backward compatibility between source code written to run on the older and now dated Classic Mac OS (Version 8.1 and later), and the newer Mac OS X. It is one of five APIs natively available for Mac OS X; the others are Cocoa, POSIX, Toolbox (for the obsolete Classic environment), and Java. Carbon is not fully compatible with 64-bit programs under Mac OS 10.5.

Overview

The Carbon APIs are published and accessed in the form of C header files and dynamically linkable libraries. In Mac OS X, much functionality is contained in "ApplicationServices.framework". In Classic Mac OS, most functions are in a single library called CarbonLib. These different implementations of the APIs are interchangeable from the perspective of the executable. This permits a program that conforms to the Carbon specification to run natively on both operating systems. However, if an application uses a single function "not" in Carbon, compatibility with Mac OS X requires the Classic environment.

The Carbon APIs were designed to include as many of the older Toolbox APIs as possible, to permit easy porting of most legacy code to Mac OS X. Such porting was known as "Carbonization". Carbon also added new functionality and new abstractions. Previously, many data structures of the OS were exposed and manipulated directly by the program. In Carbon, most such structures became fully opaque, and many new APIs were added to access them. This encouraged cleaner and less error-prone code, and made it easier for Apple to modify the operating system. Carbon removed some functions that were specifically attached to the older Mac OS, and removed some obsolete technologies altogether. Backward compatibility remained a focus as long as Mac OS 9 was developed, as later updates such as 9.2.2 were largely to improve support for newer software. However, little Carbon software today remains compatible with Mac OS 9, as the interface has continued to evolve. Carbon was not intended to guarantee backward compatibility. If a programmer desires compatibility with Mac OS 9.1, they must test and debug it with Mac OS 9.1 specifically. Between Mac OS 8.6 and Mac OS 9.2.2, CarbonLib gradually evolved from an adaptation of the QuickTime for Windows user interface API into the basis for much of the later Classic Mac OS development.

Carbon is sometimes seen as a transitional or legacy technology. This is incorrect, and it is misleading to describe it as a technology per se. Carbon is a set of application-level Mac OS X APIs for the C programming language. They are the most efficient alternative when the underlying operating system functionality is also implemented in C. They are also the most versatile, accessible from C, C++, Pascal, Ada, or any other language with suitable interface headers. A higher level approach may be taken with Carbon by using an application framework built on it, for example MacApp, Metrowerks PowerPlant or MacZoop. Many parts of the Cocoa API likewise implement Carbon for Objective-C. Also, many Carbon APIs provide C language access to functionality implemented in Objective-C. In general, it is inefficient for a programmer to be overly concerned with the underlying operating system implementation.

At WWDC 2007, Apple revealed that it will not be possible to compile Carbon apps as 64-bit code for Leopard, contrary to previous statements. [ [http://arstechnica.com/journals/apple.ars/2007/06/13/64-bit-support-in-leopard-no-carbon-love "64-bit support in Leopard: no Carbon love"] ] Some lower-level parts of Carbon, such as the File Manager, are expected to be available in 64 bit.

Architecture

Carbon descends from the Toolbox, and as such, is composed of "Managers". Each Manager is a functionally-related API, defining sets of data structures and functions to manipulate them. Managers are often interdependent or layered.

Newer parts of Carbon tend to be much more object-oriented in their conception, most of them based on Core Foundation. Some Managers, such as the HIView Manager (a superset of the Control Manager), are implemented in C++, but Carbon remains a C API.

Some examples of Carbon Managers:

* File Manager — manages access to the file system, opening closing, reading and writing files.
* Resource Manager — manages access to resources, which are predefined chunks of data a program may require. Calls File Manager to read and write resources from disk files. Examples of resources include icons, sounds, images, templates for widgets, etc.
* Font Manager — manages fonts. Deprecated since Mac OS X v10.4 because it is part of QuickDraw in favor of Apple Type Services (ATS).
* QuickDraw — 2D graphics primitives. Deprecated since Mac OS X v10.4 in favor of Quartz 2D.
* Carbon Event Manager — converts user and system activity into events that code can recognise and respond to.
* HIObject — a completely new object-oriented API which brings to Carbon an OO model for building GUIs. This is available in Mac OS X v10.2 or later, and gives Carbon programmers some of the tools that Cocoa developers have long been familiar with. Starting with Mac OS X v10.2, HIObject is the base class for all GUI elements in Carbon. HIView is supported by Interface Builder, part of Apple's developer tools. Traditionally GUI architectures of this sort have been left to third-party application frameworks to provide. Starting with Mac OS X v10.4, HIObjects are NSObjects and inherit the ability to be serialized into data streams for transport or saving to disk.
* HITheme — uses QuickDraw and Quartz to render graphical user interface (GUI) elements to the screen. HITheme was introduced in Mac OS X v10.3, and Appearance Manager is a compatibility layer on top of HITheme since that version.
* HIView Manager — manages creation, drawing, hit-testing, and manipulation of controls. Since Mac OS X v10.2, all controls are HIViews. In Mac OS X v10.4, the Control Manager was renamed HIView Manager.
* Window Manager — manages creation, positioning, updating, and manipulation of windows. Since Mac OS X v10.2, windows have a root HIView.
* Menu Manager — manages creation, selection, and manipulation of menus. Since Mac OS X v10.2, menus are HIObjects. Since Mac OS X v10.3, menu content may be drawn using HIViews, and all standard menus use HIViews to draw.

Event handling

The Mac Toolbox's Event Manager originally used a polling model for application design. The application's main event loop asks the Event Manager for an event using GetNextEvent. If there is an event in the queue, the Event Manager passes it back to the application, where it is handled, otherwise it returns immediately. This behavior is called "busy-waiting", running the event loop unnecessarily. Busy-waiting reduces the amount of CPU time available for other applications and decreases battery power on laptops. The classic Event Manager dates from the original Mac OS in 1984, when whatever application was running was guaranteed to be the "only" application running, and where power management was not a concern.

With the advent of System 7.0 and the ability to run more than one application simultaneously came a new Event Manager call, "WaitNextEvent", which allows an application to specify a sleep interval. One easy trick for legacy code to adopt a more efficient model without major changes to its source code is simply to set the sleep parameter passed to "WaitNextEvent" to a very large value—on OS X, this puts the thread to sleep whenever there is nothing to do, and only returns an event when there is one to process. In this way, the polling model is quickly inverted to become equivalent to the callback model, with the application performing its own event dispatching in the original manner. There are loopholes, though. For one, the legacy toolbox call "ModalDialog", for example, calls the older "GetNextEvent" function internally, resulting in polling in a tight loop without blocking.

Carbon introduces a replacement system, called the Carbon Event Manager. The original Event Manager still exists for compatibility with legacy applications). Carbon Event Manager provides the event loop for the developer (based on Core Foundation's CFRunLoop in the current implementation); the developer sets up event handlers and enters the event loop in the main function, and waits for Carbon Event Manager to dispatch events to the application.

Timers

In the classic Mac OS, there was no operating system support for application level timers (the lower level Time Manager was available, but executed timer callbacks at interrupt time, during which you could not safely make calls to most Toolbox routines). Timers were usually left to application developers to implement, and this was usually done by counting elapsed time during the "idle" event - that is, an event that was returned by "WaitNextEvent" when any other event wasn't available. In order for such timers to have reasonable resolution, developers could not afford WNE to delay too long, and so low "sleep" parameters were usually set. This results in highly inefficient scheduling behaviour, since the thread will not sleep for very long, instead repeatedly waking to return these idle events. Apple added timer support to Carbon to address this problem -- the system can schedule timers with great efficiency.

Notes

External links

* [http://developer.apple.com/carbon/ Apple Developer Connection: Carbon]
* [http://carbondev.com/ Carbon Dev]


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать курсовую

Look at other dictionaries:

  • Carbon (API) — Saltar a navegación, búsqueda Carbon es una API procedimental del sistema operativo Mac OS y que ofrece un alto grado de retrocompatibilidad con el código escrito para versiones de Mac OS Classic (de Mac OS 8.1 en adelante hasta Mac OS 9). Carbon …   Wikipedia Español

  • Carbon (API) — У этого термина существуют и другие значения, см. Carbon. Carbon  это рабочая среда приложений API, выпущенная компанией Apple Inc. для операционной системы Mac OS. Является упрощённой и обновлённой версией предыдущей рабочей среды Mac OS 9 …   Википедия

  • Carbon (disambiguation) — Carbon may refer to:Chemical element*Carbon, the chemical element *Carbon black, a filler often used to improve the properties of rubber or plastic compounds *Carbon chauvinism, a term meant to disparage the assumption that the molecules… …   Wikipedia

  • Carbon (Mac OS X) — Carbon est l une des Interface de programmation (API) du Mac OS. Il fourni des accès en langage C aux services du système. Carbon permet une bonne rétrocompatibilité des programmes afin qu il fonctionne sur les versions désormais obsolètes que… …   Wikipédia en Français

  • Carbon dioxide flooding — Carbon dioxide (CO2) flooding is a process whereby carbon dioxide is injected into an oil reservoir in order to increase output when extracting oil.When a reservoir’s pressure is depleted through primary and secondary production, Carbon Dioxide… …   Wikipedia

  • Windows API — The Windows API, informally WinAPI, is Microsoft s core set of application programming interfaces (APIs) available in the Microsoft Windows operating systems. It was formerly called the Win32 API; however, the name Windows API more accurately… …   Wikipedia

  • Windows API — (англ. application programming interfaces)  общее наименование целого набора базовых функций интерфейсов программирования приложений операционных систем семейств Microsoft Windows корпорации «Майкрософт» и совместимой с ними свободной… …   Википедия

  • Win32 API — Windows API (application programming interfaces) общее наименование целого набора базовых функций интерфейсов программирования приложений операционных систем семейств Windows и Windows NT корпорации «Майкрософт». Является самым прямым способом… …   Википедия

  • Cocoa (API) — Cocoa Developer(s) Apple Written in Objective C Operating system Mac OS X Type Software framework …   Wikipedia

  • TextEdit (API) — TextEdit was the name of a collection of application programming interfaces (APIs) in the classic Mac OS for performing text editing.These APIs were originally designed to provide a common text handling system to support text entry fields in… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”