home *** CD-ROM | disk | FTP | other *** search
- [ 8. Sample IPC Application]
- EMBEDDED LAN SAMPLE IPC APPLICATION
- ═════════════════════════════════════════════════════════════════════════
- The Embedded LAN Inter-Process Communication Interface is easily called
- in C, just like the Transport Driver Interface. The following simple IPC
- application shows how easy it is to send and receive data on an IPC queue
- no matter where it is located. The Embedded LAN IPC Provider translates
- names of queues and message ports such as "\\JAGUAR\JUNGLE" into their
- component parts (JAGUAR is the machine name, and JUNGLE in this case is
- the queue/message port name), and also allows programs running on the
- JAGUAR machine to access its queue or message port as "JUNGLE" without
- specifying the full syntax.
-
- //
- // PROGRAM NAME: TESTIPC.C.
- //
- // FUNCTIONAL DESCRIPTION.
- // This program is a test program for the IPC interface.
- //
- // MODIFICATION HISTORY.
- // S. E. Jones 93/03/18. Original for Embedded LAN.
- //
- // NOTICE: Copyright (C) 1993 General Software, Inc.
- // All rights reserved.
- //
-
- #include <stdlib.h>
- #include <stdio.h>
- #include <conio.h>
- #include <malloc.h>
- #include <string.h>
- #include <ctype.h>
- #include <time.h>
- #include <dos.h>
- #include "ipc.h"
- #include "..\inc\kernel.h"
-
- VOID SleepTimerExpireRoutine (HANDLE EventHandle)
- {
- SetEvent (EventHandle);
- } // SleepTimerExpireRoutine
-
- VOID SleepMs (USHORT NumberOfMilliseconds)
- {
- HANDLE SleepEvent, SleepTimer;
-
- if (NumberOfMilliseconds == 0) {
- PassTimeSlice ();
- return;
- }
-
- AllocateEvent (&SleepEvent);
- AllocateTimer (&SleepTimer, SleepEvent, SleepTimerExpireRoutine);
-
- StartTimer (SleepTimer, NumberOfMilliseconds);
- WaitEvent (SleepEvent);
-
- DeallocateEvent (SleepEvent);
- DeallocateTimer (SleepTimer);
- } // SleepMs
-
- VOID main (argc, argv)
- USHORT argc;
- UCHAR *argv [];
- {
- IPCSTATUS rc;
- IPCHANDLE Handle, Handle2;
- ULONG InValue=0L;
- ULONG OutValue;
- ULONG Counter=1L;
- ULONG Count=0L;
- ULONG MaxCount = 0xffffffffL;
-
- if (argc == 3) {
- MaxCount = atol (argv [2]);
- if (MaxCount == 0L) {
- printf ("The maxcount parameter must be greater than 0.\n");
- exit (1);
- }
- } else if (argc != 2) {
- printf ("Usage: TESTIPC queuename\n");
- exit (1);
- }
-
- printf ("Opening queue '%s' for %lu cycles.\n", argv [1], MaxCount);
-
- printf (" queue operations (open,push,pop,close)\r");
-
- while (TRUE) {
- if (Count == MaxCount) {
- break;
- }
- Count++;
-
- SleepMs (500);
-
- if (kbhit ()) {
- getch (); // eat the character.
- break;
- }
-
- printf ("%8ld\r", Counter++);
- rc = IpcCreateQueue (argv [1], &Handle);
- if (rc != IPCSTATUS_SUCCESS) {
- printf ("IpcCreateQueue returned status %u (0x%04x).\n", rc, rc);
- exit (2);
- }
-
- printf ("%8ld\r", Counter++);
- rc = IpcPushQueue (Handle, (PVOID)InValue);
- if (rc != IPCSTATUS_SUCCESS) {
- printf ("IpcPushQueue returned status %u (0x%04x).\n", rc, rc);
- IpcCloseQueue (Handle);
- exit (3);
- }
-
- printf ("%8ld\r", Counter++);
- rc = IpcPopQueue (Handle, &(PVOID)OutValue);
- if (rc != IPCSTATUS_SUCCESS) {
- printf ("IpcPopQueue returned status %u (0x%04x).\n", rc, rc);
- IpcCloseQueue (Handle);
- exit (4);
- }
-
- if (InValue != OutValue) {
- printf ("Value pushed (0x%08lx) is not equal to value popped (0x%08lx).\n",
- InValue, OutValue);
- IpcCloseQueue (Handle);
- exit (5);
- }
-
- InValue++;
-
- //
- // Open up a second handle and append something to the queue.
- // Then have the first handle instance pop it off.
- //
-
- printf ("%8ld\r", Counter++);
- rc = IpcOpenQueue (argv [1], &Handle2);
- if (rc != IPCSTATUS_SUCCESS) {
- printf ("IpcOpenQueue returned status %u (0x%04x).\n", rc, rc);
- exit (2);
- }
- printf ("%8ld\r", Counter++);
- rc = IpcAppendQueue (Handle2, (PVOID)InValue);
- if (rc != IPCSTATUS_SUCCESS) {
- printf ("IpcAppendQueue returned status %u (0x%04x).\n", rc, rc);
- IpcCloseQueue (Handle);
- exit (3);
- }
- IpcCloseQueue (Handle2);
-
- printf ("%8ld\r", Counter++);
- rc = IpcPopQueue (Handle, &(PVOID)OutValue);
- if (rc != IPCSTATUS_SUCCESS) {
- printf ("IpcPopQueue #2 returned status %u (0x%04x).\n", rc, rc);
- IpcCloseQueue (Handle);
- exit (4);
- }
-
- printf ("%8ld\r", Counter++);
- IpcCloseQueue (Handle);
- if (rc != IPCSTATUS_SUCCESS) {
- printf ("IpcCloseQueue returned status %u (0x%04x).\n", rc, rc);
- exit (5);
- }
- }
-
- //
- // Eat the character and exit the program.
- //
-
- printf ("\nIPC test completed.\n");
- exit (0); // exit to DOS with success.
- } /* testipc.c */
-