source: rtems/cpukit/libmisc/monitor/mon-object.c @ e642446

4.104.114.84.95
Last change on this file since e642446 was e642446, checked in by Joel Sherrill <joel.sherrill@…>, on Mar 6, 1996 at 9:37:43 PM

As part of reducing visibility into rtems and hiding the .inl files
from the application code, this file required more visibility than
is given by default to application code.

  • Property mode set to 100644
File size: 10.9 KB
Line 
1/*
2 *      @(#)object.c    1.9 - 96/01/03
3 *     
4 *
5 * RTEMS Monitor "object" support.
6 *
7 * Used to traverse object lists and print them out.
8 * An object can be an RTEMS object (chain based stuff) or
9 * a "misc" object such as a device driver.
10 *
11 * Each object has its own file in this directory (eg: extension.c)
12 * That file provides routines to convert a "native" structure
13 * to its canonical form, print a canonical structure, etc.
14 *
15 * TODO:
16 *     should allow for non-numeric id's???
17 *
18 *  $Id$
19 */
20
21#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
22#include <rtems.h>
23#include "monitor.h"
24
25#include <stdio.h>
26#include <stdlib.h>             /* strtoul() */
27
28#include <monitor.h>
29
30#define NUMELEMS(arr)   (sizeof(arr) / sizeof(arr[0]))
31
32/*
33 * add:
34 *     next
35 */
36
37rtems_monitor_object_info_t rtems_monitor_object_info[] =
38{
39    { RTEMS_MONITOR_OBJECT_CONFIG,
40      (void *) 0,
41      sizeof(rtems_monitor_config_t),
42      (rtems_monitor_object_next_fn)        rtems_monitor_config_next,
43      (rtems_monitor_object_canonical_fn)   rtems_monitor_config_canonical,
44      (rtems_monitor_object_dump_header_fn) rtems_monitor_config_dump_header,
45      (rtems_monitor_object_dump_fn)        rtems_monitor_config_dump,
46    },
47    { RTEMS_MONITOR_OBJECT_MPCI,
48      (void *) 0,
49      sizeof(rtems_monitor_mpci_t),
50      (rtems_monitor_object_next_fn)        rtems_monitor_mpci_next,
51      (rtems_monitor_object_canonical_fn)   rtems_monitor_mpci_canonical,
52      (rtems_monitor_object_dump_header_fn) rtems_monitor_mpci_dump_header,
53      (rtems_monitor_object_dump_fn)        rtems_monitor_mpci_dump,
54    },
55    { RTEMS_MONITOR_OBJECT_INIT_TASK,
56      (void *) 0,
57      sizeof(rtems_monitor_init_task_t),
58      (rtems_monitor_object_next_fn)        rtems_monitor_init_task_next,
59      (rtems_monitor_object_canonical_fn)   rtems_monitor_init_task_canonical,
60      (rtems_monitor_object_dump_header_fn) rtems_monitor_init_task_dump_header,
61      (rtems_monitor_object_dump_fn)        rtems_monitor_init_task_dump,
62    },
63    { RTEMS_MONITOR_OBJECT_TASK,
64      (void *) &_RTEMS_tasks_Information,
65      sizeof(rtems_monitor_task_t),
66      (rtems_monitor_object_next_fn)        rtems_monitor_manager_next,
67      (rtems_monitor_object_canonical_fn)   rtems_monitor_task_canonical,
68      (rtems_monitor_object_dump_header_fn) rtems_monitor_task_dump_header,
69      (rtems_monitor_object_dump_fn)        rtems_monitor_task_dump,
70    },
71    { RTEMS_MONITOR_OBJECT_QUEUE,
72      (void *) &_Message_queue_Information,
73      sizeof(rtems_monitor_queue_t),
74      (rtems_monitor_object_next_fn)        rtems_monitor_manager_next,
75      (rtems_monitor_object_canonical_fn)   rtems_monitor_queue_canonical,
76      (rtems_monitor_object_dump_header_fn) rtems_monitor_queue_dump_header,
77      (rtems_monitor_object_dump_fn)        rtems_monitor_queue_dump,
78    },
79    { RTEMS_MONITOR_OBJECT_EXTENSION,
80      (void *) &_Extension_Information,
81      sizeof(rtems_monitor_extension_t),
82      (rtems_monitor_object_next_fn)        rtems_monitor_manager_next,
83      (rtems_monitor_object_canonical_fn)   rtems_monitor_extension_canonical,
84      (rtems_monitor_object_dump_header_fn) rtems_monitor_extension_dump_header,
85      (rtems_monitor_object_dump_fn)        rtems_monitor_extension_dump,
86    },
87    { RTEMS_MONITOR_OBJECT_DRIVER,
88      (void *) 0,
89      sizeof(rtems_monitor_driver_t),
90      (rtems_monitor_object_next_fn)        rtems_monitor_driver_next,
91      (rtems_monitor_object_canonical_fn)   rtems_monitor_driver_canonical,
92      (rtems_monitor_object_dump_header_fn) rtems_monitor_driver_dump_header,
93      (rtems_monitor_object_dump_fn)        rtems_monitor_driver_dump,
94    },
95    { RTEMS_MONITOR_OBJECT_DNAME,
96      /* XXX now that the driver name table is allocated from the */
97      /* XXX Workspace, this does not work */
98      (void *) 0,
99      /* (void *) _IO_Driver_name_table, */
100      sizeof(rtems_monitor_dname_t),
101      (rtems_monitor_object_next_fn)        rtems_monitor_dname_next,
102      (rtems_monitor_object_canonical_fn)   rtems_monitor_dname_canonical,
103      (rtems_monitor_object_dump_header_fn) rtems_monitor_dname_dump_header,
104      (rtems_monitor_object_dump_fn)        rtems_monitor_dname_dump,
105    },
106};
107
108/*
109 * Allow id's to be specified without the node number or
110 * type for convenience.
111 */
112
113rtems_id
114rtems_monitor_id_fixup(
115    rtems_id            id,
116    unsigned32          default_node,
117    rtems_monitor_object_type_t type
118)
119{
120    unsigned32  node;
121   
122    node = rtems_get_node(id);
123    if (node == 0)
124    {
125        if (rtems_get_class(id) != OBJECTS_NO_CLASS)
126            type = rtems_get_class(id);
127
128        id = _Objects_Build_id(type, default_node, rtems_get_index(id));
129    }
130    return id;
131}
132
133
134rtems_monitor_object_info_t *
135rtems_monitor_object_lookup(
136    rtems_monitor_object_type_t type
137)
138{
139    rtems_monitor_object_info_t *p;
140    for (p = &rtems_monitor_object_info[0];
141         p < &rtems_monitor_object_info[NUMELEMS(rtems_monitor_object_info)];
142         p++)
143    {
144        if (p->type == type)
145            return p;
146    }
147    return 0;
148}
149
150rtems_id
151rtems_monitor_object_canonical_next_remote(
152    rtems_monitor_object_type_t type,
153    rtems_id            id,
154    void               *canonical
155)
156{
157    rtems_id                        next_id;
158    rtems_status_code               status;
159    rtems_monitor_server_request_t  request;
160    rtems_monitor_server_response_t response;
161
162    /*
163     * Send request
164     */
165   
166    request.command = RTEMS_MONITOR_SERVER_CANONICAL;
167    request.argument0 = (unsigned32) type;
168    request.argument1 = (unsigned32) id;
169
170    status = rtems_monitor_server_request(rtems_get_node(id), &request, &response);
171    if (status != RTEMS_SUCCESSFUL)
172        goto failed;
173
174    /*
175     * process response
176     */
177   
178    next_id = (rtems_id) response.result0;
179    if (next_id != RTEMS_OBJECT_ID_FINAL)
180        (void) memcpy(canonical, &response.payload, response.result1);
181
182    return next_id;
183
184failed:
185    return RTEMS_OBJECT_ID_FINAL;
186
187}
188
189
190rtems_id
191rtems_monitor_object_canonical_next(
192    rtems_monitor_object_info_t *info,
193    rtems_id                     id,
194    void                        *canonical
195)
196{
197    rtems_id                     next_id;
198    void                        *raw_item;
199
200    if ( ! _Objects_Is_local_id(id))
201        next_id = rtems_monitor_object_canonical_next_remote(info->type,
202                                                             id,
203                                                             canonical);
204    else
205    {
206        next_id = id;
207       
208        raw_item = (void *) info->next(info->object_information,
209                                       canonical,
210                                       &next_id);
211
212        if (raw_item)
213        {
214            info->canonical(canonical, raw_item);
215            _Thread_Enable_dispatch();
216        }   
217    }   
218    return next_id;
219}
220
221
222/*
223 * this is routine server invokes locally to get the type
224 */
225
226rtems_id
227rtems_monitor_object_canonical_get(
228    rtems_monitor_object_type_t  type,
229    rtems_id             id,
230    void                *canonical,
231    unsigned32          *size_p
232)
233{
234    rtems_monitor_object_info_t *info;
235    rtems_id                     next_id;
236
237    *size_p = 0;
238
239    info = rtems_monitor_object_lookup(type);
240
241    if (info == 0)
242        return RTEMS_OBJECT_ID_FINAL;
243
244    next_id = rtems_monitor_object_canonical_next(info, id, canonical);
245    *size_p = info->size;
246
247    return next_id;
248}
249
250
251void
252rtems_monitor_object_dump_1(
253    rtems_monitor_object_info_t *info,
254    rtems_id                     id,
255    boolean                      verbose
256)
257{
258    rtems_id next_id;
259    rtems_monitor_union_t canonical;
260
261    if ((next_id = rtems_monitor_object_canonical_next(
262                                     info,
263                                     id,
264                                     &canonical)) != RTEMS_OBJECT_ID_FINAL)
265    {
266        /*
267         * If the one we actually got is the one we wanted, then
268         * print it out.
269         * For ones that have an id field, this works fine,
270         * for all others, always dump it out.
271         *
272         * HACK: the way we determine whether there is an id is a hack.
273         *
274         * by the way: the reason we try to not have an id, is that some
275         *   of the canonical structures are almost too big for shared
276         *   memory driver (eg: mpci)
277         */
278       
279        if ((info->next != rtems_monitor_manager_next) ||
280            (id == canonical.generic.id))
281            info->dump(&canonical, verbose);
282    }
283}
284
285void
286rtems_monitor_object_dump_all(
287    rtems_monitor_object_info_t *info,
288    boolean                      verbose
289)
290{
291    rtems_id next_id;
292    rtems_monitor_union_t canonical;
293
294    next_id = RTEMS_OBJECT_ID_INITIAL(info->type, rtems_monitor_default_node);
295
296    while ((next_id = rtems_monitor_object_canonical_next(
297                                         info,
298                                         next_id,
299                                         &canonical)) != RTEMS_OBJECT_ID_FINAL)
300    {
301        info->dump(&canonical, verbose);
302    }
303}
304
305void
306rtems_monitor_object_cmd(
307    int        argc,
308    char     **argv,
309    unsigned32 command_arg,
310    boolean    verbose
311)
312{
313    int arg;
314    rtems_monitor_object_info_t *info = 0;
315    rtems_monitor_object_type_t  type = (rtems_monitor_object_type_t) command_arg;
316   
317    /* what is the default type? */
318    type = (rtems_monitor_object_type_t) command_arg;
319
320    if (argc == 1)
321    {
322        if (type == RTEMS_MONITOR_OBJECT_INVALID)
323        {
324            printf("A type must be specified to \"dump all\"\n");
325            goto done;
326        }
327       
328        info = rtems_monitor_object_lookup(type);
329        if (info == 0)
330            goto not_found;
331
332        if (info->dump_header)
333            info->dump_header(verbose);
334        rtems_monitor_object_dump_all(info, verbose);
335    }
336    else
337    {
338        unsigned32          default_node = rtems_monitor_default_node;
339        rtems_monitor_object_type_t last_type = RTEMS_MONITOR_OBJECT_INVALID;
340        rtems_id            id;
341
342        for (arg=1; argv[arg]; arg++)
343        {
344            id = (rtems_id) strtoul(argv[arg], 0, 0);
345            id = rtems_monitor_id_fixup(id, default_node, type);
346            type = (rtems_monitor_object_type_t) rtems_get_class(id);
347
348            /*
349             * Allow the item type to change in the middle
350             * of the command.  If the type changes, then
351             * just dump out a new header and keep on going.
352             */
353            if (type != last_type)
354            {
355                info = rtems_monitor_object_lookup(type);
356                if (info == 0)
357                    goto not_found;
358           
359                if (info->dump_header)
360                    info->dump_header(verbose);
361            }
362
363            if (info == 0)
364            {
365not_found:      printf("Invalid or unsupported type %d\n", type);
366                goto done;
367            }
368
369            rtems_monitor_object_dump_1(info, id, verbose);
370
371            default_node = rtems_get_node(id);
372           
373            last_type = type;
374        }
375    }
376done:
377}
Note: See TracBrowser for help on using the repository browser.