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/ipc/shm.h>
26#include <utils/system/console_colors.h>
27
28#include <cstdio>
29#include <iostream>
30
31using namespace std;
32namespace 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 */
43{
44 num = 0;
45}
46
47/** Destructor */
49{
50}
51
52/** Print header of the table.
53 * This should fit on the terminal and thus have a width of at most
54 * 79 columns.
55 */
56void
58{
59 cout << endl
60 << cblue << "Fawkes BlackBoard Shared Memory Segments" << cnormal << endl
61 << "========================================================================" << endl
62 << cdarkgray;
63 printf(
64 "%-3s %-10s %-11s %-16s %-12s %s\n", "#", "ShmID", "Semaphore", "Bytes", "# attached", "State");
65 cout << cnormal << "------------------------------------------------------------------------"
66 << endl;
67 num = 0;
68}
69
70/** Print footer of the table.
71 * This should fit on the terminal and thus have a width of at most
72 * 79 columns.
73 */
74void
76{
77 cout << "========================================================================" << endl;
78}
79
80/** Print this if no matching segment was found.
81 * Called by SharedMemory if no matching segment could be found.
82 */
83void
85{
86 cout << "No Fawkes BlackBoard shared memory segments found" << endl;
87}
88
89/** Print this if no matching orphaned segment was found.
90 * Called by SharedMemory::erase_orphaned() if no matching segment
91 * could be found.
92 */
93void
95{
96 cout << "No " << cdarkgray << "orphaned" << cnormal
97 << " Fawkes BlackBoard shared memory segments found" << endl;
98}
99
100/** Print info about segment.
101 * This method is called for every matching shared memory segment.
102 * You should print a line of information (maybe more than one line
103 * if needed) about the segment.
104 * @param header The data-specific header
105 * @param shm_id The id of the shared memory segment
106 * @param semaphore semaphore assigned to the shared memory segment
107 * @param mem_size the total memory size
108 * @param memptr pointer to the data segment.
109 */
110void
112 int shm_id,
113 int semaphore,
114 unsigned int mem_size,
115 const void * memptr)
116{
117 unsigned int nattch = SharedMemory::num_attached(shm_id);
118 bool swapable = SharedMemory::is_swapable(shm_id);
119 bool destroyed = SharedMemory::is_destroyed(shm_id);
120
121 printf("%-3u %-10d 0x%08x %-16u %-12u %s%s%s%s%s\n",
122 ++num,
123 shm_id,
124 semaphore,
125 mem_size,
126 nattch,
127 ((nattch > 1) ? "active" : "orphaned"),
128 ((swapable || destroyed) ? " (" : ""),
129 (swapable ? "S" : ""),
130 (destroyed ? "D" : ""),
131 ((swapable || destroyed) ? ")" : ""));
132}
133
134} // end namespace fawkes
virtual void print_no_segments()
Print this if no matching segment was found.
Definition: lister.cpp:84
virtual void print_header()
Print header of the table.
Definition: lister.cpp:57
virtual void print_footer()
Print footer of the table.
Definition: lister.cpp:75
virtual void print_no_orphaned_segments()
Print this if no matching orphaned segment was found.
Definition: lister.cpp:94
virtual void print_info(const SharedMemoryHeader *header, int shm_id, int semaphore, unsigned int mem_size, const void *memptr)
Print info about segment.
Definition: lister.cpp:111
virtual ~BlackBoardSharedMemoryLister()
Destructor.
Definition: lister.cpp:48
BlackBoardSharedMemoryLister()
Constructor.
Definition: lister.cpp:42
Interface for shared memory header.
Definition: shm.h:34
bool is_destroyed() const
Check if segment has been destroyed This can be used if the segment has been destroyed.
Definition: shm.cpp:788
bool is_swapable() const
Check if memory can be swapped out.
Definition: shm.cpp:798
unsigned int num_attached() const
Get number of attached processes.
Definition: shm.cpp:763
Fawkes library namespace.
static std::string cdarkgray
Print dark gray on console.
static std::string cnormal
Print normal on console, without colors, depends on console settings.
static std::string cblue
Print blue on console.