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

4.104.114.84.95
Last change on this file since 9863dbf was 9863dbf, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 18, 1995 at 9:42:58 PM

+ Added object type field to object id.

+ Added name pointer to Object_Control.

+ Modified Object Open and Close to address name field.

+ Removed name as separate element from Thread and Proxy Control.

+ Added parameter "object class" to calls to Initialize Information

  • Property mode set to 100644
File size: 10.8 KB
Line 
1/*
2 *      @(#)object.c    1.7 - 95/08/02
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_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_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_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_OBJECT_TASK,
63      (void *) &_Thread_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_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_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_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_OBJECT_DNAME,
95      (void *) &rtems_driver_name_table[0],
96      sizeof(rtems_monitor_dname_t),
97      (rtems_monitor_object_next_fn)        rtems_monitor_dname_next,
98      (rtems_monitor_object_canonical_fn)   rtems_monitor_dname_canonical,
99      (rtems_monitor_object_dump_header_fn) rtems_monitor_dname_dump_header,
100      (rtems_monitor_object_dump_fn)        rtems_monitor_dname_dump,
101    },
102};
103
104/*
105 * Allow id's to be specified without the node number or
106 * type for convenience.
107 */
108
109rtems_id
110rtems_monitor_id_fixup(
111    rtems_id            id,
112    unsigned32          default_node,
113    rtems_object_type_t type
114)
115{
116    unsigned32  node;
117   
118    node = rtems_get_node(id);
119    if (node == 0)
120    {
121#if 0
122        /* XXX Uncomment this when types are added to id's */
123        if (rtems_get_class(id) != OBJECTS_NO_CLASS)
124            type = rtems_get_class(id);
125
126        id = _Objects_Build_id(type, default_node, rtems_get_index(id));
127#else
128#warning "TONY... FIX ME!!!!!"
129#if defined(hppa1_1)
130#error "TONY... I SAID TO FIX ME!!!!!  <HAHAHAHAHA>"
131#endif
132        id = _Objects_Build_id(0, default_node, rtems_get_index(id));
133#endif
134    }
135    return id;
136}
137
138
139rtems_monitor_object_info_t *
140rtems_monitor_object_lookup(
141    rtems_object_type_t type
142)
143{
144    rtems_monitor_object_info_t *p;
145    for (p = &rtems_monitor_object_info[0];
146         p < &rtems_monitor_object_info[NUMELEMS(rtems_monitor_object_info)];
147         p++)
148    {
149        if (p->type == type)
150            return p;
151    }
152    return 0;
153}
154
155rtems_id
156rtems_monitor_object_canonical_next_remote(
157    rtems_object_type_t type,
158    rtems_id            id,
159    void               *canonical
160)
161{
162    rtems_id                        next_id;
163    rtems_status_code               status;
164    rtems_monitor_server_request_t  request;
165    rtems_monitor_server_response_t response;
166
167    /*
168     * Send request
169     */
170   
171    request.command = RTEMS_MONITOR_SERVER_CANONICAL;
172    request.argument0 = (unsigned32) type;
173    request.argument1 = (unsigned32) id;
174
175    status = rtems_monitor_server_request(rtems_get_node(id), &request, &response);
176    if (status != RTEMS_SUCCESSFUL)
177        goto failed;
178
179    /*
180     * process response
181     */
182   
183    next_id = (rtems_id) response.result0;
184    if (next_id != RTEMS_OBJECT_ID_FINAL)
185        (void) memcpy(canonical, &response.payload, response.result1);
186
187    return next_id;
188
189failed:
190    return RTEMS_OBJECT_ID_FINAL;
191
192}
193
194
195rtems_id
196rtems_monitor_object_canonical_next(
197    rtems_monitor_object_info_t *info,
198    rtems_id                     id,
199    void                        *canonical
200)
201{
202    rtems_id                     next_id;
203    void                        *raw_item;
204
205    if ( ! _Objects_Is_local_id(id))
206        next_id = rtems_monitor_object_canonical_next_remote(info->type,
207                                                             id,
208                                                             canonical);
209    else
210    {
211        next_id = id;
212       
213        raw_item = (void *) info->next(info->object_information,
214                                       canonical,
215                                       &next_id);
216
217        if (raw_item)
218        {
219            info->canonical(canonical, raw_item);
220            _Thread_Enable_dispatch();
221        }   
222    }   
223    return next_id;
224}
225
226
227/*
228 * this is routine server invokes locally to get the type
229 */
230
231rtems_id
232rtems_monitor_object_canonical_get(
233    rtems_object_type_t  type,
234    rtems_id             id,
235    void                *canonical,
236    unsigned32          *size_p
237)
238{
239    rtems_monitor_object_info_t *info;
240    rtems_id                     next_id;
241
242    *size_p = 0;
243
244    info = rtems_monitor_object_lookup(type);
245
246    if (info == 0)
247        return RTEMS_OBJECT_ID_FINAL;
248
249    next_id = rtems_monitor_object_canonical_next(info, id, canonical);
250    *size_p = info->size;
251
252    return next_id;
253}
254
255
256void
257rtems_monitor_object_dump_1(
258    rtems_monitor_object_info_t *info,
259    rtems_id                     id,
260    boolean                      verbose
261)
262{
263    rtems_id next_id;
264    rtems_monitor_union_t canonical;
265
266    if ((next_id = rtems_monitor_object_canonical_next(
267                                     info,
268                                     id,
269                                     &canonical)) != RTEMS_OBJECT_ID_FINAL)
270    {
271        /*
272         * If the one we actually got is the one we wanted, then
273         * print it out.
274         * For ones that have an id field, this works fine,
275         * for all others, always dump it out.
276         *
277         * HACK: the way we determine whether there is an id is a hack.
278         *
279         * by the way: the reason we try to not have an id, is that some
280         *   of the canonical structures are almost too big for shared
281         *   memory driver (eg: mpci)
282         */
283       
284        if ((info->next != rtems_monitor_manager_next) ||
285            (id == canonical.generic.id))
286            info->dump(&canonical, verbose);
287    }
288}
289
290void
291rtems_monitor_object_dump_all(
292    rtems_monitor_object_info_t *info,
293    boolean                      verbose
294)
295{
296    rtems_id next_id;
297    rtems_monitor_union_t canonical;
298
299    next_id = RTEMS_OBJECT_ID_INITIAL(rtems_monitor_default_node);
300
301    while ((next_id = rtems_monitor_object_canonical_next(
302                                         info,
303                                         next_id,
304                                         &canonical)) != RTEMS_OBJECT_ID_FINAL)
305    {
306        info->dump(&canonical, verbose);
307    }
308}
309
310void
311rtems_monitor_object_cmd(
312    int        argc,
313    char     **argv,
314    unsigned32 command_arg,
315    boolean    verbose
316)
317{
318    int arg;
319    rtems_monitor_object_info_t *info = 0;
320    rtems_object_type_t          type = (rtems_object_type_t) command_arg;
321   
322    /* what is the default type? */
323    type = (rtems_object_type_t) command_arg;
324
325    if (argc == 1)
326    {
327        if (type == RTEMS_OBJECT_INVALID)
328        {
329            printf("A type must be specified to \"dump all\"\n");
330            goto done;
331        }
332       
333        info = rtems_monitor_object_lookup(type);
334        if (info == 0)
335            goto not_found;
336
337        if (info->dump_header)
338            info->dump_header(verbose);
339        rtems_monitor_object_dump_all(info, verbose);
340    }
341    else
342    {
343        unsigned32          default_node = rtems_monitor_default_node;
344        rtems_object_type_t last_type = RTEMS_OBJECT_INVALID;
345        rtems_id            id;
346
347        for (arg=1; argv[arg]; arg++)
348        {
349            id = (rtems_id) strtoul(argv[arg], 0, 0);
350            id = rtems_monitor_id_fixup(id, default_node, type);
351#if 0
352            type = rtems_get_type(id);
353#endif
354            /*
355             * Allow the item type to change in the middle
356             * of the command.  If the type changes, then
357             * just dump out a new header and keep on going.
358             */
359            if (type != last_type)
360            {
361                info = rtems_monitor_object_lookup(type);
362                if (info == 0)
363                {
364not_found:          printf("Invalid or unsupported type %d\n", type);
365                    goto done;
366                }
367           
368                if (info->dump_header)
369                    info->dump_header(verbose);
370            }
371
372            rtems_monitor_object_dump_1(info, id, verbose);
373
374            default_node = rtems_get_node(id);
375           
376            last_type = type;
377        }
378    }
379done:
380}
Note: See TracBrowser for help on using the repository browser.