Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

testshm.cc

Go to the documentation of this file.
00001 
00002 extern "C"
00003 {
00004 #include <stdio.h>              /* printf(), scanf(), NULL */
00005 #include <string.h>             /* strcpy() */
00006 }
00007 #include "sharedmem.hh"
00008 
00009 #ifdef VXWORKS
00010 extern "C" int testshm ();      /* make it easily shell-accessible */
00011 int
00012 testshm (int create)            /* run this in the foreground */
00013 #else
00014 int
00015 main (int argc, char **argv)
00016 #endif
00017 {
00018   RCS_SHAREDMEM *shm;
00019 
00020 #if defined (VXWORKS)
00021   shm =
00022     new RCS_SHAREDMEM (0x100, 256,
00023                        create ? RCS_SHAREDMEM_CREATE : RCS_SHAREDMEM_NOCREATE,
00024                        0664);
00025 #else
00026   if (argc > 1)
00027     {
00028       /* any cmd line args mean this is the sharedmem creator */
00029       shm = new RCS_SHAREDMEM (0x100, 256, RCS_SHAREDMEM_CREATE, 0664);
00030     }
00031   else
00032     {
00033       shm = new RCS_SHAREDMEM (0x100, 256, RCS_SHAREDMEM_NOCREATE);
00034     }
00035 #endif
00036 
00037   if (shm->addr == NULL)
00038     {
00039       printf ("can't create shared memory-- exiting\n");
00040       return 1;
00041     }
00042 
00043   /* run give and take, interactively */
00044   while (!feof (stdin))
00045     {
00046 #define BUFFERSIZE 256
00047       char buf[BUFFERSIZE];
00048       fputs ("r, w, or q? ", stdout);
00049       fgets (buf, BUFFERSIZE, stdin);
00050 
00051       if (buf[0] == 'q')
00052         break;
00053       if (buf[0] == 'r')
00054         {
00055           printf ("%s\n", shm->addr);
00056         }
00057       if (buf[0] == 'w')
00058         {
00059           printf ("what string? ");
00060           scanf ("%s", buf);
00061           strcpy ((char *) shm->addr, buf);
00062         }
00063     }
00064 
00065   delete shm;
00066   return 0;
00067 }

Generated on Sun Dec 2 15:56:53 2001 for rcslib by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001