ASAP 1.1 Hybrid Manual
HP NonStop ASAP Hybrid Manual – 529729-004
Page 4-28
Sample Client Application
This small sample application for ASAP Hybrid for Linux takes a domain name
that you specify, registers it, updates data items, and then removes the domain.
It demonstrates the use of the asap_register, asap_update, asap_opstate, and
asap_remove API procedures.
// ASAP Hybrid for Linux sample client application
//
// Include the asapx.h header file
#include "asapx.h"
#include <string.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
char DomainName[ASAP_MAX_DOMAIN_NAME_LENGTH + 1]; // Domain name to register
void *Handle; // Handle from asap_register
short ErrorDetail; // Error detail from calls
short ReturnValue; // Return value from calls
while (true)
{
// Get a domain name to register
::printf("Enter domain name, EXIT to stop: ");
::scanf("%s", DomainName);
if (::strcmp(DomainName, "EXIT") == 0) break;
// Register the domain
ReturnValue = ::asap_register(DomainName, // Supply the domain name
&Handle, // Returned handle
&ErrorDetail, // Returned error information
NULL, // Default ASAP ID
true, // Enable ranking
true, // Concat PID to domain name
3000, // Wait up to 3 seconds
"V1"); // Application version V1
::printf("asap_register returned %d, error detail = %d\n", ReturnValue,
ErrorDetail);
// Check return value
if (ReturnValue != ASAP_ERROR_NONE) continue; // Registration error
// Registered o.k.; update data items
// Add 1000 to data item 2 for the domain
ReturnValue = ::asap_update(Handle, // Handle from asap_register
2, // Data item 2
1000LL, // Value = 1000
ASAP_MATH_ADD, // Add it to the value
&ErrorDetail); // Returned error information
::printf("asap_update returned %d, error detail = %d\n", ReturnValue, ErrorDetail);
// Set data item 5 to 1234
ReturnValue = ::asap_update(Handle, // Handle from asap_register
5, // Data item 5
1234LL, // Value = 1234
ASAP_MATH_REPLACE_NUMBER, // Set the value
&ErrorDetail); // Returned error information
::printf("asap_update returned %d, error detail = %d\n", ReturnValue, ErrorDetail);
// Data items updated; now set status & status text (note that you do not have to
// update status and state information if you update data items, nor do you have to
// update data items if you update status and state information. They're
// completely independent of each other; you can use either or both).
ReturnValue = ::asap_opstate(Handle, // Handle from asap_register
"Sample text", // Status text; 15 bytes max
ASAP_STATE_CRITICAL, // Critical state
&ErrorDetail); // Returned error information