Remote Administration Daemon Developer Guide

Exit Print View

Updated: July 2014
 
 

Example radadrgen Output

When radadrgen is run on the Example 4–7 given in the ADR chapter two files result. One, api_example_impl.c, holds the implementation of the GrabBag interface and data types it depends on, and should be simply be compiled and linked with the GrabBag consumer. The other, api_example.h, exposes only the relevant symbols defined by api_example_impl.c and should be included by consumers of the GrabBag interface and its related types as shown in the following example.

Example 5-6  Sample radadrgen-Generated C Header File
#include <rad/adr.h>
#include <rad/adr_object.h>
#include <rad/rad_modapi.h>

extern adr_type_t t__Mood;
extern adr_data_t e__Mood_IRREVERENT;
extern adr_data_t e__Mood_MAUDLIN;
extern adr_type_t t__SqrtError;
extern adr_type_t t__StringInfo;
extern adr_type_t t__MoodStatus;
extern adr_object_t interface_GrabBag;

A consumer who needs to create a MoodStatus structure indicating the mood is IRREVERENT and has changed, would issue the instructions shown in the following example.

Example 5-7  Consuming radadrgen-Generated Definitions
status = adr_data_new_struct(&t__MoodStatus);
adr_struct_set(status, "mood", e__Mood_IRREVERENT);
/* adr_struct_set(status, "mood", adr_data_new_enum_byname(&t__Mood, "IRREVERENT")); */
adr_struct_set(status, "changed", adr_data_new_boolean(B_TRUE));

if (!adr_data_verify(status, NULL, B_TRUE)) {
        ...

In addition to showing how to use the type definitions, this example also illustrates the multiple ways of referencing an enumerated value. Using the defined symbols is faster and can be checked by the compiler. The commented-out line uses adr_data_new_enum_byname which offers flexibility that could be useful in some situations but necessarily defers error checking until runtime. For example, if you mistype the value IRREVERENT, it would not be detected until the code is run. It is preferable to use the enumerated value symbols when possible.