source: rtems/c/src/libmisc/monitor/mon-object.c @ 72c440e

4.104.114.84.95
Last change on this file since 72c440e was 72c440e, checked in by Joel Sherrill <joel.sherrill@…>, on Jan 17, 1996 at 8:13:45 PM

Update from Tony Bennett (tbennett@…)

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