[Cover] [Previous Section] [Next Section] [Index]

Current chapter: Creating HDML Services that "Push" Information
Section 38 out of 67 total sections , Section 7 out of 11 sections in this chapter


Using the COM Notification library to send notifications

The UP.SDK includes a Component Object Model (COM) notification library for Windows. This library is language-independent; you can call it from code written in a variety of languages (such as C++, Visual Basic, J++, and Perl).

The COM Notification library contains the following classes:

The Ntfn3Client and Ntfn3SClient classes are supersets of the NtfnClient and NtfnSClient classes. The NtfnClient and NtfnSClient classes are provided primarily for backward compatibility. Use them if you need to send notifications to version 2.0.3 (or earlier) UP.Link servers.

The sections below provide a brief overview of how to use these classes. For complete documentation of the classes and their methods, see the UP.SDK Tools and APIs Reference.

To implement notifications with the COM library, follow these general steps:

  1. Configure your development environment so that your code can reference the library.
  2. What you need to do depends on your development environment. For instructions on setting up each supported environment, see Configuring your environment.

  3. Create a notification object instance.
  4. To send non-secure notifications, create a NtfnClient object. To send secure or secure-preferred notifications, create a NtfnSClient object. You can use a single object to send multiple notifications; in fact, it is more efficient to do this.

    Note that the each language has different ways of creating objects and calling COM library methods. For more information, see the documentation for the language you are using. The examples in COM library examples provide useful starting points.

    COM objects are automatically destroyed when they go out of scope. You do not need to destroy them.

  5. If you are sending secure or "secure-preferred" notifications, use the NtfnSClient object's NtfnLoadCertAndKey method to load the application certificate file and key.
  6. Only the NtfnSClient object provides the NtfnLoadCertAndKey method. The certificate file is the .pem file you installed in Step 2 in How to send notifications in seven simple steps.

  7. If you are sending notifications to an UP.Link server that does not use the standard notification port numbers, call NtfnSetNonSecurePort or NtfnSetSecurePort to set the port number you want to use.
  8. For information on notification port numbers, see Notification port numbers. If you are using the default port numbers, you do not need to call NtfnSetNonSecurePort or NtfnSetSecurePort.

  9. If you are sending a secure notification and you want to prevent it from "failing over" to the non-secure notification port, call the NtfnRequireSecureConnection method.
  10. If you do not call this method, the library uses secure-preferred mode by default.

  11. Use the NtfnSetHost method to specify the domain of the UP.Link server to which you are sending the notifications.
  12. If the notification includes an alert with text that uses a character set other than UTF-8, call NtfnSetCharset to set the character set.
  13. Use the NtfnPush, NtfnPostAlert, NtfnPostCacheOp, NtfnPostPrefetch, or NtfnPostAlertAndInvalURL1 methods to send push or pull notifications.
  14. These methods allow you to set an expiration time (TTL) for the notifications. To set the TTL to the maximum allowed by the UP.Link server, specify 0.

  15. Use the NtfnGetLastResult method to check the status of notifications you have just sent.
  16. The NtfnGetLastResult method returns an HTTP status code indicating whether the UP.Link server accepted the notification. If the UP.Link server did not receive or accept the notification, you can call NtfnGetErrorDetail to retrieve additional information on why the notification failed.

    If the notifications do not appear to be working, see Debugging notifications for some tips on tracking down the problem.

  17. Use the NtfnGetStatus method to check the status of notifications that have been accepted by the UP.Link server.
  18. The NtfnGetStatus method indicates whether the notification has been successfully sent to the user or is still pending.

  19. Use NtfnClearPending, NtfnDeleteAlert, NtfnDeletePrefetch, or NtfnRemoveAlertFromInbox methods to delete (cancel) pending notifications that you no longer want to send.


Configuring your environment

The UP.SDK installation utility automatically installs the COM library on your system. However, to use the COM object library in your code, you must configure your environment to allow you to reference it. The sections below describe what you must to for each of the supported environments.


Perl

To access the COM notification library, include a line like the following in your code (before any calls to the library):


Microsoft Developer Studio (Visual C++)

Make sure the path sdk_installdir\lib is in your Developer Studio include and library paths. To do this:

  1. Choose Options from the Developer Studio Tools menu.
  2. In the Options dialog box, click the Directories tab.
  3. Choose Include Files from the Show Directories For popup menu.
  4. Add sdk_installdir\lib to the list of paths.

  5. Choose Libraries from the Show Directories For popup menu.
  6. Add sdk_installdir\lib to the list of paths.

    Make sure your project includes the following source file:

    Also, make sure that any source files that use the COM library methods include the following header file:


Microsoft Visual Basic 5.0

In Visual Basic, follow these steps for each project that uses the library:

  1. Choose References from the Project menu.
  2. In the References dialog box, click the checkbox next to the UPNotify Type Library (as shown in Figure 5-6).

FIGURE  5-6.     VB References Dialog box with UPnotify Library activated



Using constants defined by the COM library

If you are calling COM library functions in Visual Basic or C++ code, you use constants defined in the library. For example, when you call the NtfnGetStatus method, you can use the CNtfnTypePrefetch or CNtfnTypeAlert constants to specify the type of notification you want status for. The constants used by the COM library are listed in the COM Library Reference section of the UP.SDK Tools and APIs Reference. With some programming languages (such as Perl) and utilities (such as Cold Fusion), you can't use these constants. Instead, you must specify the actual values. The actual values are listed along with the constants in the COM Library Reference section.



COM library examples

The following sections provide very simple examples of how to use the COM Notification library with Visual Basic, Perl, and Visual C++. Before you implement notifications in your own code, it is strongly recommended that you look at the following extended examples provided with the UP.SDK:

sdk_installdir\examples\vb\SendNtfn (Windows only)
sdk_installdir\examples\vc\SendNtfn (Windows only)
sdk_installdir\examples\scripts\sendalert.cgi
sdk_installdir\examples\scripts\fetch.cgi


Example: using Visual Basic to send a non-secure push notification containing an alert

Suppose you want to use Visual Basic to post a non-secure push notification containing an alert specifying the URL of the Unwired Planet Developer Support Home deck. To do this, you could create the simple form shown in Figure 5-7.

FIGURE  5-7.     Simple user interface for sending an alert

If you name the controls as shown in Figure 5-7, the following Click callback function sends an alert to the subscriber ID specified in the TextBox when the user clicks the CommandButton.

Figure 5-8 shows the alert sent by this code.

FIGURE  5-8.     Simple alert that specifies URL of the UP.Dev home deck


Example: posting a secure pull notification with Perl

The following routine posts a secure pull notification.


[Cover] [Previous Section] [Next Section] [Index]

Current chapter: Creating HDML Services that "Push" Information
Section 38 out of 67 total sections , Section 7 out of 11 sections in this chapter


1 To support backward compatibility with earlier UP.SDK versions, the notification library includes function names containing the terms "prefetch" and "alert". In the context of these function names, "prefetch" means "pull notification" and "alert" means "a push notification containing an alert".
Copyright © 1999, Unwired Planet, Inc. All rights reserved.