Fawkes API Fawkes Development Version
shmem.cpp
1
2/***************************************************************************
3 * shmem.cpp - Shared memory management tool
4 *
5 * Generated: Mon Jan 16 22:51:34 2006
6 * Copyright 2005-2006 Tim Niemueller [www.niemueller.de]
7 *
8 ****************************************************************************/
9
10/* This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library General Public License for more details.
19 *
20 * Read the full text in the LICENSE.GPL file in the doc directory.
21 */
22
23#include <fvutils/ipc/shm_image.h>
24#include <fvutils/ipc/shm_lut.h>
25#include <fvutils/writers/fvraw.h>
26#include <utils/system/argparser.h>
27
28#include <cstdio>
29#include <cstring>
30#include <iostream>
31
32using namespace std;
33using namespace fawkes;
34using namespace firevision;
35
36int
37main(int argc, char **argv)
38{
39 ArgumentParser *argp = new ArgumentParser(argc, argv, "c::hl::i:");
40 bool action_done = false;
41
42 if (argp->has_arg("h")) {
43 // Show usage note
44 cout << endl
45 << "Usage: " << argv[0] << " [-h] [-c] [-c[t]] [-l] [-i image_id] [file]" << endl
46 << " -h Show this help message" << endl
47 << " -i id Save image ID to file" << endl
48 << " -c[t] Cleanup (remove all FireVision related shmem segments of given type)" << endl
49 << " -l[t] List shared memory segments of given type" << endl
50 << endl
51 << " [t] type is a combination of" << endl
52 << " i images" << endl
53 << " l lookup tables" << endl
54 << " or empty in which case all known shared memory segments are mangled" << endl
55 << endl
56 << " [file] is a file name. Content depends on the action. The possibilities are: "
57 << endl
58 << " for -i File where the saved image is stored" << endl
59 << endl
60 << "By default all known shared memory segments are listed" << endl
61 << endl;
62 action_done = true;
63 } else {
64 if (argp->has_arg("i")) {
65 if (argp->num_items() == 0) {
66 printf("You have to give a file name where to store the image\n");
67 } else {
68 const char *image_id = argp->arg("i");
69
70 try {
72
73 FvRawWriter *w = new FvRawWriter(
74 argp->items()[0], b->width(), b->height(), b->colorspace(), b->buffer());
75 w->write();
76 delete w;
77 delete b;
78 printf("Image '%s' saved to %s\n", image_id, argp->items()[0]);
79 } catch (Exception &e) {
80 printf("Failed top save image\n");
81 e.print_trace();
82 }
83 }
84 }
85 if (argp->has_arg("c")) {
86 const char *tmp;
87 if ((tmp = argp->arg("c")) != NULL) {
88 if (strchr(tmp, 'i') != NULL) {
89 SharedMemoryImageBuffer::cleanup();
90 }
91 if (strchr(tmp, 'l') != NULL) {
92 SharedMemoryLookupTable::cleanup();
93 }
94 } else {
95 SharedMemoryImageBuffer::cleanup();
96 SharedMemoryLookupTable::cleanup();
97 }
98
99 action_done = true;
100 }
101 if (argp->has_arg("l")) {
102 const char *tmp;
103 if ((tmp = argp->arg("l")) != NULL) {
104 if (strchr(tmp, 'i') != NULL) {
105 SharedMemoryImageBuffer::list();
106 }
107 if (strchr(tmp, 'l') != NULL) {
108 SharedMemoryLookupTable::list();
109 }
110 } else {
111 SharedMemoryImageBuffer::list();
112 SharedMemoryLookupTable::list();
113 }
114
115 action_done = true;
116 }
117 }
118
119 if (!action_done) {
120 SharedMemoryImageBuffer::list();
121 cout << endl;
122 SharedMemoryLookupTable::list();
123 }
124
125 cout << endl;
126}
Parse command line arguments.
Definition: argparser.h:64
const std::vector< const char * > & items() const
Get non-option items.
Definition: argparser.cpp:447
const char * arg(const char *argn)
Get argument value.
Definition: argparser.cpp:177
std::vector< constchar * >::size_type num_items() const
Get number of non-option items.
Definition: argparser.cpp:456
bool has_arg(const char *argn)
Check if argument has been supplied.
Definition: argparser.cpp:165
Base class for exceptions in Fawkes.
Definition: exception.h:36
void print_trace() noexcept
Prints trace to stderr.
Definition: exception.cpp:601
FvRaw Writer implementation.
Definition: fvraw.h:32
virtual void write()
Write to file.
Definition: fvraw.cpp:118
Shared memory image buffer.
Definition: shm_image.h:184
unsigned int height() const
Get image height.
Definition: shm_image.cpp:255
colorspace_t colorspace() const
Get color space.
Definition: shm_image.cpp:237
unsigned int width() const
Get image width.
Definition: shm_image.cpp:246
unsigned char * buffer() const
Get image buffer.
Definition: shm_image.cpp:228
Fawkes library namespace.