PreviousNext

Coding the Serviceability Calls

The bare minimum required to initialize the serviceability interface and use it to display our message is

· Call dce_svc_register( ) to get a serviceability handle that we can pass to serviceability message routines.

· Call dce_msg_define_msg_table( ) to set up the in-memory message table.

· Call dce_svc_printf( ) to print the message.

To call dce_svc_register( ), you must declare the serviceability handle that you defined in hel.sams:

#include "dcehelsvc.h"


<. . .>


dce_svc_handle_t hel_svc_handle;

unsigned32 status;


<. . .>


hel_svc_handle = dce_svc_register(hel_svc_table, \

(idl_char*)"hel", &status);

if (status != svc_s_ok)

{

printf("dce_svc_register failed\n");

exit(1);

}

This call is the only initialization we need if we have installed our message catalog and are willing to depend on the message(s) being extracted from there. However, if we wish to have the messages available in program memory (and thus not depend on the catalog's being correctly installed), then we have to call dce_msg_define_msg_table( ) to initialize the in-memory table, as follows:

#include <dce/dce_msg.h>

#include "dcehelmsg.h"


<. . .>


dce_msg_define_msg_table(hel_msg_table,

sizeof(hel_msg_table) / sizeof(hel_msg_table[0]),

&status);

if (status != svc_s_ok)

{

printf("dce_svc_define_msg_table failed\n");

exit(1);

}

Now we can call dce_svc_printf( ) to print the message, as follows:

#include "dcehelmac.h"


<. . .>


dce_svc_printf(HEL_S_HELLO_MSG);

Note the argument HEL_S_HELLO_MSG, which we did not define in the hel.sams file. HEL_S_HELLO_MSG is, in fact, a macro that was generated by sams from our definition for the hel_s_hello message, as you can see from the following code:

start

code hel_s_hello

subcomponent hel_s_main

attributes "svc_c_sev_notice | svc_c_route_stderr"

text "Hello World"

explanation "?"

action "None required."

end

The macro automatically generates the long argument list that must be passed to dce_svc_printf( ) to get it to print the message. The code for this convenience macro is contained in dcehelmac.h.

A convenience macro is generated for every message in a sams file that has both sub-component and attributes specified. The macro's name is formed from the uppercase version of its code value (as specified in the sams file), with the string _MSG appended.

The complete source code for hello_svc.c is as follows:

#include <dce/dce.h>

#include <stdio.h>

#include <stdlib.h>

#include <stddef.h>

#include <dce/utctypes.h>

#include <pthread.h>

#include <dce/dce_msg.h>


#include "hel_svc.h"

#include <dce/dcesvcmsg.h>

#include "dcehelmsg.h"

#include "dcehelsvc.h"

#include "dcehelmac.h"


int main( int argc,

char *argv[] )

{


dce_svc_handle_t hel_svc_handle;

unsigned32 status;


hel_svc_handle = dce_svc_register(hel_svc_table, \

(idl_char*)"hel", &status);

if (status != svc_s_ok)

{

printf("dce_svc_register failed\n");

exit(1);

}


dce_msg_define_msg_table(hel_msg_table,

sizeof(hel_msg_table) / sizeof(hel_msg_table[0]),

&status);

if (status != svc_s_ok)

printf("dce_svc_define_msg_table failed \

-- will use catalogs\n");


dce_svc_printf(HEL_S_HELLO_MSG);


}