PMDF Programmer's Reference Manual


Previous Next Contents Index

1.12.1 Enqueuing a Simple Message

The programs shown in Examples 1-2 and 1-3 demonstrate how to enqueue a simple "Hello world" message. The "From:" address associated with the message is that of the process running the program; the "To:" address is the local SYSTEM account. The output of these programs is given in Example 1-4. The callouts shown in the first two examples produce the corresponding output shown in the third example.

Example 1-2 Enqueuing a Message (Pascal)

(* api_example1.pas -- Send a "Hello world!" message to SYSTEM *) 
 
[inherit ('pmdf_exe:apidef')] program example1; 
 
  type uword = [word] 0..65535; 
 
  var 
    nq_context : PMDF_nq; 
    user       : packed array [1..ALFA_SIZE] of char; 
    user_len   : uword; 
 
function SYS$EXIT (%immed status : integer := %immed 1) : integer; extern; 
 
procedure check (status : integer); 
 
  begin (* check *) 
    if not odd (status) then begin 
      if nq_context <> nil then PMDF_abort_message (nq_context); 
      SYS$EXIT (status); 
    end; (* if *) 
  end; (* check *) 
 
begin (* example1 *) 
  nq_context := nil; 
  check (PMDF_initialize (false)); 
  check (PMDF_get_user_name (user, user_len)); 
  check (PMDF_enqueue_initialize); 
  check (PMDF_start_message_envelope (nq_context, 'l', 
                                      substr (user, 1, user_len))); (1)
  check (PMDF_add_recipient (nq_context, 'system', 'system')); (2)
  check (PMDF_start_message_header (nq_context)); 
  check (PMDF_write_from (nq_context, substr (user, 1, user_len))); (3)
  check (PMDF_write_date (nq_context)); (4)
  check (PMDF_write_subject (nq_context, 'Hello world!')); (5)
  check (PMDF_start_message_body (nq_context)); 
  check (PMDF_write_line (nq_context, 'Hello')); (6)
  check (PMDF_write_line (nq_context, '  world!')); (7)
  check (PMDF_enqueue_message (nq_context)); 
  check (PMDF_done); 
end. (* example1 *) 

Example 1-3 Enqueuing a Message (C)

/* api_example2.c -- Send a "Hello world!" message to SYSTEM */ 
 
#include <stdlib.h> 
 
#ifdef __VMS 
#include "pmdf_com:apidef.h" 
#else 
#include "/pmdf/include/apidef.h" 
#endif 
 
PMDF_nq *nq_context = 0; 
 
void check (int stat) 
{ 
  if (!(1 & stat)) { 
    if (nq_context) PMDFabortMessage (&nq_context); 
    exit (stat); 
  } 
} 
 
main () 
{ 
  char user[ALFA_SIZE+1]; 
  int user_len = ALFA_SIZE; 
 
  check (PMDFinitialize (0)); 
  check (PMDFgetUserName (user, &user_len)); 
  check (PMDFenqueueInitialize ()); 
  check (PMDFstartMessageEnvelope (&nq_context, "l", 1, user, user_len)); (1)
  check (PMDFaddRecipient (&nq_context, "system", 6, "system", 6)); (2)
  check (PMDFstartMessageHeader (&nq_context)); 
  check (PMDFwriteFrom (&nq_context, user, user_len)); (3)
  check (PMDFwriteDate (&nq_context)); (4)
  check (PMDFwriteSubject (&nq_context, "Hello world!", 12)); (5)
  check (PMDFstartMessageBody (&nq_context)); 
  check (PMDFwriteLine (&nq_context, "Hello", 5)); (6)
  check (PMDFwriteLine (&nq_context, "  world!", 8)); (7)
  check (PMDFenqueueMessage (&nq_context)); 
  check (PMDFdone ()); 
} 

Example 1-4 Output of Examples 1-2 and 1-3

Received: from EXAMPLE.COM by EXAMPLE.COM (PMDF #1339) id 
 <01GP37SOPRW0A9KZFV@EXAMPLE.COM>; Sat, 4 May 2012 18:04:00 EDT 
Date: 4 May 2012 18:04:00 -0400 (EDT) (4)
From: STEPHANO@EXAMPLE.COM (3)
Subject: Hello world! (5)
To: system@EXAMPLE.COM (2)
Message-id: <01GP37SOPRW2A9KZFV@EXAMPLE.COM> 
X-Envelope-to: system 
Content-type: TEXT/PLAIN; CHARSET=US-ASCII 
Content-transfer-encoding: 7BIT 
 
Hello (6)
  world! (7)


Previous Next Contents Index