Fawkes API  Fawkes Development Version
lister.cpp
1 
2 /***************************************************************************
3  * shmem_lister.cpp - BlackBoard shared memory lister
4  *
5  * Created: Fri Oct 20 11:50:03 2006
6  * Copyright 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. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #include <blackboard/shmem/lister.h>
25 #include <utils/system/console_colors.h>
26 #include <utils/ipc/shm.h>
27 
28 #include <iostream>
29 #include <cstdio>
30 
31 using namespace std;
32 namespace fawkes {
33 
34 /** @class BlackBoardSharedMemoryLister <blackboard/shmem/lister.h>
35  * BlackBoard shared memory lister.
36  * Lister that can be used to print infos about BlackBoard shared memory
37  * segments.
38  * @author Tim Niemueller
39  */
40 
41 /** Constructor */
42 BlackBoardSharedMemoryLister::BlackBoardSharedMemoryLister()
43 {
44  num = 0;
45 }
46 
47 
48 /** Destructor */
49 BlackBoardSharedMemoryLister::~BlackBoardSharedMemoryLister()
50 {
51 }
52 
53 
54 /** Print header of the table.
55  * This should fit on the terminal and thus have a width of at most
56  * 79 columns.
57  */
58 void
59 BlackBoardSharedMemoryLister::print_header()
60 {
61  cout << endl << cblue << "Fawkes BlackBoard Shared Memory Segments" << cnormal << endl
62  << "========================================================================" << endl
63  << cdarkgray;
64  printf ("%-3s %-10s %-11s %-16s %-12s %s\n",
65  "#", "ShmID", "Semaphore", "Bytes", "# attached", "State");
66  cout << cnormal
67  << "------------------------------------------------------------------------" << endl;
68  num = 0;
69 }
70 
71 
72 /** Print footer of the table.
73  * This should fit on the terminal and thus have a width of at most
74  * 79 columns.
75  */
76 void
77 BlackBoardSharedMemoryLister::print_footer()
78 {
79  cout << "========================================================================" << endl;
80 }
81 
82 
83 /** Print this if no matching segment was found.
84  * Called by SharedMemory if no matching segment could be found.
85  */
86 void
87 BlackBoardSharedMemoryLister::print_no_segments()
88 {
89  cout << "No Fawkes BlackBoard shared memory segments found" << endl;
90 }
91 
92 
93 /** Print this if no matching orphaned segment was found.
94  * Called by SharedMemory::erase_orphaned() if no matching segment
95  * could be found.
96  */
97 void
98 BlackBoardSharedMemoryLister::print_no_orphaned_segments()
99 {
100  cout << "No " << cdarkgray << "orphaned" << cnormal
101  << " Fawkes BlackBoard shared memory segments found" << endl;
102 }
103 
104 
105 /** Print info about segment.
106  * This method is called for every matching shared memory segment.
107  * You should print a line of information (maybe more than one line
108  * if needed) about the segment.
109  * @param header The data-specific header
110  * @param shm_id The id of the shared memory segment
111  * @param semaphore semaphore assigned to the shared memory segment
112  * @param mem_size the total memory size
113  * @param memptr pointer to the data segment.
114  */
115 void
116 BlackBoardSharedMemoryLister::print_info(const SharedMemoryHeader *header,
117  int shm_id, int semaphore,
118  unsigned int mem_size,
119  const void *memptr)
120 {
121  unsigned int nattch = SharedMemory::num_attached(shm_id);
122  bool swapable = SharedMemory::is_swapable(shm_id);
123  bool destroyed = SharedMemory::is_destroyed(shm_id);
124 
125  printf ("%-3u %-10d 0x%08x %-16u %-12u %s%s%s%s%s\n",
126  ++num, shm_id, semaphore, mem_size, nattch,
127  ((nattch > 1) ? "active" : "orphaned"),
128  ((swapable || destroyed) ? " (" : ""),
129  (swapable ? "S" : ""),
130  (destroyed ? "D" : ""),
131  ((swapable || destroyed) ? ")" : "")
132  );
133 }
134 
135 } // end namespace fawkes
Fawkes library namespace.
STL namespace.
Interface for shared memory header.
Definition: shm.h:33