shmem.cpp

00001 
00002 /***************************************************************************
00003  *  shmem.cpp - Shared memory management tool
00004  *
00005  *  Generated: Mon Jan 16 22:51:34 2006
00006  *  Copyright  2005-2006  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  Read the full text in the LICENSE.GPL file in the doc directory.
00021  */
00022 
00023 #include <fvutils/ipc/shm_image.h>
00024 #include <fvutils/ipc/shm_lut.h>
00025 #include <utils/system/argparser.h>
00026 #include <fvutils/writers/fvraw.h>
00027 
00028 #include <iostream>
00029 #include <cstring>
00030 #include <cstdio>
00031 
00032 using namespace std;
00033 using namespace fawkes;
00034 using namespace firevision;
00035 
00036 int
00037 main(int argc, char **argv)
00038 {
00039 
00040   ArgumentParser *argp = new ArgumentParser(argc, argv, "c::hl::i:");
00041   bool action_done = false;
00042 
00043   if ( argp->has_arg("h") ) {
00044     // Show usage note
00045     cout << endl << "Usage: " << argv[0] << " [-h] [-c] [-c[t]] [-l] [-i image_id] [file]" << endl
00046          << " -h     Show this help message" << endl
00047          << " -i id  Save image ID to file" << endl
00048          << " -c[t]  Cleanup (remove all FireVision related shmem segments of given type)"
00049          << endl
00050          << " -l[t]  List shared memory segments of given type" << endl
00051          << endl
00052          << "        [t] type is a combination of" << endl
00053          << "          i  images" << endl
00054          << "          l  lookup tables" << endl
00055          << "        or empty in which case all known shared memory segments are mangled" << endl
00056          << endl
00057          << "        [file] is a file name. Content depends on the action. The possibilities are: " << endl
00058          << "        for  -i   File where the saved image is stored" << endl
00059          << endl
00060          << "By default all known shared memory segments are listed" << endl
00061          << endl;
00062     action_done = true;
00063   } else {
00064     if ( argp->has_arg("i") ) {
00065       if ( argp->num_items() == 0 ) {
00066         printf("You have to give a file name where to store the image\n");
00067       } else {
00068         const char *image_id = argp->arg("i");
00069 
00070         try {
00071           SharedMemoryImageBuffer *b = new SharedMemoryImageBuffer(image_id);
00072           
00073           FvRawWriter *w = new FvRawWriter(argp->items()[0], b->width(), b->height(),
00074                                          b->colorspace(), b->buffer());
00075           w->write();
00076           delete w;
00077           delete b;
00078           printf("Image '%s' saved to %s\n", image_id, argp->items()[0]);
00079         } catch (Exception &e) {
00080           printf("Failed top save image\n");
00081           e.print_trace();
00082         }
00083       }
00084     }
00085     if ( argp->has_arg("c") ) {
00086       const char *tmp;
00087       if ( (tmp = argp->arg("c")) != NULL) {
00088         if ( strchr(tmp, 'i') != NULL) {
00089           SharedMemoryImageBuffer::cleanup();
00090         }
00091         if ( strchr(tmp, 'l') != NULL) {
00092           SharedMemoryLookupTable::cleanup();
00093         }
00094       } else {
00095         SharedMemoryImageBuffer::cleanup();
00096         SharedMemoryLookupTable::cleanup();
00097       }
00098 
00099       action_done = true;
00100     }
00101     if ( argp->has_arg("l") ) {
00102       const char *tmp;
00103       if ( (tmp = argp->arg("l")) != NULL) {
00104         if ( strchr(tmp, 'i') != NULL) {
00105           SharedMemoryImageBuffer::list();
00106         }
00107         if ( strchr(tmp, 'l') != NULL) {
00108           SharedMemoryLookupTable::list();
00109         }
00110       } else {
00111         SharedMemoryImageBuffer::list();
00112         SharedMemoryLookupTable::list();
00113       }
00114 
00115       action_done = true;
00116     }
00117   }
00118 
00119   if (! action_done) {
00120     SharedMemoryImageBuffer::list();
00121     cout << endl;
00122     SharedMemoryLookupTable::list();
00123   }
00124 
00125   cout << endl;
00126 }

Generated on 1 Mar 2011 for Fawkes API by  doxygen 1.6.1