Medium 9781565928565

Palm OS Programming: The Developer's Guide

Views: 1363
Ratings: (0)

With more than 16 million PDAs shipped to date, Palm has defined the market for handhelds, having dominated this class of computing devices ever since it began to outpace competitors six years ago. The company's strength is the Palm OS, and developers loyal to this powerful and versatile operating system have created more than 10,000 applications for it. Devices from Handspring, Sony, Symbol, HandEra, Kyocera, and Samsung now use Palm OS, and the number of registered Palm Developers has jumped to 130,000.If you know C or C++, and want to join those who are satisfying the demand for wireless applications, then Palm OS Programming: The Developer's Guide, Second Edition is the book for you. With expanded coverage of the Palm OS--up to and including the latest version, 4.0--this new edition shows intermediate to experienced C programmers how to build a Palm application from the ground up. There is even useful information for beginners.Everything you need to write a Palm OS application is here, from user interface design, to coding a handheld application, to writing an associated desktop conduit. All the major development environments are discussed, including commercial products such as Metroworks CodeWarrior, Java-based environments such as Sun KVM and IBM VisualAge Micro Edition, and the Free Software Foundation's PRC-Tools or GCC. The focus, however, is C programming with CodeWarrior and PRC-Tools. New additions to the second edition include:

  • A tutorial that takes a C programmer through the installation of necessary tools and the creation of a small handheld application.
  • A new chapter on memory, with a comprehensive discussion of the Memory Manager APIs.
  • Greatly expanded discussions of forms, forms objects, and new APIs for the Palm OS.
  • Updated chapters on conduits that reflect the newer Conduit Development Kit.
The best-selling first edition of this book is still considered the definitive guide for serious Palm programmers; it's used as the basis of Palm's own developer training materials. Our expanded second edition promises to set the standard for the next generation of Palm developers.

List price: $51.99

Your Price: $41.59

You Save: 20%

 

19 Slices

Format Buy Remix

1. The Palm Solution

ePub

Over the last five years, the market for handhelds has changed dramatically in many ways. The customer base has significantly broadenedthere are early adopters, loyal followers, and business enterprise users, mixed with growing numbers of less-sophisticated general consumers. All of these folks are buying handhelds to organize differing aspects of their lives and they have enormously varying tolerances for difficulty and desires for the latest cool features. As of mid-2001, Palm and its licensees have sold more than 13 million handhelds and they control close to 80 percent of the market. This is a lot of people using a lot of handhelds.

This is all great news if you want to write software for the Palm OS platform. There are lots of potential customers. Whether you are developing consumer software, or enterprise software for thousands to tens of thousands of units, or a vertical application for a particular niche market, the Palm OS/device combination will work for you. It will, that is, if you pay attention to the key features that have made it successful.

 

2. Technical Overview and Development Environments

ePub

Developing for the Palm OS is in some ways similar to other platforms and in other ways strikingly different. Two important similarities are as follows:

Applications are event-driven.

You can use anything from C++, to standard C code, to assembler, to scripting.

Differences tend to center around features crucial to the device size and purpose. These include how the Palm OS handles:

Memory requirements

Application and data storage

Connectivity of the device to the desktop

Most importantly, you should remember that the relationship between the device and the OS is extremely tight. Further, everything has been built on the premise that the handheld is an extension, not a miniature version, of the desktop. It specializes in ensuring that mobile tasks are simple and fast.

First, lets examine this tight interaction of the OS and the applications on the handheld. The Palm OS runs on top of a preemptive multitasking kernel. One task runs the UI, while other tasks handle things like monitoring input from the stylus. The UI permits only one application to be open at a time. Thus, when your application is open, it (more or less) has control of the entire screen.

 

3. Designing a Solution

ePub

Now that you know about the features of the Palm OS and you have figured out what development environment you are going to use, it is time to design a new application. To do this, you need to know what the Palm OS provides by way of UI elements. Second, you need a description of how and where these elements are used in an application. To this end, we show you several forms, dialog boxes, and alerts; we discuss what works and what doesnt, so that you can intelligently design your own projects.

From this discussion of UI elements, we move to the more general discussion of key issues that need to be addressed in the design of any Palm OS application. We cover everything from what OS versions you should support to determining what tasks an application should accomplish.

From this general overview, we move to a concrete example: the UI of the Sales application. This is the sample application that we are going to create and then dissect in this book. We show you its design, what actions the user performs, how we prototyped it, and the design complications we encountered. Once weve covered the handheld portion of the application, we turn to a description of its conduit.

 

4. Tutorial

ePub

You have learned all about development environments, design issues, and the Palm platform and now its time to put all that knowledge to work. With our help, you are going to create, build, and download a simple Palm OS application. The good and bad news is that we are going to walk you through this process step by step. Its good news because a good programmer, new to the platform, can often use just this type of help. Its bad news because it involves telling you how to use a bunch of different tools and development environments that have their own release cycles that will most likely be obsolete within six months.

The software tools discussed here are those current as of mid-2001. Each discussion of a tool will include its version number. As newer versions of tools are made and installation procedures change, well update the relevant sections of this chapter online.

Thus, the first thing you should do before reading the printed version of this chapter is to go to our web site ( http://www.calliopeinc.com/palmprog2/) to see whether there are newer instructions.

 

5. Structure of an Application

ePub

Before you can write a Palm application, you need to know how it interacts with the OS and how it is organized. Prior to this discussion, we cover the standard terminology and naming conventions within the Palm OS. Once you know what the words mean, we can talk about the application and the OS.

We start with a discussion of how an application is structured to run on the Palm OS. You will learn that a Palm application is an event-driven system and that its routines are structured to handle various types of events. We will describe an applications life cycleits starting, running, and closing. To help solidify your understanding of these points, we provide a simple application, OReilly Starter, which is a prototypical Palm application. We walk you through its organization (for example, its source files, utility files, and so on) and then show you the source code in its routines. While the application doesnt do much, it contains all of the standard routines and has the correct structure for any Palm application. You can use it as the starting point for your own work.

 

6. Memory Manager

ePub

All Palm devices have two types of memory: read-only memory (ROM) and random access memory (RAM). This may not seem so different from other operating systems, you might be thinking to yourself. Well, there are some unique twists in the Palm OS. Lets talk about ROM first and then RAM to see how they are used differently.

Read-only memory (ROM) contains:

The operating system

The built-in applications

Default databases

This ROM is an actual masked ROM on some devices (for example, Handspring Visor and Palm m100). On most devices, however, this memory is actually Flash RAM, which can be programmatically changed. The fact that Flash can be changed is what allows most devices to be updated with later versions of the OS. In addition, there are third-party applications that allow users to add databases or applications to the Flash. This is normally done to take advantage of unused space in Flash, and to have databases or applications that will be preserved even after a hard reset.

At this point, there is no official support for adding databases or applications to Flash other than in the Symbol units (the Symbol SDK has a utility for creating ROM images that includes specific databases and applications).

 

7. Debugging Palm Applications

ePub

There are a variety of useful debugging tools for your Palm OS application. The best by far is the Palm OS Emulator (POSE). With it you can code, build, and test your handheld application, with nothing more than a desktop computer. The strategic use of the reset buttons can be useful as well. There are also a number of hidden Graffiti shortcut characters that offer you debugging aids and shortcuts. Source-level debugging is available for both CodeWarrior and the PRC-Tools and can go a long way towards easier problem fixing.

In this chapter, we will show you how to use all of these methods to debug your applications. We will also discuss Gremlinsthe useful testing creatures that bear not the slightest resemblance to the fanciful beings. Gremlins in the Palm world are little monkeys who bash about randomly on your code looking for problems. You may not like them, but you will find them very helpful for catching bugs you might otherwise miss.

In the first edition of this book, we put this chapter much later, at the end of the section. Upon reflection, we think this was a mistake. We moved it to the front because we want you to become familiar with these tools as soon as possible, and certainly before you delve too deeply into any real coding. Read this chapter carefully and take the time to learn how to use all of these tools before you start writing your own application. Following this one bit of advice will save you hours of frustration.

 

8. Resources and Forms

ePub

This chapter describes the forms you create in a Palm OS application. We also explain how the resources associated with these forms are created and used. We explain each type of form, describe important APIs, and then give you some programming tips where applicable. After looking at each type of form, we show you sample code in which the forms are implemented. Many of these forms are in our Sales application. Some, however, are more easily understood in smaller pieces of sample code and so we show them to you in this way.

A form without any objects would be no more interesting than a blank window. In order to make a form useful it needs to be populated with form objects, which are the subject of the following chapter. In this chapter, you learn the details of implementing forms in an application. In the next chapter, you learn any remaining form details and how to implement the objects in those forms. If it were not already obvious, these two chapters are closely related and should be read together.

 

9. Form Objects

ePub

The elements that populate a form are called form objects. Before getting into the details of specific form objects, however, there are some important things to know about how forms deal with all form objects.

The form contains an array of form objects. Each form object has the following:

For example, a checkbox contains a Boolean with the current checkbox value. A label contains the text and the font used for the label. A scrollbar contains the current scroll value, along with minimum and maximum values.

The index is the (0-based) index of the form object within the form. Most (but, to keep you on your toes, not quite all) Form Manager routines require a form object index to specify a particular form object.

The form object ID is a number that you specify for the form object in the form resource. These ID numbers are commonly unique across all forms (for example, the form object IDs for a form with ID 1000 would commonly have IDs 1001, 1002, 1003, and so on), but theres nothing preventing form objects in different forms from sharing a common ID. Youll need to convert an ID into an index number before calling most Form Manager routines.

 

10. Databases

ePub

Now we are going to talk about how data is organized. In Chapter 6, we told you that data, rather unusually, resides in RAM memory in the Palm OS. This memory is in turn divided into two sections: the dynamic and storage heaps. Permanent data resides in the storage heap and is accessed via the Data Manager (the dynamic heap that we talked about in Chapter 6 is managed strictly by the Memory Manager).

We will give you an overview of how data and databases are organized in the Palm OS. We will cover everything you need to know, from types of databases to creating databases, modifying them, creating individual data records; adding, modifying, and deleting them from a database; and different ways of handling sorting. We will also cover other essential topics such as how to deal with secret records and working around the 64K size limitation. Finally, we will take all this information and apply it to the creation of the databases and records in our Sales sample application. We will show you the source code for the routines that handle all of these database and record tasks.

 

11. Menus

ePub

Palm application menus should look the same from application to application; they should share a consistent organization and set of menu items. Indeed, some menus, such as the Edit menu, should be identically organized regardless of the application.

Figure 11-1 shows a sample menu bar containing two menus: Customer and Options. The open Customer menu contains two menu items: New Customer and Beam all Customers.

Figure11-1.Application menu bar, menus, and menu items

Note that menu items commonly have shortcuts associated with them. These are Graffiti letters that are unique to each menu item. By doing the stroke-and-letter shortcut, the user can perform the operation without first selecting the menu item. For example, / N brings up a New Customer form. As a rule, you should add these shortcuts to menu items wherever necessary and always with standard menu items. Make sure that the most frequent operations have shortcuts, and dont put a shortcut on an infrequent action (such as the About box).

 

12. Extras

ePub

In this section, we discuss the Find feature of the Palm OS. First, we give you an overview of Find, the UI, and its intended goals. Second, we walk through the entire Find process from beginning to end. Third, we implement Find in our sample application and discuss important aspects of the code.

The Palm OS UI supports a global Finda user can find all the instances of a string in all applications. The operating system doesnt do the work, however. Instead, it orders each application, in turn, to search through its own databases and return the results.

There is much to be said for this approach. The most obvious rationale is that the operating system has no idea whats inside the records of a database: strings, numbers, or other data. Therefore, its in no position to know whats a reasonable return result and whats nonsense. Indeed, the application is uniquely positioned to interpret the Find request and determine the display of the found information to the user.

Find requests are sent from the OS by calling the applications PilotMain (see Section 5.5) with a specific launch codesysAppLaunchCmdFind along with parameters having to do with interpreting the Find.

 

13. Communications

ePub

In this chapter, we discuss the types of communication available on the Palm OS. We go into detail about two of these types and show you how to write code for each type.

Palm OS supports three kinds of communication:

Serial communication occurs between the handheld and other devices using the cradle port. This is the most common form of communication on the Palm OS. For an example, well develop a special serial application that communicates (indirectly) with satellites.

Currently, this communication standard is available only via a serial or modem connection. The future has no boundaries, however, so you may see built-in Ethernet or devices using wireless TCP/IP appear some day. To show you how to use TCP/IP, well create a small application that sends email to a server.

This is an industry-standard hardware and software protocol for communicating over infrared. We wont discuss the details of communicating using IrDA in this chapter. We will, however, show you how to use the Exchange Manager to implement beaming (see Section 12.2). Beaming is a data-exchange method built on top of IrDA.

 

14. Getting Started with Conduits

ePub

It is time to discuss conduitswhat they do and how to create them. In this chapter well describe the conduit development environment, important APIs, tricky little problems you might encounter when installing a conduit, conduit entry points, and information that gets sent to the HotSync log. Since it will also help if you understand (code-wise) what happens when a Palm device is plopped into a cradle and the user pushes the HotSync button, well show you those events too.

Understanding these events is useful if you want to know what happens when your conduit code is called and how it interacts with the Sync Manager to perform its tasks.

After all of this, well take a brief detour to discuss the types of applications that can profitably use the Backup conduit (a conduit that simply archives databases on the desktop). Well also show you the code changes required in your application if you want to use the Backup conduit as your conduit solution.

Last of all, well create an actual conduit and show you how to use the Conduit Inspector and POSE to debug it. This conduit is for the Sales application and is built using Visual C++. It doesnt do muchit just writes a message to the log filebut its still quite useful. This example will demonstrate what is involved in creating a minimal conduit and what it takes to get to the point where syncing is ready to begin.

 

15. Moving Data to and from the Handheld with a Conduit

ePub

Database management during synchronization is handled completely by the conduit.

There is a standard database call used by the Sync Manager to create a database:

Like all the Sync Manager routines, SyncCreateDB returns SYNCERR_NONE if no error occurs; otherwise, it returns an error code. SyncCreateDB creates a new record or resource database on the handheld and then opens it. You have the same control over database creation from within the conduit that you have on the handheld.

The rDbStats parameter is of the type CDbCreateDBClass and contains the following important fields:

Output field. On a successful return, this contains a handle to the created database with read or write access.

Database creator ID. This should typically match the creator ID of the application.

The database attributes. Choose one of the following: eRecord for a standard database or eResource for a resource database. Another flag within which you can do a bitwise-or is eBackupDB (this sets the backup bit of the database).

 

16. Two-Way Syncing

ePub

Because handhelds can be synced to more than one desktop machine, there are two different forms of syncing. These two forms are:

This occurs when the handheld is being synced to the same desktop machine that it was synced to the previous time.

This occurs when a handheld is synced to a different machine from its previous sync. In such cases, a set of problems arise in determining what changes have been made.

Before discussing either type of syncing, however, we need to explain some of the difficulties that can arise in situations in which the same record can be modified in more than one location. After we give you some rules for handling these conflicts, we discuss fast syncing and then turn to the more difficult slow syncing.

There are some very thorny cases of record conflicts we have to consider. When you give users the capability of modifying a record in more than one location, some twists result. The problem occurs when you have a record that can be changed simultaneously on the handheld and on the local database, but in different ways. For example, a customer record in our Sales application has its address changed on the handheld database and its name changed on the local database. Or a record was deleted on one platform and changed on another. The number of scenarios is so great that some formal rules are required to govern cases of conflict.

 

A. Where to Go from Here

ePub

Palms official Palm OS developer site is http://www.palmos.com/dev.

This is the place you should go to check for the most recent versions of the SDK, CDK, and information on updates to the operating system. There are also a lot of other resources at this siteeverything from white papers on various topics to Palms FAQ for developers.

Palms developer site is also where you go to register your application and obtain your applications unique creator ID. A creator ID is a four-ASCII-character ID that each application needs to distinguish itself from all other applications. This is an essential part of application development and you shouldnt leave it until the last minute.

Palms developer site has a knowledge base containing a collection of articles, documentation, and sample code. A query engine allows easy search of the collection.

The Resource Pavilion is a private area for members of the Palm Alliance program. It contains technical and marketing information, prerelease development tools, a hardware purchase discount program, and other opportunities available to program members. This is also where you can download ROM files.

 

B. Sales Source Code

ePub

 

Load more


Details

Print Book
E-Books
Slices

Format name
ePub
Encrypted
No
Sku
9781449369071
Isbn
9781449369071
File size
0 Bytes
Printing
Not Allowed
Copying
Not Allowed
Read aloud
No
Format name
ePub
Encrypted
No
Printing
Allowed
Copying
Allowed
Read aloud
Allowed
Sku
In metadata
Isbn
In metadata
File size
In metadata